1use anyhow::{Result, anyhow};
7use std::fs::{File, OpenOptions};
8use std::io::Write;
9use std::path::Path;
10
11pub fn update_global_idle_resume_latency(value_us: i32) -> Result<File> {
15 if value_us < 0 {
16 return Err(anyhow!("Latency value must be non-negative"));
17 }
18
19 let mut file = OpenOptions::new()
20 .write(true)
21 .open("/dev/cpu_dma_latency")?;
22 let bytes = value_us.to_le_bytes(); file.write_all(&bytes)?;
24 Ok(file) }
26
27pub fn update_cpu_idle_resume_latency(cpu_num: usize, value_us: i32) -> Result<()> {
29 if value_us < 0 {
30 return Err(anyhow!("Latency value must be non-negative"));
31 }
32
33 let path = format!(
34 "/sys/devices/system/cpu/cpu{}/power/pm_qos_resume_latency_us",
35 cpu_num
36 );
37
38 let mut file = File::create(Path::new(&path))?;
39 write!(file, "{}", value_us)?;
40 Ok(())
41}
42
43pub fn cpu_idle_resume_latency_supported() -> bool {
45 std::fs::exists("/sys/devices/system/cpu/cpu0/power/pm_qos_resume_latency_us").unwrap_or(false)
46}