From 358bddf990e204f1de7fb20a133a14e1af2bbe43 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:47:05 -0400 Subject: [PATCH] bug: when getting Linux temps, don't bail ASAP if they fail (#1186) * bug: when getting Linux temps, don't bail ASAP if they fail This meant that if hwmon failed, it would never try and get temperatures from thermal or GPU. The same is true for thermal failing leading to GPU never running. * update docs --- src/app/data_harvester/temperature/linux.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/data_harvester/temperature/linux.rs b/src/app/data_harvester/temperature/linux.rs index 8e5f7674..c3f250ec 100644 --- a/src/app/data_harvester/temperature/linux.rs +++ b/src/app/data_harvester/temperature/linux.rs @@ -11,8 +11,9 @@ use crate::app::{ }; /// Get temperature sensors from the linux sysfs interface `/sys/class/hwmon`. -/// See [here](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-hwmon) for -/// details. +/// +/// See [the Linux kernel documentation](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-hwmon) +/// for more details. /// /// This method will return `0` as the temperature for devices, such as GPUs, /// that support power management features and power themselves off. @@ -191,8 +192,10 @@ fn get_from_hwmon( } /// Gets data from `/sys/class/thermal/thermal_zone*`. This should only be used if -/// [`get_from_hwmon`] doesn't return anything. See -/// [here](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal) for details. +/// [`get_from_hwmon`] doesn't return anything. +/// +/// See [the Linux kernel documentation](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal) +/// for more details. fn get_from_thermal_zone( temp_type: &TemperatureType, filter: &Option, ) -> Result> { @@ -238,11 +241,12 @@ fn get_from_thermal_zone( pub fn get_temperature_data( temp_type: &TemperatureType, filter: &Option, ) -> Result>> { - let mut temperature_vec: Vec = get_from_hwmon(temp_type, filter)?; + let mut temperature_vec: Vec = + get_from_hwmon(temp_type, filter).unwrap_or_default(); if temperature_vec.is_empty() { - // If it's empty, fall back to checking `thermal_zone*`. - temperature_vec = get_from_thermal_zone(temp_type, filter)?; + // If it's empty, try to fall back to checking `thermal_zone*`. + temperature_vec = get_from_thermal_zone(temp_type, filter).unwrap_or_default(); } #[cfg(feature = "nvidia")]