DPDK  19.08.0-rc0
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 #elif defined(__FreeBSD__)
29 #include <pthread_np.h>
30 typedef cpuset_t rte_cpuset_t;
31 #define RTE_CPU_AND(dst, src1, src2) do \
32 { \
33  cpuset_t tmp; \
34  CPU_COPY(src1, &tmp); \
35  CPU_AND(&tmp, src2); \
36  CPU_COPY(&tmp, dst); \
37 } while (0)
38 #endif
39 
43 struct lcore_config {
44  unsigned detected;
45  pthread_t thread_id;
48  lcore_function_t * volatile f;
49  void * volatile arg;
50  volatile int ret;
51  volatile enum rte_lcore_state_t state;
52  unsigned socket_id;
53  unsigned core_id;
54  int core_index;
55  rte_cpuset_t cpuset;
56  uint8_t core_role;
57 };
58 
62 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
63 
64 RTE_DECLARE_PER_LCORE(unsigned, _lcore_id);
65 RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset);
79 static inline unsigned
81 {
82  return RTE_PER_LCORE(_lcore_id);
83 }
84 
91 static inline unsigned
93 {
95 }
96 
103 static inline unsigned
105 {
106  const struct rte_config *cfg = rte_eal_get_configuration();
107  return cfg->lcore_count;
108 }
109 
124 int rte_lcore_index(int lcore_id);
125 
132 unsigned int rte_socket_id(void);
133 
144 unsigned int
145 rte_socket_count(void);
146 
161 int
162 rte_socket_id_by_idx(unsigned int idx);
163 
172 unsigned int
173 rte_lcore_to_socket_id(unsigned int lcore_id);
174 
186 __rte_experimental int
187 rte_lcore_to_cpu_id(int lcore_id);
188 
199 __rte_experimental rte_cpuset_t
200 rte_lcore_cpuset(unsigned int lcore_id);
201 
211 static inline int
212 rte_lcore_is_enabled(unsigned int lcore_id)
213 {
214  struct rte_config *cfg = rte_eal_get_configuration();
215  if (lcore_id >= RTE_MAX_LCORE)
216  return 0;
217  return cfg->lcore_role[lcore_id] == ROLE_RTE;
218 }
219 
233 static inline unsigned int
234 rte_get_next_lcore(unsigned int i, int skip_master, int wrap)
235 {
236  i++;
237  if (wrap)
238  i %= RTE_MAX_LCORE;
239 
240  while (i < RTE_MAX_LCORE) {
241  if (!rte_lcore_is_enabled(i) ||
242  (skip_master && (i == rte_get_master_lcore()))) {
243  i++;
244  if (wrap)
245  i %= RTE_MAX_LCORE;
246  continue;
247  }
248  break;
249  }
250  return i;
251 }
255 #define RTE_LCORE_FOREACH(i) \
256  for (i = rte_get_next_lcore(-1, 0, 0); \
257  i<RTE_MAX_LCORE; \
258  i = rte_get_next_lcore(i, 0, 0))
259 
263 #define RTE_LCORE_FOREACH_SLAVE(i) \
264  for (i = rte_get_next_lcore(-1, 1, 0); \
265  i<RTE_MAX_LCORE; \
266  i = rte_get_next_lcore(i, 1, 0))
267 
277 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
278 
287 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
288 
301 int rte_thread_setname(pthread_t id, const char *name);
302 
325 int
326 rte_ctrl_thread_create(pthread_t *thread, const char *name,
327  const pthread_attr_t *attr,
328  void *(*start_routine)(void *), void *arg);
329 
341 int
342 rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 
348 
349 #endif /* _RTE_LCORE_H_ */
int pipe_slave2master[2]
Definition: rte_lcore.h:47
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:46
unsigned core_id
Definition: rte_lcore.h:53
int rte_thread_setname(pthread_t id, const char *name)
static unsigned rte_lcore_count(void)
Definition: rte_lcore.h:104
rte_lcore_role_t
Definition: rte_eal.h:37
uint8_t core_role
Definition: rte_lcore.h:56
int rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role)
unsigned socket_id
Definition: rte_lcore.h:52
static int rte_lcore_is_enabled(unsigned int lcore_id)
Definition: rte_lcore.h:212
unsigned int rte_socket_count(void)
volatile int ret
Definition: rte_lcore.h:50
rte_cpuset_t cpuset
Definition: rte_lcore.h:55
unsigned int rte_lcore_to_socket_id(unsigned int lcore_id)
enum rte_lcore_state_t state
Definition: rte_lcore.h:51
int() lcore_function_t(void *)
Definition: rte_launch.h:30
int core_index
Definition: rte_lcore.h:54
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:80
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:44
lcore_function_t *volatile f
Definition: rte_lcore.h:48
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:92
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
pthread_t thread_id
Definition: rte_lcore.h:45
#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:49
static unsigned int rte_get_next_lcore(unsigned int i, int skip_master, int wrap)
Definition: rte_lcore.h:234