mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 01:41:59 -04:00
steamosctl: Use GPUPerformanceLevel where applicable
This commit is contained in:
parent
d8cbf1d1c4
commit
e25b1a7ca7
3 changed files with 16 additions and 12 deletions
|
@ -9,6 +9,7 @@ use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use steamos_manager::power::GPUPerformanceLevel;
|
||||||
use steamos_manager::proxy::ManagerProxy;
|
use steamos_manager::proxy::ManagerProxy;
|
||||||
use steamos_manager::wifi::WifiBackend;
|
use steamos_manager::wifi::WifiBackend;
|
||||||
use zbus::fdo::PropertiesProxy;
|
use zbus::fdo::PropertiesProxy;
|
||||||
|
@ -44,8 +45,8 @@ enum Commands {
|
||||||
|
|
||||||
/// Set the GPU performance level
|
/// Set the GPU performance level
|
||||||
SetGPUPerformanceLevel {
|
SetGPUPerformanceLevel {
|
||||||
/// 0 = Auto, 1 = Low, 2 = High, 3 = Manual, 4 = Profile Peak
|
/// Allowed levels are auto, low, high, manual, peak_performance
|
||||||
level: u32,
|
level: GPUPerformanceLevel,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Get the GPU performance level
|
/// Get the GPU performance level
|
||||||
|
@ -182,11 +183,14 @@ async fn main() -> Result<()> {
|
||||||
proxy.set_fan_control_state(*state).await?;
|
proxy.set_fan_control_state(*state).await?;
|
||||||
}
|
}
|
||||||
Commands::SetGPUPerformanceLevel { level } => {
|
Commands::SetGPUPerformanceLevel { level } => {
|
||||||
proxy.set_gpu_performance_level(*level).await?;
|
proxy.set_gpu_performance_level(*level as u32).await?;
|
||||||
}
|
}
|
||||||
Commands::GetGPUPerformanceLevel => {
|
Commands::GetGPUPerformanceLevel => {
|
||||||
let level = proxy.gpu_performance_level().await?;
|
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 } => {
|
Commands::SetManualGPUClock { freq } => {
|
||||||
proxy.set_manual_gpu_clock(*freq).await?;
|
proxy.set_manual_gpu_clock(*freq).await?;
|
||||||
|
|
|
@ -19,12 +19,12 @@ mod ds_inhibit;
|
||||||
mod error;
|
mod error;
|
||||||
mod hardware;
|
mod hardware;
|
||||||
mod manager;
|
mod manager;
|
||||||
mod power;
|
|
||||||
mod process;
|
mod process;
|
||||||
mod sls;
|
mod sls;
|
||||||
mod systemd;
|
mod systemd;
|
||||||
|
|
||||||
pub mod daemon;
|
pub mod daemon;
|
||||||
|
pub mod power;
|
||||||
pub mod proxy;
|
pub mod proxy;
|
||||||
pub mod wifi;
|
pub mod wifi;
|
||||||
|
|
||||||
|
|
14
src/power.rs
14
src/power.rs
|
@ -75,7 +75,7 @@ impl ToString for GPUPerformanceLevel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_gpu_performance_level() -> Result<GPUPerformanceLevel> {
|
pub(crate) async fn get_gpu_performance_level() -> Result<GPUPerformanceLevel> {
|
||||||
let base = find_hwmon().await?;
|
let base = find_hwmon().await?;
|
||||||
let level = fs::read_to_string(base.join(GPU_PERFORMANCE_LEVEL_SUFFIX))
|
let level = fs::read_to_string(base.join(GPU_PERFORMANCE_LEVEL_SUFFIX))
|
||||||
.await
|
.await
|
||||||
|
@ -84,7 +84,7 @@ pub async fn get_gpu_performance_level() -> Result<GPUPerformanceLevel> {
|
||||||
GPUPerformanceLevel::from_str(level.trim())
|
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 level: String = level.to_string();
|
||||||
let base = find_hwmon().await?;
|
let base = find_hwmon().await?;
|
||||||
write_synced(base.join(GPU_PERFORMANCE_LEVEL_SUFFIX), level.as_bytes())
|
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}"))
|
.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
|
// Set GPU clocks to given value valid between 200 - 1600
|
||||||
// Only used when GPU Performance Level is manual, but write whenever called.
|
// Only used when GPU Performance Level is manual, but write whenever called.
|
||||||
ensure!((200..=1600).contains(&clocks), "Invalid clocks");
|
ensure!((200..=1600).contains(&clocks), "Invalid clocks");
|
||||||
|
@ -125,7 +125,7 @@ pub async fn set_gpu_clocks(clocks: u32) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_gpu_clocks() -> Result<u32> {
|
pub(crate) async fn get_gpu_clocks() -> Result<u32> {
|
||||||
let base = find_hwmon().await?;
|
let base = find_hwmon().await?;
|
||||||
let clocks_file = File::open(base.join(GPU_CLOCKS_SUFFIX)).await?;
|
let clocks_file = File::open(base.join(GPU_CLOCKS_SUFFIX)).await?;
|
||||||
let mut reader = BufReader::new(clocks_file);
|
let mut reader = BufReader::new(clocks_file);
|
||||||
|
@ -170,14 +170,14 @@ async fn find_hwmon() -> Result<PathBuf> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_tdp_limit() -> Result<u32> {
|
pub(crate) async fn get_tdp_limit() -> Result<u32> {
|
||||||
let base = find_hwmon().await?;
|
let base = find_hwmon().await?;
|
||||||
let power1cap = fs::read_to_string(base.join(TDP_LIMIT1)).await?;
|
let power1cap = fs::read_to_string(base.join(TDP_LIMIT1)).await?;
|
||||||
let power1cap: u32 = power1cap.trim_end().parse()?;
|
let power1cap: u32 = power1cap.trim_end().parse()?;
|
||||||
Ok(power1cap / 1000000)
|
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)
|
// Set TDP limit given if within range (3-15)
|
||||||
// Returns false on error or out of range
|
// Returns false on error or out of range
|
||||||
ensure!((3..=15).contains(&limit), "Invalid limit");
|
ensure!((3..=15).contains(&limit), "Invalid limit");
|
||||||
|
@ -201,7 +201,7 @@ pub async fn set_tdp_limit(limit: u32) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test {
|
pub(crate) mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::testing;
|
use crate::testing;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue