DPDK  19.08.2
rte_lcore.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_LCORE_H_
6 #define _RTE_LCORE_H_
7 
14 #include <rte_config.h>
15 #include <rte_per_lcore.h>
16 #include <rte_eal.h>
17 #include <rte_launch.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #define LCORE_ID_ANY UINT32_MAX
25 #if defined(__linux__)
26 typedef cpu_set_t rte_cpuset_t;
27 #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
28 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
29 #define RTE_CPU_FILL(set) do \
30 { \
31  unsigned int i; \
32  CPU_ZERO(set); \
33  for (i = 0; i < CPU_SETSIZE; i++) \
34  CPU_SET(i, set); \
35 } while (0)
36 #define RTE_CPU_NOT(dst, src) do \
37 { \
38  cpu_set_t tmp; \
39  RTE_CPU_FILL(&tmp); \
40  CPU_XOR(dst, &tmp, src); \
41 } while (0)
42 #elif defined(__FreeBSD__)
43 #include <pthread_np.h>
44 typedef cpuset_t rte_cpuset_t;
45 #define RTE_CPU_AND(dst, src1, src2) do \
46 { \
47  cpuset_t tmp; \
48  CPU_COPY(src1, &tmp); \
49  CPU_AND(&tmp, src2); \
50  CPU_COPY(&tmp, dst); \
51 } while (0)
52 #define RTE_CPU_OR(dst, src1, src2) do \
53 { \
54  cpuset_t tmp; \
55  CPU_COPY(src1, &tmp); \
56  CPU_OR(&tmp, src2); \
57  CPU_COPY(&tmp, dst); \
58 } while (0)
59 #define RTE_CPU_FILL(set) CPU_FILL(set)
60 #define RTE_CPU_NOT(dst, src) do \
61 { \
62  cpuset_t tmp; \
63  CPU_FILL(&tmp); \
64  CPU_NAND(&tmp, src); \
65  CPU_COPY(&tmp, dst); \
66 } while (0)
67 #endif
68 
72 struct lcore_config {
73  unsigned detected;
74  pthread_t thread_id;
77  lcore_function_t * volatile f;
78  void * volatile arg;
79  volatile int ret;
80  volatile enum rte_lcore_state_t state;
81  unsigned socket_id;
82  unsigned core_id;
83  int core_index;
84  rte_cpuset_t cpuset;
85  uint8_t core_role;
86 };
87 
91 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
92 
93 RTE_DECLARE_PER_LCORE(unsigned, _lcore_id);
94 RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset);
108 static inline unsigned
110 {
111  return RTE_PER_LCORE(_lcore_id);
112 }
113 
120 static inline unsigned
122 {
124 }
125 
132 static inline unsigned
134 {
135  const struct rte_config *cfg = rte_eal_get_configuration();
136  return cfg->lcore_count;
137 }
138 
153 int rte_lcore_index(int lcore_id);
154 
161 unsigned int rte_socket_id(void);
162 
173 unsigned int
174 rte_socket_count(void);
175 
190 int
191 rte_socket_id_by_idx(unsigned int idx);
192 
201 unsigned int
202 rte_lcore_to_socket_id(unsigned int lcore_id);
203 
215 __rte_experimental
216 int
217 rte_lcore_to_cpu_id(int lcore_id);
218 
229 __rte_experimental
230 rte_cpuset_t
231 rte_lcore_cpuset(unsigned int lcore_id);
232 
242 static inline int
243 rte_lcore_is_enabled(unsigned int lcore_id)
244 {
245  struct rte_config *cfg = rte_eal_get_configuration();
246  if (lcore_id >= RTE_MAX_LCORE)
247  return 0;
248  return cfg->lcore_role[lcore_id] == ROLE_RTE;
249 }
250 
264 static inline unsigned int
265 rte_get_next_lcore(unsigned int i, int skip_master, int wrap)
266 {
267  i++;
268  if (wrap)
269  i %= RTE_MAX_LCORE;
270 
271  while (i < RTE_MAX_LCORE) {
272  if (!rte_lcore_is_enabled(i) ||
273  (skip_master && (i == rte_get_master_lcore()))) {
274  i++;
275  if (wrap)
276  i %= RTE_MAX_LCORE;
277  continue;
278  }
279  break;
280  }
281  return i;
282 }
286 #define RTE_LCORE_FOREACH(i) \
287  for (i = rte_get_next_lcore(-1, 0, 0); \
288  i<RTE_MAX_LCORE; \
289  i = rte_get_next_lcore(i, 0, 0))
290 
294 #define RTE_LCORE_FOREACH_SLAVE(i) \
295  for (i = rte_get_next_lcore(-1, 1, 0); \
296  i<RTE_MAX_LCORE; \
297  i = rte_get_next_lcore(i, 1, 0))
298 
308 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
309 
318 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
319 
332 int rte_thread_setname(pthread_t id, const char *name);
333 
356 int
357 rte_ctrl_thread_create(pthread_t *thread, const char *name,
358  const pthread_attr_t *attr,
359  void *(*start_routine)(void *), void *arg);
360 
372 int
373 rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);
374 
375 #ifdef __cplusplus
376 }
377 #endif
378 
379 
380 #endif /* _RTE_LCORE_H_ */
int pipe_slave2master[2]
Definition: rte_lcore.h:76
void rte_thread_get_affinity(rte_cpuset_t *cpusetp)
uint32_t lcore_count
Definition: rte_eal.h:59
int pipe_master2slave[2]
Definition: rte_lcore.h:75
unsigned core_id
Definition: rte_lcore.h:82
int rte_thread_setname(pthread_t id, const char *name)
static unsigned rte_lcore_count(void)
Definition: rte_lcore.h:133
rte_lcore_role_t
Definition: rte_eal.h:37
uint8_t core_role
Definition: rte_lcore.h:85
int rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role)
unsigned socket_id
Definition: rte_lcore.h:81
static int rte_lcore_is_enabled(unsigned int lcore_id)
Definition: rte_lcore.h:243
unsigned int rte_socket_count(void)
volatile int ret
Definition: rte_lcore.h:79
rte_cpuset_t cpuset
Definition: rte_lcore.h:84
unsigned int rte_lcore_to_socket_id(unsigned int lcore_id)
enum rte_lcore_state_t state
Definition: rte_lcore.h:80
int core_index
Definition: rte_lcore.h:83
unsigned int rte_socket_id(void)
__rte_experimental rte_cpuset_t rte_lcore_cpuset(unsigned int lcore_id)
static unsigned rte_lcore_id(void)
Definition: rte_lcore.h:109
enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]
Definition: rte_eal.h:63
struct rte_config * rte_eal_get_configuration(void)
unsigned detected
Definition: rte_lcore.h:73
lcore_function_t *volatile f
Definition: rte_lcore.h:77
int rte_socket_id_by_idx(unsigned int idx)
__rte_experimental int rte_lcore_to_cpu_id(int lcore_id)
static unsigned rte_get_master_lcore(void)
Definition: rte_lcore.h:121
int rte_lcore_index(int lcore_id)
int rte_ctrl_thread_create(pthread_t *thread, const char *name, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
uint32_t master_lcore
Definition: rte_eal.h:58
int( lcore_function_t)(void *)
Definition: rte_launch.h:30
pthread_t thread_id
Definition: rte_lcore.h:74
#define RTE_PER_LCORE(name)
Definition: rte_per_lcore.h:44
RTE_DECLARE_PER_LCORE(unsigned, _lcore_id)
int rte_thread_set_affinity(rte_cpuset_t *cpusetp)
rte_lcore_state_t
Definition: rte_launch.h:21
void *volatile arg
Definition: rte_lcore.h:78
static unsigned int rte_get_next_lcore(unsigned int i, int skip_master, int wrap)
Definition: rte_lcore.h:265