mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-08 15:40:34 -04:00
power: Change range values from tuple to RangeInclusive
This commit is contained in:
parent
d5f4de72ca
commit
93a78041fb
2 changed files with 31 additions and 16 deletions
|
@ -363,12 +363,18 @@ impl GpuPerformanceLevel1 {
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn manual_gpu_clock_min(&self) -> fdo::Result<u32> {
|
async fn manual_gpu_clock_min(&self) -> fdo::Result<u32> {
|
||||||
Ok(get_gpu_clocks_range().await.map_err(to_zbus_fdo_error)?.0)
|
Ok(*get_gpu_clocks_range()
|
||||||
|
.await
|
||||||
|
.map_err(to_zbus_fdo_error)?
|
||||||
|
.start())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn manual_gpu_clock_max(&self) -> fdo::Result<u32> {
|
async fn manual_gpu_clock_max(&self) -> fdo::Result<u32> {
|
||||||
Ok(get_gpu_clocks_range().await.map_err(to_zbus_fdo_error)?.1)
|
Ok(*get_gpu_clocks_range()
|
||||||
|
.await
|
||||||
|
.map_err(to_zbus_fdo_error)?
|
||||||
|
.end())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,12 +486,12 @@ impl TdpLimit1 {
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn tdp_limit_min(&self) -> u32 {
|
async fn tdp_limit_min(&self) -> u32 {
|
||||||
get_tdp_limit_range().await.map(|(min, _)| min).unwrap_or(0)
|
get_tdp_limit_range().await.map(|r| *r.start()).unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property(emits_changed_signal = "const"))]
|
#[zbus(property(emits_changed_signal = "const"))]
|
||||||
async fn tdp_limit_max(&self) -> u32 {
|
async fn tdp_limit_max(&self) -> u32 {
|
||||||
get_tdp_limit_range().await.map(|(_, max)| max).unwrap_or(0)
|
get_tdp_limit_range().await.map(|r| *r.end()).unwrap_or(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
33
src/power.rs
33
src/power.rs
|
@ -9,6 +9,7 @@ use anyhow::{anyhow, bail, ensure, Result};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
use std::ops::RangeInclusive;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use strum::{Display, EnumString};
|
use strum::{Display, EnumString};
|
||||||
|
@ -255,13 +256,13 @@ pub(crate) async fn set_cpu_scaling_governor(governor: CPUScalingGovernor) -> Re
|
||||||
write_cpu_governor_sysfs_contents(name).await
|
write_cpu_governor_sysfs_contents(name).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_gpu_clocks_range() -> Result<(u32, u32)> {
|
pub(crate) async fn get_gpu_clocks_range() -> Result<RangeInclusive<u32>> {
|
||||||
if let Some(range) = platform_config()
|
if let Some(range) = platform_config()
|
||||||
.await?
|
.await?
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|config| config.gpu_clocks)
|
.and_then(|config| config.gpu_clocks)
|
||||||
{
|
{
|
||||||
return Ok((range.min, range.max));
|
return Ok(range.min..=range.max);
|
||||||
}
|
}
|
||||||
let contents = read_gpu_sysfs_contents(GPU_CLOCK_LEVELS_SUFFIX).await?;
|
let contents = read_gpu_sysfs_contents(GPU_CLOCK_LEVELS_SUFFIX).await?;
|
||||||
let lines = contents.lines();
|
let lines = contents.lines();
|
||||||
|
@ -284,7 +285,7 @@ pub(crate) async fn get_gpu_clocks_range() -> Result<(u32, u32)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure!(min <= max, "Could not read any clocks");
|
ensure!(min <= max, "Could not read any clocks");
|
||||||
Ok((min, max))
|
Ok(min..=max)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn set_gpu_clocks(clocks: u32) -> Result<()> {
|
pub(crate) async fn set_gpu_clocks(clocks: u32) -> Result<()> {
|
||||||
|
@ -371,9 +372,10 @@ pub(crate) async fn get_tdp_limit() -> Result<u32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) 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)
|
ensure!(
|
||||||
// Returns false on error or out of range
|
get_tdp_limit_range().await?.contains(&limit),
|
||||||
ensure!((3..=15).contains(&limit), "Invalid limit");
|
"Invalid limit"
|
||||||
|
);
|
||||||
let data = format!("{limit}000000");
|
let data = format!("{limit}000000");
|
||||||
|
|
||||||
let base = find_hwmon(GPU_HWMON_NAME).await?;
|
let base = find_hwmon(GPU_HWMON_NAME).await?;
|
||||||
|
@ -393,13 +395,13 @@ pub(crate) async fn set_tdp_limit(limit: u32) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_tdp_limit_range() -> Result<(u32, u32)> {
|
pub(crate) async fn get_tdp_limit_range() -> Result<RangeInclusive<u32>> {
|
||||||
let range = platform_config()
|
let range = platform_config()
|
||||||
.await?
|
.await?
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|config| config.tdp_limit)
|
.and_then(|config| config.tdp_limit)
|
||||||
.ok_or(anyhow!("No TDP limit range configured"))?;
|
.ok_or(anyhow!("No TDP limit range configured"))?;
|
||||||
Ok((range.min, range.max))
|
Ok(range.min..=range.max)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_max_charge_level() -> Result<i32> {
|
pub(crate) async fn get_max_charge_level() -> Result<i32> {
|
||||||
|
@ -438,7 +440,7 @@ pub(crate) mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::hardware::test::fake_model;
|
use crate::hardware::test::fake_model;
|
||||||
use crate::hardware::SteamDeckVariant;
|
use crate::hardware::SteamDeckVariant;
|
||||||
use crate::platform::{BatteryChargeLimitConfig, PlatformConfig};
|
use crate::platform::{BatteryChargeLimitConfig, PlatformConfig, RangeConfig};
|
||||||
use crate::{enum_roundtrip, testing};
|
use crate::{enum_roundtrip, testing};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use tokio::fs::{create_dir_all, read_to_string, remove_dir, write};
|
use tokio::fs::{create_dir_all, read_to_string, remove_dir, write};
|
||||||
|
@ -623,7 +625,14 @@ CCLK_RANGE in Core0:
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_set_tdp_limit() {
|
async fn test_set_tdp_limit() {
|
||||||
let _h = testing::start();
|
let handle = testing::start();
|
||||||
|
|
||||||
|
let mut platform_config = PlatformConfig::default();
|
||||||
|
platform_config.tdp_limit = Some(RangeConfig {
|
||||||
|
min: 3,
|
||||||
|
max: 15,
|
||||||
|
});
|
||||||
|
handle.test.platform_config.replace(Some(platform_config));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
set_tdp_limit(2).await.unwrap_err().to_string(),
|
set_tdp_limit(2).await.unwrap_err().to_string(),
|
||||||
|
@ -736,13 +745,13 @@ CCLK_RANGE in Core0:
|
||||||
1: 1100Mhz
|
1: 1100Mhz
|
||||||
2: 1600Mhz";
|
2: 1600Mhz";
|
||||||
write(filename.as_path(), contents).await.expect("write");
|
write(filename.as_path(), contents).await.expect("write");
|
||||||
assert_eq!(get_gpu_clocks_range().await.unwrap(), (200, 1600));
|
assert_eq!(get_gpu_clocks_range().await.unwrap(), 200..=1600);
|
||||||
|
|
||||||
let contents = "0: 1600Mhz *
|
let contents = "0: 1600Mhz *
|
||||||
1: 200Mhz
|
1: 200Mhz
|
||||||
2: 1100Mhz";
|
2: 1100Mhz";
|
||||||
write(filename.as_path(), contents).await.expect("write");
|
write(filename.as_path(), contents).await.expect("write");
|
||||||
assert_eq!(get_gpu_clocks_range().await.unwrap(), (200, 1600));
|
assert_eq!(get_gpu_clocks_range().await.unwrap(), 200..=1600);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue