-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#4766] Win32: Added support NUMA configuration with multiple count CPU sockets #4896
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,67 @@ | |
# endif | ||
#endif | ||
|
||
#ifdef GIT_WINDOWS_NATIVE | ||
/// defines the GetLogicalProcessorInformationEx function | ||
typedef BOOL (*WINAPI glpie_t)( | ||
LOGICAL_PROCESSOR_RELATIONSHIP, | ||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, | ||
PDWORD); | ||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this code to |
||
|
||
// Classic way to get number of cores in windows. | ||
static size_t get_windows_compatible_n_cores() { | ||
Check failure on line 29 in thread-utils.c GitHub Actions / win build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not add an extra function here. Instead, let's declare a single |
||
SYSTEM_INFO info; | ||
GetSystemInfo(&info); | ||
if ((int)info.dwNumberOfProcessors > 0) | ||
return (int)info.dwNumberOfProcessors; | ||
} | ||
|
||
/* | ||
* Windows NUMA support is particular | ||
* https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlogicalprocessorinformationex#remarks | ||
* | ||
* New api here: | ||
* https://learn.microsoft.com/en-us/windows/win32/procthread/numa-support | ||
*/ | ||
static size_t get_windows_numa_n_cores() { | ||
Check failure on line 43 in thread-utils.c GitHub Actions / win build
|
||
uint8_t *buffer = NULL; | ||
size_t n_cores = 0; | ||
DWORD length = 0; | ||
HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); | ||
|
||
glpie_t GetLogicalProcessorInformationEx = (glpie_t)GetProcAddress(kernel32, "GetLogicalProcessorInformationEx"); | ||
Check failure on line 49 in thread-utils.c GitHub Actions / win build
|
||
if (!GetLogicalProcessorInformationEx) { | ||
return 0; | ||
} | ||
|
||
GetLogicalProcessorInformationEx(RelationAll, NULL, &length); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not forget to check the return value. |
||
if (length < 1 || GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | ||
return 0; | ||
} | ||
|
||
buffer = malloc(length); | ||
if (!buffer || !GetLogicalProcessorInformationEx(RelationAll, (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)buffer, &length)) { | ||
free(buffer); | ||
return 0; | ||
} | ||
|
||
for (DWORD offset = 0; offset < length;) { | ||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX info = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)(buffer + offset); | ||
offset += info->Size; | ||
if (info->Relationship != RelationProcessorCore) { | ||
continue; | ||
} | ||
for (WORD group = 0; group < info->Processor.GroupCount; ++group) { | ||
for (KAFFINITY mask = info->Processor.GroupMask[group].Mask; mask != 0; mask >>= 1) { | ||
n_cores += mask & 1; | ||
} | ||
} | ||
} | ||
free(buffer); | ||
return n_cores; | ||
} | ||
#endif | ||
|
||
int online_cpus(void) | ||
{ | ||
#ifdef NO_PTHREADS | ||
|
@@ -28,11 +89,11 @@ | |
#endif | ||
|
||
#ifdef GIT_WINDOWS_NATIVE | ||
SYSTEM_INFO info; | ||
GetSystemInfo(&info); | ||
|
||
if ((int)info.dwNumberOfProcessors > 0) | ||
return (int)info.dwNumberOfProcessors; | ||
size_t n_cores = get_windows_numa_n_cores(); | ||
if (n_cores > 0) { | ||
return n_cores; | ||
} | ||
return get_windows_compatible_n_cores(); | ||
#elif defined(hpux) || defined(__hpux) || defined(_hpux) | ||
struct pst_dynamic psd; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid C++-style comments. The existing code does not use them.