Various bugfixes

This commit is contained in:
Luke D. Jones
2024-01-05 13:53:57 +13:00
parent 124c17aadc
commit f64253d633
6 changed files with 93 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
use config_traits::{StdConfig, StdConfigLoad2};
use config_traits::{StdConfig, StdConfigLoad3};
use rog_platform::platform::PlatformPolicy;
use serde_derive::{Deserialize, Serialize};
@@ -13,9 +13,7 @@ pub struct Config {
pub disable_nvidia_powerd_on_battery: bool,
pub ac_command: String,
pub bat_command: String,
/// Restored on boot as well as when power is plugged
#[serde(skip)]
pub platform_policy_to_restore: PlatformPolicy,
pub platform_policy_linked_epp: bool,
pub platform_policy_on_battery: PlatformPolicy,
pub platform_policy_on_ac: PlatformPolicy,
//
@@ -50,9 +48,56 @@ impl StdConfig for Config {
}
}
impl StdConfigLoad2<Config462, Config472> for Config {}
impl StdConfigLoad3<Config462, Config472, Config506> for Config {}
#[derive(Deserialize, Serialize, Default, Debug)]
#[derive(Deserialize, Serialize)]
pub struct Config506 {
/// Save charge limit for restoring on boot
pub charge_control_end_threshold: u8,
pub panel_od: bool,
pub mini_led_mode: bool,
pub disable_nvidia_powerd_on_battery: bool,
pub ac_command: String,
pub bat_command: String,
/// Restored on boot as well as when power is plugged
#[serde(skip)]
pub platform_policy_to_restore: PlatformPolicy,
pub platform_policy_on_battery: PlatformPolicy,
pub platform_policy_on_ac: PlatformPolicy,
//
pub ppt_pl1_spl: Option<u8>,
pub ppt_pl2_sppt: Option<u8>,
pub ppt_fppt: Option<u8>,
pub ppt_apu_sppt: Option<u8>,
pub ppt_platform_sppt: Option<u8>,
pub nv_dynamic_boost: Option<u8>,
pub nv_temp_target: Option<u8>,
}
impl From<Config506> for Config {
fn from(c: Config506) -> Self {
Self {
charge_control_end_threshold: c.charge_control_end_threshold,
panel_od: c.panel_od,
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
ac_command: c.ac_command,
bat_command: c.bat_command,
mini_led_mode: c.mini_led_mode,
platform_policy_linked_epp: true,
platform_policy_on_battery: c.platform_policy_on_battery,
platform_policy_on_ac: c.platform_policy_on_ac,
ppt_pl1_spl: c.ppt_pl1_spl,
ppt_pl2_sppt: c.ppt_pl2_sppt,
ppt_fppt: c.ppt_fppt,
ppt_apu_sppt: c.ppt_apu_sppt,
ppt_platform_sppt: c.ppt_platform_sppt,
nv_dynamic_boost: c.nv_dynamic_boost,
nv_temp_target: c.nv_temp_target,
}
}
}
#[derive(Deserialize, Serialize)]
pub struct Config472 {
/// Save charge limit for restoring on boot
pub bat_charge_limit: u8,

View File

@@ -296,16 +296,18 @@ impl CtrlTask for CtrlFanCurveZbus {
impl crate::Reloadable for CtrlFanCurveZbus {
/// Fetch the active profile and use that to set all related components up
async fn reload(&mut self) -> Result<(), RogError> {
// let active = self.platform.get_throttle_thermal_policy()?.into();
// if let Ok(mut device) = find_fan_curve_node() {
// // There is a possibility that the curve was default zeroed, so this call
// // initialises the data from system read and we need to save it
// // after
// self.fan_curves
// .lock()
// .await
// .write_profile_curve_to_platform(active, &mut device)?;
// }
let active = self.platform.get_throttle_thermal_policy()?.into();
if let Ok(mut device) = find_fan_curve_node() {
// There is a possibility that the curve was default zeroed, so this call
// initialises the data from system read and we need to save it
// after
loop {
if let Ok(mut curves) = self.fan_curves.try_lock() {
curves.write_profile_curve_to_platform(active, &mut device)?;
break;
}
}
}
Ok(())
}
}

View File

@@ -180,7 +180,11 @@ impl CtrlPlatform {
}
}
fn check_and_set_epp(&self, profile: PlatformPolicy) {
fn check_and_set_epp(&self, profile: PlatformPolicy, change_epp: bool) {
if !change_epp {
info!("PlatformPolicy unlinked from EPP");
return;
}
info!("PlatformPolicy setting EPP");
if let Some(cpu) = self.cpu_control.as_ref() {
if let Ok(epp) = cpu.get_available_epp() {
@@ -197,7 +201,7 @@ impl CtrlPlatform {
}
}
async fn update_policy_ac_or_bat(&self, power_plugged: bool) {
async fn update_policy_ac_or_bat(&self, power_plugged: bool, change_epp: bool) {
let profile = if power_plugged {
self.config.lock().await.platform_policy_on_ac
} else {
@@ -206,7 +210,7 @@ impl CtrlPlatform {
self.platform
.set_throttle_thermal_policy(profile.into())
.ok();
self.check_and_set_epp(profile);
self.check_and_set_epp(profile, change_epp);
}
}
@@ -340,14 +344,14 @@ impl CtrlPlatform {
let policy = PlatformPolicy::next(&policy);
if self.platform.has_throttle_thermal_policy() {
self.check_and_set_epp(policy);
let change_epp = self.config.lock().await.platform_policy_linked_epp;
self.check_and_set_epp(policy, change_epp);
self.platform
.set_throttle_thermal_policy(policy.into())
.map_err(|err| {
warn!("RogPlatform: throttle_thermal_policy {}", err);
FdoErr::Failed(format!("RogPlatform: throttle_thermal_policy: {err}"))
})?;
self.config.lock().await.platform_policy_to_restore = policy;
Ok(self.throttle_thermal_policy_changed(&ctxt).await?)
} else {
Err(FdoErr::NotSupported(
@@ -366,8 +370,8 @@ impl CtrlPlatform {
async fn set_throttle_thermal_policy(&mut self, policy: PlatformPolicy) -> Result<(), FdoErr> {
// TODO: watch for external changes
if self.platform.has_throttle_thermal_policy() {
self.check_and_set_epp(policy);
self.config.lock().await.platform_policy_to_restore = policy;
let change_epp = self.config.lock().await.platform_policy_linked_epp;
self.check_and_set_epp(policy, change_epp);
self.platform
.set_throttle_thermal_policy(policy.into())
.map_err(|err| {
@@ -534,7 +538,9 @@ impl crate::Reloadable for CtrlPlatform {
if let Ok(power_plugged) = self.power.get_online() {
if self.platform.has_throttle_thermal_policy() {
self.update_policy_ac_or_bat(power_plugged > 0).await;
let change_epp = self.config.lock().await.platform_policy_linked_epp;
self.update_policy_ac_or_bat(power_plugged > 0, change_epp)
.await;
}
self.run_ac_or_bat_cmd(power_plugged > 0).await;
}
@@ -614,7 +620,11 @@ impl CtrlTask for CtrlPlatform {
}
if let Ok(power_plugged) = platform1.power.get_online() {
if !sleeping && platform1.platform.has_throttle_thermal_policy() {
platform1.update_policy_ac_or_bat(power_plugged > 0).await;
let change_epp =
platform1.config.lock().await.platform_policy_linked_epp;
platform1
.update_policy_ac_or_bat(power_plugged > 0, change_epp)
.await;
}
if !sleeping {
platform1.run_ac_or_bat_cmd(power_plugged > 0).await;
@@ -648,7 +658,10 @@ impl CtrlTask for CtrlPlatform {
// power change
async move {
if platform3.platform.has_throttle_thermal_policy() {
platform3.update_policy_ac_or_bat(power_plugged).await;
let change_epp = platform3.config.lock().await.platform_policy_linked_epp;
platform3
.update_policy_ac_or_bat(power_plugged, change_epp)
.await;
}
platform3.run_ac_or_bat_cmd(power_plugged).await;
}
@@ -697,8 +710,8 @@ impl CtrlTask for CtrlPlatform {
error!("Platform: get_throttle_thermal_policy error: {e}");
})
{
ctrl.check_and_set_epp(profile);
ctrl.config.lock().await.platform_policy_to_restore = profile;
let change_epp = ctrl.config.lock().await.platform_policy_linked_epp;
ctrl.check_and_set_epp(profile, change_epp);
}
}
}

View File

@@ -15,7 +15,7 @@ use asusd::ctrl_aura::trait_impls::CtrlAuraZbus;
use asusd::ctrl_fancurves::CtrlFanCurveZbus;
use asusd::ctrl_platform::CtrlPlatform;
use asusd::{print_board_info, CtrlTask, Reloadable, ZbusRun, DBUS_NAME};
use config_traits::{StdConfig, StdConfigLoad2};
use config_traits::{StdConfig, StdConfigLoad2, StdConfigLoad3};
use log::{error, info, warn};
use rog_aura::aura_detection::LaptopLedData;
use tokio::time::sleep;