From 85597e4d46878ce2205fee3ef4fdea5985d9e111 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 22 Jun 2023 04:06:08 +0000 Subject: [PATCH] CPU (FreeBSD): actually support temp detection --- CMakeLists.txt | 2 +- src/detection/cpu/cpu_bsd.c | 12 +++--------- src/detection/gpu/gpu_linux.c | 7 +++++-- src/detection/temps/temps_bsd.c | 13 +++++++++++++ src/detection/temps/temps_bsd.h | 8 ++++++++ 5 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/detection/temps/temps_bsd.c create mode 100644 src/detection/temps/temps_bsd.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 36d44d31a..96cb3784e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -462,7 +462,7 @@ elseif(BSD) src/detection/gtk_qt/qt.c src/detection/sound/sound_linux.c src/detection/swap/swap_bsd.c - src/detection/temps/temps_linux.c + src/detection/temps/temps_bsd.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/theme/theme_linux.c diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 8f6ca0956..fe3315e61 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -1,5 +1,6 @@ #include "cpu.h" #include "common/sysctl.h" +#include "detection/temps/temps_bsd.h" const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFinstance* instance, const FFCPUOptions* options, FFCPUResult* cpu) { @@ -12,17 +13,10 @@ const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFinstance* instance, const FF cpu->frequencyMin = ffSysctlGetInt("hw.clockrate", 0) / 1000.0; cpu->frequencyMax = cpu->frequencyMin; + cpu->temperature = FF_CPU_TEMP_UNSET; if (options->temp) - { - FF_STRBUF_AUTO_DESTROY cpuTemp = ffStrbufCreate(); - if(ffSysctlGetString("hw.acpi.thermal.tz0.temperature", &cpuTemp)) - cpu->temperature = FF_CPU_TEMP_UNSET; - else - cpu->temperature = ffStrbufToDouble(&cpuTemp); - } - else - cpu->temperature = FF_CPU_TEMP_UNSET; + ffDetectThermalTemp(&cpu->temperature); return NULL; } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index f7f9a5a34..8b9478e1b 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -122,7 +122,7 @@ static void pciDetectDriverName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* } } -static void pciDetectTemperatur(FFGPUResult* gpu, struct pci_dev* device) +FF_MAYBE_UNUSED static void pciDetectTemperatur(FFGPUResult* gpu, struct pci_dev* device) { const FFTempsResult* tempsResult = ffDetectTemps(); @@ -171,7 +171,7 @@ static void detectType(FFGPUResult* gpu, const PCIData* pci, struct pci_dev* dev gpu->type = FF_GPU_TYPE_INTEGRATED; } -static void pciHandleDevice(const FFinstance* instance, const FFGPUOptions* options, FFlist* results, PCIData* pci, struct pci_dev* device) +static void pciHandleDevice(const FFinstance* instance, FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* results, PCIData* pci, struct pci_dev* device) { pci->ffpci_fill_info(device, PCI_FILL_CLASS); @@ -206,8 +206,11 @@ static void pciHandleDevice(const FFinstance* instance, const FFGPUOptions* opti gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->temperature = FF_GPU_TEMP_UNSET; + + #ifdef __linux__ if(options->temp) pciDetectTemperatur(gpu, device); + #endif } jmp_buf pciInitJmpBuf; diff --git a/src/detection/temps/temps_bsd.c b/src/detection/temps/temps_bsd.c new file mode 100644 index 000000000..39693d65d --- /dev/null +++ b/src/detection/temps/temps_bsd.c @@ -0,0 +1,13 @@ +#include "temps_bsd.h" +#include "common/sysctl.h" + +const char* ffDetectThermalTemp(double* current) +{ + int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999); + if (temp == -999999) + return "ffSysctlGetInt(\"hw.acpi.thermal.tz0.temperature\") failed"; + + // In tenth of degrees Kelvin + *current = (double) temp / 10 - 273.15; + return NULL; +} diff --git a/src/detection/temps/temps_bsd.h b/src/detection/temps/temps_bsd.h new file mode 100644 index 000000000..a41aba6bc --- /dev/null +++ b/src/detection/temps/temps_bsd.h @@ -0,0 +1,8 @@ +#pragma once + +#ifndef FF_INCLUDED_detection_temps_windows +#define FF_INCLUDED_detection_temps_windows + +const char* ffDetectThermalTemp(double* current); + +#endif