From 0d68ae996c8bad3806cd36c64472bc0fc1d2ff23 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 1 Apr 2023 20:11:02 -0400 Subject: [PATCH 1/4] Reset PPT to max when limits disabled --- backend/src/settings/steam_deck/gpu.rs | 32 ++++++++++++++++++++++++++ backend/src/state/steam_deck/gpu.rs | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/backend/src/settings/steam_deck/gpu.rs b/backend/src/settings/steam_deck/gpu.rs index 596c6e0..cf168c8 100644 --- a/backend/src/settings/steam_deck/gpu.rs +++ b/backend/src/settings/steam_deck/gpu.rs @@ -199,6 +199,22 @@ impl Gpu { let mut errors = Vec::new(); // set fast PPT if let Some(fast_ppt) = &self.fast_ppt { + self.state.fast_ppt_set = true; + let fast_ppt_path = gpu_power_path(FAST_PPT); + usdpl_back::api::files::write_single(&fast_ppt_path, fast_ppt) + .map_err(|e| SettingError { + msg: format!( + "Failed to write `{}` to `{}`: {}", + fast_ppt, &fast_ppt_path, e + ), + setting: crate::settings::SettingVariant::Gpu, + }) + .unwrap_or_else(|e| { + errors.push(e); + }); + } else if self.state.fast_ppt_set { + self.state.fast_ppt_set = false; + let fast_ppt = self.limits.fast_ppt.max; let fast_ppt_path = gpu_power_path(FAST_PPT); usdpl_back::api::files::write_single(&fast_ppt_path, fast_ppt) .map_err(|e| SettingError { @@ -214,6 +230,22 @@ impl Gpu { } // set slow PPT if let Some(slow_ppt) = &self.slow_ppt { + self.state.slow_ppt_set = true; + let slow_ppt_path = gpu_power_path(SLOW_PPT); + usdpl_back::api::files::write_single(&slow_ppt_path, slow_ppt) + .map_err(|e| SettingError { + msg: format!( + "Failed to write `{}` to `{}`: {}", + slow_ppt, &slow_ppt_path, e + ), + setting: crate::settings::SettingVariant::Gpu, + }) + .unwrap_or_else(|e| { + errors.push(e); + }); + } else if self.state.slow_ppt_set { + self.state.slow_ppt_set = false; + let slow_ppt = self.limits.slow_ppt.max; let slow_ppt_path = gpu_power_path(SLOW_PPT); usdpl_back::api::files::write_single(&slow_ppt_path, slow_ppt) .map_err(|e| SettingError { diff --git a/backend/src/state/steam_deck/gpu.rs b/backend/src/state/steam_deck/gpu.rs index 3091f70..d7f31b1 100644 --- a/backend/src/state/steam_deck/gpu.rs +++ b/backend/src/state/steam_deck/gpu.rs @@ -1,6 +1,8 @@ #[derive(Debug, Clone)] pub struct Gpu { pub clock_limits_set: bool, + pub fast_ppt_set: bool, + pub slow_ppt_set: bool, pub is_resuming: bool, } @@ -8,6 +10,8 @@ impl std::default::Default for Gpu { fn default() -> Self { Self { clock_limits_set: true, + fast_ppt_set: false, + slow_ppt_set: false, is_resuming: false, } } From d654e3ee06a4915534eb91c4b7daec1f99499a35 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 1 Apr 2023 20:18:16 -0400 Subject: [PATCH 2/4] Remove redundant sysfs commit --- backend/src/api/handler.rs | 9 ++++--- backend/src/settings/steam_deck/cpu.rs | 35 ++++++++------------------ 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index 0b947ad..d44afb9 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -262,15 +262,16 @@ fn print_errors(call_name: &str, errors: Vec) { impl ApiMessageHandler { pub fn process_forever(&mut self, settings: &mut Settings) { - let mut dirty_echo = true; // set everything twice, to make sure PowerTools wins on race conditions + //let mut dirty_echo = true; // set everything twice, to make sure PowerTools wins on race conditions while let Ok(msg) = self.intake.recv() { let mut dirty = self.process(settings, msg); while let Ok(msg) = self.intake.try_recv() { dirty |= self.process(settings, msg); } - if dirty || dirty_echo { - dirty_echo = dirty; // echo only once - // run on_set + if dirty /*|| dirty_echo */ { + //dirty_echo = dirty; // echo only once + + // run on_set if let Err(e) = settings.on_set() { print_errors("on_set", e); } diff --git a/backend/src/settings/steam_deck/cpu.rs b/backend/src/settings/steam_deck/cpu.rs index 4b641f1..91ec128 100644 --- a/backend/src/settings/steam_deck/cpu.rs +++ b/backend/src/settings/steam_deck/cpu.rs @@ -300,14 +300,6 @@ impl Cpu { setting: crate::settings::SettingVariant::Cpu, }) .unwrap_or_else(|e| errors.push(e)); - usdpl_back::api::files::write_single(CPU_CLOCK_LIMITS_PATH, "c\n").unwrap_or_else( - |e| { - errors.push(SettingError { - msg: format!("Failed to write `c` to `{}`: {}", CPU_CLOCK_LIMITS_PATH, e), - setting: crate::settings::SettingVariant::Cpu, - }); - }, - ); } else if self.state.clock_limits_set || (self.state.is_resuming && !self.limits.skip_resume_reclock) || POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.needs_manual() @@ -339,17 +331,6 @@ impl Cpu { setting: crate::settings::SettingVariant::Cpu, }) .unwrap_or_else(|e| errors.push(e)); - usdpl_back::api::files::write_single(CPU_CLOCK_LIMITS_PATH, "c\n").unwrap_or_else( - |e| { - errors.push(SettingError { - msg: format!( - "Failed to write `c` to `{}`: {}", - CPU_CLOCK_LIMITS_PATH, e - ), - setting: crate::settings::SettingVariant::Cpu, - }); - }, - ); } POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.set_cpu(false, self.index); POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT @@ -358,12 +339,16 @@ impl Cpu { } // commit changes (if no errors have already occured) if errors.is_empty() { - usdpl_back::api::files::write_single(CPU_CLOCK_LIMITS_PATH, "c\n").map_err(|e| { - vec![SettingError { - msg: format!("Failed to write `c` to `{}`: {}", CPU_CLOCK_LIMITS_PATH, e), - setting: crate::settings::SettingVariant::Cpu, - }] - }) + if POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.needs_manual() { + usdpl_back::api::files::write_single(CPU_CLOCK_LIMITS_PATH, "c\n").map_err(|e| { + vec![SettingError { + msg: format!("Failed to write `c` to `{}`: {}", CPU_CLOCK_LIMITS_PATH, e), + setting: crate::settings::SettingVariant::Cpu, + }] + }) + } else { + Ok(()) + } } else { Err(errors) } From 2f8c0a017207018d62d04e266638635ddb3a5266 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 1 Apr 2023 20:43:26 -0400 Subject: [PATCH 3/4] Fix unecessary calls to on_set() from battery vibe checks and reset ppt to default instead of max --- backend/Cargo.lock | 2 +- backend/Cargo.toml | 2 +- backend/src/api/handler.rs | 2 +- backend/src/resume_worker.rs | 2 +- backend/src/settings/general.rs | 10 +++++----- backend/src/settings/steam_deck/gpu.rs | 4 ++-- backend/src/settings/steam_deck/oc_limits.rs | 4 ++++ package.json | 2 +- pt_oc.json | 2 ++ 9 files changed, 18 insertions(+), 12 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 4aa53b0..f8baccd 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1053,7 +1053,7 @@ dependencies = [ [[package]] name = "powertools" -version = "1.3.0-beta4" +version = "1.4.0-alpha" dependencies = [ "async-trait", "libryzenadj", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 0ceb00f..c441c74 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "powertools" -version = "1.3.0-beta4" +version = "1.4.0-alpha" edition = "2021" authors = ["NGnius (Graham) "] description = "Backend (superuser) functionality for PowerTools" diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index d44afb9..57f57f5 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -355,7 +355,7 @@ impl ApiMessageHandler { } } } - true + false // on_power_event() should apply everything } ApiMessage::WaitForEmptyQueue(callback) => { self.on_empty.push(callback); diff --git a/backend/src/resume_worker.rs b/backend/src/resume_worker.rs index ca5c639..dfa4d8f 100644 --- a/backend/src/resume_worker.rs +++ b/backend/src/resume_worker.rs @@ -10,7 +10,7 @@ const ALLOWED_ERROR: f64 = 100.0; // period of 10ms with 100x means sleep has to pub fn spawn(sender: Sender) -> JoinHandle<()> { thread::spawn(move || { log::info!("resume_worker starting..."); - let duration = Duration::from_millis(10); // very low so it detects before Steam client does + let duration = Duration::from_millis(50); // very low so it detects before Steam client does // this allows PowerTools to set some values at wakeup and Steam to override them before user notices let mut start = Instant::now(); loop { diff --git a/backend/src/settings/general.rs b/backend/src/settings/general.rs index 348b10f..5e39694 100644 --- a/backend/src/settings/general.rs +++ b/backend/src/settings/general.rs @@ -96,23 +96,23 @@ impl OnSet for Settings { fn on_set(&mut self) -> Result<(), Vec> { let mut errors = Vec::new(); - log::debug!("Applying settings for on_resume"); + log::debug!("Applying settings for on_set"); self.general .on_set() .unwrap_or_else(|mut e| errors.append(&mut e)); - log::debug!("Resumed general"); + log::debug!("Set general"); self.battery .on_set() .unwrap_or_else(|mut e| errors.append(&mut e)); - log::debug!("Resumed battery"); + log::debug!("Set battery"); self.cpus .on_set() .unwrap_or_else(|mut e| errors.append(&mut e)); - log::debug!("Resumed CPUs"); + log::debug!("Set CPUs"); self.gpu .on_set() .unwrap_or_else(|mut e| errors.append(&mut e)); - log::debug!("Resumed GPU"); + log::debug!("Set GPU"); if errors.is_empty() { Ok(()) diff --git a/backend/src/settings/steam_deck/gpu.rs b/backend/src/settings/steam_deck/gpu.rs index cf168c8..83bf2bd 100644 --- a/backend/src/settings/steam_deck/gpu.rs +++ b/backend/src/settings/steam_deck/gpu.rs @@ -214,7 +214,7 @@ impl Gpu { }); } else if self.state.fast_ppt_set { self.state.fast_ppt_set = false; - let fast_ppt = self.limits.fast_ppt.max; + let fast_ppt = self.limits.fast_ppt_default; let fast_ppt_path = gpu_power_path(FAST_PPT); usdpl_back::api::files::write_single(&fast_ppt_path, fast_ppt) .map_err(|e| SettingError { @@ -245,7 +245,7 @@ impl Gpu { }); } else if self.state.slow_ppt_set { self.state.slow_ppt_set = false; - let slow_ppt = self.limits.slow_ppt.max; + let slow_ppt = self.limits.slow_ppt_default; let slow_ppt_path = gpu_power_path(SLOW_PPT); usdpl_back::api::files::write_single(&slow_ppt_path, slow_ppt) .map_err(|e| SettingError { diff --git a/backend/src/settings/steam_deck/oc_limits.rs b/backend/src/settings/steam_deck/oc_limits.rs index 29aae00..d0cbeac 100644 --- a/backend/src/settings/steam_deck/oc_limits.rs +++ b/backend/src/settings/steam_deck/oc_limits.rs @@ -123,7 +123,9 @@ impl Default for CpuLimits { #[derive(Serialize, Deserialize, Clone, Debug)] pub(super) struct GpuLimits { pub fast_ppt: MinMax, + pub fast_ppt_default: u64, pub slow_ppt: MinMax, + pub slow_ppt_default: u64, pub ppt_divisor: u64, pub ppt_step: u64, pub clock_min: MinMax, @@ -139,10 +141,12 @@ impl Default for GpuLimits { min: 1000000, max: 30_000_000, }, + fast_ppt_default: 15_000_000, slow_ppt: MinMax { min: 1000000, max: 29_000_000, }, + slow_ppt_default: 15_000_000, ppt_divisor: 1_000_000, ppt_step: 1, clock_min: MinMax { diff --git a/package.json b/package.json index 81359e9..993f9aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PowerTools", - "version": "1.3.0-beta4", + "version": "1.4.0-alpha", "description": "Power tweaks for power users", "scripts": { "build": "shx rm -rf dist && rollup -c", diff --git a/pt_oc.json b/pt_oc.json index 3ee8234..79d3c37 100644 --- a/pt_oc.json +++ b/pt_oc.json @@ -111,10 +111,12 @@ "min": 1000000, "max": 30000000 }, + "fast_ppt_default": 15000000, "slow_ppt": { "min": 1000000, "max": 29000000 }, + "slow_ppt_default": 15000000, "ppt_divisor": 1000000, "ppt_step": 1, "clock_min": { From 533beaf289505ef9467ac58d4d150218374b6a87 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 2 Apr 2023 13:36:33 -0400 Subject: [PATCH 4/4] Fix loading battery settings from json, update some deps --- backend/Cargo.lock | 20 ++++++++++---------- backend/build-docker.sh | 2 +- backend/src/settings/steam_deck/battery.rs | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index f8baccd..0f3aad4 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -85,7 +85,7 @@ checksum = "0e97ce7de6cf12de5d7226c73f5ba9811622f4db3a5b91b55c53e987e5f91cba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.13", ] [[package]] @@ -96,7 +96,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.13", ] [[package]] @@ -330,7 +330,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.12", + "syn 2.0.13", ] [[package]] @@ -347,7 +347,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.13", ] [[package]] @@ -1086,9 +1086,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.54" +version = "1.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" +checksum = "1d0dd4be24fcdcfeaa12a432d588dc59bbad6cad3510c67e74a2b6b2fc950564" dependencies = [ "unicode-ident", ] @@ -1199,7 +1199,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.13", ] [[package]] @@ -1291,9 +1291,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.12" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" dependencies = [ "proc-macro2", "quote", @@ -1326,7 +1326,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.13", ] [[package]] diff --git a/backend/build-docker.sh b/backend/build-docker.sh index a8f84b1..9736989 100755 --- a/backend/build-docker.sh +++ b/backend/build-docker.sh @@ -10,7 +10,7 @@ mkdir -p out echo "--- Building ryzenadj lib ---" git clone https://github.com/FlyGoat/RyzenAdj ryzenadj cd ryzenadj -git checkout -q 187549bd0a92f84508161aabfd958b09540c7e56 +git checkout -q 160502771054d31d2f4c2fa46ad42c96336f3a74 mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release .. make diff --git a/backend/src/settings/steam_deck/battery.rs b/backend/src/settings/steam_deck/battery.rs index 2c939ac..4a5305c 100644 --- a/backend/src/settings/steam_deck/battery.rs +++ b/backend/src/settings/steam_deck/battery.rs @@ -93,18 +93,18 @@ impl EventInstruction { #[inline] fn str_to_trigger(s: &str) -> Option { match s { - "normal" => Some(EventTrigger::PluggedIn), - "idle" => Some(EventTrigger::PluggedOut), + "plug-in" => Some(EventTrigger::PluggedIn), + "plug-out" => Some(EventTrigger::PluggedOut), s if s.starts_with('>') => s .trim_start_matches('>') .parse::() .ok() - .map(|x| EventTrigger::BatteryAbove(x)), + .map(|x| EventTrigger::BatteryAbove(x/100.0)), s if s.starts_with('<') => s .trim_start_matches('<') .parse::() .ok() - .map(|x| EventTrigger::BatteryBelow(x)), + .map(|x| EventTrigger::BatteryBelow(x/100.0)), _ => None, } }