mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
cpu: support AMD properly
This commit is contained in:
parent
9f7d86ff01
commit
262c70fb85
1 changed files with 38 additions and 5 deletions
35
src/cpu.rs
35
src/cpu.rs
|
@ -105,19 +105,52 @@ pub fn set_turbo(setting: TurboSetting) -> Result<()> {
|
|||
TurboSetting::Auto => return Err(ControlError::InvalidValueError("Turbo Auto cannot be directly set via intel_pstate/no_turbo or cpufreq/boost. System default.".to_string())),
|
||||
};
|
||||
|
||||
// AMD specific paths
|
||||
let amd_pstate_path = "/sys/devices/system/cpu/amd_pstate/cpufreq/boost";
|
||||
let msr_boost_path = "/sys/devices/system/cpu/cpufreq/amd_pstate_enable_boost";
|
||||
|
||||
// Path priority (from most to least specific)
|
||||
let pstate_path = "/sys/devices/system/cpu/intel_pstate/no_turbo";
|
||||
let boost_path = "/sys/devices/system/cpu/cpufreq/boost";
|
||||
|
||||
// Try each boost control path in order of specificity
|
||||
if Path::new(pstate_path).exists() {
|
||||
write_sysfs_value(pstate_path, value_pstate)
|
||||
} else if Path::new(amd_pstate_path).exists() {
|
||||
write_sysfs_value(amd_pstate_path, value_boost)
|
||||
} else if Path::new(msr_boost_path).exists() {
|
||||
write_sysfs_value(msr_boost_path, value_boost)
|
||||
} else if Path::new(boost_path).exists() {
|
||||
write_sysfs_value(boost_path, value_boost)
|
||||
} else {
|
||||
// Also try per-core cpufreq boost for some AMD systems
|
||||
let result = try_set_per_core_boost(value_boost)?;
|
||||
if result {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ControlError::NotSupported(
|
||||
"Neither intel_pstate/no_turbo nor cpufreq/boost found.".to_string(),
|
||||
"No supported CPU boost control mechanism found.".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to set boost on a per-core basis for systems that support it
|
||||
fn try_set_per_core_boost(value: &str) -> Result<bool> {
|
||||
let mut success = false;
|
||||
let num_cores = get_logical_core_count()?;
|
||||
|
||||
for core_id in 0..num_cores {
|
||||
let boost_path = format!("/sys/devices/system/cpu/cpu{}/cpufreq/boost", core_id);
|
||||
|
||||
if Path::new(&boost_path).exists() {
|
||||
write_sysfs_value(&boost_path, value)?;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(success)
|
||||
}
|
||||
|
||||
pub fn set_epp(epp: &str, core_id: Option<u32>) -> Result<()> {
|
||||
let action = |id: u32| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue