mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-07 15:10:29 -04:00
power: Add interface for accessing platform-profiles
This commit is contained in:
parent
b26cc0f45c
commit
45edfe2c7c
10 changed files with 305 additions and 12 deletions
|
@ -26,9 +26,9 @@ use crate::job::JobManagerCommand;
|
|||
use crate::platform::platform_config;
|
||||
use crate::power::{
|
||||
get_available_cpu_scaling_governors, get_available_gpu_performance_levels,
|
||||
get_available_gpu_power_profiles, get_cpu_scaling_governor, get_gpu_clocks,
|
||||
get_gpu_clocks_range, get_gpu_performance_level, get_gpu_power_profile, get_max_charge_level,
|
||||
get_tdp_limit, get_tdp_limit_range,
|
||||
get_available_gpu_power_profiles, get_available_platform_profiles, get_cpu_scaling_governor,
|
||||
get_gpu_clocks, get_gpu_clocks_range, get_gpu_performance_level, get_gpu_power_profile,
|
||||
get_max_charge_level, get_platform_profile, get_tdp_limit, get_tdp_limit_range,
|
||||
};
|
||||
use crate::wifi::{
|
||||
get_wifi_backend, get_wifi_power_management_state, list_wifi_interfaces, WifiBackend,
|
||||
|
@ -143,6 +143,10 @@ struct Manager2 {
|
|||
channel: Sender<Command>,
|
||||
}
|
||||
|
||||
struct PerformanceProfile1 {
|
||||
proxy: Proxy<'static>,
|
||||
}
|
||||
|
||||
struct Storage1 {
|
||||
proxy: Proxy<'static>,
|
||||
job_manager: UnboundedSender<JobManagerCommand>,
|
||||
|
@ -456,6 +460,54 @@ impl Manager2 {
|
|||
}
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.PerformanceProfile1")]
|
||||
impl PerformanceProfile1 {
|
||||
#[zbus(property(emits_changed_signal = "false"))]
|
||||
async fn available_performance_profiles(&self) -> fdo::Result<Vec<String>> {
|
||||
let config = platform_config().await.map_err(to_zbus_fdo_error)?;
|
||||
let config = config
|
||||
.as_ref()
|
||||
.and_then(|config| config.performance_profile.as_ref())
|
||||
.ok_or(fdo::Error::Failed(String::from(
|
||||
"No performance platform-profile configured",
|
||||
)))?;
|
||||
get_available_platform_profiles(&config.platform_profile_name)
|
||||
.await
|
||||
.map_err(to_zbus_fdo_error)
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "false"))]
|
||||
async fn performance_profile(&self) -> fdo::Result<String> {
|
||||
let config = platform_config().await.map_err(to_zbus_fdo_error)?;
|
||||
let config = config
|
||||
.as_ref()
|
||||
.and_then(|config| config.performance_profile.as_ref())
|
||||
.ok_or(fdo::Error::Failed(String::from(
|
||||
"No performance platform-profile configured",
|
||||
)))?;
|
||||
get_platform_profile(&config.platform_profile_name)
|
||||
.await
|
||||
.map_err(to_zbus_fdo_error)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_performance_profile(&self, profile: &str) -> zbus::Result<()> {
|
||||
self.proxy.call("SetPerformanceProfile", &(profile)).await
|
||||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "const"))]
|
||||
async fn suggested_default_performance_profile(&self) -> fdo::Result<String> {
|
||||
let config = platform_config().await.map_err(to_zbus_fdo_error)?;
|
||||
let config = config
|
||||
.as_ref()
|
||||
.and_then(|config| config.performance_profile.as_ref())
|
||||
.ok_or(fdo::Error::Failed(String::from(
|
||||
"No performance platform-profile configured",
|
||||
)))?;
|
||||
Ok(config.suggested_default.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.Storage1")]
|
||||
impl Storage1 {
|
||||
async fn format_device(
|
||||
|
@ -591,6 +643,9 @@ async fn create_config_interfaces(
|
|||
let fan_control = FanControl1 {
|
||||
proxy: proxy.clone(),
|
||||
};
|
||||
let performance_profile = PerformanceProfile1 {
|
||||
proxy: proxy.clone(),
|
||||
};
|
||||
let storage = Storage1 {
|
||||
proxy: proxy.clone(),
|
||||
job_manager: job_manager.clone(),
|
||||
|
@ -612,6 +667,16 @@ async fn create_config_interfaces(
|
|||
object_server.at(MANAGER_PATH, fan_control).await?;
|
||||
}
|
||||
|
||||
if let Some(ref config) = config.performance_profile {
|
||||
if !get_available_platform_profiles(&config.platform_profile_name)
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.is_empty()
|
||||
{
|
||||
object_server.at(MANAGER_PATH, performance_profile).await?;
|
||||
}
|
||||
}
|
||||
|
||||
if config.storage.is_some() {
|
||||
object_server.at(MANAGER_PATH, storage).await?;
|
||||
}
|
||||
|
@ -756,8 +821,8 @@ mod test {
|
|||
use crate::hardware::test::fake_model;
|
||||
use crate::hardware::SteamDeckVariant;
|
||||
use crate::platform::{
|
||||
BatteryChargeLimitConfig, PlatformConfig, RangeConfig, ResetConfig, ScriptConfig,
|
||||
ServiceConfig, StorageConfig,
|
||||
BatteryChargeLimitConfig, PerformanceProfileConfig, PlatformConfig, RangeConfig,
|
||||
ResetConfig, ScriptConfig, ServiceConfig, StorageConfig,
|
||||
};
|
||||
use crate::systemd::test::{MockManager, MockUnit};
|
||||
use crate::{path, power, testing};
|
||||
|
@ -791,6 +856,10 @@ mod test {
|
|||
hwmon_name: String::from("steamdeck_hwmon"),
|
||||
attribute: String::from("max_battery_charge_level"),
|
||||
}),
|
||||
performance_profile: Some(PerformanceProfileConfig {
|
||||
platform_profile_name: String::from("power-driver"),
|
||||
suggested_default: String::from("balanced"),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -989,6 +1058,24 @@ mod test {
|
|||
.unwrap());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn interface_matches_performance_profile1() {
|
||||
let test = start(all_config()).await.expect("start");
|
||||
|
||||
assert!(
|
||||
test_interface_matches::<PerformanceProfile1>(&test.connection)
|
||||
.await
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn interface_missing_performance_profile1() {
|
||||
let test = start(None).await.expect("start");
|
||||
|
||||
assert!(test_interface_missing::<PerformanceProfile1>(&test.connection).await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn interface_matches_storage1() {
|
||||
let test = start(all_config()).await.expect("start");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue