use 'processor' field in /proc/cpuinfo to calculate thread count

This fixes too few nodes appearing for CPUs that have more than one
thread per core
This commit is contained in:
Jussi Kuokkanen 2023-11-27 13:11:42 +02:00
parent 29c7f6df00
commit 00fa886e54

View File

@ -85,7 +85,10 @@ std::vector<CPUData> fromCPUInfoData(std::vector<CPUInfoData> dataVec) {
auto smallerCoreId = [](CPUInfoData a, CPUInfoData b) { return a.processor < b.processor; };
std::vector<CPUData> retval;
for (auto &cpu : cpus) {
// These are actually threads, and not the 'core count' field,
// since one core may have more than one thread, and threads are used in sysfs
auto firstCore = minimum_by(smallerCoreId, cpu).processor;
auto lastCore = fplus::maximum_by(smallerCoreId, cpu).processor;
auto first = cpu.front();
// Create identifier
char identBuf[20];
@ -93,7 +96,7 @@ std::vector<CPUData> fromCPUInfoData(std::vector<CPUInfoData> dataVec) {
CPUData data{
.identifier = identBuf,
.firstCoreIndex = firstCore,
.coreCount = first.cores,
.coreCount = (lastCore - firstCore) + 1,
.name = first.name,
.cpuIndex = first.physicalId,
};