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