diff --git a/src/detection/cpu/cpu.h b/src/detection/cpu/cpu.h index 59343dd98..5af7a8275 100644 --- a/src/detection/cpu/cpu.h +++ b/src/detection/cpu/cpu.h @@ -15,7 +15,7 @@ typedef struct FFCPUResult FFstrbuf name; FFstrbuf vendor; - uint16_t cpuCount; + uint16_t packages; 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 f2b4c4256..8d5cbf0a4 100644 --- a/src/detection/cpu/cpu_apple.c +++ b/src/detection/cpu/cpu_apple.c @@ -109,7 +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); + cpu->packages = (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 5a306d473..e90663d52 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -464,7 +464,7 @@ FF_MAYBE_UNUSED static void detectArmSoc(FFCPUResult* cpu) } } -FF_MAYBE_UNUSED static uint16_t getCPUCount(FFstrbuf* cpuinfo) +FF_MAYBE_UNUSED static uint16_t getPackageCount(FFstrbuf* cpuinfo) { const char* p = cpuinfo->chars; uint64_t bits = 0; @@ -502,7 +502,9 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) cpu->coresLogical = (uint16_t) get_nprocs_conf(); cpu->coresOnline = (uint16_t) get_nprocs(); cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, cpu->coresLogical); - cpu->cpuCount = getCPUCount(&cpuinfo); + #if __x86_64__ || __i386__ + cpu->packages = getPackageCount(&cpuinfo); + #endif // 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 313e7487e..411571010 100644 --- a/src/detection/cpu/cpu_windows.c +++ b/src/detection/cpu/cpu_windows.c @@ -112,7 +112,7 @@ static const char* detectNCores(FFCPUResult* cpu) } if (ptr->Relationship == RelationProcessorPackage) { - cpu->cpuCount++; + cpu->packages++; } } diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 1ee351229..1a924ca5d 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -6,7 +6,7 @@ #include "modules/cpu/cpu.h" #include "util/stringUtils.h" -#define FF_CPU_NUM_FORMAT_ARGS 9 +#define FF_CPU_NUM_FORMAT_ARGS 10 static int sortCores(const FFCPUCore* a, const FFCPUCore* b) { @@ -55,8 +55,8 @@ void ffPrintCPU(FFCPUOptions* options) FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); - if(cpu.cpuCount > 1) - ffStrbufAppendF(&str, "%u x ", cpu.cpuCount); + if(cpu.packages > 1) + ffStrbufAppendF(&str, "%u x ", cpu.packages); if(cpu.name.length > 0) ffStrbufAppend(&str, &cpu.name); @@ -72,7 +72,7 @@ void ffPrintCPU(FFCPUOptions* options) ffStrbufAppendF(&str, " (%s)", coreTypes.chars); else if(cpu.coresOnline > 1) { - if(cpu.cpuCount > 1) + if(cpu.packages > 1) ffStrbufAppendF(&str, " (%u)", cpu.coresOnline / 2); else ffStrbufAppendF(&str, " (%u)", cpu.coresOnline); @@ -114,6 +114,7 @@ void ffPrintCPU(FFCPUOptions* options) FF_FORMAT_ARG(freqMax, "freq-max"), FF_FORMAT_ARG(tempStr, "temperature"), FF_FORMAT_ARG(coreTypes, "core-types"), + FF_FORMAT_ARG(cpu.packages, "packages"), })); } } @@ -211,6 +212,10 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_ yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "cpu", &cpu.name); yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &cpu.vendor); + if (cpu.packages == 0) + yyjson_mut_obj_add_null(doc, obj, "packages"); + else + yyjson_mut_obj_add_uint(doc, obj, "packages", cpu.packages); yyjson_mut_val* cores = yyjson_mut_obj_add_obj(doc, obj, "cores"); yyjson_mut_obj_add_uint(doc, cores, "physical", cpu.coresPhysical); @@ -248,6 +253,7 @@ void ffPrintCPUHelpFormat(void) "Max frequency (formatted) - freq-max", "Temperature (formatted) - temperature", "Logical core count grouped by frequency - core-types", + "Processor package count - packages", })); }