diff --git a/lact-daemon/src/server/gpu_controller/mod.rs b/lact-daemon/src/server/gpu_controller/mod.rs index 25ee588..15da3e3 100644 --- a/lact-daemon/src/server/gpu_controller/mod.rs +++ b/lact-daemon/src/server/gpu_controller/mod.rs @@ -19,6 +19,7 @@ use lact_schema::{ PciInfo, PmfwInfo, PowerState, PowerStates, PowerStats, VoltageStats, VramStats, }; use pciid_parser::Database; +use std::collections::BTreeMap; use std::{ borrow::Cow, cell::RefCell, @@ -309,9 +310,38 @@ impl GpuController { .get_pcie_clock_levels() .ok() .and_then(|levels| levels.active), + throttle_info: self.get_throttle_info(), } } + #[cfg(not(feature = "libdrm_amdgpu_sys"))] + fn get_throttle_info(&self) -> Option>> { + None + } + + #[cfg(feature = "libdrm_amdgpu_sys")] + fn get_throttle_info(&self) -> Option>> { + use libdrm_amdgpu_sys::AMDGPU::ThrottlerType; + + self.drm_handle + .as_ref() + .and_then(|drm_handle| drm_handle.get_gpu_metrics().ok()) + .and_then(|metrics| metrics.get_throttle_status_info()) + .map(|throttle| { + let mut result: BTreeMap> = BTreeMap::new(); + + for bit in throttle.get_all_throttler() { + let throttle_type = ThrottlerType::from(bit); + result + .entry(throttle_type.to_string()) + .or_default() + .push(bit.to_string()); + } + + result + }) + } + pub fn get_clocks_info(&self) -> anyhow::Result { let clocks_table = self .handle diff --git a/lact-gui/src/app/root_stack/oc_page/gpu_stats_section.rs b/lact-gui/src/app/root_stack/oc_page/gpu_stats_section.rs index 8d689a7..58450c5 100644 --- a/lact-gui/src/app/root_stack/oc_page/gpu_stats_section.rs +++ b/lact-gui/src/app/root_stack/oc_page/gpu_stats_section.rs @@ -61,6 +61,24 @@ impl GpuStatsSection { power_current.unwrap_or(0.0), power_cap_current.unwrap_or(0.0) )); + + match &stats.throttle_info { + Some(throttle_info) => { + if throttle_info.is_empty() { + self.set_throttling("No") + } else { + let type_text: Vec = throttle_info + .iter() + .map(|(throttle_type, details)| { + format!("{throttle_type} ({})", details.join(", ")) + }) + .collect(); + let text = type_text.join(", "); + self.set_throttling(text); + } + } + None => self.set_throttling("Unknown"), + } } } @@ -105,6 +123,8 @@ mod imp { vram_usage: RefCell, #[property(get, set)] vram_usage_text: RefCell, + #[property(get, set)] + throttling: RefCell, } #[glib::object_subclass] diff --git a/lact-gui/ui/oc_page/gpu_stats_section.blp b/lact-gui/ui/oc_page/gpu_stats_section.blp index 40db416..790a901 100644 --- a/lact-gui/ui/oc_page/gpu_stats_section.blp +++ b/lact-gui/ui/oc_page/gpu_stats_section.blp @@ -75,6 +75,11 @@ template $GpuStatsSection: $PageSection { name: "Power Usage:"; value: bind template.power-usage; } + + $InfoRow { + name: "Throttling:"; + value: bind template.throttling; + } } } } diff --git a/lact-schema/src/lib.rs b/lact-schema/src/lib.rs index 1f90c77..9d248ec 100644 --- a/lact-schema/src/lib.rs +++ b/lact-schema/src/lib.rs @@ -179,6 +179,7 @@ pub struct DeviceStats { pub core_power_state: Option, pub memory_power_state: Option, pub pcie_power_state: Option, + pub throttle_info: Option>>, } #[derive(Serialize, Deserialize, Debug, Clone)]