mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 09:22:26 -04:00
Implement SetTdpLimit.
Write given limit to /sys/class/hwmon/hwmon5/power[12]_cap if in the range of 3..15. Return false if out of range or unable to write.
This commit is contained in:
parent
e2190d69eb
commit
bc3ad0a54f
2 changed files with 39 additions and 2 deletions
|
@ -160,8 +160,8 @@
|
|||
</method>
|
||||
|
||||
<!--
|
||||
SetTDPLimit:
|
||||
@limit: The upper limit to use.
|
||||
SetTdpLimit:
|
||||
@limit: The upper limit to use (between 3 and 15).
|
||||
@success: True on success. False otherwise.
|
||||
|
||||
Set the TDP limit to the given value.
|
||||
|
|
|
@ -200,6 +200,43 @@ impl SMManager {
|
|||
}
|
||||
}
|
||||
|
||||
async fn set_tdp_limit(&self, limit: i32) -> bool {
|
||||
// Set TDP limit given if within range (3-15)
|
||||
// Returns false on error or out of range
|
||||
// Writes value to /sys/class/hwmon/hwmon5/power[12]_cap
|
||||
if !(3..=15).contains(&limit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let result = File::create("/sys/class/hwmon/hwmon5/power1_cap").await;
|
||||
let mut power1file;
|
||||
match result {
|
||||
Ok(f) => power1file = f,
|
||||
Err(message) => { println!("Error opening sysfs power1_cap file for writing TDP limits {message}"); return false; }
|
||||
};
|
||||
|
||||
let result = File::create("/sys/class/hwmon/hwmon5/power2_cap").await;
|
||||
let mut power2file;
|
||||
match result {
|
||||
Ok(f) => power2file = f,
|
||||
Err(message) => { println!("Error opening sysfs power2_cap file for wtriting TDP limits {message}"); return false; }
|
||||
};
|
||||
|
||||
// Now write the value * 1,000,000
|
||||
let data = format!("{limit}000000");
|
||||
let result = power1file.write(data.as_bytes()).await;
|
||||
match result {
|
||||
Ok(_worked) => {
|
||||
let result = power2file.write(data.as_bytes()).await;
|
||||
match result {
|
||||
Ok(_worked) => true,
|
||||
Err(message) => { println!("Error writing to power2_cap file: {message}"); false }
|
||||
}
|
||||
},
|
||||
Err(message) => { println!("Error writing to power1_cap file: {message}"); false }
|
||||
}
|
||||
}
|
||||
|
||||
/// A version property.
|
||||
#[dbus_interface(property)]
|
||||
async fn version(&self) -> u32 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue