mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 01:41:59 -04:00
power: Implement get_gpu_clocks and ManualGPUClock
This commit is contained in:
parent
d751110086
commit
d13010dcb0
2 changed files with 41 additions and 6 deletions
|
@ -15,8 +15,8 @@ use zbus::{interface, Connection, SignalContext};
|
|||
|
||||
use crate::hardware::{check_support, variant, HardwareVariant};
|
||||
use crate::power::{
|
||||
get_gpu_performance_level, set_gpu_clocks, set_gpu_performance_level, set_tdp_limit,
|
||||
GPUPerformanceLevel,
|
||||
get_gpu_clocks, get_gpu_performance_level, set_gpu_clocks, set_gpu_performance_level,
|
||||
set_tdp_limit, GPUPerformanceLevel,
|
||||
};
|
||||
use crate::process::{run_script, script_output};
|
||||
use crate::systemd::SystemdUnit;
|
||||
|
@ -277,8 +277,14 @@ impl SteamOSManager {
|
|||
.map_err(anyhow_to_zbus)
|
||||
}
|
||||
|
||||
async fn set_gpu_clocks(&self, clocks: i32) -> bool {
|
||||
set_gpu_clocks(clocks).await.is_ok()
|
||||
#[zbus(property)]
|
||||
async fn manual_gpu_clock(&self) -> zbus::fdo::Result<u32> {
|
||||
get_gpu_clocks().await.map_err(anyhow_to_zbus_fdo)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_manual_gpu_clock(&self, clocks: u32) -> zbus::Result<()> {
|
||||
set_gpu_clocks(clocks).await.map_err(anyhow_to_zbus)
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "const"))]
|
||||
|
|
33
src/power.rs
33
src/power.rs
|
@ -8,7 +8,7 @@
|
|||
use anyhow::{anyhow, bail, ensure, Error, Result};
|
||||
use std::str::FromStr;
|
||||
use tokio::fs::{self, File};
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||
use tracing::error;
|
||||
|
||||
use crate::path;
|
||||
|
@ -93,7 +93,7 @@ pub async fn set_gpu_performance_level(level: GPUPerformanceLevel) -> Result<()>
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_gpu_clocks(clocks: i32) -> Result<()> {
|
||||
pub 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");
|
||||
|
@ -121,6 +121,35 @@ pub async fn set_gpu_clocks(clocks: i32) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_gpu_clocks() -> Result<u32> {
|
||||
let clocks_file = File::open(GPU_CLOCKS_PATH).await?;
|
||||
let mut reader = BufReader::new(clocks_file);
|
||||
loop {
|
||||
let mut line = String::new();
|
||||
if reader.read_line(&mut line).await? == 0 {
|
||||
break;
|
||||
}
|
||||
if line != "OD_SCLK:\n" {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut line = String::new();
|
||||
if reader.read_line(&mut line).await? == 0 {
|
||||
break;
|
||||
}
|
||||
let mhz = match line.split_whitespace().nth(1) {
|
||||
Some(mhz) if mhz.ends_with("Mhz") => mhz.trim_end_matches("Mhz"),
|
||||
_ => break,
|
||||
};
|
||||
|
||||
match mhz.parse() {
|
||||
Ok(mhz) => return Ok(mhz),
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
}
|
||||
Err(anyhow!("Couldn't find GPU clocks"))
|
||||
}
|
||||
|
||||
pub async fn set_tdp_limit(limit: i32) -> Result<()> {
|
||||
// Set TDP limit given if within range (3-15)
|
||||
// Returns false on error or out of range
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue