manager/user: Dynamically add or remove the TdpLimit1 interface if needed

This commit is contained in:
Vicki Pfau 2025-04-11 18:43:30 -07:00
parent 6086e23cc8
commit c8eb661bec
2 changed files with 54 additions and 14 deletions

View file

@ -107,6 +107,9 @@ pub(crate) trait TdpLimitManager: Send + Sync {
async fn get_tdp_limit(&self) -> Result<u32>;
async fn set_tdp_limit(&self, limit: u32) -> Result<()>;
async fn get_tdp_limit_range(&self) -> Result<RangeInclusive<u32>>;
async fn is_active(&self) -> Result<bool> {
Ok(true)
}
}
pub(crate) async fn tdp_limit_manager() -> Result<Box<dyn TdpLimitManager>> {
@ -531,6 +534,18 @@ impl TdpLimitManager for LenovoWmiTdpLimitManager {
.map_err(|e| anyhow!("Error parsing value: {e}"))?;
Ok(min..=max)
}
async fn is_active(&self) -> Result<bool> {
let config = platform_config().await?;
if let Some(config) = config
.as_ref()
.and_then(|config| config.performance_profile.as_ref())
{
Ok(get_platform_profile(&config.platform_profile_name).await? == "custom")
} else {
Ok(true)
}
}
}
pub(crate) async fn get_max_charge_level() -> Result<i32> {