Skip to content

Commit

Permalink
Merge pull request #952 from fastfetch-cli/dev
Browse files Browse the repository at this point in the history
Release: v2.13.1
  • Loading branch information
CarterLi committed May 21, 2024
2 parents 43bdb68 + 01d1336 commit 36cf585
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 37 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 2.13.1

Fix a regression introduced in v2.13.0

Bugfixes:
* Fix CPU frequency not displayed if `bios_limit` is not available (CPU, Linux)

Features:
* Add `--cpu-show-pe-core-count` to detect and display core count for performance / efficiency cores (CPU, FreeBSD)

# 2.13.0

Changes:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url

project(fastfetch
VERSION 2.13.0
VERSION 2.13.1
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
Expand Down
5 changes: 5 additions & 0 deletions doc/json_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,11 @@
"maximum": 9,
"default": 2
},
"showPeCoreCount": {
"description": "Detect and display CPU frequency of different core types (eg. Pcore and Ecore) if supported",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
Expand Down
9 changes: 9 additions & 0 deletions src/data/help.json
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,15 @@
"default": 2
}
},
{
"long": "cpu-show-pe-core-count",
"desc": "Detect and display CPU frequency of different core types (eg. Pcore and Ecore) if supported",
"arg": {
"type": "bool",
"optional": true,
"default": false
}
},
{
"long": "cpuusage-separate",
"desc": "Display CPU usage per CPU logical core, instead of an average result",
Expand Down
2 changes: 1 addition & 1 deletion src/detection/cpu/cpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);

detectFrequency(cpu);
detectCoreCount(cpu);
if (options->showPeCoreCount) detectCoreCount(cpu);

cpu->temperature = options->temp ? detectCpuTemp(&cpu->name) : FF_CPU_TEMP_UNSET;

Expand Down
16 changes: 9 additions & 7 deletions src/detection/cpu/cpu_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
}
}

uint32_t ifreq = (uint32_t) -1;
for (uint16_t i = 0; i < cpu->coresLogical; ++i)
{
ffStrbufClear(&buffer);
Expand All @@ -56,12 +55,15 @@ 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;

uint32_t ifreq = 0;
while (cpu->coreTypes[ifreq].freq != fmax && cpu->coreTypes[ifreq].freq > 0)
++ifreq;
if (cpu->coreTypes[ifreq].freq == 0)
cpu->coreTypes[ifreq].freq = fmax;
cpu->coreTypes[ifreq].count++;
if (options->showPeCoreCount)
{
uint32_t ifreq = 0;
while (cpu->coreTypes[ifreq].freq != fmax && cpu->coreTypes[ifreq].freq > 0)
++ifreq;
if (cpu->coreTypes[ifreq].freq == 0)
cpu->coreTypes[ifreq].freq = fmax;
cpu->coreTypes[ifreq].count++;
}
}
}
cpu->frequencyMin /= 1000;
Expand Down
21 changes: 12 additions & 9 deletions src/detection/cpu/cpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static uint8_t getNumCores(FFstrbuf* basePath, FFstrbuf* buffer)
return 0;
}

static bool detectFrequency(FFCPUResult* cpu)
static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options)
{
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/devices/system/cpu/cpufreq/");
FF_AUTO_CLOSE_DIR DIR* dir = opendir(path.chars);
Expand Down Expand Up @@ -175,13 +175,16 @@ static bool detectFrequency(FFCPUResult* cpu)
cpu->frequencyMin = fmin;
}

uint32_t freq = fbase == 0 ? fmax : fbase; // seems base frequencies are more stable
uint32_t ifreq = 0;
while (cpu->coreTypes[ifreq].freq != freq && cpu->coreTypes[ifreq].freq > 0)
++ifreq;
if (cpu->coreTypes[ifreq].freq == 0)
cpu->coreTypes[ifreq].freq = freq;
cpu->coreTypes[ifreq].count += getNumCores(&path, &buffer);
if (options->showPeCoreCount)
{
uint32_t freq = fbase == 0 ? fmax : fbase; // seems base frequencies are more stable
uint32_t ifreq = 0;
while (cpu->coreTypes[ifreq].freq != freq && cpu->coreTypes[ifreq].freq > 0)
++ifreq;
if (cpu->coreTypes[ifreq].freq == 0)
cpu->coreTypes[ifreq].freq = freq;
cpu->coreTypes[ifreq].count += getNumCores(&path, &buffer);
}
ffStrbufSubstrBefore(&path, baseLen);
}
}
Expand Down Expand Up @@ -270,7 +273,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
cpu->coresOnline = (uint16_t) get_nprocs();
cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, cpu->coresLogical);

if (!detectFrequency(cpu) || cpu->frequencyBase != cpu->frequencyBase)
if (!detectFrequency(cpu, options) || cpu->frequencyBase != cpu->frequencyBase)
cpu->frequencyBase = ffStrbufToDouble(&cpuMHz) / 1000;

if(cpuUarch.length > 0)
Expand Down
6 changes: 5 additions & 1 deletion src/detection/cpu/cpu_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ static const char* detectByRegistry(FFCPUResult* cpu)
cpu->coresOnline = cpu->coresPhysical = cpu->coresLogical = (uint16_t) cores;
}

uint32_t mhz;
if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL))
cpu->frequencyBase = mhz / 1000.0;

return NULL;
}

Expand Down Expand Up @@ -190,7 +194,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
return error;

