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 = [
"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]]
@ -1053,7 +1053,7 @@ dependencies = [
[[package]]
name = "powertools"
version = "1.3.0"
version = "1.3.1"
dependencies = [
"async-trait",
"libryzenadj",
@ -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]]

View file

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

View file

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

View file

@ -262,15 +262,16 @@ fn print_errors(call_name: &str, errors: Vec<crate::settings::SettingError>) {
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);
}
@ -354,7 +355,7 @@ impl ApiMessageHandler {
}
}
}
true
false // on_power_event() should apply everything
}
ApiMessage::WaitForEmptyQueue(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<()> {
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 {

View file

@ -96,23 +96,23 @@ impl OnSet for Settings {
fn on_set(&mut self) -> Result<(), Vec<SettingError>> {
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(())

View file

@ -93,18 +93,18 @@ impl EventInstruction {
#[inline]
fn str_to_trigger(s: &str) -> Option<EventTrigger> {
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::<f64>()
.ok()
.map(|x| EventTrigger::BatteryAbove(x)),
.map(|x| EventTrigger::BatteryAbove(x/100.0)),
s if s.starts_with('<') => s
.trim_start_matches('<')
.parse::<f64>()
.ok()
.map(|x| EventTrigger::BatteryBelow(x)),
.map(|x| EventTrigger::BatteryBelow(x/100.0)),
_ => None,
}
}

View file

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

View file

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

View file

@ -123,7 +123,9 @@ impl Default for CpuLimits {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(super) struct GpuLimits {
pub fast_ppt: MinMax<u64>,
pub fast_ppt_default: u64,
pub slow_ppt: MinMax<u64>,
pub slow_ppt_default: u64,
pub ppt_divisor: u64,
pub ppt_step: u64,
pub clock_min: MinMax<u64>,
@ -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 {

View file

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

View file

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

View file

@ -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": {