From 5f2de533c332e070c4a45a9833abc6cc51e72620 Mon Sep 17 00:00:00 2001 From: Lennard Kittner Date: Fri, 28 Mar 2025 14:49:50 +0100 Subject: Add switch_governor function --- src/freq.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/freq.rs b/src/freq.rs index 239aba4..7bba4f8 100644 --- a/src/freq.rs +++ b/src/freq.rs @@ -204,7 +204,7 @@ impl SysFSFrequencyService { self.cpu_descriptors = CPUDescriptors::new_range(&self.cpus).unwrap(); let ranges = self.get_freq_limits().unwrap(); self.frequency_ranges = ranges; - self.switch_to_userspace_governor().unwrap(); + self.switch_governor("conservative").unwrap(); loop { self.handle_requests().unwrap(); @@ -263,11 +263,11 @@ impl SysFSFrequencyService { Ok(ranges) } - fn switch_to_userspace_governor(&self) -> io::Result<()> { + fn switch_governor(&self, governor: &str) -> io::Result<()> { let available_governor = fs::read_to_string("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors")?; - if !available_governor.contains("userspace") { - io::Error::new(io::ErrorKind::NotFound, "userspace"); + if !available_governor.contains(governor) { + io::Error::new(io::ErrorKind::NotFound, governor); } for cpu in self.cpus.clone() { @@ -275,13 +275,13 @@ impl SysFSFrequencyService { "/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor", cpu ))?; - if current_governor != "userspace" { + if current_governor != governor { fs::write( format!( "/sys/devices/system/cpu/cpu{}/cpufreq/scaling_governor", cpu ), - "userspace", + governor, )?; } } -- cgit v1.3.1