From e3ecaa92bd77ed52a464dd0cc1f872bac40c52a1 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Tue, 3 Jan 2023 20:17:52 +1300 Subject: [PATCH] Add disable_nvidia_powerd_on_battery option --- CHANGELOG.md | 4 ++++ daemon/src/config.rs | 26 +++++++++++++++++++++++++ daemon/src/ctrl_power.rs | 21 +++++++++++++------- daemon/src/ctrl_profiles/trait_impls.rs | 25 ++---------------------- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 470492ba..8ad13eef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Added option to set `disable_nvidia_powerd_on_battery` +- Add short log entry to throttle_thermal_policy change detection + ## [v4.5.8] ### Changed - Fix incorrect stop/start order of nvidia-powerd on AC plug/unplug diff --git a/daemon/src/config.rs b/daemon/src/config.rs index 2cba83a6..8a832d01 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -11,6 +11,7 @@ pub struct Config { /// Save charge limit for restoring on boot pub bat_charge_limit: u8, pub panel_od: bool, + pub disable_nvidia_powerd_on_battery: bool, pub ac_command: String, pub bat_command: String, } @@ -20,6 +21,7 @@ impl Config { Config { bat_charge_limit: 100, panel_od: false, + disable_nvidia_powerd_on_battery: true, ac_command: String::new(), bat_command: String::new(), } @@ -42,6 +44,8 @@ impl Config { config = data; } else if let Ok(data) = serde_json::from_str::(&buf) { config = data.into(); + } else if let Ok(data) = serde_json::from_str::(&buf) { + config = data.into(); } else { warn!( "Could not deserialise {}.\nWill rename to {}-old and recreate config", @@ -100,8 +104,30 @@ impl From for Config { Self { bat_charge_limit: c.bat_charge_limit, panel_od: c.panel_od, + disable_nvidia_powerd_on_battery: true, ac_command: String::new(), bat_command: String::new(), } } } + +#[derive(Deserialize, Serialize, Default)] +pub struct Config458 { + /// Save charge limit for restoring on boot + pub bat_charge_limit: u8, + pub panel_od: bool, + pub ac_command: String, + pub bat_command: String, +} + +impl From for Config { + fn from(c: Config458) -> Self { + Self { + bat_charge_limit: c.bat_charge_limit, + panel_od: c.panel_od, + disable_nvidia_powerd_on_battery: true, + ac_command: c.ac_command, + bat_command: c.bat_command, + } + } +} diff --git a/daemon/src/ctrl_power.rs b/daemon/src/ctrl_power.rs index a62fc2e9..20537fd5 100644 --- a/daemon/src/ctrl_power.rs +++ b/daemon/src/ctrl_power.rs @@ -176,8 +176,10 @@ impl CtrlTask for CtrlPower { }) .ok(); - if let Ok(value) = power.power.get_online() { - do_nvidia_powerd_action(&sysd, value == 1).await; + if lock.disable_nvidia_powerd_on_battery { + if let Ok(value) = power.power.get_online() { + do_nvidia_powerd_action(&sysd, value == 1).await; + } } } }, @@ -196,8 +198,10 @@ impl CtrlTask for CtrlPower { }) .ok(); - if let Ok(value) = power.power.get_online() { - do_nvidia_powerd_action(&sysd, value == 1).await; + if lock.disable_nvidia_powerd_on_battery { + if let Ok(value) = power.power.get_online() { + do_nvidia_powerd_action(&sysd, value == 1).await; + } } } }, @@ -215,14 +219,17 @@ impl CtrlTask for CtrlPower { if let Ok(value) = ctrl.power.get_online() { if online != value { online = value; - do_nvidia_powerd_action(&sysd3, value == 1).await; + let mut config = config.lock().await; + config.read(); + + if config.disable_nvidia_powerd_on_battery { + do_nvidia_powerd_action(&sysd3, value == 1).await; + } Self::notify_mains_online(&signal_ctxt, value == 1) .await .unwrap(); - let mut config = config.lock().await; - config.read(); let mut prog: Vec<&str> = Vec::new(); if value == 1 { // AC ONLINE diff --git a/daemon/src/ctrl_profiles/trait_impls.rs b/daemon/src/ctrl_profiles/trait_impls.rs index 6451bb9b..50708e3a 100644 --- a/daemon/src/ctrl_profiles/trait_impls.rs +++ b/daemon/src/ctrl_profiles/trait_impls.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +use log::info; use log::warn; use rog_profiles::fan_curve_set::CurveData; use rog_profiles::fan_curve_set::FanCurveSet; @@ -200,29 +201,6 @@ impl CtrlTask for ProfileZbus { } async fn create_tasks(&self, signal_ctxt: SignalContext<'static>) -> Result<(), RogError> { - // let ctrl = self.0.clone(); - // let mut watch = self.0.lock().await.platform.monitor_platform_profile()?; - // let sig_ctx = signal_ctxt.clone(); - // tokio::spawn(async move { - // let mut buffer = [0; 32]; - // watch - // .event_stream(&mut buffer) - // .unwrap() - // .for_each(|_| async { - // let mut lock = ctrl.lock().await; - // let new_profile = Profile::get_active_profile().unwrap(); - // if new_profile != lock.config.active_profile { - // lock.config.active_profile = new_profile; - // lock.write_profile_curve_to_platform().unwrap(); - // lock.save_config(); - // } - // Self::notify_profile(&sig_ctx, lock.config.active_profile) - // .await - // .ok(); - // }) - // .await; - // }); - let ctrl = self.0.clone(); let mut watch = self .0 @@ -241,6 +219,7 @@ impl CtrlTask for ProfileZbus { let new_thermal = lock.platform.get_throttle_thermal_policy().unwrap(); let new_profile = Profile::from_throttle_thermal_policy(new_thermal); if new_profile != lock.config.active_profile { + info!("throttle_thermal_policy changed to {new_profile}"); lock.config.active_profile = new_profile; lock.write_profile_curve_to_platform().unwrap(); lock.save_config();