From 2f65474577fe71be4383ff2c82ea5cdeccda832e Mon Sep 17 00:00:00 2001 From: Xeonacid Date: Tue, 11 Feb 2025 13:09:42 +0100 Subject: [PATCH] SystemInformation: Let NumberOf{Physical,Logical}CPU respect each other --- SystemInformation.cxx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/SystemInformation.cxx b/SystemInformation.cxx index c679c48..aca0324 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -3441,7 +3441,6 @@ bool SystemInformationImplementation::RetrieveInformationFromCpuInfoFile() this->CurrentPositionInFile + 1); } uint64_t NumberOfSockets = PhysicalIDs.size(); - NumberOfSockets = std::max(NumberOfSockets, (uint64_t)1); // Physical ids returned by Linux don't distinguish cores. // We want to record the total number of cores in this->NumberOfPhysicalCPU // (checking only the first proc) @@ -3451,9 +3450,11 @@ bool SystemInformationImplementation::RetrieveInformationFromCpuInfoFile() Cores = this->ExtractValueFromCpuInfoFile(buffer, "ncpus probed"); } auto NumberOfCoresPerSocket = (unsigned int)atoi(Cores.c_str()); - NumberOfCoresPerSocket = std::max(NumberOfCoresPerSocket, 1u); - this->NumberOfPhysicalCPU = - NumberOfCoresPerSocket * (unsigned int)NumberOfSockets; + // If either one is 0, will be assigned with NumberOfLogicalCPU or 1 below. + if (NumberOfSockets > 0 && NumberOfCoresPerSocket > 0) { + this->NumberOfPhysicalCPU = + NumberOfCoresPerSocket * (unsigned int)NumberOfSockets; + } #else // For systems which do not have "physical id" entries, neither "cpu cores" @@ -3465,10 +3466,11 @@ bool SystemInformationImplementation::RetrieveInformationFromCpuInfoFile() #endif // gotta have one, and if this is 0 then we get a / by 0n // better to have a bad answer than a crash - if (this->NumberOfPhysicalCPU <= 0) { - this->NumberOfPhysicalCPU = 1; - } - if (this->NumberOfLogicalCPU == 0) { + if (this->NumberOfPhysicalCPU == 0 && this->NumberOfLogicalCPU == 0) { + this->NumberOfPhysicalCPU = this->NumberOfLogicalCPU = 1; + } else if (this->NumberOfPhysicalCPU == 0) { + this->NumberOfPhysicalCPU = this->NumberOfLogicalCPU; + } else if (this->NumberOfLogicalCPU == 0) { this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU; } // LogicalProcessorsPerPhysical>1 => SMT. -- GitLab