Skip to content

Commit

Permalink
CPU (Linux): remove bios_limit detection
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 28, 2024
1 parent acd5d4a commit a424839
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 2.26.0

Changes:
* To be consistent to other platforms, CPU frequency detection on Linux no longer checks `bios_limit`

Features:
* Detect GPU index (#1267, GPU)
* Count Flatpak runtime packages (#1085, Packages, Linux)
Expand Down
1 change: 0 additions & 1 deletion src/detection/cpu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typedef struct FFCPUResult

uint32_t frequencyBase; // GHz
uint32_t frequencyMax; // GHz
uint32_t frequencyBiosLimit; // GHz

FFCPUCore coreTypes[16]; // number of P cores, E cores, etc.

Expand Down
23 changes: 15 additions & 8 deletions src/detection/cpu/cpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,25 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options)
if (ffStrStartsWith(entry->d_name, "policy") && ffCharIsDigit(entry->d_name[strlen("policy")]))
{
ffStrbufAppendS(&path, entry->d_name);

uint32_t fmax = getFrequency(&path, "/cpuinfo_max_freq", "/scaling_max_freq", &buffer);
if (fmax == 0) continue;

if (cpu->frequencyMax >= fmax)
{
if (!options->showPeCoreCount)
{
ffStrbufSubstrBefore(&path, baseLen);
continue;
}
}
else
cpu->frequencyMax = fmax;

uint32_t fbase = getFrequency(&path, "/base_frequency", NULL, &buffer);
if (fbase > 0)
cpu->frequencyBase = cpu->frequencyBase > fbase ? cpu->frequencyBase : fbase;

uint32_t fbioslimit = getFrequency(&path, "/bios_limit", NULL, &buffer);
if (fbioslimit > 0)
cpu->frequencyBiosLimit = cpu->frequencyBiosLimit > fbioslimit ? cpu->frequencyBiosLimit : fbioslimit;

uint32_t fmax = getFrequency(&path, "/cpuinfo_max_freq", "/scaling_max_freq", &buffer);
if (fmax > 0)
cpu->frequencyMax = cpu->frequencyMax > fmax ? cpu->frequencyMax : fmax;

if (options->showPeCoreCount)
{
uint32_t freq = fbase == 0 ? fmax : fbase; // seems base frequencies are more stable
Expand Down
13 changes: 2 additions & 11 deletions src/modules/cpu/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "modules/cpu/cpu.h"
#include "util/stringUtils.h"

#define FF_CPU_NUM_FORMAT_ARGS 10
#define FF_CPU_NUM_FORMAT_ARGS 9

static int sortCores(const FFCPUCore* a, const FFCPUCore* b)
{
Expand All @@ -19,7 +19,6 @@ void ffPrintCPU(FFCPUOptions* options)
.temperature = FF_CPU_TEMP_UNSET,
.frequencyMax = 0,
.frequencyBase = 0,
.frequencyBiosLimit = 0,
.name = ffStrbufCreate(),
.vendor = ffStrbufCreate(),
};
Expand Down Expand Up @@ -71,9 +70,7 @@ void ffPrintCPU(FFCPUOptions* options)
else if(cpu.coresOnline > 1)
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline);

uint32_t freq = cpu.frequencyBiosLimit;
if(freq == 0)
freq = cpu.frequencyMax;
uint32_t freq = cpu.frequencyMax;
if(freq == 0)
freq = cpu.frequencyBase;
if(freq > 0)
Expand All @@ -96,8 +93,6 @@ void ffPrintCPU(FFCPUOptions* options)
ffParseFrequency(cpu.frequencyBase, &freqBase);
FF_STRBUF_AUTO_DESTROY freqMax = ffStrbufCreate();
ffParseFrequency(cpu.frequencyMax, &freqMax);
FF_STRBUF_AUTO_DESTROY freqBioslimit = ffStrbufCreate();
ffParseFrequency(cpu.frequencyBiosLimit, &freqBioslimit);

FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate();
ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig, &options->moduleArgs);
Expand All @@ -111,7 +106,6 @@ void ffPrintCPU(FFCPUOptions* options)
FF_FORMAT_ARG(freqMax, "freq-max"),
FF_FORMAT_ARG(tempStr, "temperature"),
FF_FORMAT_ARG(coreTypes, "core-types"),
FF_FORMAT_ARG(freqBioslimit, "freq-bios-limit"),
}));
}
}
Expand Down Expand Up @@ -190,7 +184,6 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
.temperature = FF_CPU_TEMP_UNSET,
.frequencyMax = 0,
.frequencyBase = 0,
.frequencyBiosLimit = 0,
.name = ffStrbufCreate(),
.vendor = ffStrbufCreate(),
};
Expand Down Expand Up @@ -219,7 +212,6 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_val* frequency = yyjson_mut_obj_add_obj(doc, obj, "frequency");
yyjson_mut_obj_add_uint(doc, frequency, "base", cpu.frequencyBase);
yyjson_mut_obj_add_uint(doc, frequency, "max", cpu.frequencyMax);
yyjson_mut_obj_add_uint(doc, frequency, "biosLimit", cpu.frequencyBiosLimit);

yyjson_mut_val* coreTypes = yyjson_mut_obj_add_arr(doc, obj, "coreTypes");
for (uint32_t i = 0; i < sizeof (cpu.coreTypes) / sizeof (cpu.coreTypes[0]) && cpu.coreTypes[i].count > 0; i++)
Expand Down Expand Up @@ -248,7 +240,6 @@ void ffPrintCPUHelpFormat(void)
"Max frequency (formatted) - freq-max",
"Temperature (formatted) - temperature",
"Logical core count grouped by frequency - core-types",
"Bios limited frequency (formatted) - freq-bios-limit",
}));
}

Expand Down
1 change: 0 additions & 1 deletion src/modules/loadavg/loadavg.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void ffPrintLoadavg(FFLoadavgOptions* options)
.temperature = FF_CPU_TEMP_UNSET,
.frequencyMax = 0,
.frequencyBase = 0,
.frequencyBiosLimit = 0,
.name = ffStrbufCreate(),
.vendor = ffStrbufCreate(),
};
Expand Down

0 comments on commit a424839

Please sign in to comment.