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
43
src/cpu.rs
43
src/cpu.rs
|
@ -102,23 +102,56 @@ pub fn set_turbo(setting: TurboSetting) -> Result<()> {
|
||||||
let value_boost = match setting {
|
let value_boost = match setting {
|
||||||
TurboSetting::Always => "1", // boost = 1 means turbo is enabled
|
TurboSetting::Always => "1", // boost = 1 means turbo is enabled
|
||||||
TurboSetting::Never => "0", // boost = 0 means turbo is disabled
|
TurboSetting::Never => "0", // boost = 0 means turbo is disabled
|
||||||
TurboSetting::Auto => return Err(ControlError::InvalidValueError("Turbo Auto cannot be directly set via intel_pstate/no_turbo or cpufreq/boost. System default.".to_string())),
|
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 pstate_path = "/sys/devices/system/cpu/intel_pstate/no_turbo";
|
||||||
let boost_path = "/sys/devices/system/cpu/cpufreq/boost";
|
let boost_path = "/sys/devices/system/cpu/cpufreq/boost";
|
||||||
|
|
||||||
|
// Try each boost control path in order of specificity
|
||||||
if Path::new(pstate_path).exists() {
|
if Path::new(pstate_path).exists() {
|
||||||
write_sysfs_value(pstate_path, value_pstate)
|
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() {
|
} else if Path::new(boost_path).exists() {
|
||||||
write_sysfs_value(boost_path, value_boost)
|
write_sysfs_value(boost_path, value_boost)
|
||||||
} else {
|
} else {
|
||||||
Err(ControlError::NotSupported(
|
// Also try per-core cpufreq boost for some AMD systems
|
||||||
"Neither intel_pstate/no_turbo nor cpufreq/boost found.".to_string(),
|
let result = try_set_per_core_boost(value_boost)?;
|
||||||
))
|
if result {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(ControlError::NotSupported(
|
||||||
|
"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<()> {
|
pub fn set_epp(epp: &str, core_id: Option<u32>) -> Result<()> {
|
||||||
let action = |id: u32| {
|
let action = |id: u32| {
|
||||||
let path = format!("/sys/devices/system/cpu/cpu{id}/cpufreq/energy_performance_preference");
|
let path = format!("/sys/devices/system/cpu/cpu{id}/cpufreq/energy_performance_preference");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue