Finalise per-profile PPT settings

This commit is contained in:
Luke D. Jones
2025-01-18 22:40:58 +13:00
parent ef3b6636f5
commit 3426591d32
4 changed files with 72 additions and 30 deletions

View File

@@ -210,19 +210,7 @@ impl AsusArmouryAttribute {
e e
})?; })?;
if matches!( if self.name().is_ppt() {
self.name(),
FirmwareAttribute::PptPl1Spl
| FirmwareAttribute::PptPl2Sppt
| FirmwareAttribute::PptPl3Fppt
| FirmwareAttribute::PptFppt
| FirmwareAttribute::PptApuSppt
| FirmwareAttribute::PptPlatformSppt
| FirmwareAttribute::NvDynamicBoost
| FirmwareAttribute::NvTempTarget
| FirmwareAttribute::DgpuBaseTgp
| FirmwareAttribute::DgpuTgp
) {
let profile: ThrottlePolicy = let profile: ThrottlePolicy =
ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?; ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?;

View File

@@ -5,6 +5,7 @@ use std::sync::Arc;
use config_traits::StdConfig; use config_traits::StdConfig;
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use rog_platform::asus_armoury::{AttrValue, FirmwareAttribute, FirmwareAttributes};
use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP}; use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP};
use rog_platform::platform::{Properties, RogPlatform, ThrottlePolicy}; use rog_platform::platform::{Properties, RogPlatform, ThrottlePolicy};
use rog_platform::power::AsusPower; use rog_platform::power::AsusPower;
@@ -43,14 +44,14 @@ pub struct CtrlPlatform {
power: AsusPower, power: AsusPower,
platform: RogPlatform, platform: RogPlatform,
cpu_control: Option<CPUControl>, cpu_control: Option<CPUControl>,
config: Arc<Mutex<Config>> config: Arc<Mutex<Config>>,
} }
impl CtrlPlatform { impl CtrlPlatform {
pub fn new( pub fn new(
config: Arc<Mutex<Config>>, config: Arc<Mutex<Config>>,
config_path: &Path, config_path: &Path,
signal_context: SignalEmitter<'static> signal_context: SignalEmitter<'static>,
) -> Result<Self, RogError> { ) -> Result<Self, RogError> {
let platform = RogPlatform::new()?; let platform = RogPlatform::new()?;
let power = AsusPower::new()?; let power = AsusPower::new()?;
@@ -63,7 +64,7 @@ impl CtrlPlatform {
config, config,
cpu_control: CPUControl::new() cpu_control: CPUControl::new()
.map_err(|e| error!("Couldn't get CPU control sysfs: {e}")) .map_err(|e| error!("Couldn't get CPU control sysfs: {e}"))
.ok() .ok(),
}; };
let mut inotify_self = ret_self.clone(); let mut inotify_self = ret_self.clone();
@@ -82,7 +83,7 @@ impl CtrlPlatform {
inotify::WatchMask::MODIFY inotify::WatchMask::MODIFY
| inotify::WatchMask::CLOSE_WRITE | inotify::WatchMask::CLOSE_WRITE
| inotify::WatchMask::ATTRIB | inotify::WatchMask::ATTRIB
| inotify::WatchMask::CREATE | inotify::WatchMask::CREATE,
) )
.inspect_err(|e| { .inspect_err(|e| {
if e.kind() == std::io::ErrorKind::NotFound { if e.kind() == std::io::ErrorKind::NotFound {
@@ -124,7 +125,7 @@ impl CtrlPlatform {
if limit > 0 if limit > 0
&& std::mem::replace( && std::mem::replace(
&mut self.config.lock().await.charge_control_end_threshold, &mut self.config.lock().await.charge_control_end_threshold,
limit limit,
) != limit ) != limit
{ {
self.power self.power
@@ -206,7 +207,7 @@ impl CtrlPlatform {
match throttle { match throttle {
ThrottlePolicy::Balanced => self.config.lock().await.throttle_balanced_epp, ThrottlePolicy::Balanced => self.config.lock().await.throttle_balanced_epp,
ThrottlePolicy::Performance => self.config.lock().await.throttle_performance_epp, ThrottlePolicy::Performance => self.config.lock().await.throttle_performance_epp,
ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp,
} }
} }
@@ -303,7 +304,7 @@ impl CtrlPlatform {
async fn one_shot_full_charge(&self) -> Result<(), FdoErr> { async fn one_shot_full_charge(&self) -> Result<(), FdoErr> {
let base_limit = std::mem::replace( let base_limit = std::mem::replace(
&mut self.config.lock().await.charge_control_end_threshold, &mut self.config.lock().await.charge_control_end_threshold,
100 100,
); );
if base_limit != 100 { if base_limit != 100 {
self.power.set_charge_control_end_threshold(100)?; self.power.set_charge_control_end_threshold(100)?;
@@ -317,7 +318,7 @@ impl CtrlPlatform {
/// If fan-curves are supported will also activate a fan curve for profile. /// If fan-curves are supported will also activate a fan curve for profile.
async fn next_throttle_thermal_policy( async fn next_throttle_thermal_policy(
&mut self, &mut self,
#[zbus(signal_context)] ctxt: SignalEmitter<'_> #[zbus(signal_context)] ctxt: SignalEmitter<'_>,
) -> Result<(), FdoErr> { ) -> Result<(), FdoErr> {
let policy: ThrottlePolicy = let policy: ThrottlePolicy =
platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy") platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy")
@@ -337,7 +338,7 @@ impl CtrlPlatform {
Ok(self.throttle_thermal_policy_changed(&ctxt).await?) Ok(self.throttle_thermal_policy_changed(&ctxt).await?)
} else { } else {
Err(FdoErr::NotSupported( Err(FdoErr::NotSupported(
"RogPlatform: throttle_thermal_policy not supported".to_owned() "RogPlatform: throttle_thermal_policy not supported".to_owned(),
)) ))
} }
} }
@@ -364,7 +365,7 @@ impl CtrlPlatform {
}) })
} else { } else {
Err(FdoErr::NotSupported( Err(FdoErr::NotSupported(
"RogPlatform: throttle_thermal_policy not supported".to_owned() "RogPlatform: throttle_thermal_policy not supported".to_owned(),
)) ))
} }
} }
@@ -389,7 +390,7 @@ impl CtrlPlatform {
#[zbus(property)] #[zbus(property)]
async fn set_throttle_policy_on_battery( async fn set_throttle_policy_on_battery(
&mut self, &mut self,
policy: ThrottlePolicy policy: ThrottlePolicy,
) -> Result<(), FdoErr> { ) -> Result<(), FdoErr> {
self.config.lock().await.throttle_policy_on_battery = policy; self.config.lock().await.throttle_policy_on_battery = policy;
self.set_throttle_thermal_policy(policy).await?; self.set_throttle_thermal_policy(policy).await?;
@@ -496,7 +497,7 @@ impl ReloadAndNotify for CtrlPlatform {
async fn reload_and_notify( async fn reload_and_notify(
&mut self, &mut self,
signal_context: &SignalEmitter<'static>, signal_context: &SignalEmitter<'static>,
data: Self::Data data: Self::Data,
) -> Result<(), RogError> { ) -> Result<(), RogError> {
let mut config = self.config.lock().await; let mut config = self.config.lock().await;
if *config != data { if *config != data {
@@ -526,7 +527,7 @@ impl ReloadAndNotify for CtrlPlatform {
let epp = match profile { let epp = match profile {
ThrottlePolicy::Balanced => data.throttle_balanced_epp, ThrottlePolicy::Balanced => data.throttle_balanced_epp,
ThrottlePolicy::Performance => data.throttle_performance_epp, ThrottlePolicy::Performance => data.throttle_performance_epp,
ThrottlePolicy::Quiet => data.throttle_quiet_epp ThrottlePolicy::Quiet => data.throttle_quiet_epp,
}; };
warn!("setting epp to {epp:?}"); warn!("setting epp to {epp:?}");
self.check_and_set_epp(epp, true); self.check_and_set_epp(epp, true);
@@ -597,7 +598,7 @@ impl CtrlTask for CtrlPlatform {
platform1 platform1
.power .power
.set_charge_control_end_threshold( .set_charge_control_end_threshold(
platform1.config.lock().await.charge_control_end_threshold platform1.config.lock().await.charge_control_end_threshold,
) )
.ok(); .ok();
} }
@@ -631,7 +632,7 @@ impl CtrlTask for CtrlPlatform {
platform2 platform2
.power .power
.set_charge_control_end_threshold( .set_charge_control_end_threshold(
lock.base_charge_control_end_threshold lock.base_charge_control_end_threshold,
) )
.map_err(|err| { .map_err(|err| {
warn!("CtrlCharge: charge_control_end_threshold {}", err); warn!("CtrlCharge: charge_control_end_threshold {}", err);
@@ -661,7 +662,7 @@ impl CtrlTask for CtrlPlatform {
platform3.restore_charge_limit().await; platform3.restore_charge_limit().await;
} }
} }
} },
) )
.await; .await;
@@ -673,6 +674,9 @@ impl CtrlTask for CtrlPlatform {
let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?; let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?;
let ctrl = self.clone(); let ctrl = self.clone();
// Need a copy here, not ideal. But first use in asus_armoury.rs is
// moved to zbus
let attrs = FirmwareAttributes::new();
tokio::spawn(async move { tokio::spawn(async move {
use futures_lite::StreamExt; use futures_lite::StreamExt;
let mut buffer = [0; 32]; let mut buffer = [0; 32];
@@ -691,6 +695,38 @@ impl CtrlTask for CtrlPlatform {
let change_epp = ctrl.config.lock().await.throttle_policy_linked_epp; let change_epp = ctrl.config.lock().await.throttle_policy_linked_epp;
let epp = ctrl.get_config_epp_for_throttle(profile).await; let epp = ctrl.get_config_epp_for_throttle(profile).await;
ctrl.check_and_set_epp(epp, change_epp); ctrl.check_and_set_epp(epp, change_epp);
ctrl.throttle_thermal_policy_changed(&signal_ctxt)
.await
.ok();
for attr in attrs.attributes().iter() {
let name: FirmwareAttribute = attr.name().into();
if name.is_ppt() {
let mut do_default = false;
if let Some(tunings) =
ctrl.config.lock().await.profile_tunings.get(&profile)
{
if let Some(tune) = tunings.get(&name) {
attr.set_current_value(AttrValue::Integer(*tune))
.map_err(|e| {
error!("Failed to set {}: {e}", <&str>::from(name));
})
.ok();
} else {
do_default = true;
}
} else {
do_default = true;
}
if do_default {
let default = attr.default_value().clone();
attr.set_current_value(default)
.map_err(|e| {
error!("Failed to set {}: {e}", <&str>::from(name));
})
.ok();
}
}
}
} }
} }
} }

View File

@@ -16,7 +16,7 @@ use crate::{set_ui_callbacks, set_ui_props_async, AttrMinMax, MainWindow, System
const MINMAX: AttrMinMax = AttrMinMax { const MINMAX: AttrMinMax = AttrMinMax {
min: 0, min: 0,
max: 0, max: 0,
val: -1.0, val: -1.0
}; };
pub fn setup_system_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) { pub fn setup_system_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {

View File

@@ -292,6 +292,24 @@ pub enum FirmwareAttribute {
None = 24 None = 24
} }
impl FirmwareAttribute {
pub fn is_ppt(&self) -> bool {
matches!(
self,
FirmwareAttribute::PptPl1Spl
| FirmwareAttribute::PptPl2Sppt
| FirmwareAttribute::PptPl3Fppt
| FirmwareAttribute::PptFppt
| FirmwareAttribute::PptApuSppt
| FirmwareAttribute::PptPlatformSppt
| FirmwareAttribute::NvDynamicBoost
| FirmwareAttribute::NvTempTarget
| FirmwareAttribute::DgpuBaseTgp
| FirmwareAttribute::DgpuTgp
)
}
}
impl From<&str> for FirmwareAttribute { impl From<&str> for FirmwareAttribute {
fn from(s: &str) -> Self { fn from(s: &str) -> Self {
match s { match s {