diff options
author | Daniel Lange <DLange@git.local> | 2024-01-10 12:40:37 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2024-01-10 12:40:37 +0100 |
commit | 7271b076b82785ffca73ee9e4ae84cabb77018ee (patch) | |
tree | e8270dd60ec096bee8157dbadf029e15ed584592 /linux/LibSensors.c | |
parent | f288666edc9180a2e81e6655951878124f321df6 (diff) | |
download | debian_htop-7271b076b82785ffca73ee9e4ae84cabb77018ee.tar.gz debian_htop-7271b076b82785ffca73ee9e4ae84cabb77018ee.tar.bz2 debian_htop-7271b076b82785ffca73ee9e4ae84cabb77018ee.zip |
New upstream version 3.3.0upstream/3.3.0upstream
Diffstat (limited to 'linux/LibSensors.c')
-rw-r--r-- | linux/LibSensors.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/linux/LibSensors.c b/linux/LibSensors.c index 9a27fe5..5373416 100644 --- a/linux/LibSensors.c +++ b/linux/LibSensors.c @@ -1,6 +1,13 @@ -#include "linux/LibSensors.h" +/* +htop - linux/LibSensors.c +(C) 2020-2023 htop dev team +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep -#include "config.h" +#include "linux/LibSensors.h" #ifdef HAVE_SENSORS_SENSORS_H @@ -9,14 +16,15 @@ #include <errno.h> #include <limits.h> #include <math.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> + #include <sensors/sensors.h> #include "Macros.h" #include "XUtils.h" -#include "linux/LinuxProcessList.h" +#include "linux/LinuxMachine.h" #ifdef BUILD_STATIC @@ -143,7 +151,8 @@ static int tempDriverPriority(const sensors_chip_name* chip) { void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, unsigned int activeCPUs) { assert(existingCPUs > 0 && existingCPUs < 16384); - double data[existingCPUs + 1]; + + double* data = xMallocArray(existingCPUs + 1, sizeof(double)); for (size_t i = 0; i < existingCPUs + 1; i++) data[i] = NAN; @@ -200,7 +209,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns continue; /* If already set, e.g. Ryzen reporting platform temperature for each die, use the bigger one */ - if (isnan(data[tempID])) { + if (isNaN(data[tempID])) { data[tempID] = temp; if (tempID > 0) coreTempCount++; @@ -220,7 +229,7 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns } /* Only package temperature - copy to all cores */ - if (coreTempCount == 0 && !isnan(data[0])) { + if (coreTempCount == 0 && !isNaN(data[0])) { for (unsigned int i = 1; i <= existingCPUs; i++) data[i] = data[0]; @@ -229,22 +238,20 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns } /* No package temperature - set to max core temperature */ - if (isnan(data[0]) && coreTempCount != 0) { - double maxTemp = NAN; + if (coreTempCount > 0 && isNaN(data[0])) { + double maxTemp = -HUGE_VAL; for (unsigned int i = 1; i <= existingCPUs; i++) { - if (isnan(data[i])) - continue; - - maxTemp = MAXIMUM(maxTemp, data[i]); + if (isgreater(data[i], maxTemp)) { + maxTemp = data[i]; + data[0] = data[i]; + } } - data[0] = maxTemp; - /* Check for further adjustments */ } /* Only temperature for core 0, maybe Ryzen - copy to all other cores */ - if (coreTempCount == 1 && !isnan(data[1])) { + if (coreTempCount == 1 && !isNaN(data[1])) { for (unsigned int i = 2; i <= existingCPUs; i++) data[i] = data[1]; @@ -264,6 +271,8 @@ void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int existingCPUs, uns out: for (unsigned int i = 0; i <= existingCPUs; i++) cpus[i].temperature = data[i]; + + free(data); } #endif /* HAVE_SENSORS_SENSORS_H */ |