mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Added ability to change what EPP is linked with each throttle profile
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use config_traits::{StdConfig, StdConfigLoad3};
|
||||
use rog_platform::platform::PlatformPolicy;
|
||||
use rog_platform::cpu::CPUEPP;
|
||||
use rog_platform::platform::ThrottlePolicy;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
const CONFIG_FILE: &str = "asusd.ron";
|
||||
@@ -13,9 +14,14 @@ pub struct Config {
|
||||
pub disable_nvidia_powerd_on_battery: bool,
|
||||
pub ac_command: String,
|
||||
pub bat_command: String,
|
||||
pub platform_policy_linked_epp: bool,
|
||||
pub platform_policy_on_battery: PlatformPolicy,
|
||||
pub platform_policy_on_ac: PlatformPolicy,
|
||||
pub throttle_policy_linked_epp: bool,
|
||||
pub throttle_policy_on_battery: ThrottlePolicy,
|
||||
pub throttle_policy_on_ac: ThrottlePolicy,
|
||||
//
|
||||
pub throttle_quiet_epp: CPUEPP,
|
||||
pub throttle_balanced_epp: CPUEPP,
|
||||
pub throttle_performance_epp: CPUEPP,
|
||||
|
||||
//
|
||||
pub ppt_pl1_spl: Option<u8>,
|
||||
pub ppt_pl2_sppt: Option<u8>,
|
||||
@@ -31,8 +37,8 @@ impl StdConfig for Config {
|
||||
Config {
|
||||
charge_control_end_threshold: 100,
|
||||
disable_nvidia_powerd_on_battery: true,
|
||||
platform_policy_on_battery: PlatformPolicy::Quiet,
|
||||
platform_policy_on_ac: PlatformPolicy::Performance,
|
||||
throttle_policy_on_battery: ThrottlePolicy::Quiet,
|
||||
throttle_policy_on_ac: ThrottlePolicy::Performance,
|
||||
ac_command: String::new(),
|
||||
bat_command: String::new(),
|
||||
..Default::default()
|
||||
@@ -48,7 +54,55 @@ impl StdConfig for Config {
|
||||
}
|
||||
}
|
||||
|
||||
impl StdConfigLoad3<Config462, Config472, Config506> for Config {}
|
||||
impl StdConfigLoad3<Config472, Config506, Config507> for Config {}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Config507 {
|
||||
/// 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,
|
||||
pub platform_policy_linked_epp: bool,
|
||||
pub platform_policy_on_battery: ThrottlePolicy,
|
||||
pub platform_policy_on_ac: ThrottlePolicy,
|
||||
//
|
||||
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<Config507> for Config {
|
||||
fn from(c: Config507) -> 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,
|
||||
throttle_policy_linked_epp: true,
|
||||
throttle_policy_on_battery: c.platform_policy_on_battery,
|
||||
throttle_policy_on_ac: c.platform_policy_on_ac,
|
||||
throttle_quiet_epp: CPUEPP::Power,
|
||||
throttle_balanced_epp: CPUEPP::BalancePower,
|
||||
throttle_performance_epp: CPUEPP::Performance,
|
||||
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 Config506 {
|
||||
@@ -61,9 +115,9 @@ pub struct Config506 {
|
||||
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 platform_policy_to_restore: ThrottlePolicy,
|
||||
pub platform_policy_on_battery: ThrottlePolicy,
|
||||
pub platform_policy_on_ac: ThrottlePolicy,
|
||||
//
|
||||
pub ppt_pl1_spl: Option<u8>,
|
||||
pub ppt_pl2_sppt: Option<u8>,
|
||||
@@ -83,9 +137,12 @@ impl From<Config506> for Config {
|
||||
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,
|
||||
throttle_policy_linked_epp: true,
|
||||
throttle_policy_on_battery: c.platform_policy_on_battery,
|
||||
throttle_policy_on_ac: c.platform_policy_on_ac,
|
||||
throttle_quiet_epp: CPUEPP::Power,
|
||||
throttle_balanced_epp: CPUEPP::BalancePower,
|
||||
throttle_performance_epp: CPUEPP::Performance,
|
||||
ppt_pl1_spl: c.ppt_pl1_spl,
|
||||
ppt_pl2_sppt: c.ppt_pl2_sppt,
|
||||
ppt_fppt: c.ppt_fppt,
|
||||
@@ -120,26 +177,3 @@ impl From<Config472> for Config {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Config462 {
|
||||
/// Save charge limit for restoring on boot
|
||||
pub bat_charge_limit: u8,
|
||||
pub panel_od: bool,
|
||||
pub disable_nvidia_powerd_on_battery: bool,
|
||||
pub ac_command: String,
|
||||
pub bat_command: String,
|
||||
}
|
||||
|
||||
impl From<Config462> for Config {
|
||||
fn from(c: Config462) -> Self {
|
||||
Self {
|
||||
charge_control_end_threshold: c.bat_charge_limit,
|
||||
panel_od: c.panel_od,
|
||||
disable_nvidia_powerd_on_battery: true,
|
||||
ac_command: String::new(),
|
||||
bat_command: String::new(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use async_trait::async_trait;
|
||||
use config_traits::{StdConfig, StdConfigLoad};
|
||||
use futures_lite::StreamExt;
|
||||
use log::{debug, error, info, warn};
|
||||
use rog_platform::platform::{PlatformPolicy, RogPlatform};
|
||||
use rog_platform::platform::{RogPlatform, ThrottlePolicy};
|
||||
use rog_profiles::error::ProfileError;
|
||||
use rog_profiles::fan_curve_set::CurveData;
|
||||
use rog_profiles::{find_fan_curve_node, FanCurvePU, FanCurveProfiles};
|
||||
@@ -70,19 +70,19 @@ impl CtrlFanCurveZbus {
|
||||
info!("{MOD_NAME}: Fetching default fan curves");
|
||||
|
||||
for this in [
|
||||
PlatformPolicy::Balanced,
|
||||
PlatformPolicy::Performance,
|
||||
PlatformPolicy::Quiet,
|
||||
ThrottlePolicy::Balanced,
|
||||
ThrottlePolicy::Performance,
|
||||
ThrottlePolicy::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.
|
||||
let next = PlatformPolicy::get_next_profile(this);
|
||||
let next = ThrottlePolicy::next(this);
|
||||
platform.set_throttle_thermal_policy(next.into())?;
|
||||
|
||||
let active = platform
|
||||
.get_throttle_thermal_policy()
|
||||
.map_or(PlatformPolicy::Balanced, |t| t.into());
|
||||
.map_or(ThrottlePolicy::Balanced, |t| t.into());
|
||||
|
||||
info!("{MOD_NAME}: {active:?}:");
|
||||
for curve in fan_curves.get_fan_curves_for(active) {
|
||||
@@ -130,7 +130,7 @@ impl CtrlFanCurveZbus {
|
||||
/// fan curve if in the same profile mode
|
||||
async fn set_fan_curves_enabled(
|
||||
&mut self,
|
||||
profile: PlatformPolicy,
|
||||
profile: ThrottlePolicy,
|
||||
enabled: bool,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
self.fan_curves
|
||||
@@ -150,7 +150,7 @@ impl CtrlFanCurveZbus {
|
||||
/// activate a fan curve if in the same profile mode
|
||||
async fn set_profile_fan_curve_enabled(
|
||||
&mut self,
|
||||
profile: PlatformPolicy,
|
||||
profile: ThrottlePolicy,
|
||||
fan: FanCurvePU,
|
||||
enabled: bool,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
@@ -170,7 +170,7 @@ impl CtrlFanCurveZbus {
|
||||
/// Get the fan-curve data for the currently active PlatformPolicy
|
||||
async fn fan_curve_data(
|
||||
&mut self,
|
||||
profile: PlatformPolicy,
|
||||
profile: ThrottlePolicy,
|
||||
) -> zbus::fdo::Result<Vec<CurveData>> {
|
||||
let curve = self
|
||||
.fan_curves
|
||||
@@ -185,7 +185,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: PlatformPolicy,
|
||||
profile: ThrottlePolicy,
|
||||
curve: CurveData,
|
||||
) -> zbus::fdo::Result<()> {
|
||||
self.fan_curves
|
||||
@@ -222,11 +222,11 @@ 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: PlatformPolicy) -> zbus::fdo::Result<()> {
|
||||
async fn reset_profile_curves(&self, profile: ThrottlePolicy) -> zbus::fdo::Result<()> {
|
||||
let active = self
|
||||
.platform
|
||||
.get_throttle_thermal_policy()
|
||||
.unwrap_or(PlatformPolicy::Balanced.into());
|
||||
.unwrap_or(ThrottlePolicy::Balanced.into());
|
||||
|
||||
self.platform.set_throttle_thermal_policy(profile.into())?;
|
||||
self.fan_curves
|
||||
|
||||
@@ -4,8 +4,8 @@ use std::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use config_traits::StdConfig;
|
||||
use log::{debug, error, info, warn};
|
||||
use rog_platform::cpu::{CPUControl, CPUGovernor};
|
||||
use rog_platform::platform::{GpuMode, PlatformPolicy, Properties, RogPlatform};
|
||||
use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP};
|
||||
use rog_platform::platform::{GpuMode, Properties, RogPlatform, ThrottlePolicy};
|
||||
use rog_platform::power::AsusPower;
|
||||
use zbus::export::futures_util::lock::Mutex;
|
||||
use zbus::fdo::Error as FdoErr;
|
||||
@@ -180,7 +180,7 @@ impl CtrlPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_and_set_epp(&self, profile: PlatformPolicy, change_epp: bool) {
|
||||
fn check_and_set_epp(&self, enegy_pref: CPUEPP, change_epp: bool) {
|
||||
if !change_epp {
|
||||
info!("PlatformPolicy unlinked from EPP");
|
||||
return;
|
||||
@@ -189,9 +189,9 @@ impl CtrlPlatform {
|
||||
if let Some(cpu) = self.cpu_control.as_ref() {
|
||||
if let Ok(epp) = cpu.get_available_epp() {
|
||||
debug!("Available EPP: {epp:?}");
|
||||
if epp.contains(&profile.into()) {
|
||||
debug!("Setting {profile:?}");
|
||||
cpu.set_epp(profile.into()).ok();
|
||||
if epp.contains(&enegy_pref) {
|
||||
debug!("Setting {enegy_pref:?}");
|
||||
cpu.set_epp(enegy_pref).ok();
|
||||
} else if let Ok(gov) = cpu.get_governor() {
|
||||
if gov != CPUGovernor::Powersave {
|
||||
warn!("powersave governor is not is use, you should use it.");
|
||||
@@ -201,16 +201,26 @@ impl CtrlPlatform {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_config_epp_for_throttle(&self, throttle: ThrottlePolicy) -> 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,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
let throttle = if power_plugged {
|
||||
self.config.lock().await.throttle_policy_on_ac
|
||||
} else {
|
||||
self.config.lock().await.platform_policy_on_battery
|
||||
self.config.lock().await.throttle_policy_on_battery
|
||||
};
|
||||
debug!("Setting {throttle:?} before EPP");
|
||||
let epp = self.get_config_epp_for_throttle(throttle).await;
|
||||
self.platform
|
||||
.set_throttle_thermal_policy(profile.into())
|
||||
.set_throttle_thermal_policy(throttle.into())
|
||||
.ok();
|
||||
self.check_and_set_epp(profile, change_epp);
|
||||
self.check_and_set_epp(epp, change_epp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +262,7 @@ impl CtrlPlatform {
|
||||
platform_name!(panel_od, Properties::PanelOd);
|
||||
platform_name!(mini_led_mode, Properties::MiniLedMode);
|
||||
platform_name!(egpu_enable, Properties::EgpuEnable);
|
||||
platform_name!(throttle_thermal_policy, Properties::PlatformPolicy);
|
||||
platform_name!(throttle_thermal_policy, Properties::ThrottlePolicy);
|
||||
|
||||
platform_name!(ppt_pl1_spl, Properties::PptPl1Spl);
|
||||
platform_name!(ppt_pl2_sppt, Properties::PptPl2Sppt);
|
||||
@@ -338,14 +348,15 @@ impl CtrlPlatform {
|
||||
&mut self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
) -> Result<(), FdoErr> {
|
||||
let policy: PlatformPolicy =
|
||||
let policy: ThrottlePolicy =
|
||||
platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy")
|
||||
.map(|n| n.into())?;
|
||||
let policy = PlatformPolicy::next(&policy);
|
||||
let policy = ThrottlePolicy::next(policy);
|
||||
|
||||
if self.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = self.config.lock().await.platform_policy_linked_epp;
|
||||
self.check_and_set_epp(policy, change_epp);
|
||||
let change_epp = self.config.lock().await.throttle_policy_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())
|
||||
.map_err(|err| {
|
||||
@@ -361,17 +372,18 @@ impl CtrlPlatform {
|
||||
}
|
||||
|
||||
#[dbus_interface(property)]
|
||||
fn throttle_thermal_policy(&self) -> Result<PlatformPolicy, FdoErr> {
|
||||
fn throttle_thermal_policy(&self) -> Result<ThrottlePolicy, FdoErr> {
|
||||
platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy")
|
||||
.map(|n| n.into())
|
||||
}
|
||||
|
||||
#[dbus_interface(property)]
|
||||
async fn set_throttle_thermal_policy(&mut self, policy: PlatformPolicy) -> Result<(), FdoErr> {
|
||||
async fn set_throttle_thermal_policy(&mut self, policy: ThrottlePolicy) -> Result<(), FdoErr> {
|
||||
// TODO: watch for external changes
|
||||
if self.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = self.config.lock().await.platform_policy_linked_epp;
|
||||
self.check_and_set_epp(policy, change_epp);
|
||||
let change_epp = self.config.lock().await.throttle_policy_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())
|
||||
.map_err(|err| {
|
||||
@@ -538,7 +550,7 @@ impl crate::Reloadable for CtrlPlatform {
|
||||
|
||||
if let Ok(power_plugged) = self.power.get_online() {
|
||||
if self.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = self.config.lock().await.platform_policy_linked_epp;
|
||||
let change_epp = self.config.lock().await.throttle_policy_linked_epp;
|
||||
self.update_policy_ac_or_bat(power_plugged > 0, change_epp)
|
||||
.await;
|
||||
}
|
||||
@@ -621,7 +633,7 @@ impl CtrlTask for CtrlPlatform {
|
||||
if let Ok(power_plugged) = platform1.power.get_online() {
|
||||
if !sleeping && platform1.platform.has_throttle_thermal_policy() {
|
||||
let change_epp =
|
||||
platform1.config.lock().await.platform_policy_linked_epp;
|
||||
platform1.config.lock().await.throttle_policy_linked_epp;
|
||||
platform1
|
||||
.update_policy_ac_or_bat(power_plugged > 0, change_epp)
|
||||
.await;
|
||||
@@ -658,7 +670,7 @@ impl CtrlTask for CtrlPlatform {
|
||||
// power change
|
||||
async move {
|
||||
if platform3.platform.has_throttle_thermal_policy() {
|
||||
let change_epp = platform3.config.lock().await.platform_policy_linked_epp;
|
||||
let change_epp = platform3.config.lock().await.throttle_policy_linked_epp;
|
||||
platform3
|
||||
.update_policy_ac_or_bat(power_plugged, change_epp)
|
||||
.await;
|
||||
@@ -705,13 +717,14 @@ impl CtrlTask for CtrlPlatform {
|
||||
if let Ok(profile) = ctrl
|
||||
.platform
|
||||
.get_throttle_thermal_policy()
|
||||
.map(PlatformPolicy::from)
|
||||
.map(ThrottlePolicy::from)
|
||||
.map_err(|e| {
|
||||
error!("Platform: get_throttle_thermal_policy error: {e}");
|
||||
})
|
||||
{
|
||||
let change_epp = ctrl.config.lock().await.platform_policy_linked_epp;
|
||||
ctrl.check_and_set_epp(profile, change_epp);
|
||||
let change_epp = ctrl.config.lock().await.throttle_policy_linked_epp;
|
||||
let epp = ctrl.get_config_epp_for_throttle(profile).await;
|
||||
ctrl.check_and_set_epp(epp, change_epp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user