diff --git a/Cargo.lock b/Cargo.lock index 4c4b60c..e313ece 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,9 +41,9 @@ dependencies = [ [[package]] name = "amdgpu-sysfs" -version = "0.12.6" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b0082f43b383acea8205b8f86c121a24d430ee53be54cdb30a1b52d6cf425c" +checksum = "f7f8d22267077f74c2ec25a8d503acd5a935963716b9e0e9165a71a30b2b623b" dependencies = [ "enum_dispatch", "serde", diff --git a/lact-daemon/src/server/gpu_controller/mod.rs b/lact-daemon/src/server/gpu_controller/mod.rs index 4113744..3871eb8 100644 --- a/lact-daemon/src/server/gpu_controller/mod.rs +++ b/lact-daemon/src/server/gpu_controller/mod.rs @@ -2,7 +2,10 @@ pub mod fan_control; use self::fan_control::FanCurve; use super::vulkan::get_vulkan_info; -use crate::{config, fork::run_forked}; +use crate::{ + config::{self, ClocksConfiguration}, + fork::run_forked, +}; use anyhow::{anyhow, Context}; use lact_schema::{ amdgpu_sysfs::{ @@ -518,44 +521,8 @@ impl GpuController { self.handle.reset_clocks_table().ok(); if config.is_core_clocks_used() { - let clocks = config.clocks_configuration; let mut table = self.handle.get_clocks_table()?; - - if let ClocksTableGen::Vega20(ref mut table) = table { - // Avoid writing settings to the clocks table except the user-specified ones - // There is an issue on some GPU models where the default values are actually outside of the allowed range - // See https://github.com/sibradzic/amdgpu-clocks/issues/32#issuecomment-829953519 (part 2) for an example - - // Do not clear if there is a VDDC curve - if it's present settings cannot be reapplied without it, - // and GPU generations which have it do not suffer from the allowed range bug anyway - if table.vddc_curve.is_empty() { - table.clear(); - } - - table.voltage_offset = clocks.voltage_offset; - } - - if let Some(min_clockspeed) = clocks.min_core_clock { - table.set_min_sclk(min_clockspeed)?; - } - - if let Some(min_clockspeed) = clocks.min_memory_clock { - table.set_min_mclk(min_clockspeed)?; - } - - if let Some(min_voltage) = clocks.min_voltage { - table.set_min_voltage(min_voltage)?; - } - - if let Some(clockspeed) = clocks.max_core_clock { - table.set_max_sclk(clockspeed)?; - } - if let Some(clockspeed) = clocks.max_memory_clock { - table.set_max_mclk(clockspeed)?; - } - if let Some(voltage) = clocks.max_voltage { - table.set_max_voltage(voltage)?; - } + config.clocks_configuration.apply_to_table(&mut table)?; debug!("writing clocks commands: {:#?}", table.get_commands()?); @@ -593,3 +560,44 @@ fn get_drm_handle(handle: &GpuHandle) -> anyhow::Result { .map_err(|err| anyhow!("Could not open drm handle, error code {err}"))?; Ok(handle) } + +impl ClocksConfiguration { + fn apply_to_table(&self, table: &mut ClocksTableGen) -> anyhow::Result<()> { + if let ClocksTableGen::Vega20(ref mut table) = table { + // Avoid writing settings to the clocks table except the user-specified ones + // There is an issue on some GPU models where the default values are actually outside of the allowed range + // See https://github.com/sibradzic/amdgpu-clocks/issues/32#issuecomment-829953519 (part 2) for an example + + if table.vddc_curve.is_empty() { + table.clear(); + } + + // Normalize the VDDC curve - make sure all of the values are within the allowed range + table.normalize_vddc_curve(); + + table.voltage_offset = self.voltage_offset; + } + + if let Some(min_clockspeed) = self.min_core_clock { + table.set_min_sclk(min_clockspeed)?; + } + if let Some(min_clockspeed) = self.min_memory_clock { + table.set_min_mclk(min_clockspeed)?; + } + if let Some(min_voltage) = self.min_voltage { + table.set_min_voltage(min_voltage)?; + } + + if let Some(clockspeed) = self.max_core_clock { + table.set_max_sclk(clockspeed)?; + } + if let Some(clockspeed) = self.max_memory_clock { + table.set_max_mclk(clockspeed)?; + } + if let Some(voltage) = self.max_voltage { + table.set_max_voltage(voltage)?; + } + + Ok(()) + } +} diff --git a/lact-gui/src/app/mod.rs b/lact-gui/src/app/mod.rs index d406eed..27e7f9e 100644 --- a/lact-gui/src/app/mod.rs +++ b/lact-gui/src/app/mod.rs @@ -559,12 +559,16 @@ enum GuiUpdateMsg { } fn show_error(parent: &ApplicationWindow, err: anyhow::Error) { - let text = format!("{err:?}"); - warn!("{}", text.trim()); + let text = format!("{err:?}") + .lines() + .map(str::trim) + .collect::>() + .join("\n"); + warn!("{text}"); let diag = MessageDialog::builder() .title("Error") .message_type(MessageType::Error) - .text(&text) + .text(text) .buttons(ButtonsType::Close) .transient_for(parent) .build(); diff --git a/lact-schema/Cargo.toml b/lact-schema/Cargo.toml index 0b22034..7fabcaf 100644 --- a/lact-schema/Cargo.toml +++ b/lact-schema/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" args = ["clap"] [dependencies] -amdgpu-sysfs = { version = "0.12.6", features = ["serde"] } +amdgpu-sysfs = { version = "0.12.7", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } indexmap = { version = "*", features = ["serde"] } clap = { version = "4.4.6", features = ["derive"], optional = true }