1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
9 #include <rte_common.h>
10 #include <rte_debug.h>
11 #include <rte_lcore.h>
13 #include "eal_private.h"
14 #include "eal_thread.h"
15 #include "eal_windows.h"
17 /** Number of logical processors (cores) in a processor group (32 or 64). */
18 #define EAL_PROCESSOR_GROUP_SIZE (sizeof(KAFFINITY) * CHAR_BIT)
30 unsigned int socket_count;
31 unsigned int lcore_count;
32 struct lcore_map lcores[RTE_MAX_LCORE];
33 struct socket_map sockets[RTE_MAX_NUMA_NODES];
36 static struct cpu_map cpu_map = { 0 };
38 /* eal_create_cpu_map() is called before logging is initialized */
40 __rte_format_printf(1, 2)
41 log_early(const char *format, ...)
46 vfprintf(stderr, format, va);
51 eal_create_cpu_map(void)
53 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *infos, *info;
58 if (!GetLogicalProcessorInformationEx(
59 RelationNumaNode, NULL, &infos_size)) {
60 DWORD error = GetLastError();
61 if (error != ERROR_INSUFFICIENT_BUFFER) {
62 log_early("Cannot get NUMA node info size, error %lu\n",
69 infos = malloc(infos_size);
71 log_early("Cannot allocate memory for NUMA node information\n");
76 if (!GetLogicalProcessorInformationEx(
77 RelationNumaNode, infos, &infos_size)) {
78 log_early("Cannot get NUMA node information, error %lu\n",
85 while ((uint8_t *)info - (uint8_t *)infos < infos_size) {
86 unsigned int node_id = info->NumaNode.NodeNumber;
87 GROUP_AFFINITY *cores = &info->NumaNode.GroupMask;
88 struct lcore_map *lcore;
89 unsigned int i, socket_id;
91 /* NUMA node may be reported multiple times if it includes
92 * cores from different processor groups, e. g. 80 cores
93 * of a physical processor comprise one NUMA node, but two
94 * processor groups, because group size is limited by 32/64.
96 for (socket_id = 0; socket_id < cpu_map.socket_count;
98 if (cpu_map.sockets[socket_id].node_id == node_id)
102 if (socket_id == cpu_map.socket_count) {
103 if (socket_id == RTE_DIM(cpu_map.sockets)) {
108 cpu_map.sockets[socket_id].node_id = node_id;
109 cpu_map.socket_count++;
112 for (i = 0; i < EAL_PROCESSOR_GROUP_SIZE; i++) {
113 if ((cores->Mask & ((KAFFINITY)1 << i)) == 0)
116 if (cpu_map.lcore_count == RTE_DIM(cpu_map.lcores)) {
121 lcore = &cpu_map.lcores[cpu_map.lcore_count];
122 lcore->socket_id = socket_id;
124 cores->Group * EAL_PROCESSOR_GROUP_SIZE + i;
125 cpu_map.lcore_count++;
128 info = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)(
129 (uint8_t *)info + info->Size);
134 /* Not a fatal error, but important for troubleshooting. */
135 log_early("Enumerated maximum of %u NUMA nodes and %u cores\n",
136 cpu_map.socket_count, cpu_map.lcore_count);
145 eal_cpu_detected(unsigned int lcore_id)
147 return lcore_id < cpu_map.lcore_count;
151 eal_cpu_socket_id(unsigned int lcore_id)
153 return cpu_map.lcores[lcore_id].socket_id;
157 eal_cpu_core_id(unsigned int lcore_id)
159 return cpu_map.lcores[lcore_id].core_id;
163 eal_socket_numa_node(unsigned int socket_id)
165 return cpu_map.sockets[socket_id].node_id;