mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Support for dual CPU systems (#1417)
* [macOS] Added support for dual CPUs on Mac computers Signed-off-by: Koneko <azimovp17@gmail.com> * Change how number of cores is displayed when the system is dual CPU * Support for dual CPU on Windows * Dual CPU detection on Linux basic implementation --------- Signed-off-by: Koneko <azimovp17@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ typedef struct FFCPUResult
|
||||
FFstrbuf name;
|
||||
FFstrbuf vendor;
|
||||
|
||||
uint16_t cpuCount;
|
||||
uint16_t coresPhysical;
|
||||
uint16_t coresLogical;
|
||||
uint16_t coresOnline;
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user