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