1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
14 #include <rte_lcore.h>
15 #include <rte_memory.h>
18 #include "eal_thread.h"
20 RTE_DECLARE_PER_LCORE(unsigned , _socket_id);
22 unsigned rte_socket_id(void)
24 return RTE_PER_LCORE(_socket_id);
28 rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role)
30 struct rte_config *cfg = rte_eal_get_configuration();
32 if (lcore_id >= RTE_MAX_LCORE)
35 if (cfg->lcore_role[lcore_id] == role)
41 int eal_cpuset_socket_id(rte_cpuset_t *cpusetp)
44 int socket_id = SOCKET_ID_ANY;
51 if (!CPU_ISSET(cpu, cpusetp))
54 if (socket_id == SOCKET_ID_ANY)
55 socket_id = eal_cpu_socket_id(cpu);
57 sid = eal_cpu_socket_id(cpu);
58 if (socket_id != sid) {
59 socket_id = SOCKET_ID_ANY;
63 } while (++cpu < RTE_MAX_LCORE);
69 rte_thread_set_affinity(rte_cpuset_t *cpusetp)
77 s = pthread_setaffinity_np(tid, sizeof(rte_cpuset_t), cpusetp);
79 RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
83 /* store socket_id in TLS for quick access */
84 RTE_PER_LCORE(_socket_id) =
85 eal_cpuset_socket_id(cpusetp);
87 /* store cpuset in TLS for quick access */
88 memmove(&RTE_PER_LCORE(_cpuset), cpusetp,
89 sizeof(rte_cpuset_t));
91 lcore_id = rte_lcore_id();
92 if (lcore_id != (unsigned)LCORE_ID_ANY) {
93 /* EAL thread will update lcore_config */
94 lcore_config[lcore_id].socket_id = RTE_PER_LCORE(_socket_id);
95 memmove(&lcore_config[lcore_id].cpuset, cpusetp,
96 sizeof(rte_cpuset_t));
103 rte_thread_get_affinity(rte_cpuset_t *cpusetp)
106 memmove(cpusetp, &RTE_PER_LCORE(_cpuset),
107 sizeof(rte_cpuset_t));
111 eal_thread_dump_affinity(char *str, unsigned size)
116 unsigned int out = 0;
118 rte_thread_get_affinity(&cpuset);
120 for (cpu = 0; cpu < RTE_MAX_LCORE; cpu++) {
121 if (!CPU_ISSET(cpu, &cpuset))
124 ret = snprintf(str + out,
125 size - out, "%u,", cpu);
126 if (ret < 0 || (unsigned)ret >= size - out) {
127 /* string will be truncated */
137 /* remove the last separator */