From e7df94495c624f112dc5d65129b43b82bce5e4e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 10 Oct 2023 09:28:31 +0800 Subject: [PATCH] Temp (FreeBSD): improve CPU temp detection --- src/detection/cpu/cpu_bsd.c | 5 ++++- src/detection/temps/temps_bsd.c | 11 +++++++++++ src/detection/temps/temps_bsd.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 835bdd4f6..2d6a1bd28 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -16,7 +16,10 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) cpu->temperature = FF_CPU_TEMP_UNSET; if (options->temp) - ffDetectThermalTemp(&cpu->temperature); + { + if (!ffDetectCpuTemp(&cpu->temperature)) + ffDetectThermalTemp(&cpu->temperature); + } return NULL; } diff --git a/src/detection/temps/temps_bsd.c b/src/detection/temps/temps_bsd.c index 39693d65d..2355ac8bf 100644 --- a/src/detection/temps/temps_bsd.c +++ b/src/detection/temps/temps_bsd.c @@ -1,6 +1,17 @@ #include "temps_bsd.h" #include "common/sysctl.h" +const char* ffDetectCpuTemp(double* current) +{ + int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999); + if (temp == -999999) + return "ffSysctlGetInt(\"dev.cpu.0.temperature\") failed"; + + // In tenth of degrees Celsius + *current = (double) temp / 10; + return NULL; +} + const char* ffDetectThermalTemp(double* current) { int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999); diff --git a/src/detection/temps/temps_bsd.h b/src/detection/temps/temps_bsd.h index a41aba6bc..b126811a0 100644 --- a/src/detection/temps/temps_bsd.h +++ b/src/detection/temps/temps_bsd.h @@ -3,6 +3,7 @@ #ifndef FF_INCLUDED_detection_temps_windows #define FF_INCLUDED_detection_temps_windows +const char* ffDetectCpuTemp(double* current); const char* ffDetectThermalTemp(double* current); #endif