mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-07 21:50:08 +01:00
CPU: print core count for different core types
This commit is contained in:
@@ -4,6 +4,12 @@
|
||||
|
||||
#define FF_CPU_TEMP_UNSET (0/0.0)
|
||||
|
||||
typedef struct FFCPUCore
|
||||
{
|
||||
uint32_t freq;
|
||||
uint32_t count;
|
||||
} FFCPUCore;
|
||||
|
||||
typedef struct FFCPUResult
|
||||
{
|
||||
FFstrbuf name;
|
||||
@@ -17,7 +23,7 @@ typedef struct FFCPUResult
|
||||
double frequencyMax; // GHz
|
||||
double frequencyMin; // GHz
|
||||
|
||||
uint8_t coreCounts[8]; // number of P cores, E cores, etc.
|
||||
FFCPUCore coreTypes[8]; // number of P cores, E cores, etc.
|
||||
|
||||
double temperature;
|
||||
} FFCPUResult;
|
||||
|
||||
@@ -85,13 +85,14 @@ static const char* detectCoreCount(FFCPUResult* cpu)
|
||||
int nPerfLevels = ffSysctlGetInt("hw.nperflevels", 0);
|
||||
if (nPerfLevels <= 0) return "sysctl(hw.nperflevels) failed";
|
||||
|
||||
if (nPerfLevels > (int) sizeof(cpu->coreCounts))
|
||||
nPerfLevels = (int) sizeof(cpu->coreCounts);
|
||||
char sysctlKey[] = "hw.perflevelN.logicalcpu";
|
||||
for (int i = 0; i < nPerfLevels; ++i)
|
||||
{
|
||||
sysctlKey[strlen("hw.perflevel")] = (char) ('0' + i);
|
||||
cpu->coreCounts[i] = (uint8_t) ffSysctlGetInt(sysctlKey, 0);
|
||||
cpu->coreTypes[i < (int) sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]) : i : (int) sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]) - 1] = {
|
||||
.freq = nPerfLevels - i,
|
||||
.count = ffSysctlGetInt(sysctlKey, 0),
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t freq = (uint64_t) -1;
|
||||
uint32_t ifreq = (uint32_t) -1;
|
||||
for (uint16_t i = 0; i < cpu->coresLogical; ++i)
|
||||
{
|
||||
@@ -57,13 +56,13 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
|
||||
if (!(cpu->frequencyMin <= fmin)) cpu->frequencyMin = fmin; // Counting for NaN
|
||||
if (!(cpu->frequencyMax >= fmax)) cpu->frequencyMax = fmax;
|
||||
|
||||
if (freq != fmax)
|
||||
if (cpu->coreTypes[ifreq].freq != fmax)
|
||||
{
|
||||
freq = fmax;
|
||||
++ifreq;
|
||||
if (cpu->coreTypes[ifreq].count && ifreq < sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]))
|
||||
++ifreq;
|
||||
cpu->coreTypes[ifreq].freq = fmax;
|
||||
}
|
||||
if (__builtin_expect(ifreq < sizeof(cpu->coreCounts), true))
|
||||
cpu->coreCounts[ifreq]++;
|
||||
cpu->coreTypes[ifreq].count++;
|
||||
}
|
||||
}
|
||||
cpu->frequencyMin /= 1000;
|
||||
|
||||
@@ -136,11 +136,9 @@ static bool detectFrequency(FFCPUResult* cpu)
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
uint32_t baseLen = path.length;
|
||||
|
||||
uint64_t freq = (uint64_t) -1;
|
||||
uint32_t ifreq = (uint32_t) -1;
|
||||
|
||||
uint32_t ifreq = 0;
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dir)) != NULL)
|
||||
while ((entry = readdir(dir)) != NULL)
|
||||
{
|
||||
if (ffStrStartsWith(entry->d_name, "policy") && isdigit(entry->d_name[strlen("policy")]))
|
||||
{
|
||||
@@ -161,13 +159,13 @@ static bool detectFrequency(FFCPUResult* cpu)
|
||||
else
|
||||
cpu->frequencyMax = fmax;
|
||||
|
||||
if (fmax != freq)
|
||||
if (cpu->coreTypes[ifreq].freq != fmax)
|
||||
{
|
||||
freq = fmax;
|
||||
++ifreq;
|
||||
if (cpu->coreTypes[ifreq].count && ifreq < sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]))
|
||||
++ifreq;
|
||||
cpu->coreTypes[ifreq].freq = fmax;
|
||||
}
|
||||
if (__builtin_expect(ifreq < sizeof(cpu->coreCounts), true))
|
||||
cpu->coreCounts[ifreq] += getNumCores(&path, &buffer);
|
||||
cpu->coreTypes[ifreq].count += getNumCores(&path, &buffer);
|
||||
}
|
||||
uint32_t fmin = getFrequency(&path, "/cpuinfo_min_freq", "/scaling_min_freq", &buffer);
|
||||
if (fmin > 0)
|
||||
|
||||
@@ -160,23 +160,22 @@ static const char* detectByRegistry(FFCPUResult* cpu)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* detectCoreCounts(FFCPUResult* cpu)
|
||||
static const char* detectCoreTypes(FFCPUResult* cpu)
|
||||
{
|
||||
FF_AUTO_FREE PROCESSOR_POWER_INFORMATION* pinfo = calloc(cpu->coresLogical, sizeof(PROCESSOR_POWER_INFORMATION));
|
||||
if (!NT_SUCCESS(NtPowerInformation(ProcessorInformation, NULL, 0, pinfo, (ULONG) sizeof(PROCESSOR_POWER_INFORMATION) * cpu->coresLogical)))
|
||||
return "NtPowerInformation(ProcessorInformation, NULL, 0, pinfo, size) failed";
|
||||
|
||||
uint64_t freq = (uint64_t) -1;
|
||||
uint32_t ifreq = (uint32_t) -1;
|
||||
for (uint32_t i = 0; i < cpu->coresLogical && pinfo[i].MhzLimit; ++i)
|
||||
uint32_t ifreq = 0;
|
||||
for (uint32_t i = 1; i < cpu->coresLogical && pinfo[i].MhzLimit; ++i)
|
||||
{
|
||||
if (freq != pinfo[i].MhzLimit)
|
||||
if (cpu->coreTypes[ifreq].freq != pinfo[i].MhzLimit)
|
||||
{
|
||||
freq = pinfo[i].MhzLimit;
|
||||
++ifreq;
|
||||
if (cpu->coreTypes[ifreq].count && ifreq < sizeof(cpu->coreTypes) / sizeof(cpu->coreTypes[0]))
|
||||
++ifreq;
|
||||
cpu->coreTypes[ifreq].freq = pinfo[i].MhzLimit;
|
||||
}
|
||||
if (__builtin_expect(ifreq < sizeof(cpu->coreCounts), true))
|
||||
cpu->coreCounts[ifreq]++;
|
||||
cpu->coreTypes[ifreq].count++;
|
||||
}
|
||||
|
||||
if (cpu->frequencyBase != cpu->frequencyBase)
|
||||
@@ -193,7 +192,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
|
||||
return error;
|
||||
|
||||
detectSpeedByCpuid(cpu);
|
||||
detectCoreCounts(cpu);
|
||||
detectCoreTypes(cpu);
|
||||
|
||||
if (cpu->frequencyMax != cpu->frequencyMax)
|
||||
detectMaxSpeedBySmbios(cpu);
|
||||
|
||||
Reference in New Issue
Block a user