summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2021-01-01 22:01:23 (GMT)
committerGitHub <noreply@github.com>2021-01-01 22:01:23 (GMT)
commitfb824d27b39e10acb97f9b105df2d9485a4677e9 (patch)
tree97d190f7cc399e8beacdcea65bd6d9727694e003 /src
parent68f971460bb21abd59dfe6253e35a55c3e1cfc64 (diff)
parent4b07ca35eb56b572720521fef7c202ec4cc1e325 (diff)
downloadNinja-fb824d27b39e10acb97f9b105df2d9485a4677e9.zip
Ninja-fb824d27b39e10acb97f9b105df2d9485a4677e9.tar.gz
Ninja-fb824d27b39e10acb97f9b105df2d9485a4677e9.tar.bz2
Merge pull request #1674 from cameron314/bugfix/core-count
Fixed processor count detection on Windows
Diffstat (limited to 'src')
-rw-r--r--src/util.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index 05bdb2d..ae2e3c2 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -487,6 +487,35 @@ string StripAnsiEscapeCodes(const string& in) {
int GetProcessorCount() {
#ifdef _WIN32
+#ifndef _WIN64
+ // 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,
+ reinterpret_cast<PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX>(
+ buf.data()), &len)) {
+ for (DWORD i = 0; i < len; ) {
+ auto info = reinterpret_cast<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 != 0) {
+ return cores;
+ }
+ }
+ }
+#endif
return GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
#else
// The number of exposed processors might not represent the actual number of