Merge branch 'dev'

This commit is contained in:
NGnius (Graham) 2023-04-02 22:47:59 -04:00
commit 2c1321b544
13 changed files with 82 additions and 54 deletions

22
backend/Cargo.lock generated
View file

@ -85,7 +85,7 @@ checksum = "0e97ce7de6cf12de5d7226c73f5ba9811622f4db3a5b91b55c53e987e5f91cba"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.12", "syn 2.0.13",
] ]
[[package]] [[package]]
@ -96,7 +96,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.12", "syn 2.0.13",
] ]
[[package]] [[package]]
@ -330,7 +330,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"scratch", "scratch",
"syn 2.0.12", "syn 2.0.13",
] ]
[[package]] [[package]]
@ -347,7 +347,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.12", "syn 2.0.13",
] ]
[[package]] [[package]]
@ -1053,7 +1053,7 @@ dependencies = [
[[package]] [[package]]
name = "powertools" name = "powertools"
version = "1.3.0" version = "1.3.1"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"libryzenadj", "libryzenadj",
@ -1086,9 +1086,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.54" version = "1.0.55"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" checksum = "1d0dd4be24fcdcfeaa12a432d588dc59bbad6cad3510c67e74a2b6b2fc950564"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1199,7 +1199,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.12", "syn 2.0.13",
] ]
[[package]] [[package]]
@ -1291,9 +1291,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.12" version = "2.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1326,7 +1326,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.12", "syn 2.0.13",
] ]
[[package]] [[package]]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "powertools" name = "powertools"
version = "1.3.0" version = "1.3.1"
edition = "2021" edition = "2021"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"] authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
description = "Backend (superuser) functionality for PowerTools" description = "Backend (superuser) functionality for PowerTools"

View file

@ -10,7 +10,7 @@ mkdir -p out
echo "--- Building ryzenadj lib ---" echo "--- Building ryzenadj lib ---"
git clone https://github.com/FlyGoat/RyzenAdj ryzenadj git clone https://github.com/FlyGoat/RyzenAdj ryzenadj
cd ryzenadj cd ryzenadj
git checkout -q 187549bd0a92f84508161aabfd958b09540c7e56 git checkout -q 160502771054d31d2f4c2fa46ad42c96336f3a74
mkdir build && cd build mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. cmake -DCMAKE_BUILD_TYPE=Release ..
make make

View file

