Fix: change epp change watch to a loop to prevent deadlock

This commit is contained in:
Luke D. Jones
2023-12-07 20:04:21 +13:00
parent 5c8bb6e6ea
commit c06f78990f

View File

@@ -1,12 +1,14 @@
use std::process::Command; use std::process::Command;
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration;
use async_trait::async_trait; use async_trait::async_trait;
use config_traits::StdConfig; use config_traits::StdConfig;
use log::{debug, error, info, warn}; use log::{error, info, warn};
use rog_platform::cpu::CPUControl; use rog_platform::cpu::{CPUControl, CPUEPP};
use rog_platform::platform::{GpuMode, PlatformPolicy, Properties, RogPlatform}; use rog_platform::platform::{GpuMode, PlatformPolicy, Properties, RogPlatform};
use rog_platform::power::AsusPower; use rog_platform::power::AsusPower;
use tokio::time::sleep;
use zbus::export::futures_util::lock::Mutex; use zbus::export::futures_util::lock::Mutex;
use zbus::fdo::Error as FdoErr; use zbus::fdo::Error as FdoErr;
use zbus::{dbus_interface, Connection, ObjectServer, SignalContext}; use zbus::{dbus_interface, Connection, ObjectServer, SignalContext};
@@ -670,31 +672,38 @@ impl CtrlTask for CtrlPlatform {
self.watch_nv_dynamic_boost(signal_ctxt.clone()).await?; self.watch_nv_dynamic_boost(signal_ctxt.clone()).await?;
self.watch_nv_temp_target(signal_ctxt.clone()).await?; self.watch_nv_temp_target(signal_ctxt.clone()).await?;
let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?; // let watch_throttle_thermal_policy =
// self.platform.monitor_throttle_thermal_policy()?;
let ctrl = self.clone(); let ctrl = self.clone();
tokio::spawn(async move { tokio::spawn(async move {
use futures_lite::StreamExt; let mut last_epp = CPUEPP::Default;
let mut buffer = [0; 32]; loop {
if let Ok(mut stream) = watch_throttle_thermal_policy.into_event_stream(&mut buffer) { if let Ok(profile) = ctrl
while (stream.next().await).is_some() { .platform
// this blocks .get_throttle_thermal_policy()
debug!("Platform: watch_throttle_thermal_policy changed"); .map(PlatformPolicy::from)
if let Ok(profile) = ctrl .map_err(|e| {
.platform error!("Platform: get_throttle_thermal_policy error: {e}");
.get_throttle_thermal_policy() })
.map(PlatformPolicy::from) {
.map_err(|e| { if let Some(cpu) = ctrl.cpu_control.as_ref() {
error!("Platform: get_throttle_thermal_policy error: {e}"); if let Ok(epp) = cpu.get_epp() {
}) if last_epp != epp {
{ info!(
if let Some(cpu) = ctrl.cpu_control.as_ref() { "PlatformPolicy setting EPP due to throttle_thermal_policy \
info!("PlatformPolicy setting EPP"); change"
cpu.set_epp(profile.into()).ok(); );
cpu.set_epp(profile.into()).ok();
last_epp = epp;
}
} }
ctrl.config.lock().await.platform_policy_to_restore = profile;
} }
ctrl.config.lock().await.platform_policy_to_restore = profile;
} }
// This needs to be a loop due to a conlict in fan_curves
// TODO: fix it
sleep(Duration::from_secs(1)).await;
} }
}); });