From af6196fe6e3e216cd9281223c77e1950b7b25180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 10 Dec 2025 16:30:23 +0800 Subject: [PATCH] CPU (FreeBSD): supports `tempSensor` --- src/detection/cpu/cpu_bsd.c | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 1ba7bf846..aff68c2a2 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -8,22 +8,26 @@ #define FF_HAVE_CPUSET 1 #endif -static const char* detectCpuTemp(double* current) +static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { - int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999); - if (temp == -999999) - return "ffSysctlGetInt(\"dev.cpu.0.temperature\") failed"; - - // In tenth of degrees Kelvin - *current = (double) temp / 10 - 273.15; - return NULL; -} - -static const char* detectThermalTemp(double* current) -{ - int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999); - if (temp == -999999) - return "ffSysctlGetInt(\"hw.acpi.thermal.tz0.temperature\") failed"; + int temp; + if (options->tempSensor.length > 0) + { + temp = ffSysctlGetInt(options->tempSensor.chars, -999999); + if (temp == -999999) + return "ffSysctlGetInt(options->tempSensor) failed"; + } + else + { + temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999); + if (temp == -999999) + { + // Thermal zone temperature + temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999); + if (temp == -999999) + return "ffSysctlGetInt(\"dev.cpu.0.temperature\" or \"hw.acpi.thermal.tz0.temperature\") failed"; + } + } // In tenth of degrees Kelvin *current = (double) temp / 10 - 273.15; @@ -94,11 +98,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) cpu->temperature = FF_CPU_TEMP_UNSET; - if (options->temp) - { - if (detectCpuTemp(&cpu->temperature) != NULL) - detectThermalTemp(&cpu->temperature); - } + if (options->temp) detectCpuTemp(options, &cpu->temperature); cpu->numaNodes = (uint16_t) ffSysctlGetInt("vm.ndomains", 0);