mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
feature: rework PPT tuning handling more
1. Per profile, per-ac/dc 2. Do not apply unless group is enabled 3. Better reset/disable handling 4. Selecting a profile defaults PPT to off/disabled
This commit is contained in:
@@ -113,15 +113,18 @@ impl crate::Reloadable for AsusArmouryAttribute {
|
||||
} else {
|
||||
&self.config.lock().await.dc_profile_tunings
|
||||
};
|
||||
if let Some(tunings) = config.get(&profile) {
|
||||
if let Some(tune) = tunings.get(&self.name()) {
|
||||
self.attr
|
||||
.set_current_value(&AttrValue::Integer(*tune))
|
||||
.map_err(|e| {
|
||||
error!("Could not set value: {e:?}");
|
||||
e
|
||||
})?;
|
||||
info!("Set {} to {:?}", self.attr.name(), tune);
|
||||
if let Some(tuning) = config.get(&profile) {
|
||||
if tuning.enabled {
|
||||
if let Some(tune) = tuning.group.get(&self.name()) {
|
||||
self.attr
|
||||
.set_current_value(&AttrValue::Integer(*tune))
|
||||
.map_err(|e| {
|
||||
error!("Could not set {} value: {e:?}", self.attr.name());
|
||||
self.attr.base_path_exists();
|
||||
e
|
||||
})?;
|
||||
info!("Set {} to {:?}", self.attr.name(), tune);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,12 +194,20 @@ impl AsusArmouryAttribute {
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut config = self.config.lock().await;
|
||||
let tunings = config.select_tunings(power_plugged == 1, profile);
|
||||
if let Some(tune) = tunings.get_mut(&self.name()) {
|
||||
let tuning = config.select_tunings(power_plugged == 1, profile);
|
||||
if let Some(tune) = tuning.group.get_mut(&self.name()) {
|
||||
if let AttrValue::Integer(i) = self.attr.default_value() {
|
||||
*tune = *i;
|
||||
}
|
||||
}
|
||||
if tuning.enabled {
|
||||
self.attr
|
||||
.set_current_value(self.attr.default_value())
|
||||
.map_err(|e| {
|
||||
error!("Could not set value: {e:?}");
|
||||
e
|
||||
})?;
|
||||
}
|
||||
config.write();
|
||||
}
|
||||
Ok(())
|
||||
@@ -236,6 +247,28 @@ impl AsusArmouryAttribute {
|
||||
|
||||
#[zbus(property)]
|
||||
async fn current_value(&self) -> fdo::Result<i32> {
|
||||
if self.name().is_ppt() {
|
||||
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||
let power_plugged = self
|
||||
.power
|
||||
.get_online()
|
||||
.map_err(|e| {
|
||||
error!("Could not get power status: {e:?}");
|
||||
e
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let mut config = self.config.lock().await;
|
||||
let tuning = config.select_tunings(power_plugged == 1, profile);
|
||||
if let Some(tune) = tuning.group.get(&self.name()) {
|
||||
return Ok(*tune);
|
||||
} else if let AttrValue::Integer(i) = self.attr.default_value() {
|
||||
return Ok(*i);
|
||||
}
|
||||
return Err(fdo::Error::Failed(
|
||||
"Could not read current value".to_string()
|
||||
));
|
||||
}
|
||||
|
||||
if let Ok(AttrValue::Integer(i)) = self.attr.current_value() {
|
||||
return Ok(i);
|
||||
}
|
||||
@@ -246,16 +279,8 @@ impl AsusArmouryAttribute {
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_current_value(&mut self, value: i32) -> fdo::Result<()> {
|
||||
self.attr
|
||||
.set_current_value(&AttrValue::Integer(value))
|
||||
.map_err(|e| {
|
||||
error!("Could not set value: {e:?}");
|
||||
e
|
||||
})?;
|
||||
|
||||
if self.name().is_ppt() {
|
||||
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||
|
||||
let power_plugged = self
|
||||
.power
|
||||
.get_online()
|
||||
@@ -264,16 +289,32 @@ impl AsusArmouryAttribute {
|
||||
e
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let mut config = self.config.lock().await;
|
||||
let tunings = config.select_tunings(power_plugged == 1, profile);
|
||||
|
||||
if let Some(tune) = tunings.get_mut(&self.name()) {
|
||||
let mut config = self.config.lock().await;
|
||||
let tuning = config.select_tunings(power_plugged == 1, profile);
|
||||
|
||||
if let Some(tune) = tuning.group.get_mut(&self.name()) {
|
||||
*tune = value;
|
||||
} else {
|
||||
tunings.insert(self.name(), value);
|
||||
debug!("Set tuning config for {} = {:?}", self.attr.name(), value);
|
||||
tuning.group.insert(self.name(), value);
|
||||
debug!("Store tuning config for {} = {:?}", self.attr.name(), value);
|
||||
}
|
||||
if tuning.enabled {
|
||||
self.attr
|
||||
.set_current_value(&AttrValue::Integer(value))
|
||||
.map_err(|e| {
|
||||
error!("Could not set value: {e:?}");
|
||||
e
|
||||
})?;
|
||||
}
|
||||
} else {
|
||||
self.attr
|
||||
.set_current_value(&AttrValue::Integer(value))
|
||||
.map_err(|e| {
|
||||
error!("Could not set value: {e:?}");
|
||||
e
|
||||
})?;
|
||||
|
||||
let has_attr = self
|
||||
.config
|
||||
.lock()
|
||||
@@ -309,9 +350,10 @@ pub async fn start_attributes_zbus(
|
||||
conn: &Connection,
|
||||
platform: RogPlatform,
|
||||
power: AsusPower,
|
||||
attributes: FirmwareAttributes,
|
||||
config: Arc<Mutex<Config>>
|
||||
) -> Result<(), RogError> {
|
||||
for attr in FirmwareAttributes::new().attributes() {
|
||||
for attr in attributes.attributes() {
|
||||
let mut attr = AsusArmouryAttribute::new(
|
||||
attr.clone(),
|
||||
platform.clone(),
|
||||
@@ -338,9 +380,13 @@ pub async fn set_config_or_default(
|
||||
for attr in attrs.attributes().iter() {
|
||||
let name: FirmwareAttribute = attr.name().into();
|
||||
if name.is_ppt() {
|
||||
let tunings = config.select_tunings(power_plugged, profile);
|
||||
let tuning = config.select_tunings(power_plugged, profile);
|
||||
if !tuning.enabled {
|
||||
debug!("Tuning group is not enabled, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(tune) = tunings.get(&name) {
|
||||
if let Some(tune) = tuning.group.get(&name) {
|
||||
attr.set_current_value(&AttrValue::Integer(*tune))
|
||||
.map_err(|e| {
|
||||
error!("Failed to set {}: {e}", <&str>::from(name));
|
||||
@@ -354,7 +400,7 @@ pub async fn set_config_or_default(
|
||||
})
|
||||
.ok();
|
||||
if let AttrValue::Integer(i) = default {
|
||||
tunings.insert(name, *i);
|
||||
tuning.group.insert(name, *i);
|
||||
info!(
|
||||
"Set default tuning config for {} = {:?}",
|
||||
<&str>::from(name),
|
||||
|
||||
@@ -7,7 +7,13 @@ use rog_platform::platform::PlatformProfile;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const CONFIG_FILE: &str = "asusd.ron";
|
||||
type Tunings = HashMap<PlatformProfile, HashMap<FirmwareAttribute, i32>>;
|
||||
|
||||
#[derive(Default, Clone, Deserialize, Serialize, PartialEq)]
|
||||
pub struct Tuning {
|
||||
pub enabled: bool,
|
||||
pub group: HashMap<FirmwareAttribute, i32>
|
||||
}
|
||||
type Tunings = HashMap<PlatformProfile, Tuning>;
|
||||
|
||||
#[derive(Deserialize, Serialize, PartialEq)]
|
||||
pub struct Config {
|
||||
@@ -47,17 +53,13 @@ pub struct Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn select_tunings(
|
||||
&mut self,
|
||||
power_plugged: bool,
|
||||
profile: PlatformProfile
|
||||
) -> &mut HashMap<FirmwareAttribute, i32> {
|
||||
pub fn select_tunings(&mut self, power_plugged: bool, profile: PlatformProfile) -> &mut Tuning {
|
||||
let config = if power_plugged {
|
||||
&mut self.ac_profile_tunings
|
||||
} else {
|
||||
&mut self.dc_profile_tunings
|
||||
};
|
||||
config.entry(profile).or_insert_with(HashMap::new)
|
||||
config.entry(profile).or_insert_with(Tuning::default)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use config_traits::StdConfig;
|
||||
use log::{debug, error, info, warn};
|
||||
use rog_platform::asus_armoury::FirmwareAttributes;
|
||||
use rog_platform::asus_armoury::{AttrValue, FirmwareAttribute, FirmwareAttributes};
|
||||
use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP};
|
||||
use rog_platform::platform::{PlatformProfile, Properties, RogPlatform};
|
||||
use rog_platform::power::AsusPower;
|
||||
@@ -43,24 +43,27 @@ macro_rules! platform_get_value {
|
||||
pub struct CtrlPlatform {
|
||||
power: AsusPower,
|
||||
platform: RogPlatform,
|
||||
attributes: FirmwareAttributes,
|
||||
cpu_control: Option<CPUControl>,
|
||||
config: Arc<Mutex<Config>>
|
||||
}
|
||||
|
||||
impl CtrlPlatform {
|
||||
pub fn new(
|
||||
platform: RogPlatform,
|
||||
power: AsusPower,
|
||||
attributes: FirmwareAttributes,
|
||||
config: Arc<Mutex<Config>>,
|
||||
config_path: &Path,
|
||||
signal_context: SignalEmitter<'static>
|
||||
) -> Result<Self, RogError> {
|
||||
let platform = RogPlatform::new()?;
|
||||
let power = AsusPower::new()?;
|
||||
let config1 = config.clone();
|
||||
let config_path = config_path.to_owned();
|
||||
|
||||
let ret_self = CtrlPlatform {
|
||||
power,
|
||||
platform,
|
||||
attributes,
|
||||
config,
|
||||
cpu_control: CPUControl::new()
|
||||
.map_err(|e| error!("Couldn't get CPU control sysfs: {e}"))
|
||||
@@ -332,6 +335,7 @@ impl CtrlPlatform {
|
||||
warn!("platform_profile {}", err);
|
||||
FdoErr::Failed(format!("RogPlatform: platform_profile: {err}"))
|
||||
})?;
|
||||
self.enable_ppt_group_changed(&ctxt).await?;
|
||||
Ok(self.platform_profile_changed(&ctxt).await?)
|
||||
} else {
|
||||
Err(FdoErr::NotSupported(
|
||||
@@ -352,6 +356,21 @@ impl CtrlPlatform {
|
||||
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);
|
||||
|
||||
let power_plugged = self
|
||||
.power
|
||||
.get_online()
|
||||
.map_err(|e| {
|
||||
error!("Could not get power status: {e:?}");
|
||||
e
|
||||
})
|
||||
.unwrap_or_default();
|
||||
self.config
|
||||
.lock()
|
||||
.await
|
||||
.select_tunings(power_plugged == 1, policy)
|
||||
.enabled = false;
|
||||
|
||||
self.config.lock().await.write();
|
||||
self.platform
|
||||
.set_platform_profile(policy.into())
|
||||
@@ -475,9 +494,96 @@ impl CtrlPlatform {
|
||||
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(())
|
||||
}
|
||||
|
||||
/// Set if the PPT tuning group for the current profile is enabled
|
||||
#[zbus(property)]
|
||||
async fn enable_ppt_group(&self) -> Result<bool, FdoErr> {
|
||||
let power_plugged = self
|
||||
.power
|
||||
.get_online()
|
||||
.map_err(|e| {
|
||||
error!("Could not get power status: {e:?}");
|
||||
e
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||
Ok(self
|
||||
.config
|
||||
.lock()
|
||||
.await
|
||||
.select_tunings(power_plugged == 1, profile)
|
||||
.enabled)
|
||||
}
|
||||
|
||||
/// Set if the PPT tuning group for the current profile is enabled
|
||||
#[zbus(property)]
|
||||
async fn set_enable_ppt_group(&mut self, enable: bool) -> Result<(), FdoErr> {
|
||||
let power_plugged = self
|
||||
.power
|
||||
.get_online()
|
||||
.map_err(|e| {
|
||||
error!("Could not get power status: {e:?}");
|
||||
e
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||
|
||||
// Clone to reduce blocking
|
||||
let tuning = self
|
||||
.config
|
||||
.lock()
|
||||
.await
|
||||
.select_tunings(power_plugged == 1, profile)
|
||||
.clone();
|
||||
|
||||
for attr in self.attributes.attributes() {
|
||||
let name: FirmwareAttribute = attr.name().into();
|
||||
if name.is_ppt() {
|
||||
// reset stored value
|
||||
if let Some(tune) = self
|
||||
.config
|
||||
.lock()
|
||||
.await
|
||||
.select_tunings(power_plugged == 1, profile)
|
||||
.group
|
||||
.get_mut(&name)
|
||||
{
|
||||
let value = if !enable {
|
||||
attr.default_value().clone()
|
||||
} else {
|
||||
tuning
|
||||
.group
|
||||
.get(&name)
|
||||
.map(|v| AttrValue::Integer(*v))
|
||||
.unwrap_or_else(|| attr.default_value().clone())
|
||||
};
|
||||
// restore default
|
||||
attr.set_current_value(&value)?;
|
||||
if let AttrValue::Integer(i) = value {
|
||||
*tune = i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !enable {
|
||||
// finally, reapply the profile to ensure acpi does the thingy
|
||||
self.platform.set_platform_profile(profile.into())?;
|
||||
}
|
||||
|
||||
self.config
|
||||
.lock()
|
||||
.await
|
||||
.select_tunings(power_plugged == 1, profile)
|
||||
.enabled = enable;
|
||||
self.config.lock().await.write();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::ZbusRun for CtrlPlatform {
|
||||
@@ -665,6 +771,7 @@ impl CtrlTask for CtrlPlatform {
|
||||
error!("Platform: get_platform_profile error: {e}");
|
||||
})
|
||||
{
|
||||
// TODO: manage this better, shouldn't need to create every time
|
||||
let attrs = FirmwareAttributes::new();
|
||||
set_config_or_default(
|
||||
&attrs,
|
||||
@@ -709,6 +816,7 @@ impl CtrlTask for CtrlPlatform {
|
||||
let epp = ctrl.get_config_epp_for_throttle(profile).await;
|
||||
ctrl.check_and_set_epp(epp, change_epp);
|
||||
ctrl.platform_profile_changed(&signal_ctxt).await.ok();
|
||||
ctrl.enable_ppt_group_changed(&signal_ctxt).await.ok();
|
||||
let power_plugged = ctrl
|
||||
.power
|
||||
.get_online()
|
||||
|
||||
@@ -12,6 +12,7 @@ use asusd::ctrl_platform::CtrlPlatform;
|
||||
use asusd::{print_board_info, start_tasks, CtrlTask, DBUS_NAME};
|
||||
use config_traits::{StdConfig, StdConfigLoad1};
|
||||
use log::{error, info};
|
||||
use rog_platform::asus_armoury::FirmwareAttributes;
|
||||
use rog_platform::platform::RogPlatform;
|
||||
use rog_platform::power::AsusPower;
|
||||
use zbus::fdo::ObjectManager;
|
||||
@@ -69,7 +70,15 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
// supported.add_to_server(&mut connection).await;
|
||||
let platform = RogPlatform::new()?; // TODO: maybe needs async mutex?
|
||||
let power = AsusPower::new()?; // TODO: maybe needs async mutex?
|
||||
start_attributes_zbus(&server, platform, power, config.clone()).await?;
|
||||
let attributes = FirmwareAttributes::new();
|
||||
start_attributes_zbus(
|
||||
&server,
|
||||
platform.clone(),
|
||||
power.clone(),
|
||||
attributes.clone(),
|
||||
config.clone()
|
||||
)
|
||||
.await?;
|
||||
|
||||
match CtrlFanCurveZbus::new() {
|
||||
Ok(ctrl) => {
|
||||
@@ -82,6 +91,9 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
match CtrlPlatform::new(
|
||||
platform,
|
||||
power,
|
||||
attributes,
|
||||
config.clone(),
|
||||
&cfg_path,
|
||||
CtrlPlatform::signal_context(&server)?
|
||||
|
||||
Reference in New Issue
Block a user