@ -262,15 +262,16 @@ fn print_errors(call_name: &str, errors: Vec<crate::settings::SettingError>) {
impl ApiMessageHandler { impl ApiMessageHandler {
pub fn process_forever(&mut self, settings: &mut Settings) { 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() { while let Ok(msg) = self.intake.recv() {
let mut dirty = self.process(settings, msg); let mut dirty = self.process(settings, msg);
while let Ok(msg) = self.intake.try_recv() { while let Ok(msg) = self.intake.try_recv() {
dirty |= self.process(settings, msg); dirty |= self.process(settings, msg);
} }
if dirty || dirty_echo { if dirty /*|| dirty_echo */ {
dirty_echo = dirty; // echo only once //dirty_echo = dirty; // echo only once
// run on_set
// run on_set
if let Err(e) = settings.on_set() { if let Err(e) = settings.on_set() {
print_errors("on_set", e); print_errors("on_set", e);
} }
@ -354,7 +355,7 @@ impl ApiMessageHandler {
} }
} }
} }
true false // on_power_event() should apply everything
} }
ApiMessage::WaitForEmptyQueue(callback) => { ApiMessage::WaitForEmptyQueue(callback) => {
self.on_empty.push(callback); self.on_empty.push(callback);

View file

@ -10,7 +10,7 @@ const ALLOWED_ERROR: f64 = 100.0; // period of 10ms with 100x means sleep has to
pub fn spawn(sender: Sender<ApiMessage>) -> JoinHandle<()> { pub fn spawn(sender: Sender<ApiMessage>) -> JoinHandle<()> {
thread::spawn(move || { thread::spawn(move || {
log::info!("resume_worker starting..."); 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 // this allows PowerTools to set some values at wakeup and Steam to override them before user notices
let mut start = Instant::now(); let mut start = Instant::now();
loop { loop {

View file

@ -96,23 +96,23 @@ impl OnSet for Settings {
fn on_set(&mut self) -> Result<(), Vec<SettingError>> { fn on_set(&mut self) -> Result<(), Vec<SettingError>> {
let mut errors = Vec::new(); let mut errors = Vec::new();
log::debug!("Applying settings for on_resume"); log::debug!("Applying settings for on_set");
self.general self.general
.on_set() .on_set()
.unwrap_or_else(|mut e| errors.append(&mut e)); .unwrap_or_else(|mut e| errors.append(&mut e));
log::debug!("Resumed general"); log::debug!("Set general");
self.battery self.battery
.on_set() .on_set()
.unwrap_or_else(|mut e| errors.append(&mut e)); .unwrap_or_else(|mut e| errors.append(&mut e));
log::debug!("Resumed battery"); log::debug!("Set battery");
self.cpus self.cpus
.on_set() .on_set()
.unwrap_or_else(|mut e| errors.append(&mut e)); .unwrap_or_else(|mut e| errors.append(&mut e));
log::debug!("Resumed CPUs"); log::debug!("Set CPUs");
self.gpu self.gpu
.on_set() .on_set()
.unwrap_or_else(|mut e| errors.append(&mut e)); .unwrap_or_else(|mut e| errors.append(&mut e));
log::debug!("Resumed GPU"); log::debug!("Set GPU");
if errors.is_empty() { if errors.is_empty() {
Ok(()) Ok(())

View file

@ -93,18 +93,18 @@ impl EventInstruction {
#[inline] #[inline]
fn str_to_trigger(s: &str) -> Option<EventTrigger> { fn str_to_trigger(s: &str) -> Option<EventTrigger> {
match s { match s {
"normal" => Some(EventTrigger::PluggedIn), "plug-in" => Some(EventTrigger::PluggedIn),
"idle" => Some(EventTrigger::PluggedOut), "plug-out" => Some(EventTrigger::PluggedOut),
s if s.starts_with('>') => s s if s.starts_with('>') => s
.trim_start_matches('>') .trim_start_matches('>')
.parse::<f64>() .parse::<f64>()
.ok() .ok()
.map(|x| EventTrigger::BatteryAbove(x)), .map(|x| EventTrigger::BatteryAbove(x/100.0)),
s if s.starts_with('<') => s s if s.starts_with('<') => s
.trim_start_matches('<') .trim_start_matches('<')
.parse::<f64>() .parse::<f64>()
.ok() .ok()
.map(|x| EventTrigger::BatteryBelow(x)), .map(|x| EventTrigger::BatteryBelow(x/100.0)),
_ => None, _ => None,
} }
} }

View file

@ -300,14 +300,6 @@ impl Cpu {
setting: crate::settings::SettingVariant::Cpu, setting: crate::settings::SettingVariant::Cpu,
}) })
.unwrap_or_else(|e| errors.push(e)); .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 } else if self.state.clock_limits_set
|| (self.state.is_resuming && !self.limits.skip_resume_reclock) || (self.state.is_resuming && !self.limits.skip_resume_reclock)
|| POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.needs_manual() || POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.needs_manual()
@ -339,17 +331,6 @@ impl Cpu {
setting: crate::settings::SettingVariant::Cpu, setting: crate::settings::SettingVariant::Cpu,
}) })
.unwrap_or_else(|e| errors.push(e)); .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.set_cpu(false, self.index);
POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT
@ -358,12 +339,16 @@ impl Cpu {
} }
// commit changes (if no errors have already occured) // commit changes (if no errors have already occured)
if errors.is_empty() { if errors.is_empty() {
usdpl_back::api::files::write_single(CPU_CLOCK_LIMITS_PATH, "c\n").map_err(|e| { if POWER_DPM_FORCE_PERFORMANCE_LEVEL_MGMT.needs_manual() {
vec![SettingError { usdpl_back::api::files::write_single(CPU_CLOCK_LIMITS_PATH, "c\n").map_err(|e| {
msg: format!("Failed to write `c` to `{}`: {}", CPU_CLOCK_LIMITS_PATH, e), vec![SettingError {
setting: crate::settings::SettingVariant::Cpu, msg: format!("Failed to write `c` to `{}`: {}", CPU_CLOCK_LIMITS_PATH, e),
}] setting: crate::settings::SettingVariant::Cpu,
}) }]
})
} else {
Ok(())
}
} else { } else {
Err(errors) Err(errors)
} }

View file

@ -199,6 +199,22 @@ impl Gpu {
let mut errors = Vec::new(); let mut errors = Vec::new();
// set fast PPT // set fast PPT
if let Some(fast_ppt) = &self.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_default;
let fast_ppt_path = gpu_power_path(FAST_PPT); let fast_ppt_path = gpu_power_path(FAST_PPT);
usdpl_back::api::files::write_single(&fast_ppt_path, fast_ppt) usdpl_back::api::files::write_single(&fast_ppt_path, fast_ppt)
.map_err(|e| SettingError { .map_err(|e| SettingError {
@ -214,6 +230,22 @@ impl Gpu {
} }
// set slow PPT // set slow PPT
if let Some(slow_ppt) = &self.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_default;
let slow_ppt_path = gpu_power_path(SLOW_PPT); let slow_ppt_path = gpu_power_path(SLOW_PPT);
usdpl_back::api::files::write_single(&slow_ppt_path, slow_ppt) usdpl_back::api::files::write_single(&slow_ppt_path, slow_ppt)
.map_err(|e| SettingError { .map_err(|e| SettingError {

View file

@ -123,7 +123,9 @@ impl Default for CpuLimits {
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub(super) struct GpuLimits { pub(super) struct GpuLimits {
pub fast_ppt: MinMax<u64>, pub fast_ppt: MinMax<u64>,
pub fast_ppt_default: u64,
pub slow_ppt: MinMax<u64>, pub slow_ppt: MinMax<u64>,
pub slow_ppt_default: u64,
pub ppt_divisor: u64, pub ppt_divisor: u64,
pub ppt_step: u64, pub ppt_step: u64,
pub clock_min: MinMax<u64>, pub clock_min: MinMax<u64>,
@ -139,10 +141,12 @@ impl Default for GpuLimits {
min: 1000000, min: 1000000,
max: 30_000_000, max: 30_000_000,
}, },
fast_ppt_default: 15_000_000,
slow_ppt: MinMax { slow_ppt: MinMax {
min: 1000000, min: 1000000,
max: 29_000_000, max: 29_000_000,
}, },
slow_ppt_default: 15_000_000,
ppt_divisor: 1_000_000, ppt_divisor: 1_000_000,
ppt_step: 1, ppt_step: 1,
clock_min: MinMax { clock_min: MinMax {

View file

@ -1,6 +1,8 @@
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Gpu { pub struct Gpu {
pub clock_limits_set: bool, pub clock_limits_set: bool,
pub fast_ppt_set: bool,
pub slow_ppt_set: bool,
pub is_resuming: bool, pub is_resuming: bool,
} }
@ -8,6 +10,8 @@ impl std::default::Default for Gpu {
fn default() -> Self { fn default() -> Self {
Self { Self {
clock_limits_set: true, clock_limits_set: true,
fast_ppt_set: false,
slow_ppt_set: false,
is_resuming: false, is_resuming: false,
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "PowerTools", "name": "PowerTools",
"version": "1.3.0", "version": "1.3.1",
"description": "Power tweaks for power users", "description": "Power tweaks for power users",
"scripts": { "scripts": {
"build": "shx rm -rf dist && rollup -c", "build": "shx rm -rf dist && rollup -c",

View file

@ -111,10 +111,12 @@
"min": 1000000, "min": 1000000,
"max": 30000000 "max": 30000000
}, },
"fast_ppt_default": 15000000,
"slow_ppt": { "slow_ppt": {
"min": 1000000, "min": 1000000,
"max": 29000000 "max": 29000000
}, },
"slow_ppt_default": 15000000,
"ppt_divisor": 1000000, "ppt_divisor": 1000000,
"ppt_step": 1, "ppt_step": 1,
"clock_min": { "clock_min": {