mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Move entirely to using only platform-profile
throttle_thermal_policy is not ideal anymore and may be removed from kernel in the future.
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use config_traits::StdConfig;
|
||||
use log::{debug, error, info, warn};
|
||||
use rog_platform::asus_armoury::FirmwareAttributes;
|
||||
use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP};
|
||||
use rog_platform::platform::{Properties, RogPlatform, ThrottlePolicy};
|
||||
use rog_platform::platform::{PlatformProfile, Properties, RogPlatform};
|
||||
use rog_platform::power::AsusPower;
|
||||
use zbus::export::futures_util::lock::Mutex;
|
||||
use zbus::fdo::Error as FdoErr;
|
||||
@@ -204,40 +203,38 @@ impl CtrlPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_config_epp_for_throttle(&self, throttle: ThrottlePolicy) -> CPUEPP {
|
||||
async fn get_config_epp_for_throttle(&self, throttle: PlatformProfile) -> CPUEPP {
|
||||
match throttle {
|
||||
ThrottlePolicy::Balanced => self.config.lock().await.throttle_balanced_epp,
|
||||
ThrottlePolicy::Performance => self.config.lock().await.throttle_performance_epp,
|
||||
ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp
|
||||
PlatformProfile::Balanced => self.config.lock().await.profile_balanced_epp,
|
||||
PlatformProfile::Performance => self.config.lock().await.profile_performance_epp,
|
||||
PlatformProfile::Quiet => self.config.lock().await.profile_quiet_epp
|
||||
}
|
||||
}
|
||||
|
||||
async fn update_policy_ac_or_bat(&self, power_plugged: bool, change_epp: bool) {
|
||||
if power_plugged && !self.config.lock().await.change_throttle_policy_on_ac {
|
||||
if power_plugged && !self.config.lock().await.change_platform_profile_on_ac {
|
||||
debug!(
|
||||
"Power status changed but set_throttle_policy_on_ac set false. Not setting the \
|
||||
"Power status changed but set_platform_profile_on_ac set false. Not setting the \
|
||||
thing"
|
||||
);
|
||||
return;
|
||||
}
|
||||
if !power_plugged && !self.config.lock().await.change_throttle_policy_on_battery {
|
||||
if !power_plugged && !self.config.lock().await.change_platform_profile_on_battery {
|
||||
debug!(
|
||||
"Power status changed but set_throttle_policy_on_battery set false. Not setting \
|
||||
"Power status changed but set_platform_profile_on_battery set false. Not setting \
|
||||
the thing"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let throttle = if power_plugged {
|
||||
self.config.lock().await.throttle_policy_on_ac
|
||||
self.config.lock().await.platform_profile_on_ac
|
||||
} else {
|
||||
self.config.lock().await.throttle_policy_on_battery
|
||||
self.config.lock().await.platform_profile_on_battery
|
||||
};
|
||||
debug!("Setting {throttle:?} before EPP");
|
||||
let epp = self.get_config_epp_for_throttle(throttle).await;
|
||||
self.platform
|
||||
.set_throttle_thermal_policy(throttle.into())
|
||||
.ok();
|
||||
self.platform.set_platform_profile(throttle.into()).ok();
|
||||
self.check_and_set_epp(epp, change_epp);
|
||||
}
|
||||
}
|
||||
@@ -279,7 +276,7 @@ impl CtrlPlatform {
|
||||
Properties::ChargeControlEndThreshold
|
||||
);
|
||||
|
||||
platform_name!(throttle_thermal_policy, Properties::ThrottlePolicy);
|
||||
platform_name!(platform_profile, Properties::ThrottlePolicy);
|
||||
|
||||
supported
|
||||
}
|
||||
@@ -317,121 +314,119 @@ impl CtrlPlatform {
|
||||
|
||||
/// Toggle to next platform_profile. Names provided by `Profiles`.
|
||||
/// If fan-curves are supported will also activate a fan curve for profile.
|
||||
async fn next_throttle_thermal_policy(
|
||||
async fn next_platform_profile(
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalEmitter<'_>
|
||||
) -> Result<(), FdoErr> {
|
||||
let policy: ThrottlePolicy =
|
||||
platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy")
|
||||
.map(|n| n.into())?;
|
||||
let policy = ThrottlePolicy::next(policy);
|
||||
let policy: PlatformProfile =
|
||||
platform_get_value!(self, platform_profile, "platform_profile").map(|n| n.into())?;
|
||||
let policy = PlatformProfile::next(policy);
|
||||
|
||||
if self.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
if self.platform.has_platform_profile() {
|
||||
let change_epp = self.config.lock().await.platform_profile_linked_epp;
|
||||
let epp = self.get_config_epp_for_throttle(policy).await;
|
||||
self.check_and_set_epp(epp, change_epp);
|
||||
self.platform
|
||||
.set_throttle_thermal_policy(policy.into())
|
||||
.set_platform_profile(policy.into())
|
||||
.map_err(|err| {
|
||||
warn!("throttle_thermal_policy {}", err);
|
||||
FdoErr::Failed(format!("RogPlatform: throttle_thermal_policy: {err}"))
|
||||
warn!("platform_profile {}", err);
|
||||
FdoErr::Failed(format!("RogPlatform: platform_profile: {err}"))
|
||||
})?;
|
||||
Ok(self.throttle_thermal_policy_changed(&ctxt).await?)
|
||||
Ok(self.platform_profile_changed(&ctxt).await?)
|
||||
} else {
|
||||
Err(FdoErr::NotSupported(
|
||||
"RogPlatform: throttle_thermal_policy not supported".to_owned()
|
||||
"RogPlatform: platform_profile not supported".to_owned()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn throttle_thermal_policy(&self) -> Result<ThrottlePolicy, FdoErr> {
|
||||
platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy")
|
||||
.map(|n| n.into())
|
||||
fn platform_profile(&self) -> Result<PlatformProfile, FdoErr> {
|
||||
platform_get_value!(self, platform_profile, "platform_profile").map(|n| n.into())
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_thermal_policy(&mut self, policy: ThrottlePolicy) -> Result<(), FdoErr> {
|
||||
async fn set_platform_profile(&mut self, policy: PlatformProfile) -> Result<(), FdoErr> {
|
||||
// TODO: watch for external changes
|
||||
if self.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
if self.platform.has_platform_profile() {
|
||||
let change_epp = self.config.lock().await.platform_profile_linked_epp;
|
||||
let epp = self.get_config_epp_for_throttle(policy).await;
|
||||
self.check_and_set_epp(epp, change_epp);
|
||||
self.config.lock().await.write();
|
||||
self.platform
|
||||
.set_throttle_thermal_policy(policy.into())
|
||||
.set_platform_profile(policy.into())
|
||||
.map_err(|err| {
|
||||
warn!("throttle_thermal_policy {}", err);
|
||||
FdoErr::Failed(format!("RogPlatform: throttle_thermal_policy: {err}"))
|
||||
warn!("platform_profile {}", err);
|
||||
FdoErr::Failed(format!("RogPlatform: platform_profile: {err}"))
|
||||
})
|
||||
} else {
|
||||
Err(FdoErr::NotSupported(
|
||||
"RogPlatform: throttle_thermal_policy not supported".to_owned()
|
||||
"RogPlatform: platform_profile not supported".to_owned()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn throttle_policy_linked_epp(&self) -> Result<bool, FdoErr> {
|
||||
Ok(self.config.lock().await.throttle_policy_linked_epp)
|
||||
async fn platform_profile_linked_epp(&self) -> Result<bool, FdoErr> {
|
||||
Ok(self.config.lock().await.platform_profile_linked_epp)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_policy_linked_epp(&self, linked: bool) -> Result<(), zbus::Error> {
|
||||
self.config.lock().await.throttle_policy_linked_epp = linked;
|
||||
async fn set_platform_profile_linked_epp(&self, linked: bool) -> Result<(), zbus::Error> {
|
||||
self.config.lock().await.platform_profile_linked_epp = linked;
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn throttle_policy_on_battery(&self) -> Result<ThrottlePolicy, FdoErr> {
|
||||
Ok(self.config.lock().await.throttle_policy_on_battery)
|
||||
async fn platform_profile_on_battery(&self) -> Result<PlatformProfile, FdoErr> {
|
||||
Ok(self.config.lock().await.platform_profile_on_battery)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_policy_on_battery(
|
||||
async fn set_platform_profile_on_battery(
|
||||
&mut self,
|
||||
policy: ThrottlePolicy
|
||||
policy: PlatformProfile
|
||||
) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.throttle_policy_on_battery = policy;
|
||||
self.set_throttle_thermal_policy(policy).await?;
|
||||
self.config.lock().await.platform_profile_on_battery = policy;
|
||||
self.set_platform_profile(policy).await?;
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn change_throttle_policy_on_battery(&self) -> Result<bool, FdoErr> {
|
||||
Ok(self.config.lock().await.change_throttle_policy_on_battery)
|
||||
async fn change_platform_profile_on_battery(&self) -> Result<bool, FdoErr> {
|
||||
Ok(self.config.lock().await.change_platform_profile_on_battery)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_change_throttle_policy_on_battery(&mut self, change: bool) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.change_throttle_policy_on_battery = change;
|
||||
async fn set_change_platform_profile_on_battery(&mut self, change: bool) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.change_platform_profile_on_battery = change;
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn throttle_policy_on_ac(&self) -> Result<ThrottlePolicy, FdoErr> {
|
||||
Ok(self.config.lock().await.throttle_policy_on_ac)
|
||||
async fn platform_profile_on_ac(&self) -> Result<PlatformProfile, FdoErr> {
|
||||
Ok(self.config.lock().await.platform_profile_on_ac)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_policy_on_ac(&mut self, policy: ThrottlePolicy) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.throttle_policy_on_ac = policy;
|
||||
self.set_throttle_thermal_policy(policy).await?;
|
||||
async fn set_platform_profile_on_ac(&mut self, policy: PlatformProfile) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.platform_profile_on_ac = policy;
|
||||
self.set_platform_profile(policy).await?;
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn change_throttle_policy_on_ac(&self) -> Result<bool, FdoErr> {
|
||||
Ok(self.config.lock().await.change_throttle_policy_on_ac)
|
||||
async fn change_platform_profile_on_ac(&self) -> Result<bool, FdoErr> {
|
||||
Ok(self.config.lock().await.change_platform_profile_on_ac)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_change_throttle_policy_on_ac(&mut self, change: bool) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.change_throttle_policy_on_ac = change;
|
||||
async fn set_change_platform_profile_on_ac(&mut self, change: bool) -> Result<(), FdoErr> {
|
||||
self.config.lock().await.change_platform_profile_on_ac = change;
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
}
|
||||
@@ -439,14 +434,14 @@ impl CtrlPlatform {
|
||||
/// The energy_performance_preference for the quiet throttle/platform
|
||||
/// profile
|
||||
#[zbus(property)]
|
||||
async fn throttle_quiet_epp(&self) -> Result<CPUEPP, FdoErr> {
|
||||
Ok(self.config.lock().await.throttle_quiet_epp)
|
||||
async fn profile_quiet_epp(&self) -> Result<CPUEPP, FdoErr> {
|
||||
Ok(self.config.lock().await.profile_quiet_epp)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_quiet_epp(&mut self, epp: CPUEPP) -> Result<(), FdoErr> {
|
||||
let change_pp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
self.config.lock().await.throttle_quiet_epp = epp;
|
||||
async fn set_profile_quiet_epp(&mut self, epp: CPUEPP) -> Result<(), FdoErr> {
|
||||
let change_pp = self.config.lock().await.platform_profile_linked_epp;
|
||||
self.config.lock().await.profile_quiet_epp = epp;
|
||||
self.check_and_set_epp(epp, change_pp);
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
@@ -455,14 +450,14 @@ impl CtrlPlatform {
|
||||
/// The energy_performance_preference for the balanced throttle/platform
|
||||
/// profile
|
||||
#[zbus(property)]
|
||||
async fn throttle_balanced_epp(&self) -> Result<CPUEPP, FdoErr> {
|
||||
Ok(self.config.lock().await.throttle_balanced_epp)
|
||||
async fn profile_balanced_epp(&self) -> Result<CPUEPP, FdoErr> {
|
||||
Ok(self.config.lock().await.profile_balanced_epp)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_balanced_epp(&mut self, epp: CPUEPP) -> Result<(), FdoErr> {
|
||||
let change_pp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
self.config.lock().await.throttle_balanced_epp = epp;
|
||||
async fn set_profile_balanced_epp(&mut self, epp: CPUEPP) -> Result<(), FdoErr> {
|
||||
let change_pp = self.config.lock().await.platform_profile_linked_epp;
|
||||
self.config.lock().await.profile_balanced_epp = epp;
|
||||
self.check_and_set_epp(epp, change_pp);
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
@@ -471,14 +466,14 @@ impl CtrlPlatform {
|
||||
/// The energy_performance_preference for the performance throttle/platform
|
||||
/// profile
|
||||
#[zbus(property)]
|
||||
async fn throttle_performance_epp(&self) -> Result<CPUEPP, FdoErr> {
|
||||
Ok(self.config.lock().await.throttle_performance_epp)
|
||||
async fn profile_performance_epp(&self) -> Result<CPUEPP, FdoErr> {
|
||||
Ok(self.config.lock().await.profile_performance_epp)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_throttle_performance_epp(&mut self, epp: CPUEPP) -> Result<(), FdoErr> {
|
||||
let change_pp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
self.config.lock().await.throttle_performance_epp = epp;
|
||||
async fn set_profile_performance_epp(&mut self, epp: CPUEPP) -> Result<(), FdoErr> {
|
||||
let change_pp = self.config.lock().await.platform_profile_linked_epp;
|
||||
self.config.lock().await.profile_performance_epp = epp;
|
||||
self.check_and_set_epp(epp, change_pp);
|
||||
self.config.lock().await.write();
|
||||
Ok(())
|
||||
@@ -519,21 +514,20 @@ impl ReloadAndNotify for CtrlPlatform {
|
||||
.or(Some(limit));
|
||||
}
|
||||
|
||||
if self.platform.has_throttle_thermal_policy()
|
||||
&& config.throttle_policy_linked_epp != data.throttle_policy_linked_epp
|
||||
if self.platform.has_platform_profile()
|
||||
&& config.platform_profile_linked_epp != data.platform_profile_linked_epp
|
||||
{
|
||||
let profile: ThrottlePolicy =
|
||||
ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?;
|
||||
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||
|
||||
let epp = match profile {
|
||||
ThrottlePolicy::Balanced => data.throttle_balanced_epp,
|
||||
ThrottlePolicy::Performance => data.throttle_performance_epp,
|
||||
ThrottlePolicy::Quiet => data.throttle_quiet_epp
|
||||
PlatformProfile::Balanced => data.profile_balanced_epp,
|
||||
PlatformProfile::Performance => data.profile_performance_epp,
|
||||
PlatformProfile::Quiet => data.profile_quiet_epp
|
||||
};
|
||||
warn!("setting epp to {epp:?}");
|
||||
self.check_and_set_epp(epp, true);
|
||||
}
|
||||
// reload_and_notify!(throttle_thermal_policy, "throttle_thermal_policy");
|
||||
// reload_and_notify!(platform_profile, "platform_profile");
|
||||
|
||||
*config = data;
|
||||
config.base_charge_control_end_threshold =
|
||||
@@ -557,8 +551,8 @@ impl crate::Reloadable for CtrlPlatform {
|
||||
|
||||
if let Ok(power_plugged) = self.power.get_online() {
|
||||
self.config.lock().await.last_power_plugged = power_plugged;
|
||||
if self.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
if self.platform.has_platform_profile() {
|
||||
let change_epp = self.config.lock().await.platform_profile_linked_epp;
|
||||
self.update_policy_ac_or_bat(power_plugged > 0, change_epp)
|
||||
.await;
|
||||
}
|
||||
@@ -605,9 +599,9 @@ impl CtrlTask for CtrlPlatform {
|
||||
}
|
||||
if let Ok(power_plugged) = platform1.power.get_online() {
|
||||
if platform1.config.lock().await.last_power_plugged != power_plugged {
|
||||
if !sleeping && platform1.platform.has_throttle_thermal_policy() {
|
||||
if !sleeping && platform1.platform.has_platform_profile() {
|
||||
let change_epp =
|
||||
platform1.config.lock().await.throttle_policy_linked_epp;
|
||||
platform1.config.lock().await.platform_profile_linked_epp;
|
||||
platform1
|
||||
.update_policy_ac_or_bat(power_plugged > 0, change_epp)
|
||||
.await;
|
||||
@@ -651,8 +645,8 @@ impl CtrlTask for CtrlPlatform {
|
||||
let platform3 = platform3.clone();
|
||||
// power change
|
||||
async move {
|
||||
if platform3.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = platform3.config.lock().await.throttle_policy_linked_epp;
|
||||
if platform3.platform.has_platform_profile() {
|
||||
let change_epp = platform3.config.lock().await.platform_profile_linked_epp;
|
||||
platform3
|
||||
.update_policy_ac_or_bat(power_plugged, change_epp)
|
||||
.await;
|
||||
@@ -665,10 +659,10 @@ impl CtrlTask for CtrlPlatform {
|
||||
|
||||
if let Ok(profile) = platform3
|
||||
.platform
|
||||
.get_throttle_thermal_policy()
|
||||
.map(ThrottlePolicy::from)
|
||||
.get_platform_profile()
|
||||
.map(|p| p.into())
|
||||
.map_err(|e| {
|
||||
error!("Platform: get_throttle_thermal_policy error: {e}");
|
||||
error!("Platform: get_platform_profile error: {e}");
|
||||
})
|
||||
{
|
||||
let attrs = FirmwareAttributes::new();
|
||||
@@ -690,7 +684,7 @@ impl CtrlTask for CtrlPlatform {
|
||||
self.watch_charge_control_end_threshold(signal_ctxt.clone())
|
||||
.await?;
|
||||
|
||||
let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?;
|
||||
let watch_platform_profile = self.platform.monitor_platform_profile()?;
|
||||
let ctrl = self.clone();
|
||||
|
||||
// Need a copy here, not ideal. But first use in asus_armoury.rs is
|
||||
@@ -699,24 +693,22 @@ impl CtrlTask for CtrlPlatform {
|
||||
tokio::spawn(async move {
|
||||
use futures_lite::StreamExt;
|
||||
let mut buffer = [0; 32];
|
||||
if let Ok(mut stream) = watch_throttle_thermal_policy.into_event_stream(&mut buffer) {
|
||||
if let Ok(mut stream) = watch_platform_profile.into_event_stream(&mut buffer) {
|
||||
while (stream.next().await).is_some() {
|
||||
// this blocks
|
||||
debug!("Platform: watch_throttle_thermal_policy changed");
|
||||
debug!("Platform: watch_platform_profile changed");
|
||||
if let Ok(profile) = ctrl
|
||||
.platform
|
||||
.get_throttle_thermal_policy()
|
||||
.map(ThrottlePolicy::from)
|
||||
.get_platform_profile()
|
||||
.map(|p| p.into())
|
||||
.map_err(|e| {
|
||||
error!("Platform: get_throttle_thermal_policy error: {e}");
|
||||
error!("Platform: get_platform_profile error: {e}");
|
||||
})
|
||||
{
|
||||
let change_epp = ctrl.config.lock().await.throttle_policy_linked_epp;
|
||||
let change_epp = ctrl.config.lock().await.platform_profile_linked_epp;
|
||||
let epp = ctrl.get_config_epp_for_throttle(profile).await;
|
||||
ctrl.check_and_set_epp(epp, change_epp);
|
||||
ctrl.throttle_thermal_policy_changed(&signal_ctxt)
|
||||
.await
|
||||
.ok();
|
||||
ctrl.platform_profile_changed(&signal_ctxt).await.ok();
|
||||
let power_plugged = ctrl
|
||||
.power
|
||||
.get_online()
|
||||
|
||||
Reference in New Issue
Block a user