detectSpeedByCpuid(cpu);
detectCoreTypes(cpu);
if (options->showPeCoreCount) detectCoreTypes(cpu);

if (cpu->frequencyMax != cpu->frequencyMax)
detectMaxSpeedBySmbios(cpu);
Expand Down
55 changes: 37 additions & 18 deletions src/modules/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ void ffPrintCPU(FFCPUOptions* options)
}
else
{
FF_STRBUF_AUTO_DESTROY coreTypes = ffStrbufCreate();
if (options->showPeCoreCount)
{
uint32_t typeCount = 0;
while (cpu.coreTypes[typeCount].count != 0 && typeCount < sizeof(cpu.coreTypes) / sizeof(cpu.coreTypes[0])) typeCount++;
if (typeCount > 0)
{
qsort(cpu.coreTypes, typeCount, sizeof(cpu.coreTypes[0]), (void*) sortCores);

for (uint32_t i = 0; i < typeCount; i++)
ffStrbufAppendF(&coreTypes, "%s%u", i == 0 ? "" : "+", cpu.coreTypes[i].count);
}
}

if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
Expand All @@ -53,13 +67,15 @@ void ffPrintCPU(FFCPUOptions* options)
else
ffStrbufAppendS(&str, "Unknown");

if(cpu.coresOnline > 1)
if(coreTypes.length > 0)
ffStrbufAppendF(&str, " (%s)", coreTypes.chars);
else if(cpu.coresOnline > 1)
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline);

double freq = cpu.frequencyBiosLimit;
if(freq <= 0.0000001)
if(!(freq > 0.0000001))
freq = cpu.frequencyMax;
if(freq <= 0.0000001)
if(!(freq > 0.0000001))
freq = cpu.frequencyBase;
if(freq > 0.0000001)
ffStrbufAppendF(&str, " @ %.*f GHz", options->freqNdigits, freq);
Expand All @@ -74,19 +90,6 @@ void ffPrintCPU(FFCPUOptions* options)
}
else
{
FF_STRBUF_AUTO_DESTROY coreTypes = ffStrbufCreate();
uint32_t typeCount = 0;
while (cpu.coreTypes[typeCount].count != 0 && typeCount < sizeof(cpu.coreTypes) / sizeof(cpu.coreTypes[0])) typeCount++;
if (typeCount > 0)
{
qsort(cpu.coreTypes, typeCount, sizeof(cpu.coreTypes[0]), (void*) sortCores);

for (uint32_t i = 0; i < typeCount; i++)
ffStrbufAppendF(&coreTypes, "%s%u", i == 0 ? "" : "+", cpu.coreTypes[i].count);
}
else
ffStrbufAppendF(&coreTypes, "%u", cpu.coresOnline);

char freqBase[32], freqMax[32], freqBioslimit[32];
if (cpu.frequencyBase > 0)
snprintf(freqBase, sizeof(freqBase), "%.*f", options->freqNdigits, cpu.frequencyBase);
Expand Down Expand Up @@ -122,7 +125,7 @@ void ffPrintCPU(FFCPUOptions* options)
ffStrbufDestroy(&cpu.vendor);
}

bool ffParseCPUCPUOptions(FFCPUOptions* options, const char* key, const char* value)
bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value)
{
const char* subKey = ffOptionTestPrefix(key, FF_CPU_MODULE_NAME);
if (!subKey) return false;
Expand All @@ -138,6 +141,12 @@ bool ffParseCPUCPUOptions(FFCPUOptions* options, const char* key, const char* va
return true;
}

if (ffStrEqualsIgnCase(subKey, "show-pe-core-count"))
{
options->showPeCoreCount = ffOptionParseBoolean(value);
return true;
}

return false;
}

Expand All @@ -163,6 +172,12 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
continue;
}

if (ffStrEqualsIgnCase(key, "showPeCoreCount"))
{
options->showPeCoreCount = yyjson_get_bool(val);
continue;
}

ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key);
}
}
Expand All @@ -178,6 +193,9 @@ void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_

if (defaultOptions.freqNdigits != options->freqNdigits)
yyjson_mut_obj_add_uint(doc, module, "freqNdigits", options->freqNdigits);

if (defaultOptions.showPeCoreCount != options->showPeCoreCount)
yyjson_mut_obj_add_bool(doc, module, "showPeCoreCount", options->showPeCoreCount);
}

void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
Expand Down Expand Up @@ -256,7 +274,7 @@ void ffInitCPUOptions(FFCPUOptions* options)
&options->moduleInfo,
FF_CPU_MODULE_NAME,
"Print CPU name, frequency, etc",
ffParseCPUCPUOptions,
ffParseCPUCommandOptions,
ffParseCPUJsonObject,
ffPrintCPU,
ffGenerateCPUJsonResult,
Expand All @@ -267,6 +285,7 @@ void ffInitCPUOptions(FFCPUOptions* options)
options->temp = false;
options->tempConfig = (FFColorRangeConfig) { 60, 80 };
options->freqNdigits = 2;
options->showPeCoreCount = false;
}

void ffDestroyCPUOptions(FFCPUOptions* options)
Expand Down
1 change: 1 addition & 0 deletions src/modules/cpu/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ typedef struct FFCPUOptions
bool temp;
FFColorRangeConfig tempConfig;
uint8_t freqNdigits;
bool showPeCoreCount;
} FFCPUOptions;

0 comments on commit 36cf585

Please sign in to comment.