1use anyhow::{anyhow, Result};
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!("/sys/devices/system/cpu/cpu{cpu_num}/power/pm_qos_resume_latency_us");
34
35 let mut file = File::create(Path::new(&path))?;
36 write!(file, "{value_us}")?;
37 Ok(())
38}
39
40pub fn cpu_idle_resume_latency_supported() -> bool {
42 std::fs::exists("/sys/devices/system/cpu/cpu0/power/pm_qos_resume_latency_us").unwrap_or(false)
43}