Fix clock speeds defaulting too low at wakeup when not set

This commit is contained in:
NGnius (Graham) 2022-09-13 17:09:51 -04:00
parent ba021c8f93
commit 6878897784
8 changed files with 18 additions and 9 deletions

2
backend/Cargo.lock generated
View file

@ -567,7 +567,7 @@ dependencies = [
[[package]]
name = "powertools-rs"
version = "1.0.3"
version = "1.0.4"
dependencies = [
"log",
"serde",

View file

@ -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

View file

@ -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();

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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,
}
}
}

View file

@ -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,
}
}
}

View file

@ -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",