Yet another build fix

This commit is contained in:
Robert Schulze 2023-01-24 09:57:12 +00:00
parent 1a1fa4a40a
commit 36d6af0e04
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A

View File

@ -11,8 +11,10 @@
#include <thread> #include <thread>
#include <set> #include <set>
namespace {
#if defined(OS_LINUX) #if defined(OS_LINUX)
static int32_t readFrom(const char * filename, int default_value) int32_t readFrom(const char * filename, int default_value)
{ {
std::ifstream infile(filename); std::ifstream infile(filename);
if (!infile.is_open()) if (!infile.is_open())
@ -25,7 +27,7 @@ static int32_t readFrom(const char * filename, int default_value)
} }
/// Try to look at cgroups limit if it is available. /// Try to look at cgroups limit if it is available.
static uint32_t getCGroupLimitedCPUCores(unsigned default_cpu_count) uint32_t getCGroupLimitedCPUCores(unsigned default_cpu_count)
{ {
uint32_t quota_count = default_cpu_count; uint32_t quota_count = default_cpu_count;
/// Return the number of milliseconds per period process is guaranteed to run. /// Return the number of milliseconds per period process is guaranteed to run.
@ -41,8 +43,8 @@ static uint32_t getCGroupLimitedCPUCores(unsigned default_cpu_count)
/// Returns number of physical cores, unlike std::thread::hardware_concurrency() which returns the logical core count. With 2-way SMT /// Returns number of physical cores, unlike std::thread::hardware_concurrency() which returns the logical core count. With 2-way SMT
/// (HyperThreading) enabled, physical_concurrency() returns half of of std::thread::hardware_concurrency(), otherwise return the same. /// (HyperThreading) enabled, physical_concurrency() returns half of of std::thread::hardware_concurrency(), otherwise return the same.
static unsigned physical_concurrency() #if defined(__x86_64__) && defined(OS_LINUX)
#if defined(OS_LINUX) unsigned physical_concurrency()
try try
{ {
/// The CPUID instruction isn't reliable across different vendors and CPU models. The best option to get the physical core count is /// The CPUID instruction isn't reliable across different vendors and CPU models. The best option to get the physical core count is
@ -87,13 +89,9 @@ catch (...)
{ {
return std::thread::hardware_concurrency(); /// parsing error return std::thread::hardware_concurrency(); /// parsing error
} }
#else
{
return std::thread::hardware_concurrency();
}
#endif #endif
static unsigned getNumberOfPhysicalCPUCoresImpl() unsigned getNumberOfPhysicalCPUCoresImpl()
{ {
unsigned cpu_count = std::thread::hardware_concurrency(); /// logical cores (with SMT/HyperThreading) unsigned cpu_count = std::thread::hardware_concurrency(); /// logical cores (with SMT/HyperThreading)
@ -115,6 +113,8 @@ static unsigned getNumberOfPhysicalCPUCoresImpl()
return cpu_count; return cpu_count;
} }
}
unsigned getNumberOfPhysicalCPUCores() unsigned getNumberOfPhysicalCPUCores()
{ {
/// Calculate once. /// Calculate once.