eal/windows: fix warnings
[dpdk.git] / lib / librte_eal / windows / eal_lcore.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #include <pthread.h>
6 #include <stdint.h>
7
8 #include <rte_common.h>
9
10 #include "eal_private.h"
11 #include "eal_thread.h"
12 #include "eal_windows.h"
13
14 /* global data structure that contains the CPU map */
15 static struct _wcpu_map {
16         unsigned int total_procs;
17         unsigned int proc_sockets;
18         unsigned int proc_cores;
19         unsigned int reserved;
20         struct _win_lcore_map {
21                 uint8_t socket_id;
22                 uint8_t core_id;
23         } wlcore_map[RTE_MAX_LCORE];
24 } wcpu_map = { 0 };
25
26 /*
27  * Create a map of all processors and associated cores on the system
28  */
29 void
30 eal_create_cpu_map(void)
31 {
32         wcpu_map.total_procs =
33                 GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
34
35         LOGICAL_PROCESSOR_RELATIONSHIP lprocRel;
36         DWORD lprocInfoSize = 0;
37         BOOL ht_enabled = FALSE;
38
39         /* First get the processor package information */
40         lprocRel = RelationProcessorPackage;
41         /* Determine the size of buffer we need (pass NULL) */
42         GetLogicalProcessorInformationEx(lprocRel, NULL, &lprocInfoSize);
43         wcpu_map.proc_sockets = lprocInfoSize / 48;
44
45         lprocInfoSize = 0;
46         /* Next get the processor core information */
47         lprocRel = RelationProcessorCore;
48         GetLogicalProcessorInformationEx(lprocRel, NULL, &lprocInfoSize);
49         wcpu_map.proc_cores = lprocInfoSize / 48;
50
51         if (wcpu_map.total_procs > wcpu_map.proc_cores)
52                 ht_enabled = TRUE;
53
54         /* Distribute the socket and core ids appropriately
55          * across the logical cores. For now, split the cores
56          * equally across the sockets.
57          */
58         unsigned int lcore = 0;
59         for (unsigned int socket = 0; socket <
60                         wcpu_map.proc_sockets; ++socket) {
61                 for (unsigned int core = 0;
62                         core < (wcpu_map.proc_cores / wcpu_map.proc_sockets);
63                         ++core) {
64                         wcpu_map.wlcore_map[lcore]
65                                         .socket_id = socket;
66                         wcpu_map.wlcore_map[lcore]
67                                         .core_id = core;
68                         lcore++;
69                         if (ht_enabled) {
70                                 wcpu_map.wlcore_map[lcore]
71                                         .socket_id = socket;
72                                 wcpu_map.wlcore_map[lcore]
73                                         .core_id = core;
74                                 lcore++;
75                         }
76                 }
77         }
78 }
79
80 /*
81  * Check if a cpu is present by the presence of the cpu information for it
82  */
83 int
84 eal_cpu_detected(unsigned int lcore_id)
85 {
86         return (lcore_id < wcpu_map.total_procs);
87 }
88
89 /*
90  * Get CPU socket id for a logical core
91  */
92 unsigned
93 eal_cpu_socket_id(unsigned int lcore_id)
94 {
95         return wcpu_map.wlcore_map[lcore_id].socket_id;
96 }
97
98 /*
99  * Get CPU socket id (NUMA node) for a logical core
100  */
101 unsigned
102 eal_cpu_core_id(unsigned int lcore_id)
103 {
104         return wcpu_map.wlcore_map[lcore_id].core_id;
105 }