manager/user: Make GPU interfaces optional

This commit is contained in:
Vicki Pfau 2024-08-08 19:19:38 -07:00
parent 53754680c1
commit f2cf6d87fe
2 changed files with 50 additions and 10 deletions

View file

@ -587,11 +587,29 @@ pub(crate) async fn create_interfaces(
object_server.at(MANAGER_PATH, cpu_scaling).await?;
object_server.at(MANAGER_PATH, factory_reset).await?;
object_server.at(MANAGER_PATH, fan_control).await?;
object_server
.at(MANAGER_PATH, gpu_performance_level)
.await?;
object_server.at(MANAGER_PATH, gpu_power_profile).await?;
object_server.at(MANAGER_PATH, gpu_tdp_limit).await?;
if !get_available_gpu_performance_levels()
.await
.unwrap_or_default()
.is_empty()
{
object_server
.at(MANAGER_PATH, gpu_performance_level)
.await?;
}
if !get_available_gpu_power_profiles()
.await
.unwrap_or_default()
.is_empty()
{
object_server.at(MANAGER_PATH, gpu_power_profile).await?;
}
if get_tdp_limit().await.is_ok() {
object_server.at(MANAGER_PATH, gpu_tdp_limit).await?;
}
object_server.at(MANAGER_PATH, hdmi_cec).await?;
object_server.at(MANAGER_PATH, manager2).await?;
object_server.at(MANAGER_PATH, storage).await?;
@ -612,7 +630,7 @@ mod test {
use crate::daemon::user::UserContext;
use crate::hardware::test::fake_model;
use crate::hardware::HardwareVariant;
use crate::testing;
use crate::{power, testing};
use std::time::Duration;
use tokio::sync::mpsc::unbounded_channel;
@ -630,6 +648,7 @@ mod test {
let (tx_job, _rx_job) = unbounded_channel::<JobManagerCommand>();
let connection = handle.new_dbus().await?;
fake_model(HardwareVariant::Jupiter).await?;
power::test::create_nodes().await?;
create_interfaces(connection.clone(), connection.clone(), tx_ctx, tx_job).await?;
sleep(Duration::from_millis(1)).await;

View file

@ -422,11 +422,32 @@ pub(crate) mod test {
let base = path(GPU_HWMON_PREFIX).join("hwmon5");
let filename = base.join(GPU_PERFORMANCE_LEVEL_SUFFIX);
// Creates hwmon path, including device subpath
create_dir_all(filename.parent().unwrap())
.await?;
create_dir_all(filename.parent().unwrap()).await?;
// Writes name file as addgpu so find_hwmon() will find it.
write_synced(base.join("name"), GPU_HWMON_NAME.as_bytes())
.await?;
write_synced(base.join("name"), GPU_HWMON_NAME.as_bytes()).await?;
Ok(())
}
pub async fn create_nodes() -> Result<()> {
setup().await?;
let base = find_hwmon().await?;
let filename = base.join(GPU_PERFORMANCE_LEVEL_SUFFIX);
write(filename.as_path(), "auto\n").await?;
let filename = base.join(GPU_POWER_PROFILE_SUFFIX);
let contents = " 1 3D_FULL_SCREEN
3 VIDEO*
4 VR
5 COMPUTE
6 CUSTOM
8 CAPPED
9 UNCAPPED";
write(filename.as_path(), contents).await?;
let filename = base.join(TDP_LIMIT1);
write(filename.as_path(), "15000000\n").await?;
Ok(())
}