51#ifdef HAVE_SCHED_GETCPU
59#define _WIN32_WINNT 0x0601
71#if defined(HAVE_LIBNUMA)
72 return (numa_available());
73#elif defined(HAVE_WINNUMA)
80 if (!GetNumaHighestNodeNumber(&highest_node)) {
84 if (highest_node > 0) {
97#if defined(HAVE_LIBNUMA)
98 return (numa_num_configured_cpus());
99#elif defined(HAVE_WINNUMA)
100 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *
buf;
103 if (GetLogicalProcessorInformationEx(RelationGroup,
nullptr, &buf_bytes)) {
108 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
116 buf =
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *
>(
117 LocalAlloc(LMEM_FIXED, buf_bytes));
119 if (
buf ==
nullptr) {
123 if (!GetLogicalProcessorInformationEx(RelationGroup,
buf, &buf_bytes)) {
130 SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buf_orig =
buf;
137 for (DWORD offset = 0; offset < buf_bytes;) {
138 for (WORD i = 0; i <
buf->Group.ActiveGroupCount; i++) {
139 n_cpus +=
buf->Group.GroupInfo[i].ActiveProcessorCount;
143 buf =
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *
>(
144 reinterpret_cast<char *
>(
buf) +
buf->Size);
164#if defined(HAVE_LIBNUMA)
165 return (numa_node_of_cpu(cpu));
166#elif defined(HAVE_WINNUMA)
173 if (GetNumaProcessorNodeEx(&
p, &node)) {
174 return (
static_cast<int>(node));
189#if defined(HAVE_LIBNUMA)
190 return (numa_alloc_onnode(
size, node));
191#elif defined(HAVE_WINNUMA)
192 return (VirtualAllocExNuma(GetCurrentProcess(),
nullptr,
size,
193 MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE, node));
204#if defined(HAVE_LIBNUMA)
205 numa_free(ptr,
size);
206#elif defined(HAVE_WINNUMA)
207 VirtualFreeEx(GetCurrentProcess(), ptr, 0, MEM_DECOMMIT | MEM_RELEASE);
213#if defined(HAVE_SCHED_GETCPU) || defined(HAVE_WINNUMA)
215#define HAVE_OS_GETCPU
219inline int os_getcpu() {
220#if defined(HAVE_SCHED_GETCPU)
221 return (sched_getcpu());
222#elif defined(HAVE_WINNUMA)
225 GetCurrentProcessorNumberEx(&
p);
227 return (
static_cast<int>(
p.Group << 6 |
p.Number));
static char buf[MAX_BUF]
Definition: conf_to_src.cc:73
const char * p
Definition: ctype-mb.cc:1235
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:96
void os_numa_free(void *ptr, size_t size)
Free a memory allocated by os_numa_alloc_onnode().
Definition: os0numa.h:203
int os_numa_available()
Check if NUMA is available.
Definition: os0numa.h:70
void * os_numa_alloc_onnode(size_t size, int node)
Allocate a memory on a given NUMA node.
Definition: os0numa.h:188
int os_numa_node_of_cpu(int cpu)
Get the NUMA node of a given CPU.
Definition: os0numa.h:163
Version control for database, common definitions, and include files.
#define ut_error
Abort execution.
Definition: ut0dbg.h:101