DPDK  18.05.1
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 #elif defined(__FreeBSD__)
28 #include <pthread_np.h>
29  typedef cpuset_t rte_cpuset_t;
30 #endif
31 
35 struct lcore_config {
36  unsigned detected;
37  pthread_t thread_id;
40  lcore_function_t * volatile f;
41  void * volatile arg;
42  volatile int ret;
43  volatile enum rte_lcore_state_t state;
44  unsigned socket_id;
45  unsigned core_id;
46  int core_index;
47  rte_cpuset_t cpuset;
48  uint8_t core_role;
49 };
50 
54 extern struct lcore_config lcore_config[RTE_MAX_LCORE];
55 
56 RTE_DECLARE_PER_LCORE(unsigned, _lcore_id);
57 RTE_DECLARE_PER_LCORE(rte_cpuset_t, _cpuset);
71 static inline unsigned
73 {
74  return RTE_PER_LCORE(_lcore_id);
75 }
76 
83 static inline unsigned
85 {
87 }
88 
95 static inline unsigned
97 {
98  const struct rte_config *cfg = rte_eal_get_configuration();
99  return cfg->lcore_count;
100 }
101 
116 static inline int
117 rte_lcore_index(int lcore_id)
118 {
119  if (lcore_id >= RTE_MAX_LCORE)
120  return -1;
121  if (lcore_id < 0)
122  lcore_id = (int)rte_lcore_id();
123  return lcore_config[lcore_id].core_index;
124 }
125 
132 unsigned rte_socket_id(void);
133 
144 unsigned int __rte_experimental
145 rte_socket_count(void);
146 
161 int __rte_experimental
162 rte_socket_id_by_idx(unsigned int idx);
163 
172 static inline unsigned
173 rte_lcore_to_socket_id(unsigned lcore_id)
174 {
175  return lcore_config[lcore_id].socket_id;
176 }
177 
187 static inline int
188 rte_lcore_is_enabled(unsigned lcore_id)
189 {
190  struct rte_config *cfg = rte_eal_get_configuration();
191  if (lcore_id >= RTE_MAX_LCORE)
192  return 0;
193  return cfg->lcore_role[lcore_id] == ROLE_RTE;
194 }
195 
209 static inline unsigned
210 rte_get_next_lcore(unsigned i, int skip_master, int wrap)
211 {
212  i++;
213  if (wrap)
214  i %= RTE_MAX_LCORE;
215 
216  while (i < RTE_MAX_LCORE) {
217  if (!rte_lcore_is_enabled(i) ||
218  (skip_master && (i == rte_get_master_lcore()))) {
219  i++;
220  if (wrap)
221  i %= RTE_MAX_LCORE;
222  continue;
223  }
224  break;
225  }
226  return i;
227 }
231 #define RTE_LCORE_FOREACH(i) \
232  for (i = rte_get_next_lcore(-1, 0, 0); \
233  i<RTE_MAX_LCORE; \
234  i = rte_get_next_lcore(i, 0, 0))
235 
239 #define RTE_LCORE_FOREACH_SLAVE(i) \
240  for (i = rte_get_next_lcore(-1, 1, 0); \
241  i<RTE_MAX_LCORE; \
242  i = rte_get_next_lcore(i, 1, 0))
243 
253 int rte_thread_set_affinity(rte_cpuset_t *cpusetp);
254 
263 void rte_thread_get_affinity(rte_cpuset_t *cpusetp);
264 
277 int rte_thread_setname(pthread_t id, const char *name);
278 
300 __rte_experimental int
301 rte_ctrl_thread_create(pthread_t *thread, const char *name,
302  const pthread_attr_t *attr,
303  void *(*start_routine)(void *), void *arg);
304 
316 int
317 rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role);
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 
323 
324 #endif /* _RTE_LCORE_H_ */