52#ifdef HAVE_SCHED_GETCPU
60#define _WIN32_WINNT 0x0601
72#if defined(HAVE_LIBNUMA)
73 return (numa_available());
74#elif defined(HAVE_WINNUMA)
81 if (!GetNumaHighestNodeNumber(&highest_node)) {
85 if (highest_node > 0) {
98#if defined(HAVE_LIBNUMA)
99 return (numa_num_configured_cpus());
100#elif defined(HAVE_WINNUMA)
101 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *
buf;
104 if (GetLogicalProcessorInformationEx(RelationGroup,
nullptr, &buf_bytes)) {
109 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
117 buf =
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *
>(
118 LocalAlloc(LMEM_FIXED, buf_bytes));
120 if (
buf ==
nullptr) {
124 if (!GetLogicalProcessorInformationEx(RelationGroup,
buf, &buf_bytes)) {
131 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buf_orig =
buf;
138 for (DWORD offset = 0; offset < buf_bytes;) {
139 for (WORD i = 0; i <
buf->Group.ActiveGroupCount; i++) {
140 n_cpus +=
buf->Group.GroupInfo[i].ActiveProcessorCount;
144 buf =
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *
>(
145 reinterpret_cast<char *
>(
buf) +
buf->Size);
161#if defined(HAVE_LIBNUMA)
162 return (numa_node_of_cpu(cpu));
163#elif defined(HAVE_WINNUMA)
170 if (GetNumaProcessorNodeEx(&
p, &node)) {
171 return (
static_cast<int>(node));
186#if defined(HAVE_LIBNUMA)
187 return (numa_alloc_onnode(
size, node));
188#elif defined(HAVE_WINNUMA)
189 return (VirtualAllocExNuma(GetCurrentProcess(),
nullptr,
size,
190 MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE, node));
201#if defined(HAVE_LIBNUMA)
202 numa_free(ptr,
size);
203#elif defined(HAVE_WINNUMA)
204 VirtualFreeEx(GetCurrentProcess(), ptr, 0, MEM_DECOMMIT | MEM_RELEASE);
210#if defined(HAVE_SCHED_GETCPU) || defined(HAVE_WINNUMA)
212#define HAVE_OS_GETCPU
216inline int os_getcpu() {
217#if defined(HAVE_SCHED_GETCPU)
218 return (sched_getcpu());
219#elif defined(HAVE_WINNUMA)
222 GetCurrentProcessorNumberEx(&
p);
224 return (
static_cast<int>(
p.Group << 6 |
p.Number));
static char buf[MAX_BUF]
Definition: conf_to_src.cc:74
const char * p
Definition: ctype-mb.cc:1227
uint32_t my_num_vcpus() noexcept
Determine the total number of logical CPUs available.
Definition: my_system.cc:80
Definition: buf0block_hint.cc:30
size_t size(const char *const c)
Definition: base64.h:46
int os_numa_num_configured_cpus()
Get the number of CPUs in the system, including disabled ones.
Definition: os0numa.h:97
void os_numa_free(void *ptr, size_t size)
Free a memory allocated by os_numa_alloc_onnode().
Definition: os0numa.h:200
int os_numa_available()
Check if NUMA is available.
Definition: os0numa.h:71
void * os_numa_alloc_onnode(size_t size, int node)
Allocate a memory on a given NUMA node.
Definition: os0numa.h:185
int os_numa_node_of_cpu(int cpu)
Get the NUMA node of a given CPU.
Definition: os0numa.h:160
Version control for database, common definitions, and include files.
#define ut_error
Abort execution.
Definition: ut0dbg.h:101