mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
cpu: add global turbo querying
This commit is contained in:
parent
07ca582760
commit
571f172cc2
3 changed files with 14 additions and 19 deletions
|
@ -12,9 +12,8 @@ pub struct CpuCoreInfo {
|
||||||
|
|
||||||
pub struct CpuGlobalInfo {
|
pub struct CpuGlobalInfo {
|
||||||
// System-wide CPU settings
|
// System-wide CPU settings
|
||||||
pub turbo_status: Option<bool>, // true for enabled, false for disabled
|
pub epp: Option<String>, // Energy Performance Preference
|
||||||
pub epp: Option<String>, // Energy Performance Preference
|
pub epb: Option<String>, // Energy Performance Bias
|
||||||
pub epb: Option<String>, // Energy Performance Bias
|
|
||||||
pub platform_profile: Option<String>,
|
pub platform_profile: Option<String>,
|
||||||
pub average_temperature_celsius: Option<f32>, // Average temperature across all cores
|
pub average_temperature_celsius: Option<f32>, // Average temperature across all cores
|
||||||
}
|
}
|
||||||
|
|
12
src/cpu.rs
12
src/cpu.rs
|
@ -553,4 +553,16 @@ impl Cpu {
|
||||||
|
|
||||||
bail!("no supported CPU boost control mechanism found");
|
bail!("no supported CPU boost control mechanism found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn turbo() -> Option<bool> {
|
||||||
|
if let Some(Ok(content)) = fs::read_u64("/sys/devices/system/cpu/intel_pstate/no_turbo") {
|
||||||
|
return Some(content == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(Ok(content)) = fs::read_u64("/sys/devices/system/cpu/cpufreq/boost") {
|
||||||
|
return Some(content == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,21 +238,6 @@ pub fn get_all_cpu_core_info() -> anyhow::Result<Vec<CpuCoreInfo>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cpu_global_info(cpu_cores: &[CpuCoreInfo]) -> CpuGlobalInfo {
|
pub fn get_cpu_global_info(cpu_cores: &[CpuCoreInfo]) -> CpuGlobalInfo {
|
||||||
let turbo_status_path = Path::new("/sys/devices/system/cpu/intel_pstate/no_turbo");
|
|
||||||
let boost_path = Path::new("/sys/devices/system/cpu/cpufreq/boost");
|
|
||||||
|
|
||||||
let turbo_status = if turbo_status_path.exists() {
|
|
||||||
// 0 means turbo enabled, 1 means disabled for intel_pstate
|
|
||||||
read_sysfs_value::<u8>(turbo_status_path)
|
|
||||||
.map(|val| val == 0)
|
|
||||||
.ok()
|
|
||||||
} else if boost_path.exists() {
|
|
||||||
// 1 means turbo enabled, 0 means disabled for generic cpufreq boost
|
|
||||||
read_sysfs_value::<u8>(boost_path).map(|val| val == 1).ok()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let platform_profile = read_sysfs_file_trimmed("/sys/firmware/acpi/platform_profile").ok();
|
let platform_profile = read_sysfs_file_trimmed("/sys/firmware/acpi/platform_profile").ok();
|
||||||
|
|
||||||
// Calculate average CPU temperature from the core temperatures
|
// Calculate average CPU temperature from the core temperatures
|
||||||
|
@ -279,7 +264,6 @@ pub fn get_cpu_global_info(cpu_cores: &[CpuCoreInfo]) -> CpuGlobalInfo {
|
||||||
|
|
||||||
// Return the constructed CpuGlobalInfo
|
// Return the constructed CpuGlobalInfo
|
||||||
CpuGlobalInfo {
|
CpuGlobalInfo {
|
||||||
turbo_status,
|
|
||||||
platform_profile,
|
platform_profile,
|
||||||
average_temperature_celsius,
|
average_temperature_celsius,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue