diff --git a/src/detection/cpu/cpu.h b/src/detection/cpu/cpu.h index eb5bd90f4..59343dd98 100644 --- a/src/detection/cpu/cpu.h +++ b/src/detection/cpu/cpu.h @@ -15,6 +15,7 @@ typedef struct FFCPUResult FFstrbuf name; FFstrbuf vendor; + uint16_t cpuCount; uint16_t coresPhysical; uint16_t coresLogical; uint16_t coresOnline; diff --git a/src/detection/cpu/cpu_apple.c b/src/detection/cpu/cpu_apple.c index 1d94b005e..f2b4c4256 100644 --- a/src/detection/cpu/cpu_apple.c +++ b/src/detection/cpu/cpu_apple.c @@ -109,6 +109,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) return "sysctlbyname(machdep.cpu.brand_string) failed"; ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor); + cpu->cpuCount = (uint16_t) ffSysctlGetInt("hw.packages", 1); if (cpu->vendor.length == 0 && ffStrbufStartsWithS(&cpu->name, "Apple ")) ffStrbufAppendS(&cpu->vendor, "Apple"); diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index 91c8ba46f..56493cf2a 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -222,6 +222,7 @@ static void detectArmName(FILE* cpuinfo, FFCPUResult* cpu, uint32_t implId) static const char* parseCpuInfo( FF_MAYBE_UNUSED FILE* cpuinfo, FF_MAYBE_UNUSED FFCPUResult* cpu, + FF_MAYBE_UNUSED FFstrbuf* cpuPhysicalId, FF_MAYBE_UNUSED FFstrbuf* physicalCoresBuffer, FF_MAYBE_UNUSED FFstrbuf* cpuMHz, FF_MAYBE_UNUSED FFstrbuf* cpuIsa, @@ -247,6 +248,9 @@ static const char* parseCpuInfo( #if !(__arm__ || __aarch64__) (cpu->name.length == 0 && ffParsePropLine(line, "model name :", &cpu->name)) || (cpu->vendor.length == 0 && ffParsePropLine(line, "vendor_id :", &cpu->vendor)) || + //Is it cheaper to just parse every physical id or to check if it's already set to the parsed value? + (cpuPhysicalId->length == 0 && ffParsePropLine(line, "physical id:", cpuPhysicalId)) || + (cpuPhysicalId->length > 0 && ffParsePropLine(line, "physical id:", cpuPhysicalId)) || (physicalCoresBuffer->length == 0 && ffParsePropLine(line, "cpu cores :", physicalCoresBuffer)) || (cpuMHz->length == 0 && ffParsePropLine(line, "cpu MHz :", cpuMHz)) || #endif @@ -473,18 +477,20 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) cpu->temperature = options->temp ? detectCPUTemp() : FF_CPU_TEMP_UNSET; + FF_STRBUF_AUTO_DESTROY cpuPhysicalId= ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY physicalCoresBuffer = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY cpuMHz = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY cpuIsa = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY cpuUarch = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY cpuImplementerStr = ffStrbufCreate(); - const char* error = parseCpuInfo(cpuinfo, cpu, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch, &cpuImplementerStr); + const char* error = parseCpuInfo(cpuinfo, cpu, &cpuPhysicalId, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch, &cpuImplementerStr); if (error) return error; cpu->coresLogical = (uint16_t) get_nprocs_conf(); cpu->coresOnline = (uint16_t) get_nprocs(); cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, cpu->coresLogical); + cpu->cpuCount = (uint16_t) ffStrbufToUInt(&cpuPhysicalId, 1) +1; //Assuming at least 1 CPU is present otherwise we wouldn't get this far // Ref https://github.com/fastfetch-cli/fastfetch/issues/1194#issuecomment-2295058252 ffCPUDetectSpeedByCpuid(cpu); diff --git a/src/detection/cpu/cpu_windows.c b/src/detection/cpu/cpu_windows.c index 7479ff6d1..313e7487e 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -110,6 +110,10 @@ static const char* detectNCores(FFCPUResult* cpu) cpu->coresLogical += ptr->Group.GroupInfo[index].MaximumProcessorCount; } } + + if (ptr->Relationship == RelationProcessorPackage) { + cpu->cpuCount++; + } } return NULL; diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 614b0bf26..1ee351229 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -55,6 +55,9 @@ void ffPrintCPU(FFCPUOptions* options) FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); + if(cpu.cpuCount > 1) + ffStrbufAppendF(&str, "%u x ", cpu.cpuCount); + if(cpu.name.length > 0) ffStrbufAppend(&str, &cpu.name); else if(cpu.vendor.length > 0) @@ -68,7 +71,12 @@ void ffPrintCPU(FFCPUOptions* options) if(coreTypes.length > 0) ffStrbufAppendF(&str, " (%s)", coreTypes.chars); else if(cpu.coresOnline > 1) - ffStrbufAppendF(&str, " (%u)", cpu.coresOnline); + { + if(cpu.cpuCount > 1) + ffStrbufAppendF(&str, " (%u)", cpu.coresOnline / 2); + else + ffStrbufAppendF(&str, " (%u)", cpu.coresOnline); + } uint32_t freq = cpu.frequencyMax; if(freq == 0)