fix: normalize VDDC curve before applying it

See https://github.com/ilya-zlobintsev/LACT/issues/212#issuecomment-1867115975
This commit is contained in:
Ilya Zlobintsev 2023-12-22 10:24:26 +02:00
parent 4f163fb323
commit 6790c7fa60
4 changed files with 56 additions and 44 deletions

4
Cargo.lock generated
View File

@ -41,9 +41,9 @@ dependencies = [
[[package]] [[package]]
name = "amdgpu-sysfs" name = "amdgpu-sysfs"
version = "0.12.6" version = "0.12.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99b0082f43b383acea8205b8f86c121a24d430ee53be54cdb30a1b52d6cf425c" checksum = "f7f8d22267077f74c2ec25a8d503acd5a935963716b9e0e9165a71a30b2b623b"
dependencies = [ dependencies = [
"enum_dispatch", "enum_dispatch",
"serde", "serde",

View File

@ -2,7 +2,10 @@ pub mod fan_control;
use self::fan_control::FanCurve; use self::fan_control::FanCurve;
use super::vulkan::get_vulkan_info; 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 anyhow::{anyhow, Context};
use lact_schema::{ use lact_schema::{
amdgpu_sysfs::{ amdgpu_sysfs::{
@ -518,44 +521,8 @@ impl GpuController {
self.handle.reset_clocks_table().ok(); self.handle.reset_clocks_table().ok();
if config.is_core_clocks_used() { if config.is_core_clocks_used() {
let clocks = config.clocks_configuration;
let mut table = self.handle.get_clocks_table()?; let mut table = self.handle.get_clocks_table()?;
config.clocks_configuration.apply_to_table(&mut 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)?;
}
debug!("writing clocks commands: {:#?}", table.get_commands()?); debug!("writing clocks commands: {:#?}", table.get_commands()?);
@ -593,3 +560,44 @@ fn get_drm_handle(handle: &GpuHandle) -> anyhow::Result<DrmHandle> {
.map_err(|err| anyhow!("Could not open drm handle, error code {err}"))?; .map_err(|err| anyhow!("Could not open drm handle, error code {err}"))?;
Ok(handle) 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(())
}
}

View File

@ -559,12 +559,16 @@ enum GuiUpdateMsg {
} }
fn show_error(parent: &ApplicationWindow, err: anyhow::Error) { fn show_error(parent: &ApplicationWindow, err: anyhow::Error) {
let text = format!("{err:?}"); let text = format!("{err:?}")
warn!("{}", text.trim()); .lines()
.map(str::trim)
.collect::<Vec<&str>>()
.join("\n");
warn!("{text}");
let diag = MessageDialog::builder() let diag = MessageDialog::builder()
.title("Error") .title("Error")
.message_type(MessageType::Error) .message_type(MessageType::Error)
.text(&text) .text(text)
.buttons(ButtonsType::Close) .buttons(ButtonsType::Close)
.transient_for(parent) .transient_for(parent)
.build(); .build();

View File

@ -7,7 +7,7 @@ edition = "2021"
args = ["clap"] args = ["clap"]
[dependencies] [dependencies]
amdgpu-sysfs = { version = "0.12.6", features = ["serde"] } amdgpu-sysfs = { version = "0.12.7", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
indexmap = { version = "*", features = ["serde"] } indexmap = { version = "*", features = ["serde"] }
clap = { version = "4.4.6", features = ["derive"], optional = true } clap = { version = "4.4.6", features = ["derive"], optional = true }