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
This commit is contained in:
Clement Tsang 2023-06-07 21:47:05 -04:00 committed by GitHub
parent 6dd4ea945b
commit 358bddf990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<Filter>,
) -> Result<Vec<TempHarvest>> {
@ -238,11 +241,12 @@ fn get_from_thermal_zone(
pub fn get_temperature_data(
temp_type: &TemperatureType, filter: &Option<Filter>,
) -> Result<Option<Vec<TempHarvest>>> {
let mut temperature_vec: Vec<TempHarvest> = get_from_hwmon(temp_type, filter)?;
let mut temperature_vec: Vec<TempHarvest> =
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")]