diff --git a/src/bin/steamosctl.rs b/src/bin/steamosctl.rs index 8f8f6ae..f697b2b 100644 --- a/src/bin/steamosctl.rs +++ b/src/bin/steamosctl.rs @@ -9,6 +9,7 @@ use anyhow::Result; use clap::{Parser, Subcommand}; use itertools::Itertools; use std::ops::Deref; +use steamos_manager::power::GPUPerformanceLevel; use steamos_manager::proxy::ManagerProxy; use steamos_manager::wifi::WifiBackend; use zbus::fdo::PropertiesProxy; @@ -44,8 +45,8 @@ enum Commands { /// Set the GPU performance level SetGPUPerformanceLevel { - /// 0 = Auto, 1 = Low, 2 = High, 3 = Manual, 4 = Profile Peak - level: u32, + /// Allowed levels are auto, low, high, manual, peak_performance + level: GPUPerformanceLevel, }, /// Get the GPU performance level @@ -182,11 +183,14 @@ async fn main() -> Result<()> { proxy.set_fan_control_state(*state).await?; } Commands::SetGPUPerformanceLevel { level } => { - proxy.set_gpu_performance_level(*level).await?; + proxy.set_gpu_performance_level(*level as u32).await?; } Commands::GetGPUPerformanceLevel => { let level = proxy.gpu_performance_level().await?; - println!("GPU performance level: {level}"); + match GPUPerformanceLevel::try_from(level) { + Ok(l) => println!("GPU performance level: {}", l.to_string()), + Err(_) => println!("Got unknown value {level} from backend"), + } } Commands::SetManualGPUClock { freq } => { proxy.set_manual_gpu_clock(*freq).await?; diff --git a/src/lib.rs b/src/lib.rs index 5eb2206..d8dcb60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,12 +19,12 @@ mod ds_inhibit; mod error; mod hardware; mod manager; -mod power; mod process; mod sls; mod systemd; pub mod daemon; +pub mod power; pub mod proxy; pub mod wifi; diff --git a/src/power.rs b/src/power.rs index 03cd43c..a514c75 100644 --- a/src/power.rs +++ b/src/power.rs @@ -75,7 +75,7 @@ impl ToString for GPUPerformanceLevel { } } -pub async fn get_gpu_performance_level() -> Result { +pub(crate) async fn get_gpu_performance_level() -> Result { let base = find_hwmon().await?; let level = fs::read_to_string(base.join(GPU_PERFORMANCE_LEVEL_SUFFIX)) .await @@ -84,7 +84,7 @@ pub async fn get_gpu_performance_level() -> Result { GPUPerformanceLevel::from_str(level.trim()) } -pub async fn set_gpu_performance_level(level: GPUPerformanceLevel) -> Result<()> { +pub(crate) async fn set_gpu_performance_level(level: GPUPerformanceLevel) -> Result<()> { let level: String = level.to_string(); let base = find_hwmon().await?; write_synced(base.join(GPU_PERFORMANCE_LEVEL_SUFFIX), level.as_bytes()) @@ -92,7 +92,7 @@ pub async fn set_gpu_performance_level(level: GPUPerformanceLevel) -> Result<()> .inspect_err(|message| error!("Error writing to sysfs file: {message}")) } -pub async fn set_gpu_clocks(clocks: u32) -> Result<()> { +pub(crate) async fn set_gpu_clocks(clocks: u32) -> Result<()> { // Set GPU clocks to given value valid between 200 - 1600 // Only used when GPU Performance Level is manual, but write whenever called. ensure!((200..=1600).contains(&clocks), "Invalid clocks"); @@ -125,7 +125,7 @@ pub async fn set_gpu_clocks(clocks: u32) -> Result<()> { Ok(()) } -pub async fn get_gpu_clocks() -> Result { +pub(crate) async fn get_gpu_clocks() -> Result { let base = find_hwmon().await?; let clocks_file = File::open(base.join(GPU_CLOCKS_SUFFIX)).await?; let mut reader = BufReader::new(clocks_file); @@ -170,14 +170,14 @@ async fn find_hwmon() -> Result { } } -pub async fn get_tdp_limit() -> Result { +pub(crate) async fn get_tdp_limit() -> Result { let base = find_hwmon().await?; let power1cap = fs::read_to_string(base.join(TDP_LIMIT1)).await?; let power1cap: u32 = power1cap.trim_end().parse()?; Ok(power1cap / 1000000) } -pub async fn set_tdp_limit(limit: u32) -> Result<()> { +pub(crate) async fn set_tdp_limit(limit: u32) -> Result<()> { // Set TDP limit given if within range (3-15) // Returns false on error or out of range ensure!((3..=15).contains(&limit), "Invalid limit"); @@ -201,7 +201,7 @@ pub async fn set_tdp_limit(limit: u32) -> Result<()> { } #[cfg(test)] -pub mod test { +pub(crate) mod test { use super::*; use crate::testing; use anyhow::anyhow;