From 373b4353bba03310f7bcbf25f3863ae257499c0b Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 13 Jan 2025 15:06:18 +0800 Subject: [PATCH] CPU (BSD): improve base freq detection --- src/detection/cpu/cpu_bsd.c | 3 ++- src/detection/cpu/cpu_nbsd.c | 3 +-- src/detection/cpu/cpu_obsd.c | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index a2ce3e5a8..bf1f29394 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -73,9 +73,10 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) CPU_SET(1, ¤tCPU); CPU_SET(2, ¤tCPU); cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), ¤tCPU); - ffCPUDetectSpeedByCpuid(cpu); #endif + ffCPUDetectSpeedByCpuid(cpu); + uint32_t clockrate = (uint32_t) ffSysctlGetInt("hw.clockrate", 0); if (clockrate > cpu->frequencyBase) cpu->frequencyBase = clockrate; cpu->temperature = FF_CPU_TEMP_UNSET; diff --git a/src/detection/cpu/cpu_nbsd.c b/src/detection/cpu/cpu_nbsd.c index 12e6bb4cd..4d9530b5a 100644 --- a/src/detection/cpu/cpu_nbsd.c +++ b/src/detection/cpu/cpu_nbsd.c @@ -58,8 +58,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) ffCPUDetectSpeedByCpuid(cpu); uint32_t freq = (uint32_t) ffSysctlGetInt("machdep.cpu.frequency.target", 0); - if (freq > cpu->frequencyBase) - cpu->frequencyBase = freq; + if (freq > cpu->frequencyBase) cpu->frequencyBase = freq; cpu->temperature = FF_CPU_TEMP_UNSET; diff --git a/src/detection/cpu/cpu_obsd.c b/src/detection/cpu/cpu_obsd.c index 298f064d6..33b754ddf 100644 --- a/src/detection/cpu/cpu_obsd.c +++ b/src/detection/cpu/cpu_obsd.c @@ -15,7 +15,9 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) ffCPUDetectSpeedByCpuid(cpu); - cpu->frequencyBase = (uint32_t) ffSysctlGetInt(CTL_HW, HW_CPUSPEED, 0); + uint32_t cpuspeed = (uint32_t) ffSysctlGetInt(CTL_HW, HW_CPUSPEED, 0); + if (cpuspeed > cpu->frequencyBase) cpu->frequencyBase = cpuspeed; + cpu->temperature = FF_CPU_TEMP_UNSET; if (options->temp) {