Skip to content

Commit 7535ce8

Browse files
authored
Support for dual CPU systems (#1417)
* [macOS] Added support for dual CPUs on Mac computers Signed-off-by: Koneko <[email protected]> * 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 <[email protected]>
1 parent b76eb87 commit 7535ce8

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

src/detection/cpu/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct FFCPUResult
1515
FFstrbuf name;
1616
FFstrbuf vendor;
1717

18+
uint16_t cpuCount;
1819
uint16_t coresPhysical;
1920
uint16_t coresLogical;
2021
uint16_t coresOnline;

src/detection/cpu/cpu_apple.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
109109
return "sysctlbyname(machdep.cpu.brand_string) failed";
110110

111111
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
112+
cpu->cpuCount = (uint16_t) ffSysctlGetInt("hw.packages", 1);
112113
if (cpu->vendor.length == 0 && ffStrbufStartsWithS(&cpu->name, "Apple "))
113114
ffStrbufAppendS(&cpu->vendor, "Apple");
114115

src/detection/cpu/cpu_linux.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static void detectArmName(FILE* cpuinfo, FFCPUResult* cpu, uint32_t implId)
222222
static const char* parseCpuInfo(
223223
FF_MAYBE_UNUSED FILE* cpuinfo,
224224
FF_MAYBE_UNUSED FFCPUResult* cpu,
225+
FF_MAYBE_UNUSED FFstrbuf* cpuPhysicalId,
225226
FF_MAYBE_UNUSED FFstrbuf* physicalCoresBuffer,
226227
FF_MAYBE_UNUSED FFstrbuf* cpuMHz,
227228
FF_MAYBE_UNUSED FFstrbuf* cpuIsa,
@@ -247,6 +248,9 @@ static const char* parseCpuInfo(
247248
#if !(__arm__ || __aarch64__)
248249
(cpu->name.length == 0 && ffParsePropLine(line, "model name :", &cpu->name)) ||
249250
(cpu->vendor.length == 0 && ffParsePropLine(line, "vendor_id :", &cpu->vendor)) ||
251+
//Is it cheaper to just parse every physical id or to check if it's already set to the parsed value?
252+
(cpuPhysicalId->length == 0 && ffParsePropLine(line, "physical id:", cpuPhysicalId)) ||
253+
(cpuPhysicalId->length > 0 && ffParsePropLine(line, "physical id:", cpuPhysicalId)) ||
250254
(physicalCoresBuffer->length == 0 && ffParsePropLine(line, "cpu cores :", physicalCoresBuffer)) ||
251255
(cpuMHz->length == 0 && ffParsePropLine(line, "cpu MHz :", cpuMHz)) ||
252256
#endif
@@ -473,18 +477,20 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
473477

474478
cpu->temperature = options->temp ? detectCPUTemp() : FF_CPU_TEMP_UNSET;
475479

480+
FF_STRBUF_AUTO_DESTROY cpuPhysicalId= ffStrbufCreate();
476481
FF_STRBUF_AUTO_DESTROY physicalCoresBuffer = ffStrbufCreate();
477482
FF_STRBUF_AUTO_DESTROY cpuMHz = ffStrbufCreate();
478483
FF_STRBUF_AUTO_DESTROY cpuIsa = ffStrbufCreate();
479484
FF_STRBUF_AUTO_DESTROY cpuUarch = ffStrbufCreate();
480485
FF_STRBUF_AUTO_DESTROY cpuImplementerStr = ffStrbufCreate();
481486

482-
const char* error = parseCpuInfo(cpuinfo, cpu, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch, &cpuImplementerStr);
487+
const char* error = parseCpuInfo(cpuinfo, cpu, &cpuPhysicalId, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch, &cpuImplementerStr);
483488
if (error) return error;
484489

485490
cpu->coresLogical = (uint16_t) get_nprocs_conf();
486491
cpu->coresOnline = (uint16_t) get_nprocs();
487492
cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, cpu->coresLogical);
493+
cpu->cpuCount = (uint16_t) ffStrbufToUInt(&cpuPhysicalId, 1) +1; //Assuming at least 1 CPU is present otherwise we wouldn't get this far
488494

489495
// Ref https://github.com/fastfetch-cli/fastfetch/issues/1194#issuecomment-2295058252
490496
ffCPUDetectSpeedByCpuid(cpu);

src/detection/cpu/cpu_windows.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ static const char* detectNCores(FFCPUResult* cpu)
110110
cpu->coresLogical += ptr->Group.GroupInfo[index].MaximumProcessorCount;
111111
}
112112
}
113+
114+
if (ptr->Relationship == RelationProcessorPackage) {
115+
cpu->cpuCount++;
116+
}
113117
}
114118

115119
return NULL;

src/modules/cpu/cpu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ void ffPrintCPU(FFCPUOptions* options)
5555

5656
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
5757

58+
if(cpu.cpuCount > 1)
59+
ffStrbufAppendF(&str, "%u x ", cpu.cpuCount);
60+
5861
if(cpu.name.length > 0)
5962
ffStrbufAppend(&str, &cpu.name);
6063
else if(cpu.vendor.length > 0)
@@ -68,7 +71,12 @@ void ffPrintCPU(FFCPUOptions* options)
6871
if(coreTypes.length > 0)
6972
ffStrbufAppendF(&str, " (%s)", coreTypes.chars);
7073
else if(cpu.coresOnline > 1)
71-
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline);
74+
{
75+
if(cpu.cpuCount > 1)
76+
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline / 2);
77+
else
78+
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline);
79+
}
7280

7381
uint32_t freq = cpu.frequencyMax;
7482
if(freq == 0)

0 commit comments

Comments
 (0)