xref: /spdk/lib/env_dpdk/threads.c (revision 588dfe314bb83d86effdf67ec42837b11c2620bf)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "env_internal.h"
7 
8 #include <rte_config.h>
9 #include <rte_lcore.h>
10 
11 uint32_t
12 spdk_env_get_core_count(void)
13 {
14 	return rte_lcore_count();
15 }
16 
17 uint32_t
18 spdk_env_get_current_core(void)
19 {
20 	return rte_lcore_id();
21 }
22 
23 uint32_t
24 spdk_env_get_first_core(void)
25 {
26 	return rte_get_next_lcore(-1, 0, 0);
27 }
28 
29 uint32_t
30 spdk_env_get_last_core(void)
31 {
32 	uint32_t i;
33 	uint32_t last_core = UINT32_MAX;
34 
35 	SPDK_ENV_FOREACH_CORE(i) {
36 		last_core = i;
37 	}
38 
39 	assert(last_core != UINT32_MAX);
40 
41 	return last_core;
42 }
43 
44 uint32_t
45 spdk_env_get_next_core(uint32_t prev_core)
46 {
47 	unsigned lcore;
48 
49 	lcore = rte_get_next_lcore(prev_core, 0, 0);
50 	if (lcore == RTE_MAX_LCORE) {
51 		return UINT32_MAX;
52 	}
53 	return lcore;
54 }
55 
56 uint32_t
57 spdk_env_get_socket_id(uint32_t core)
58 {
59 	if (core >= RTE_MAX_LCORE) {
60 		return SPDK_ENV_SOCKET_ID_ANY;
61 	}
62 
63 	return rte_lcore_to_socket_id(core);
64 }
65 
66 int
67 spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg)
68 {
69 	int rc;
70 
71 	rc = rte_eal_remote_launch(fn, arg, core);
72 
73 	return rc;
74 }
75 
76 void
77 spdk_env_thread_wait_all(void)
78 {
79 	rte_eal_mp_wait_lcore();
80 }
81