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:
Luke D. Jones
2025-01-19 21:34:38 +13:00
parent 450205f9a9
commit b9296862df
18 changed files with 404 additions and 379 deletions

View File

@@ -1,11 +1,10 @@
use std::str::FromStr;
use std::sync::Arc;
use ::zbus::export::futures_util::lock::Mutex;
use config_traits::StdConfig;
use log::{debug, error, info};
use rog_platform::asus_armoury::{AttrValue, Attribute, FirmwareAttribute, FirmwareAttributes};
use rog_platform::platform::{RogPlatform, ThrottlePolicy};
use rog_platform::platform::{PlatformProfile, RogPlatform};
use rog_platform::power::AsusPower;
use serde::{Deserialize, Serialize};
use zbus::object_server::SignalEmitter;
@@ -100,8 +99,7 @@ impl AsusArmouryAttribute {
impl crate::Reloadable for AsusArmouryAttribute {
async fn reload(&mut self) -> Result<(), RogError> {
info!("Reloading {}", self.attr.name());
let profile: ThrottlePolicy =
ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?;
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
let power_plugged = self
.power
.get_online()
@@ -182,8 +180,7 @@ impl AsusArmouryAttribute {
async fn restore_default(&self) -> fdo::Result<()> {
self.attr.restore_default()?;
if self.name().is_ppt() {
let profile: ThrottlePolicy =
ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?;
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
let power_plugged = self
.power
.get_online()
@@ -257,8 +254,7 @@ impl AsusArmouryAttribute {
})?;
if self.name().is_ppt() {
let profile: ThrottlePolicy =
ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?;
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
let power_plugged = self
.power
@@ -337,7 +333,7 @@ pub async fn set_config_or_default(
attrs: &FirmwareAttributes,
config: &mut Config,
power_plugged: bool,
profile: ThrottlePolicy
profile: PlatformProfile
) {
for attr in attrs.attributes().iter() {
let name: FirmwareAttribute = attr.name().into();

View File

@@ -3,11 +3,11 @@ use std::collections::HashMap;
use config_traits::{StdConfig, StdConfigLoad1};
use rog_platform::asus_armoury::FirmwareAttribute;
use rog_platform::cpu::CPUEPP;
use rog_platform::platform::ThrottlePolicy;
use rog_platform::platform::PlatformProfile;
use serde::{Deserialize, Serialize};
const CONFIG_FILE: &str = "asusd.ron";
type Tunings = HashMap<ThrottlePolicy, HashMap<FirmwareAttribute, i32>>;
type Tunings = HashMap<PlatformProfile, HashMap<FirmwareAttribute, i32>>;
#[derive(Deserialize, Serialize, PartialEq)]
pub struct Config {
@@ -22,22 +22,22 @@ pub struct Config {
/// An optional command/script to run when power is changed to battery
pub bat_command: String,
/// Set true if energy_performance_preference should be set if the
/// throttle/platform profile is changed
pub throttle_policy_linked_epp: bool,
/// Which throttle/profile to use on battery power
pub throttle_policy_on_battery: ThrottlePolicy,
/// platform profile is changed
pub platform_profile_linked_epp: bool,
/// Which platform profile to use on battery power
pub platform_profile_on_battery: PlatformProfile,
/// Should the throttle policy be set on bat/ac change?
pub change_throttle_policy_on_battery: bool,
/// Which throttle/profile to use on AC power
pub throttle_policy_on_ac: ThrottlePolicy,
/// Should the throttle policy be set on bat/ac change?
pub change_throttle_policy_on_ac: bool,
/// The energy_performance_preference for this throttle/platform profile
pub throttle_quiet_epp: CPUEPP,
/// The energy_performance_preference for this throttle/platform profile
pub throttle_balanced_epp: CPUEPP,
/// The energy_performance_preference for this throttle/platform profile
pub throttle_performance_epp: CPUEPP,
pub change_platform_profile_on_battery: bool,
/// Which platform profile to use on AC power
pub platform_profile_on_ac: PlatformProfile,
/// Should the platform profile be set on bat/ac change?
pub change_platform_profile_on_ac: bool,
/// The energy_performance_preference for this platform profile
pub profile_quiet_epp: CPUEPP,
/// The energy_performance_preference for this platform profile
pub profile_balanced_epp: CPUEPP,
/// The energy_performance_preference for this platform profile
pub profile_performance_epp: CPUEPP,
pub ac_profile_tunings: Tunings,
pub dc_profile_tunings: Tunings,
pub armoury_settings: HashMap<FirmwareAttribute, i32>,
@@ -50,7 +50,7 @@ impl Config {
pub fn select_tunings(
&mut self,
power_plugged: bool,
profile: ThrottlePolicy
profile: PlatformProfile
) -> &mut HashMap<FirmwareAttribute, i32> {
let config = if power_plugged {
&mut self.ac_profile_tunings
@@ -69,14 +69,14 @@ impl Default for Config {
disable_nvidia_powerd_on_battery: true,
ac_command: Default::default(),
bat_command: Default::default(),
throttle_policy_linked_epp: true,
throttle_policy_on_battery: ThrottlePolicy::Quiet,
change_throttle_policy_on_battery: true,
throttle_policy_on_ac: ThrottlePolicy::Performance,
change_throttle_policy_on_ac: true,
throttle_quiet_epp: CPUEPP::Power,
throttle_balanced_epp: CPUEPP::BalancePower,
throttle_performance_epp: CPUEPP::Performance,
platform_profile_linked_epp: true,
platform_profile_on_battery: PlatformProfile::Quiet,
change_platform_profile_on_battery: true,
platform_profile_on_ac: PlatformProfile::Performance,
change_platform_profile_on_ac: true,
profile_quiet_epp: CPUEPP::Power,
profile_balanced_epp: CPUEPP::BalancePower,
profile_performance_epp: CPUEPP::Performance,
ac_profile_tunings: HashMap::default(),
dc_profile_tunings: HashMap::default(),
armoury_settings: HashMap::default(),
@@ -90,8 +90,8 @@ impl StdConfig for Config {
Config {
charge_control_end_threshold: 100,
disable_nvidia_powerd_on_battery: true,
throttle_policy_on_battery: ThrottlePolicy::Quiet,
throttle_policy_on_ac: ThrottlePolicy::Performance,
platform_profile_on_battery: PlatformProfile::Quiet,
platform_profile_on_ac: PlatformProfile::Performance,
ac_command: String::new(),
bat_command: String::new(),
..Default::default()
@@ -120,14 +120,14 @@ pub struct Config601 {
pub disable_nvidia_powerd_on_battery: bool,
pub ac_command: String,
pub bat_command: String,
pub throttle_policy_linked_epp: bool,
pub throttle_policy_on_battery: ThrottlePolicy,
pub change_throttle_policy_on_battery: bool,
pub throttle_policy_on_ac: ThrottlePolicy,
pub change_throttle_policy_on_ac: bool,
pub throttle_quiet_epp: CPUEPP,
pub throttle_balanced_epp: CPUEPP,
pub throttle_performance_epp: CPUEPP,
pub platform_profile_linked_epp: bool,
pub platform_profile_on_battery: PlatformProfile,
pub change_platform_profile_on_battery: bool,
pub platform_profile_on_ac: PlatformProfile,
pub change_platform_profile_on_ac: bool,
pub profile_quiet_epp: CPUEPP,
pub profile_balanced_epp: CPUEPP,
pub profile_performance_epp: CPUEPP,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub ppt_pl1_spl: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none", default)]
@@ -157,14 +157,14 @@ impl From<Config601> for Config {
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
ac_command: c.ac_command,
bat_command: c.bat_command,
throttle_policy_linked_epp: c.throttle_policy_linked_epp,
throttle_policy_on_battery: c.throttle_policy_on_battery,
change_throttle_policy_on_battery: c.change_throttle_policy_on_battery,
throttle_policy_on_ac: c.throttle_policy_on_ac,
change_throttle_policy_on_ac: c.change_throttle_policy_on_ac,
throttle_quiet_epp: c.throttle_quiet_epp,
throttle_balanced_epp: c.throttle_balanced_epp,
throttle_performance_epp: c.throttle_performance_epp,
platform_profile_linked_epp: c.platform_profile_linked_epp,
platform_profile_on_battery: c.platform_profile_on_battery,
change_platform_profile_on_battery: c.change_platform_profile_on_battery,
platform_profile_on_ac: c.platform_profile_on_ac,
change_platform_profile_on_ac: c.change_platform_profile_on_ac,
profile_quiet_epp: c.profile_quiet_epp,
profile_balanced_epp: c.profile_balanced_epp,
profile_performance_epp: c.profile_performance_epp,
last_power_plugged: c.last_power_plugged,
ac_profile_tunings: HashMap::default(),
dc_profile_tunings: HashMap::default(),

View File

@@ -4,7 +4,7 @@ use std::sync::Arc;
use config_traits::{StdConfig, StdConfigLoad};
use futures_lite::StreamExt;
use log::{debug, error, info, warn};
use rog_platform::platform::{RogPlatform, ThrottlePolicy};
use rog_platform::platform::{PlatformProfile, RogPlatform};
use rog_profiles::error::ProfileError;
use rog_profiles::fan_curve_set::CurveData;
use rog_profiles::{find_fan_curve_node, FanCurvePU, FanCurveProfiles};
@@ -23,7 +23,7 @@ pub const FAN_CURVE_ZBUS_PATH: &str = "/xyz/ljones";
pub struct FanCurveConfig {
pub profiles: FanCurveProfiles,
#[serde(skip)]
pub current: u8
pub current: PlatformProfile
}
impl StdConfig for FanCurveConfig {
@@ -54,7 +54,7 @@ pub struct CtrlFanCurveZbus {
impl CtrlFanCurveZbus {
pub fn new() -> Result<Self, RogError> {
let platform = RogPlatform::new()?;
if platform.has_throttle_thermal_policy() {
if platform.has_platform_profile() {
info!("Device has profile control available");
find_fan_curve_node()?;
info!("Device has fan curves available");
@@ -65,16 +65,16 @@ impl CtrlFanCurveZbus {
if config.profiles.balanced.is_empty() || !config.file_path().exists() {
info!("Fetching default fan curves");
let current = platform.get_throttle_thermal_policy()?;
let current = platform.get_platform_profile()?;
for this in [
ThrottlePolicy::Balanced,
ThrottlePolicy::Performance,
ThrottlePolicy::Quiet
PlatformProfile::Balanced,
PlatformProfile::Performance,
PlatformProfile::Quiet
] {
// For each profile we need to switch to it before we
// can read the existing values from hardware. The ACPI method used
// for this is what limits us.
platform.set_throttle_thermal_policy(this.into())?;
platform.set_platform_profile(this.into())?;
let mut dev = find_fan_curve_node()?;
fan_curves.set_active_curve_to_defaults(this, &mut dev)?;
@@ -83,7 +83,7 @@ impl CtrlFanCurveZbus {
info!("{}", String::from(curve));
}
}
platform.set_throttle_thermal_policy(current)?;
platform.set_platform_profile(current.as_str())?;
config.profiles = fan_curves;
config.write();
} else {
@@ -107,7 +107,7 @@ impl CtrlFanCurveZbus {
/// fan curve if in the same profile mode
async fn set_fan_curves_enabled(
&mut self,
profile: ThrottlePolicy,
profile: PlatformProfile,
enabled: bool
) -> zbus::fdo::Result<()> {
self.config
@@ -128,7 +128,7 @@ impl CtrlFanCurveZbus {
/// activate a fan curve if in the same profile mode
async fn set_profile_fan_curve_enabled(
&mut self,
profile: ThrottlePolicy,
profile: PlatformProfile,
fan: FanCurvePU,
enabled: bool
) -> zbus::fdo::Result<()> {
@@ -149,7 +149,7 @@ impl CtrlFanCurveZbus {
/// Get the fan-curve data for the currently active ThrottlePolicy
async fn fan_curve_data(
&mut self,
profile: ThrottlePolicy
profile: PlatformProfile
) -> zbus::fdo::Result<Vec<CurveData>> {
let curve = self
.config
@@ -165,7 +165,7 @@ impl CtrlFanCurveZbus {
/// Will also activate the fan curve if the user is in the same mode.
async fn set_fan_curve(
&mut self,
profile: ThrottlePolicy,
profile: PlatformProfile,
curve: CurveData
) -> zbus::fdo::Result<()> {
self.config
@@ -173,7 +173,7 @@ impl CtrlFanCurveZbus {
.await
.profiles
.save_fan_curve(curve, profile)?;
let active: ThrottlePolicy = self.platform.get_throttle_thermal_policy()?.into();
let active: PlatformProfile = self.platform.get_platform_profile()?.into();
if active == profile {
self.config
.lock()
@@ -190,15 +190,15 @@ impl CtrlFanCurveZbus {
///
/// Each platform_profile has a different default and the default can be
/// read only for the currently active profile.
async fn set_curves_to_defaults(&mut self, profile: ThrottlePolicy) -> zbus::fdo::Result<()> {
let active = self.platform.get_throttle_thermal_policy()?;
self.platform.set_throttle_thermal_policy(profile.into())?;
async fn set_curves_to_defaults(&mut self, profile: PlatformProfile) -> zbus::fdo::Result<()> {
let active = self.platform.get_platform_profile()?;
self.platform.set_platform_profile(profile.into())?;
self.config
.lock()
.await
.profiles
.set_active_curve_to_defaults(profile, &mut find_fan_curve_node()?)?;
self.platform.set_throttle_thermal_policy(active)?;
self.platform.set_platform_profile(active.as_str())?;
self.config.lock().await.write();
Ok(())
}
@@ -208,16 +208,16 @@ impl CtrlFanCurveZbus {
///
/// Each platform_profile has a different default and the defualt can be
/// read only for the currently active profile.
async fn reset_profile_curves(&self, profile: ThrottlePolicy) -> zbus::fdo::Result<()> {
let active = self.platform.get_throttle_thermal_policy()?;
async fn reset_profile_curves(&self, profile: PlatformProfile) -> zbus::fdo::Result<()> {
let active = self.platform.get_platform_profile()?;
self.platform.set_throttle_thermal_policy(profile.into())?;
self.platform.set_platform_profile(profile.into())?;
self.config
.lock()
.await
.profiles
.set_active_curve_to_defaults(active.into(), &mut find_fan_curve_node()?)?;
self.platform.set_throttle_thermal_policy(active)?;
.set_active_curve_to_defaults((&active).into(), &mut find_fan_curve_node()?)?;
self.platform.set_platform_profile(active.as_str())?;
self.config.lock().await.write();
Ok(())
@@ -236,26 +236,31 @@ impl CtrlTask for CtrlFanCurveZbus {
}
async fn create_tasks(&self, _signal_ctxt: SignalEmitter<'static>) -> Result<(), RogError> {
let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?;
let watch_platform_profile = self.platform.monitor_platform_profile()?;
let platform = self.platform.clone();
let config = self.config.clone();
let fan_curves = self.config.clone();
tokio::spawn(async move {
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() {
debug!("watch_throttle_thermal_policy changed");
if let Ok(profile) = platform.get_throttle_thermal_policy().map_err(|e| {
error!("get_throttle_thermal_policy error: {e}");
}) {
debug!("watch_platform_profile changed");
if let Ok(profile) =
platform
.get_platform_profile()
.map(|p| p.into())
.map_err(|e| {
error!("get_platform_profile error: {e}");
})
{
if profile != config.lock().await.current {
fan_curves
.lock()
.await
.profiles
.write_profile_curve_to_platform(
profile.into(),
profile,
&mut find_fan_curve_node().unwrap()
)
.map_err(|e| warn!("write_profile_curve_to_platform, {}", e))
@@ -274,7 +279,7 @@ 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();
let active = self.platform.get_platform_profile()?.into();
let mut config = self.config.lock().await;
if let Ok(mut device) = find_fan_curve_node() {
config

View File

@@ -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()