From d4c68546e716219d6ba41eecbc926874db7782b2 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Mon, 15 Jan 2024 18:00:27 +1300 Subject: [PATCH] Added ability to change what EPP is linked with each throttle profile --- CHANGELOG.md | 3 + Cargo.lock | 1 + asusctl/Cargo.toml | 1 + asusctl/src/cli_opts.rs | 4 +- asusctl/src/fan_curve_cli.rs | 4 +- asusctl/src/main.rs | 6 +- asusd/src/config.rs | 106 ++++++++++++------ asusd/src/ctrl_fancurves.rs | 24 ++-- asusd/src/ctrl_platform.rs | 65 ++++++----- .../src/pages/fan_curve_page.rs | 4 +- rog-control-center/src/system_state.rs | 16 +-- rog-control-center/src/update_and_notify.rs | 10 +- rog-control-center/src/widgets/fan_graph.rs | 4 +- rog-control-center/src/widgets/rog_bios.rs | 6 +- rog-dbus/src/zbus_fan_curves.rs | 12 +- rog-dbus/src/zbus_platform.rs | 6 +- rog-platform/src/cpu.rs | 25 +++-- rog-platform/src/platform.rs | 50 ++++----- rog-profiles/src/lib.rs | 60 +++++----- 19 files changed, 230 insertions(+), 177 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d9c6bfb..9a4bc274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Added ability to change what EPP is linked with each throttle profile + ## [v5.0.7] ### Changed - Fix to suspend process in anime thread to let custom anims run on wake. diff --git a/Cargo.lock b/Cargo.lock index b8840ff7..6c740a2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,6 +213,7 @@ dependencies = [ "rog_platform", "rog_profiles", "tinybmp", + "tokio", "toml 0.5.11", ] diff --git a/asusctl/Cargo.toml b/asusctl/Cargo.toml index 0bf9ae0a..79db9b66 100644 --- a/asusctl/Cargo.toml +++ b/asusctl/Cargo.toml @@ -22,5 +22,6 @@ gif.workspace = true tinybmp.workspace = true glam.workspace = true rog_dbus = { path = "../rog-dbus" } +tokio = { version = "^1.23.0", default-features = false, features = ["macros", "sync", "rt", "time"]} cargo-husky.workspace = true \ No newline at end of file diff --git a/asusctl/src/cli_opts.rs b/asusctl/src/cli_opts.rs index bcb7e279..ba248371 100644 --- a/asusctl/src/cli_opts.rs +++ b/asusctl/src/cli_opts.rs @@ -1,5 +1,5 @@ use gumdrop::Options; -use rog_platform::platform::PlatformPolicy; +use rog_platform::platform::ThrottlePolicy; use crate::anime_cli::AnimeCommand; use crate::aura_cli::{LedBrightness, LedPowerCommand1, LedPowerCommand2, SetAuraBuiltin}; @@ -60,7 +60,7 @@ pub struct ProfileCommand { pub profile_get: bool, #[options(meta = "", help = "set the active profile")] - pub profile_set: Option, + pub profile_set: Option, } #[derive(Options)] diff --git a/asusctl/src/fan_curve_cli.rs b/asusctl/src/fan_curve_cli.rs index 59a8b456..77488726 100644 --- a/asusctl/src/fan_curve_cli.rs +++ b/asusctl/src/fan_curve_cli.rs @@ -1,5 +1,5 @@ use gumdrop::Options; -use rog_platform::platform::PlatformPolicy; +use rog_platform::platform::ThrottlePolicy; use rog_profiles::fan_curve_set::CurveData; use rog_profiles::FanCurvePU; @@ -18,7 +18,7 @@ pub struct FanCurveCommand { meta = "", help = "profile to modify fan-curve for. Shows data if no options provided" )] - pub mod_profile: Option, + pub mod_profile: Option, #[options( meta = "", diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 4462f004..b53fac26 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -18,7 +18,7 @@ use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraPowerDev}; use rog_aura::{self, AuraEffect}; use rog_dbus::RogDbusClientBlocking; use rog_platform::error::PlatformError; -use rog_platform::platform::{GpuMode, PlatformPolicy, Properties}; +use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy}; use rog_profiles::error::ProfileError; use crate::aura_cli::{AuraPowerStates, LedBrightness}; @@ -662,7 +662,7 @@ fn handle_throttle_profile( supported: &[Properties], cmd: &ProfileCommand, ) -> Result<(), Box> { - if !supported.contains(&Properties::PlatformPolicy) { + if !supported.contains(&Properties::ThrottlePolicy) { println!("Profiles not supported by either this kernel or by the laptop."); return Err(ProfileError::NotSupported.into()); } @@ -691,7 +691,7 @@ fn handle_throttle_profile( } if cmd.list { - let res = PlatformPolicy::list(); + let res = ThrottlePolicy::list(); for p in &res { println!("{:?}", p); } diff --git a/asusd/src/config.rs b/asusd/src/config.rs index ffd0349e..7ea0a4b2 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -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, pub ppt_pl2_sppt: Option, @@ -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 for Config {} +impl StdConfigLoad3 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, + pub ppt_pl2_sppt: Option, + pub ppt_fppt: Option, + pub ppt_apu_sppt: Option, + pub ppt_platform_sppt: Option, + pub nv_dynamic_boost: Option, + pub nv_temp_target: Option, +} + +impl From 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, pub ppt_pl2_sppt: Option, @@ -83,9 +137,12 @@ impl From 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 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 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() - } - } -} diff --git a/asusd/src/ctrl_fancurves.rs b/asusd/src/ctrl_fancurves.rs index b558c361..2e3daf05 100644 --- a/asusd/src/ctrl_fancurves.rs +++ b/asusd/src/ctrl_fancurves.rs @@ -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> { 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 diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index cfa4b97b..69ede817 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -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 { + fn throttle_thermal_policy(&self) -> Result { 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); } } } diff --git a/rog-control-center/src/pages/fan_curve_page.rs b/rog-control-center/src/pages/fan_curve_page.rs index cfaa83ea..c2b24655 100644 --- a/rog-control-center/src/pages/fan_curve_page.rs +++ b/rog-control-center/src/pages/fan_curve_page.rs @@ -1,5 +1,5 @@ use egui::{RichText, Ui}; -use rog_platform::platform::PlatformPolicy; +use rog_platform::platform::ThrottlePolicy; use crate::system_state::{FanCurvesState, SystemState}; use crate::widgets::fan_graphs; @@ -29,7 +29,7 @@ impl RogApp { } fn fan_curve( - current: &mut PlatformPolicy, + current: &mut ThrottlePolicy, curves: &mut FanCurvesState, dbus: &RogDbusClientBlocking<'_>, do_error: &mut Option, diff --git a/rog-control-center/src/system_state.rs b/rog-control-center/src/system_state.rs index 5ca3d104..9b9f8683 100644 --- a/rog-control-center/src/system_state.rs +++ b/rog-control-center/src/system_state.rs @@ -10,7 +10,7 @@ use rog_aura::aura_detection::PowerZones; use rog_aura::layouts::KeyLayout; use rog_aura::usb::{AuraDevice, AuraPowerDev}; use rog_aura::{AuraEffect, AuraModeNum, AuraZone, LedBrightness}; -use rog_platform::platform::{GpuMode, PlatformPolicy}; +use rog_platform::platform::{GpuMode, ThrottlePolicy}; use rog_profiles::fan_curve_set::CurveData; use rog_profiles::FanCurvePU; use supergfxctl::pci_device::{GfxMode, GfxPower}; @@ -34,7 +34,7 @@ pub struct PlatformState { pub mini_led_mode: Option, pub dgpu_disable: Option, pub egpu_enable: Option, - pub throttle: Option, + pub throttle: Option, pub charge_limit: Option, } @@ -65,9 +65,9 @@ impl PlatformState { #[derive(Clone, Debug, Default)] pub struct FanCurvesState { - pub show_curve: PlatformPolicy, + pub show_curve: ThrottlePolicy, pub show_graph: FanCurvePU, - pub curves: BTreeMap>, + pub curves: BTreeMap>, pub available_fans: HashSet, pub drag_delta: Vec2, } @@ -75,13 +75,13 @@ pub struct FanCurvesState { impl FanCurvesState { pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result { let profiles = vec![ - PlatformPolicy::Balanced, - PlatformPolicy::Quiet, - PlatformPolicy::Performance, + ThrottlePolicy::Balanced, + ThrottlePolicy::Quiet, + ThrottlePolicy::Performance, ]; let mut available_fans = HashSet::new(); - let mut curves: BTreeMap> = BTreeMap::new(); + let mut curves: BTreeMap> = BTreeMap::new(); for p in &profiles { if let Ok(curve) = dbus.proxies().fan_curves().fan_curve_data(*p) { if available_fans.is_empty() { diff --git a/rog-control-center/src/update_and_notify.rs b/rog-control-center/src/update_and_notify.rs index f0a1ebe5..9384e796 100644 --- a/rog-control-center/src/update_and_notify.rs +++ b/rog-control-center/src/update_and_notify.rs @@ -14,7 +14,7 @@ use notify_rust::{Hint, Notification, NotificationHandle, Urgency}; use rog_dbus::zbus_anime::AnimeProxy; use rog_dbus::zbus_aura::AuraProxy; use rog_dbus::zbus_platform::PlatformProxy; -use rog_platform::platform::{GpuMode, PlatformPolicy}; +use rog_platform::platform::{GpuMode, ThrottlePolicy}; use serde::{Deserialize, Serialize}; use supergfxctl::actions::UserActionRequired as GfxUserAction; use supergfxctl::pci_device::{GfxMode, GfxPower}; @@ -546,11 +546,11 @@ fn _ac_power_notification(message: &str, on: &bool) -> Result Result { +fn do_thermal_notif(message: &str, profile: &ThrottlePolicy) -> Result { let icon = match profile { - PlatformPolicy::Balanced => "asus_notif_yellow", - PlatformPolicy::Performance => "asus_notif_red", - PlatformPolicy::Quiet => "asus_notif_green", + ThrottlePolicy::Balanced => "asus_notif_yellow", + ThrottlePolicy::Performance => "asus_notif_red", + ThrottlePolicy::Quiet => "asus_notif_green", }; let profile: &str = (*profile).into(); let mut notif = base_notification(message, &profile.to_uppercase()); diff --git a/rog-control-center/src/widgets/fan_graph.rs b/rog-control-center/src/widgets/fan_graph.rs index c5b7eec9..e78708f0 100644 --- a/rog-control-center/src/widgets/fan_graph.rs +++ b/rog-control-center/src/widgets/fan_graph.rs @@ -1,6 +1,6 @@ use egui::plot::{Line, Plot, Points}; use egui::Ui; -use rog_platform::platform::PlatformPolicy; +use rog_platform::platform::ThrottlePolicy; use rog_profiles::fan_curve_set::CurveData; use rog_profiles::FanCurvePU; @@ -15,7 +15,7 @@ pub fn fan_graphs( ) { ui.separator(); - let mut item = |profile: PlatformPolicy, ui: &mut Ui| { + let mut item = |profile: ThrottlePolicy, ui: &mut Ui| { ui.group(|ui| { if ui .selectable_value(&mut curves.show_curve, profile, format!("{profile:?}")) diff --git a/rog-control-center/src/widgets/rog_bios.rs b/rog-control-center/src/widgets/rog_bios.rs index 27032854..32153a14 100644 --- a/rog-control-center/src/widgets/rog_bios.rs +++ b/rog-control-center/src/widgets/rog_bios.rs @@ -1,5 +1,5 @@ use egui::Ui; -use rog_platform::platform::{GpuMode, PlatformPolicy}; +use rog_platform::platform::{GpuMode, ThrottlePolicy}; use crate::system_state::SystemState; @@ -7,7 +7,7 @@ pub fn platform_profile(states: &mut SystemState, ui: &mut Ui) { if let Some(mut throttle) = states.bios.throttle { ui.heading("Platform profile"); - let mut item = |p: PlatformPolicy, ui: &mut Ui| { + let mut item = |p: ThrottlePolicy, ui: &mut Ui| { if ui .selectable_value(&mut throttle, p, format!("{p:?}")) .clicked() @@ -25,7 +25,7 @@ pub fn platform_profile(states: &mut SystemState, ui: &mut Ui) { }; ui.horizontal_wrapped(|ui| { - for a in PlatformPolicy::list() { + for a in ThrottlePolicy::list() { item(a, ui); } }); diff --git a/rog-dbus/src/zbus_fan_curves.rs b/rog-dbus/src/zbus_fan_curves.rs index 90590bf2..b44689f2 100644 --- a/rog-dbus/src/zbus_fan_curves.rs +++ b/rog-dbus/src/zbus_fan_curves.rs @@ -20,7 +20,7 @@ //! //! …consequently `zbus-xmlgen` did not generate code for the above interfaces. -use rog_platform::platform::PlatformPolicy; +use rog_platform::platform::ThrottlePolicy; use rog_profiles::fan_curve_set::CurveData; use rog_profiles::FanCurvePU; use zbus::dbus_proxy; @@ -32,30 +32,30 @@ use zbus::dbus_proxy; )] trait FanCurves { /// Get the fan-curve data for the currently active PlatformProfile - fn fan_curve_data(&self, profile: PlatformPolicy) -> zbus::Result>; + fn fan_curve_data(&self, profile: ThrottlePolicy) -> zbus::Result>; /// Reset the stored (self) and device curve to the defaults of the /// platform. /// /// Each platform_profile has a different default and the defualt can be /// read only for the currently active profile. - fn reset_profile_curves(&self, profile: PlatformPolicy) -> zbus::fdo::Result<()>; + fn reset_profile_curves(&self, profile: ThrottlePolicy) -> zbus::fdo::Result<()>; /// SetActiveCurveToDefaults method fn set_active_curve_to_defaults(&self) -> zbus::Result<()>; /// Set the fan curve for the specified profile, or the profile the user is /// currently in if profile == None. Will also activate the fan curve. - fn set_fan_curve(&self, profile: PlatformPolicy, curve: CurveData) -> zbus::Result<()>; + fn set_fan_curve(&self, profile: ThrottlePolicy, curve: CurveData) -> zbus::Result<()>; /// Set a profile fan curve enabled status. Will also activate a fan curve. - fn set_fan_curves_enabled(&self, profile: PlatformPolicy, enabled: bool) -> zbus::Result<()>; + fn set_fan_curves_enabled(&self, profile: ThrottlePolicy, enabled: bool) -> zbus::Result<()>; /// Set a single fan curve for a profile to enabled status. Will also /// activate a fan curve. async fn set_profile_fan_curve_enabled( &self, - profile: PlatformPolicy, + profile: ThrottlePolicy, fan: FanCurvePU, enabled: bool, ) -> zbus::Result<()>; diff --git a/rog-dbus/src/zbus_platform.rs b/rog-dbus/src/zbus_platform.rs index a3c53617..17887845 100644 --- a/rog-dbus/src/zbus_platform.rs +++ b/rog-dbus/src/zbus_platform.rs @@ -20,7 +20,7 @@ //! //! …consequently `zbus-xmlgen` did not generate code for the above interfaces. -use rog_platform::platform::{GpuMode, PlatformPolicy, Properties}; +use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy}; use zbus::dbus_proxy; #[dbus_proxy( @@ -120,7 +120,7 @@ trait Platform { /// PlatformPolicy property #[dbus_proxy(property)] - fn throttle_thermal_policy(&self) -> zbus::Result; + fn throttle_thermal_policy(&self) -> zbus::Result; #[dbus_proxy(property)] - fn set_throttle_thermal_policy(&self, value: PlatformPolicy) -> zbus::Result<()>; + fn set_throttle_thermal_policy(&self, value: ThrottlePolicy) -> zbus::Result<()>; } diff --git a/rog-platform/src/cpu.rs b/rog-platform/src/cpu.rs index deb0f5e4..a09c3dd5 100644 --- a/rog-platform/src/cpu.rs +++ b/rog-platform/src/cpu.rs @@ -6,7 +6,7 @@ use typeshare::typeshare; use zbus::zvariant::{OwnedValue, Type, Value}; use crate::error::{PlatformError, Result}; -use crate::platform::PlatformPolicy; +use crate::platform::ThrottlePolicy; use crate::{read_attr_string, to_device}; const ATTR_AVAILABLE_GOVERNORS: &str = "cpufreq/scaling_available_governors"; @@ -182,10 +182,21 @@ impl From for String { #[typeshare] #[repr(u8)] #[derive( - Deserialize, Serialize, Type, Value, OwnedValue, Debug, PartialEq, PartialOrd, Clone, Copy, + Deserialize, + Serialize, + Type, + Value, + OwnedValue, + Default, + Debug, + PartialEq, + PartialOrd, + Clone, + Copy, )] #[zvariant(signature = "s")] pub enum CPUEPP { + #[default] Default = 0, Performance = 1, BalancePerformance = 2, @@ -193,12 +204,12 @@ pub enum CPUEPP { Power = 4, } -impl From for CPUEPP { - fn from(value: PlatformPolicy) -> Self { +impl From for CPUEPP { + fn from(value: ThrottlePolicy) -> Self { match value { - PlatformPolicy::Balanced => CPUEPP::BalancePerformance, - PlatformPolicy::Performance => CPUEPP::Performance, - PlatformPolicy::Quiet => CPUEPP::Power, + ThrottlePolicy::Balanced => CPUEPP::BalancePerformance, + ThrottlePolicy::Performance => CPUEPP::Performance, + ThrottlePolicy::Quiet => CPUEPP::Power, } } } diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index be6522f3..932116ee 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -268,15 +268,15 @@ impl Display for GpuMode { )] #[zvariant(signature = "s")] /// `throttle_thermal_policy` in asus_wmi -pub enum PlatformPolicy { +pub enum ThrottlePolicy { #[default] Balanced = 0, Performance = 1, Quiet = 2, } -impl PlatformPolicy { - pub const fn next(&self) -> Self { +impl ThrottlePolicy { + pub const fn next(self) -> Self { match self { Self::Balanced => Self::Performance, Self::Performance => Self::Quiet, @@ -289,7 +289,7 @@ impl PlatformPolicy { } } -impl From for PlatformPolicy { +impl From for ThrottlePolicy { fn from(num: u8) -> Self { match num { 0 => Self::Balanced, @@ -303,55 +303,45 @@ impl From for PlatformPolicy { } } -impl From for u8 { - fn from(p: PlatformPolicy) -> Self { +impl From for u8 { + fn from(p: ThrottlePolicy) -> Self { match p { - PlatformPolicy::Balanced => 0, - PlatformPolicy::Performance => 1, - PlatformPolicy::Quiet => 2, + ThrottlePolicy::Balanced => 0, + ThrottlePolicy::Performance => 1, + ThrottlePolicy::Quiet => 2, } } } -impl From for &str { - fn from(profile: PlatformPolicy) -> &'static str { +impl From for &str { + fn from(profile: ThrottlePolicy) -> &'static str { match profile { - PlatformPolicy::Balanced => "balanced", - PlatformPolicy::Performance => "performance", - PlatformPolicy::Quiet => "quiet", + ThrottlePolicy::Balanced => "balanced", + ThrottlePolicy::Performance => "performance", + ThrottlePolicy::Quiet => "quiet", } } } -impl std::str::FromStr for PlatformPolicy { +impl std::str::FromStr for ThrottlePolicy { type Err = PlatformError; fn from_str(profile: &str) -> Result { match profile.to_ascii_lowercase().trim() { - "balanced" => Ok(PlatformPolicy::Balanced), - "performance" => Ok(PlatformPolicy::Performance), - "quiet" => Ok(PlatformPolicy::Quiet), + "balanced" => Ok(ThrottlePolicy::Balanced), + "performance" => Ok(ThrottlePolicy::Performance), + "quiet" => Ok(ThrottlePolicy::Quiet), _ => Err(PlatformError::NotSupported), } } } -impl Display for PlatformPolicy { +impl Display for ThrottlePolicy { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self) } } -impl PlatformPolicy { - pub fn get_next_profile(current: PlatformPolicy) -> PlatformPolicy { - match current { - PlatformPolicy::Balanced => PlatformPolicy::Performance, - PlatformPolicy::Performance => PlatformPolicy::Quiet, - PlatformPolicy::Quiet => PlatformPolicy::Balanced, - } - } -} - /// CamelCase names of the properties. Intended for use with DBUS #[typeshare] #[repr(u8)] @@ -365,7 +355,7 @@ pub enum Properties { PanelOd, MiniLedMode, EgpuEnable, - PlatformPolicy, + ThrottlePolicy, PptPl1Spl, PptPl2Sppt, PptFppt, diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index 1bf621bb..77345421 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -4,7 +4,7 @@ pub mod fan_curve_set; use error::ProfileError; use fan_curve_set::CurveData; use log::debug; -use rog_platform::platform::PlatformPolicy; +use rog_platform::platform::ThrottlePolicy; use serde_derive::{Deserialize, Serialize}; use typeshare::typeshare; pub use udev::Device; @@ -118,7 +118,7 @@ impl FanCurveProfiles { /// pub fn read_from_dev_profile( &mut self, - profile: PlatformPolicy, + profile: ThrottlePolicy, device: &Device, ) -> Result<(), ProfileError> { let fans = Self::supported_fans()?; @@ -136,9 +136,9 @@ impl FanCurveProfiles { } match profile { - PlatformPolicy::Balanced => self.balanced = curves, - PlatformPolicy::Performance => self.performance = curves, - PlatformPolicy::Quiet => self.quiet = curves, + ThrottlePolicy::Balanced => self.balanced = curves, + ThrottlePolicy::Performance => self.performance = curves, + ThrottlePolicy::Quiet => self.quiet = curves, } Ok(()) } @@ -150,7 +150,7 @@ impl FanCurveProfiles { /// read only for the currently active profile. pub fn set_active_curve_to_defaults( &mut self, - profile: PlatformPolicy, + profile: ThrottlePolicy, device: &mut Device, ) -> Result<(), ProfileError> { let fans = Self::supported_fans()?; @@ -170,13 +170,13 @@ impl FanCurveProfiles { // TODO: Make this return an error if curve is zeroed pub fn write_profile_curve_to_platform( &mut self, - profile: PlatformPolicy, + profile: ThrottlePolicy, device: &mut Device, ) -> Result<(), ProfileError> { let fans = match profile { - PlatformPolicy::Balanced => &mut self.balanced, - PlatformPolicy::Performance => &mut self.performance, - PlatformPolicy::Quiet => &mut self.quiet, + ThrottlePolicy::Balanced => &mut self.balanced, + ThrottlePolicy::Performance => &mut self.performance, + ThrottlePolicy::Quiet => &mut self.quiet, }; for fan in fans { debug!("write_profile_curve_to_platform: writing profile:{profile}, {fan:?}"); @@ -185,19 +185,19 @@ impl FanCurveProfiles { Ok(()) } - pub fn set_profile_curves_enabled(&mut self, profile: PlatformPolicy, enabled: bool) { + pub fn set_profile_curves_enabled(&mut self, profile: ThrottlePolicy, enabled: bool) { match profile { - PlatformPolicy::Balanced => { + ThrottlePolicy::Balanced => { for curve in self.balanced.iter_mut() { curve.enabled = enabled; } } - PlatformPolicy::Performance => { + ThrottlePolicy::Performance => { for curve in self.performance.iter_mut() { curve.enabled = enabled; } } - PlatformPolicy::Quiet => { + ThrottlePolicy::Quiet => { for curve in self.quiet.iter_mut() { curve.enabled = enabled; } @@ -207,12 +207,12 @@ impl FanCurveProfiles { pub fn set_profile_fan_curve_enabled( &mut self, - profile: PlatformPolicy, + profile: ThrottlePolicy, fan: FanCurvePU, enabled: bool, ) { match profile { - PlatformPolicy::Balanced => { + ThrottlePolicy::Balanced => { for curve in self.balanced.iter_mut() { if curve.fan == fan { curve.enabled = enabled; @@ -220,7 +220,7 @@ impl FanCurveProfiles { } } } - PlatformPolicy::Performance => { + ThrottlePolicy::Performance => { for curve in self.performance.iter_mut() { if curve.fan == fan { curve.enabled = enabled; @@ -228,7 +228,7 @@ impl FanCurveProfiles { } } } - PlatformPolicy::Quiet => { + ThrottlePolicy::Quiet => { for curve in self.quiet.iter_mut() { if curve.fan == fan { curve.enabled = enabled; @@ -239,31 +239,31 @@ impl FanCurveProfiles { } } - pub fn get_fan_curves_for(&self, name: PlatformPolicy) -> &[CurveData] { + pub fn get_fan_curves_for(&self, name: ThrottlePolicy) -> &[CurveData] { match name { - PlatformPolicy::Balanced => &self.balanced, - PlatformPolicy::Performance => &self.performance, - PlatformPolicy::Quiet => &self.quiet, + ThrottlePolicy::Balanced => &self.balanced, + ThrottlePolicy::Performance => &self.performance, + ThrottlePolicy::Quiet => &self.quiet, } } - pub fn get_fan_curve_for(&self, name: &PlatformPolicy, pu: FanCurvePU) -> Option<&CurveData> { + pub fn get_fan_curve_for(&self, name: &ThrottlePolicy, pu: FanCurvePU) -> Option<&CurveData> { match name { - PlatformPolicy::Balanced => { + ThrottlePolicy::Balanced => { for this_curve in self.balanced.iter() { if this_curve.fan == pu { return Some(this_curve); } } } - PlatformPolicy::Performance => { + ThrottlePolicy::Performance => { for this_curve in self.performance.iter() { if this_curve.fan == pu { return Some(this_curve); } } } - PlatformPolicy::Quiet => { + ThrottlePolicy::Quiet => { for this_curve in self.quiet.iter() { if this_curve.fan == pu { return Some(this_curve); @@ -277,10 +277,10 @@ impl FanCurveProfiles { pub fn save_fan_curve( &mut self, curve: CurveData, - profile: PlatformPolicy, + profile: ThrottlePolicy, ) -> Result<(), ProfileError> { match profile { - PlatformPolicy::Balanced => { + ThrottlePolicy::Balanced => { for this_curve in self.balanced.iter_mut() { if this_curve.fan == curve.fan { *this_curve = curve; @@ -288,7 +288,7 @@ impl FanCurveProfiles { } } } - PlatformPolicy::Performance => { + ThrottlePolicy::Performance => { for this_curve in self.performance.iter_mut() { if this_curve.fan == curve.fan { *this_curve = curve; @@ -296,7 +296,7 @@ impl FanCurveProfiles { } } } - PlatformPolicy::Quiet => { + ThrottlePolicy::Quiet => { for this_curve in self.quiet.iter_mut() { if this_curve.fan == curve.fan { *this_curve = curve;