From c0de618177c4ba9da37d0508da049263f922d7a4 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 17 Jul 2024 09:29:18 +0800 Subject: [PATCH] CPU: remove support of min freq detection --- src/detection/cpu/cpu.h | 1 - src/detection/cpu/cpu_apple.c | 26 +++++++++++--------------- src/detection/cpu/cpu_bsd.c | 6 ------ src/detection/cpu/cpu_linux.c | 9 --------- src/modules/cpu/cpu.c | 3 --- src/modules/loadavg/loadavg.c | 1 - 6 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/detection/cpu/cpu.h b/src/detection/cpu/cpu.h index fc9b7e080..c37fc1997 100644 --- a/src/detection/cpu/cpu.h +++ b/src/detection/cpu/cpu.h @@ -21,7 +21,6 @@ typedef struct FFCPUResult double frequencyBase; // GHz double frequencyMax; // GHz - double frequencyMin; // GHz double frequencyBiosLimit; // GHz FFCPUCore coreTypes[16]; // number of P cores, E cores, etc. diff --git a/src/detection/cpu/cpu_apple.c b/src/detection/cpu/cpu_apple.c index e33916558..398c0ca9e 100644 --- a/src/detection/cpu/cpu_apple.c +++ b/src/detection/cpu/cpu_apple.c @@ -2,6 +2,7 @@ #include "common/sysctl.h" #include "detection/temps/temps_apple.h" #include "util/stringUtils.h" +#include "util/apple/cf_helpers.h" static double detectCpuTemp(const FFstrbuf* cpuName) { @@ -43,23 +44,19 @@ static const char* detectFrequency(FFCPUResult* cpu) if (!IOObjectConformsTo(entryDevice, "AppleARMIODevice")) return "\"pmgr\" should conform to \"AppleARMIODevice\""; - FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef properties = NULL; - if (IORegistryEntryCreateCFProperties(entryDevice, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) - return "IORegistryEntryCreateCFProperties() failed"; - - uint32_t pMin, eMin, aMax, pCoreLength; - if (ffCfDictGetData(properties, CFSTR("voltage-states5-sram"), 0, 4, (uint8_t*) &pMin, &pCoreLength) != NULL) // pCore + FF_CFTYPE_AUTO_RELEASE CFDataRef pFreqProperty = (CFDataRef) IORegistryEntryCreateCFProperty(entryDevice, CFSTR("voltage-states5-sram"), kCFAllocatorDefault, kNilOptions); + if (CFGetTypeID(pFreqProperty) != CFDataGetTypeID()) return "\"voltage-states5-sram\" in \"pmgr\" is not found"; - if (ffCfDictGetData(properties, CFSTR("voltage-states1-sram"), 0, 4, (uint8_t*) &eMin, NULL) != NULL) // eCore - return "\"voltage-states1-sram\" in \"pmgr\" is not found"; - cpu->frequencyMin = (pMin < eMin ? pMin : eMin) / (1000.0 * 1000 * 1000); + // voltage-states5-sram stores supported frequencies of pcores from the lowest to the highest + CFIndex pCoreFreqLength = CFDataGetLength(pFreqProperty); + uint32_t* pStart = (uint32_t*) CFDataGetBytePtr(pFreqProperty); + uint32_t pMax = 0; + for (CFIndex i = 0; i < pCoreFreqLength && pStart[i] > 0; i += 4) + pMax = pMax > pStart[i] ? pMax : pStart[i]; - if (pCoreLength >= 8) - { - ffCfDictGetData(properties, CFSTR("voltage-states5-sram"), pCoreLength - 8, 4, (uint8_t*) &aMax, NULL); - cpu->frequencyMax = aMax / (1000.0 * 1000 * 1000); - } + if (pMax > 0) + cpu->frequencyMax = pMax / 1000.0 / 1000.0 / 1000.0; return NULL; } @@ -67,7 +64,6 @@ static const char* detectFrequency(FFCPUResult* cpu) static const char* detectFrequency(FFCPUResult* cpu) { cpu->frequencyBase = ffSysctlGetInt64("hw.cpufrequency", 0) / 1000.0 / 1000.0 / 1000.0; - cpu->frequencyMin = ffSysctlGetInt64("hw.cpufrequency_min", 0) / 1000.0 / 1000.0 / 1000.0; cpu->frequencyMax = ffSysctlGetInt64("hw.cpufrequency_max", 0) / 1000.0 / 1000.0 / 1000.0; if(cpu->frequencyBase != cpu->frequencyBase) { diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 582053eac..710963a1f 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -48,11 +48,6 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { // MHz/Watts pairs like: 2501/32000 2187/27125 2000/24000 uint32_t fmax = (uint32_t) strtoul(buffer.chars, NULL, 10); - uint32_t fmin = fmax; - uint32_t i = ffStrbufLastIndexC(&buffer, ' '); - if (i < buffer.length) - fmin = (uint32_t) strtoul(buffer.chars + i + 1, NULL, 10); - if (!(cpu->frequencyMin <= fmin)) cpu->frequencyMin = fmin; // Counting for NaN if (!(cpu->frequencyMax >= fmax)) cpu->frequencyMax = fmax; if (options->showPeCoreCount) @@ -66,7 +61,6 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) } } } - cpu->frequencyMin /= 1000; cpu->frequencyMax /= 1000; int clockRate = ffSysctlGetInt("hw.clockrate", 0); diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index 3a8df2565..2886fd2ff 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -165,14 +165,6 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options) else cpu->frequencyMax = fmax; } - uint32_t fmin = getFrequency(&path, "/cpuinfo_min_freq", "/scaling_min_freq", &buffer); - if (fmin > 0) - { - if (cpu->frequencyMin == cpu->frequencyMin) - cpu->frequencyMin = cpu->frequencyMin < fmin ? cpu->frequencyMin : fmin; - else - cpu->frequencyMin = fmin; - } if (options->showPeCoreCount) { @@ -189,7 +181,6 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options) } cpu->frequencyBase /= 1e6; cpu->frequencyMax /= 1e6; - cpu->frequencyMin /= 1e6; cpu->frequencyBiosLimit /= 1e6; return true; } diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 044284a63..20607ba84 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -17,7 +17,6 @@ void ffPrintCPU(FFCPUOptions* options) { FFCPUResult cpu = { .temperature = FF_CPU_TEMP_UNSET, - .frequencyMin = 0.0/0.0, .frequencyMax = 0.0/0.0, .frequencyBase = 0.0/0.0, .frequencyBiosLimit = 0.0/0.0, @@ -202,7 +201,6 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_ { FFCPUResult cpu = { .temperature = FF_CPU_TEMP_UNSET, - .frequencyMin = 0.0/0.0, .frequencyMax = 0.0/0.0, .frequencyBase = 0.0/0.0, .frequencyBiosLimit = 0.0/0.0, @@ -234,7 +232,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_real(doc, frequency, "base", cpu.frequencyBase); yyjson_mut_obj_add_real(doc, frequency, "max", cpu.frequencyMax); - yyjson_mut_obj_add_real(doc, frequency, "min", cpu.frequencyMin); yyjson_mut_obj_add_real(doc, frequency, "biosLimit", cpu.frequencyBiosLimit); yyjson_mut_val* coreTypes = yyjson_mut_obj_add_arr(doc, obj, "coreTypes"); diff --git a/src/modules/loadavg/loadavg.c b/src/modules/loadavg/loadavg.c index 42df9c60c..0fb9e73de 100644 --- a/src/modules/loadavg/loadavg.c +++ b/src/modules/loadavg/loadavg.c @@ -30,7 +30,6 @@ void ffPrintLoadavg(FFLoadavgOptions* options) { FFCPUResult cpu = { .temperature = FF_CPU_TEMP_UNSET, - .frequencyMin = 0.0/0.0, .frequencyMax = 0.0/0.0, .frequencyBase = 0.0/0.0, .frequencyBiosLimit = 0.0/0.0,