BUG:Fixed NumberOfLogicalCPU, NumberOfPhysicalCPU and LogicalProcessorsPerPhysical under Linux. Some part was just wrong. Some other part missed to take the multicore value into account.

This commit is contained in:
Francois Bertel 2008-05-31 11:23:15 -04:00
parent d0d3c6c212
commit f9ce6fcb5a

View File

@ -2161,38 +2161,46 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
buffer.resize(fileSize-2); buffer.resize(fileSize-2);
// Number of CPUs // Number of logical CPUs (combination of multiple processors, multi-core
// and hyperthreading)
size_t pos = buffer.find("processor\t"); size_t pos = buffer.find("processor\t");
while(pos != buffer.npos) while(pos != buffer.npos)
{ {
this->NumberOfLogicalCPU++; this->NumberOfLogicalCPU++;
this->NumberOfPhysicalCPU++;
pos = buffer.find("processor\t",pos+1); pos = buffer.find("processor\t",pos+1);
} }
// Count the number of physical ids that are the same // Find the largest physical id.
int currentId = -1; int maxId = -1;
kwsys_stl::string idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id"); kwsys_stl::string idc =
this->ExtractValueFromCpuInfoFile(buffer,"physical id");
while(this->CurrentPositionInFile != buffer.npos) while(this->CurrentPositionInFile != buffer.npos)
{ {
int id = atoi(idc.c_str()); int id = atoi(idc.c_str());
if(id == currentId) if(id > maxId)
{ {
this->NumberOfPhysicalCPU--; maxId=id;
} }
currentId = id; idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",
idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",this->CurrentPositionInFile+1); this->CurrentPositionInFile+1);
} }
if(this->NumberOfPhysicalCPU>0) // Physical ids returned by Linux don't distinguish cores.
{ // We want to record the total number of cores in this->NumberOfPhysicalCPU
this->NumberOfLogicalCPU /= this->NumberOfPhysicalCPU; // (checking only the first proc)
} kwsys_stl::string cores =
this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
int numberOfCoresPerCPU=atoi(cores.c_str());
this->NumberOfPhysicalCPU=numberOfCoresPerCPU*(maxId+1);
// LogicalProcessorsPerPhysical>1 => hyperthreading.
this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical=
this->NumberOfLogicalCPU/this->NumberOfPhysicalCPU;
// CPU speed (checking only the first proc // CPU speed (checking only the first proc
kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz"); kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
this->CPUSpeedInMHz = (float)atof(CPUSpeed.c_str()); this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
// Chip family // Chip family
this->ChipID.Family = atoi(this->ExtractValueFromCpuInfoFile(buffer,"cpu family").c_str()); this->ChipID.Family = atoi(this->ExtractValueFromCpuInfoFile(buffer,"cpu family").c_str());