From 6878897784b49ac6f05180d47fac02eb1b857dc9 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Tue, 13 Sep 2022 17:09:51 -0400 Subject: [PATCH] Fix clock speeds defaulting too low at wakeup when not set --- backend/Cargo.lock | 2 +- backend/Cargo.toml | 2 +- backend/src/resume_worker.rs | 5 +++-- backend/src/settings/cpu.rs | 6 ++++-- backend/src/settings/gpu.rs | 6 ++++-- backend/src/state/cpu.rs | 2 ++ backend/src/state/gpu.rs | 2 ++ package.json | 2 +- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 718fc0a..223334d 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -567,7 +567,7 @@ dependencies = [ [[package]] name = "powertools-rs" -version = "1.0.3" +version = "1.0.4" dependencies = [ "log", "serde", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 1fda63f..769e94a 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "powertools-rs" -version = "1.0.3" +version = "1.0.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/backend/src/resume_worker.rs b/backend/src/resume_worker.rs index 40bed26..9560d84 100644 --- a/backend/src/resume_worker.rs +++ b/backend/src/resume_worker.rs @@ -4,12 +4,13 @@ use std::time::{Duration, Instant}; use crate::settings::{OnResume, Settings}; use crate::utility::unwrap_maybe_fatal; -const ALLOWED_ERROR: f64 = 0.001; +const ALLOWED_ERROR: f64 = 100.0; // period of 10ms with 100x means sleep has to be >= 1s to be detected pub fn spawn(settings: Settings) -> JoinHandle<()> { thread::spawn(move || { log::info!("resume_worker starting..."); - let duration = Duration::from_millis(5000); + let duration = Duration::from_millis(10); // 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 { let old_start = start.elapsed(); diff --git a/backend/src/settings/cpu.rs b/backend/src/settings/cpu.rs index 70e465a..dd27ab7 100644 --- a/backend/src/settings/cpu.rs +++ b/backend/src/settings/cpu.rs @@ -90,7 +90,7 @@ impl Cpu { setting: super::SettingVariant::Cpu, }, )?; - } else if self.state.clock_limits_set { + } else if self.state.clock_limits_set || self.state.is_resuming { self.state.clock_limits_set = false; // disable manual clock limits log::debug!("Setting CPU {} to default clockspeed", self.index); @@ -209,7 +209,9 @@ impl OnSet for Cpu { impl OnResume for Cpu { fn on_resume(&self) -> Result<(), SettingError> { - self.clone().set_all() + let mut copy = self.clone(); + copy.state.is_resuming = true; + copy.set_all() } } diff --git a/backend/src/settings/gpu.rs b/backend/src/settings/gpu.rs index ae950e9..3a3b15a 100644 --- a/backend/src/settings/gpu.rs +++ b/backend/src/settings/gpu.rs @@ -114,7 +114,7 @@ impl Gpu { setting: super::SettingVariant::Gpu, }, )?; - } else if self.state.clock_limits_set { + } else if self.state.clock_limits_set || self.state.is_resuming { self.state.clock_limits_set = false; // disable manual clock limits // max clock @@ -206,7 +206,9 @@ impl OnSet for Gpu { impl OnResume for Gpu { fn on_resume(&self) -> Result<(), SettingError> { - self.clone().set_all() + let mut copy = self.clone(); + copy.state.is_resuming = true; + copy.set_all() } } diff --git a/backend/src/state/cpu.rs b/backend/src/state/cpu.rs index 8f9a083..e122115 100644 --- a/backend/src/state/cpu.rs +++ b/backend/src/state/cpu.rs @@ -1,12 +1,14 @@ #[derive(Debug, Clone)] pub struct Cpu { pub clock_limits_set: bool, + pub is_resuming: bool, } impl std::default::Default for Cpu { fn default() -> Self { Self { clock_limits_set: false, + is_resuming: false, } } } diff --git a/backend/src/state/gpu.rs b/backend/src/state/gpu.rs index ab39b11..fd3e6de 100644 --- a/backend/src/state/gpu.rs +++ b/backend/src/state/gpu.rs @@ -1,12 +1,14 @@ #[derive(Debug, Clone)] pub struct Gpu { pub clock_limits_set: bool, + pub is_resuming: bool, } impl std::default::Default for Gpu { fn default() -> Self { Self { clock_limits_set: false, + is_resuming: false, } } } diff --git a/package.json b/package.json index 6ec7639..f1a707b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "PowerTools", - "version": "1.0.3", + "version": "1.0.4", "description": "Power tweaks for power users", "scripts": { "build": "shx rm -rf dist && rollup -c",