summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCameron Desrochers <Cameron.Desrochers@octasic.com>2019-11-12 20:47:27 (GMT)
committerCameron Desrochers <Cameron.Desrochers@octasic.com>2019-11-12 20:47:27 (GMT)
commitde6485646ddf3248871e1af6dcd1de180742b8e6 (patch)
treec5801ddfc4ef1236ad7b7412a0b88d80a81a1368 /src
parent3ef623acf15460c6256e1793c1d7206cb9399305 (diff)
downloadNinja-de6485646ddf3248871e1af6dcd1de180742b8e6.zip
Ninja-de6485646ddf3248871e1af6dcd1de180742b8e6.tar.gz
Ninja-de6485646ddf3248871e1af6dcd1de180742b8e6.tar.bz2
Fixed processor count detection on Windows when multiple processor groups (i.e. >64 processors) are present
Diffstat (limited to 'src')
-rw-r--r--src/util.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index 4df2bb2..7893f61 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -481,6 +481,32 @@ string StripAnsiEscapeCodes(const string& in) {
int GetProcessorCount() {
#ifdef _WIN32
+#if _WIN32_WINNT >= 0x0601
+ // Need to use GetLogicalProcessorInformationEx to get real core count on
+ // machines with >64 cores. See https://stackoverflow.com/a/31209344/21475
+ DWORD len = 0;
+ if (!GetLogicalProcessorInformationEx(RelationProcessorCore, nullptr, &len)
+ && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
+ std::vector<char> buf(len);
+ int cores = 0;
+ if (GetLogicalProcessorInformationEx(RelationProcessorCore,
+ (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)buf.data(), &len)) {
+ for (DWORD i = 0; i < len; ) {
+ PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX info =
+ (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)(buf.data() + i);
+ if (info->Relationship == RelationProcessorCore &&
+ info->Processor.GroupCount == 1) {
+ for (KAFFINITY core_mask = info->Processor.GroupMask[0].Mask;
+ core_mask; core_mask >>= 1)
+ cores += (core_mask & 1);
+ }
+ i += info->Size;
+ }
+ if (cores)
+ return cores;
+ }
+ }
+#endif
return GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
#else
#ifdef CPU_COUNT