diff options
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index 76bc262..b40a636 100644 --- a/src/util.cc +++ b/src/util.cc @@ -508,6 +508,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 @@ -617,6 +646,10 @@ double GetLoadAverage() { return -0.0f; return 1.0 / (1 << SI_LOAD_SHIFT) * si.loads[0]; } +#elif defined(__HAIKU__) +double GetLoadAverage() { + return -0.0f; +} #else double GetLoadAverage() { double loadavg[3] = { 0.0f, 0.0f, 0.0f }; |