From c75c50762d06d0c6ff7a9c85b7501116ad54b455 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Wed, 12 Jun 2024 16:08:56 -0600 Subject: [PATCH] Add cpu governor getting and setting to steamosctl. TODO: Need to test this manually but config issues are causing daemon's to die here currently because of missing paths. --- src/bin/steamosctl.rs | 38 +++++++++++++++++++++++++++++++++++++- src/proxy.rs | 10 ++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/bin/steamosctl.rs b/src/bin/steamosctl.rs index 1fdc326..3236f1d 100644 --- a/src/bin/steamosctl.rs +++ b/src/bin/steamosctl.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use std::ops::Deref; use steamos_manager::cec::HdmiCecState; use steamos_manager::hardware::FanControlState; -use steamos_manager::power::{GPUPerformanceLevel, GPUPowerProfile}; +use steamos_manager::power::{CPUGovernor, GPUPerformanceLevel, GPUPowerProfile}; use steamos_manager::proxy::ManagerProxy; use steamos_manager::wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement}; use zbus::fdo::PropertiesProxy; @@ -45,6 +45,18 @@ enum Commands { /// Get the fan control state GetFanControlState, + /// Get the CPU governors supported on this device + GetCpuGovernors, + + /// Get the current CPU governor + GetCpuGovernor, + + /// Set the current CPU governor + SetCpuGovernor { + /// Valid governors are get-cpu-governors. + governor: CPUGovernor, + }, + /// Get the GPU power profiles supported on this device GetGPUPowerProfiles, @@ -203,6 +215,30 @@ async fn main() -> Result<()> { Err(_) => println!("Got unknown value {state} from backend"), } } + Commands::GetCpuGovernors => { + let governors = proxy.cpu_governors().await?; + println!("Governors:\n"); + for key in governors.keys().sorted() { + let name = &governors[key]; + println!("{key}: {name}"); + } + } + Commands::GetCpuGovernor => { + let governor = proxy.cpu_governor().await?; + let governor_type = CPUGovernor::try_from(governor); + match governor_type { + Ok(t) => { + let name = t.to_string(); + println!("CPU Governor: {governor} {name}"); + } + Err(_) => { + println!("Unknown CPU governor or unable to get type from {governor}"); + } + } + } + Commands::SetCpuGovernor { governor } => { + proxy.set_cpu_governor(*governor as u32).await?; + } Commands::GetGPUPowerProfiles => { let profiles = proxy.gpu_power_profiles().await?; println!("Profiles:\n"); diff --git a/src/proxy.rs b/src/proxy.rs index 513d6a3..60c4421 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -65,6 +65,16 @@ trait Manager { #[zbus(property)] fn set_gpu_performance_level(&self, value: u32) -> zbus::Result<()>; + /// CpuGovernor property + #[zbus(property)] + fn cpu_governor(&self) -> zbus::Result; + #[zbus(property)] + fn set_cpu_governor(&self, value: u32) -> zbus::Result<()>; + + /// CpuGovernors property + #[zbus(property)] + fn cpu_governors(&self) -> zbus::Result>; + /// GpuPowerProfile property #[zbus(property)] fn gpu_power_profile(&self) -> zbus::Result;