Add disable_nvidia_powerd_on_battery option

This commit is contained in:
Luke D. Jones
2023-01-03 20:17:52 +13:00
parent 067738b94f
commit e3ecaa92bd
4 changed files with 46 additions and 30 deletions

View File

@@ -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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Changed
- Added option to set `disable_nvidia_powerd_on_battery`
- Add short log entry to throttle_thermal_policy change detection
## [v4.5.8] ## [v4.5.8]
### Changed ### Changed
- Fix incorrect stop/start order of nvidia-powerd on AC plug/unplug - Fix incorrect stop/start order of nvidia-powerd on AC plug/unplug

View File

@@ -11,6 +11,7 @@ pub struct Config {
/// Save charge limit for restoring on boot /// Save charge limit for restoring on boot
pub bat_charge_limit: u8, pub bat_charge_limit: u8,
pub panel_od: bool, pub panel_od: bool,
pub disable_nvidia_powerd_on_battery: bool,
pub ac_command: String, pub ac_command: String,
pub bat_command: String, pub bat_command: String,
} }
@@ -20,6 +21,7 @@ impl Config {
Config { Config {
bat_charge_limit: 100, bat_charge_limit: 100,
panel_od: false, panel_od: false,
disable_nvidia_powerd_on_battery: true,
ac_command: String::new(), ac_command: String::new(),
bat_command: String::new(), bat_command: String::new(),
} }
@@ -42,6 +44,8 @@ impl Config {
config = data; config = data;
} else if let Ok(data) = serde_json::from_str::<Config455>(&buf) { } else if let Ok(data) = serde_json::from_str::<Config455>(&buf) {
config = data.into(); config = data.into();
} else if let Ok(data) = serde_json::from_str::<Config458>(&buf) {
config = data.into();
} else { } else {
warn!( warn!(
"Could not deserialise {}.\nWill rename to {}-old and recreate config", "Could not deserialise {}.\nWill rename to {}-old and recreate config",
@@ -100,8 +104,30 @@ impl From<Config455> for Config {
Self { Self {
bat_charge_limit: c.bat_charge_limit, bat_charge_limit: c.bat_charge_limit,
panel_od: c.panel_od, panel_od: c.panel_od,
disable_nvidia_powerd_on_battery: true,
ac_command: String::new(), ac_command: String::new(),
bat_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<Config458> 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,
}
}
}

View File

@@ -176,8 +176,10 @@ impl CtrlTask for CtrlPower {
}) })
.ok(); .ok();
if let Ok(value) = power.power.get_online() { if lock.disable_nvidia_powerd_on_battery {
do_nvidia_powerd_action(&sysd, value == 1).await; 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(); .ok();
if let Ok(value) = power.power.get_online() { if lock.disable_nvidia_powerd_on_battery {
do_nvidia_powerd_action(&sysd, value == 1).await; 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 let Ok(value) = ctrl.power.get_online() {
if online != value { if online != value {
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) Self::notify_mains_online(&signal_ctxt, value == 1)
.await .await
.unwrap(); .unwrap();
let mut config = config.lock().await;
config.read();
let mut prog: Vec<&str> = Vec::new(); let mut prog: Vec<&str> = Vec::new();
if value == 1 { if value == 1 {
// AC ONLINE // AC ONLINE

View File

@@ -1,4 +1,5 @@
use async_trait::async_trait; use async_trait::async_trait;
use log::info;
use log::warn; use log::warn;
use rog_profiles::fan_curve_set::CurveData; use rog_profiles::fan_curve_set::CurveData;
use rog_profiles::fan_curve_set::FanCurveSet; 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> { 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 ctrl = self.0.clone();
let mut watch = self let mut watch = self
.0 .0
@@ -241,6 +219,7 @@ impl CtrlTask for ProfileZbus {
let new_thermal = lock.platform.get_throttle_thermal_policy().unwrap(); let new_thermal = lock.platform.get_throttle_thermal_policy().unwrap();
let new_profile = Profile::from_throttle_thermal_policy(new_thermal); let new_profile = Profile::from_throttle_thermal_policy(new_thermal);
if new_profile != lock.config.active_profile { if new_profile != lock.config.active_profile {
info!("throttle_thermal_policy changed to {new_profile}");
lock.config.active_profile = new_profile; lock.config.active_profile = new_profile;
lock.write_profile_curve_to_platform().unwrap(); lock.write_profile_curve_to_platform().unwrap();
lock.save_config(); lock.save_config();