-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asus_wmi): Add Asus WMI TDP methods.
- Make Ryzenadj a separate interface from AMDGPU. Use it as fallback when AsusWmi is not available. - Add AsusWmi TDP interface. This interface is currently only supported for AMD ROG devices. This interface can be adapted for use on Intel devices as well. - Update Cargo.toml - Misc clean ups.
- Loading branch information
Showing
20 changed files
with
972 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod core; | ||
pub mod cpu; | ||
pub mod cpu_features; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
use crate::performance::gpu::tdp::{TDPError, TDPResult}; | ||
|
||
use std::fs; | ||
|
||
const PLATFORM_PROFILE_PATH: &str = "/sys/firmware/acpi/platform_profile"; | ||
const PLATFORM_PROFILES_AVAIAL_PATH: &str = "/sys/firmware/acpi/platform_profile_choices"; | ||
|
||
/// Implementation of acpi sysfs | ||
pub struct Acpi {} | ||
|
||
impl Acpi { | ||
/// Check if ACPI supports platform profiles on this device | ||
pub async fn new() -> Option<Self> { | ||
if fs::metadata(PLATFORM_PROFILE_PATH).is_err() | ||
|| fs::metadata(PLATFORM_PROFILES_AVAIAL_PATH).is_err() | ||
{ | ||
return None; | ||
} | ||
Some(Self {}) | ||
} | ||
|
||
/// Reads the currently set power profile | ||
pub async fn power_profile(&self) -> TDPResult<String> { | ||
match fs::read(PLATFORM_PROFILE_PATH) { | ||
Ok(data) => { | ||
let profile = match String::from_utf8(data) { | ||
Ok(profile) => profile.split_whitespace().collect(), | ||
Err(e) => { | ||
return Err(TDPError::IOError(format!( | ||
"Failed to convert utf8 data to string: {e:?}" | ||
))) | ||
} | ||
}; | ||
|
||
log::info!("Platform profile is currently set to {profile}"); | ||
Ok(profile) | ||
} | ||
Err(e) => Err(TDPError::IOError(format!( | ||
"Failed to read platform profile: {e:?}" | ||
))), | ||
} | ||
} | ||
|
||
/// Returns a list of valid power profiles for this interface | ||
pub async fn power_profiles_available(&self) -> TDPResult<Vec<String>> { | ||
match fs::read(PLATFORM_PROFILES_AVAIAL_PATH) { | ||
Ok(data) => { | ||
let profiles_raw = match String::from_utf8(data) { | ||
Ok(profile) => profile, | ||
Err(e) => { | ||
return Err(TDPError::IOError(format!( | ||
"Failed to convert utf8 data to string: {e:?}" | ||
))) | ||
} | ||
}; | ||
let mut profiles = Vec::new(); | ||
for profile in profiles_raw.split_whitespace() { | ||
profiles.push(profile.to_string()); | ||
} | ||
|
||
log::info!("Available platform profiles: {profiles:?}"); | ||
Ok(profiles) | ||
} | ||
Err(e) => Err(TDPError::IOError(format!( | ||
"Failed to read platform profile: {e:?}" | ||
))), | ||
} | ||
} | ||
|
||
/// Sets the power profile to the given value | ||
pub async fn set_power_profile(&mut self, profile: String) -> TDPResult<()> { | ||
// Get the current profile so we can check if it needs to be set. | ||
let current = self.power_profile().await?; | ||
if current == profile { | ||
return Ok(()); | ||
} | ||
|
||
let valid_profiles = self.power_profiles_available().await?; | ||
//TODO: This supports a legacy interface from when only RyzenAdj was supported. Once | ||
//OpenGamepadUI is updated to use the new power_profiles_available methods, switch to | ||
//only returning and error here. | ||
if !valid_profiles.contains(&profile) { | ||
log::warn!("Incompatible profile requested: {profile}. Attempting to translate to valid profile."); | ||
match profile.as_str() { | ||
"max-performance" => match fs::write(PLATFORM_PROFILE_PATH, "performance") { | ||
Ok(_) => { | ||
log::info!("Set platform perfomance profile to performance"); | ||
return Ok(()); | ||
} | ||
Err(e) => { | ||
return Err(TDPError::IOError(format!( | ||
"Failed to set power profile: {e:?}" | ||
))) | ||
} | ||
}, | ||
"power-saving" => match fs::write(PLATFORM_PROFILE_PATH, "balanced") { | ||
Ok(_) => { | ||
log::info!("Set platform perfomance profile to balanced"); | ||
return Ok(()); | ||
} | ||
Err(e) => { | ||
return Err(TDPError::IOError(format!( | ||
"Failed to set power profile: {e:?}" | ||
))) | ||
} | ||
}, | ||
_ => { | ||
return Err(TDPError::InvalidArgument(format!( | ||
"{profile} is not a valid profile for Asus WMI." | ||
))) | ||
} | ||
}; | ||
}; | ||
|
||
match fs::write(PLATFORM_PROFILE_PATH, profile.clone()) { | ||
Ok(_) => { | ||
log::info!("Set platform perfomance profile to {profile}"); | ||
Ok(()) | ||
} | ||
Err(e) => Err(TDPError::IOError(format!( | ||
"Failed to set power profile: {e:?}" | ||
))), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod firmware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod amdgpu; | ||
pub mod ryzenadj; | ||
pub mod tdp; |
Oops, something went wrong.