add power cap reset

This commit is contained in:
Ilya Zlobintsev
2022-11-20 19:18:47 +02:00
parent a7fac939ac
commit 94e35da8d4
3 changed files with 13 additions and 7 deletions

View File

@@ -173,16 +173,22 @@ impl<'a> Handler {
}
}
pub fn set_power_limit(&'a self, id: &str, limit: f64) -> anyhow::Result<()> {
self.controller_by_id(id)?
pub fn set_power_cap(&'a self, id: &str, maybe_cap: Option<f64>) -> anyhow::Result<()> {
let hw_mon = self
.controller_by_id(id)?
.handle
.hw_monitors
.first()
.context("GPU has no hardware monitor")?
.set_power_cap(limit)?;
.context("GPU has no hardware monitor")?;
let cap = match maybe_cap {
Some(cap) => cap,
None => hw_mon.get_power_cap_default()?,
};
hw_mon.set_power_cap(cap)?;
self.edit_gpu_config(id.to_owned(), |gpu_config| {
gpu_config.power_cap = Some(limit);
gpu_config.power_cap = maybe_cap;
})
}

View File

@@ -86,7 +86,7 @@ async fn handle_request<'a>(request: Request<'a>, handler: &'a Handler) -> anyho
Request::SetFanControl { id, enabled } => {
ok_response(handler.set_fan_control(id, enabled).await?)
}
Request::SetPowerLimit { id, limit } => ok_response(handler.set_power_limit(id, limit)?),
Request::SetPowerCap { id, cap } => ok_response(handler.set_power_cap(id, cap)?),
}
}

View File

@@ -8,5 +8,5 @@ pub enum Request<'a> {
DeviceInfo { id: &'a str },
DeviceStats { id: &'a str },
SetFanControl { id: &'a str, enabled: bool },
SetPowerLimit { id: &'a str, limit: f64 },
SetPowerCap { id: &'a str, cap: Option<f64> },
}