From c9f70fd926630c0439994f57d8a853c2d9315e0c Mon Sep 17 00:00:00 2001 From: Camerooooon Date: Fri, 11 Feb 2022 18:17:23 -0800 Subject: [PATCH 1/6] Add powersave on overheat rules --- src/daemon.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/daemon.rs b/src/daemon.rs index 85a2d23b..8ebf60a3 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -40,6 +40,10 @@ pub trait Checker { // Under Powersave Under Rule fn under_powersave_under_rule(&mut self) -> Result<(), Error>; + // High Temperature Rule + fn start_high_temperature_rule(&mut self) -> Result<(), Error>; + fn end_high_temperature_rule(&mut self) -> Result<(), Error>; + // Other methods fn run(&mut self) -> Result<(), Error>; fn init(&mut self); @@ -70,10 +74,12 @@ pub struct Daemon { pub already_charging: bool, pub already_closed: bool, pub already_under_powersave_under_percent: bool, + pub already_high_temp: bool, pub should_graph: bool, pub graph: String, pub grapher: Graph, pub commit: bool, + pub temp_max: i32, pub commit_hash: String, pub timeout: time::Duration, } @@ -88,6 +94,16 @@ fn make_gov_performance(cpu: &mut CPU) -> Result<(), Error> { Ok(()) } +fn get_highest_temp(cpus: &Vec) -> i32 { + let mut temp_max: i32 = 0; + for cpu in cpus { + if cpu.cur_temp > temp_max { + temp_max = cpu.cur_temp; + } + } + temp_max +} + fn get_battery_status() -> String { match has_battery() { Ok(has) => { @@ -189,6 +205,31 @@ impl Checker for Daemon { Ok(()) } + fn start_high_temperature_rule(&mut self) -> Result<(), Error> { + if !self.already_high_temp && self.temp_max > 80 { + self.logger.log( + "Governor set to powersave because CPU temperature is high", + logger::Severity::Log, + ); + self.apply_to_cpus(&make_gov_powersave)?; + self.already_high_temp = true; + } + Ok(()) + } + + fn end_high_temperature_rule(&mut self) -> Result<(), Error> { + if self.already_high_temp && self.temp_max < 70 { + + self.logger.log( + "Governor set to powesave because CPU temperature is high", + logger::Severity::Log, + ); + self.already_high_temp = false; + } + Ok(()) + } + + fn lid_close_rule(&mut self) -> Result<(), Error> { if self.lid_state == LidState::Closed && !self.already_closed { self.logger.log( @@ -291,6 +332,8 @@ impl Checker for Daemon { self.lid_state = read_lid_state()?; // Call all rules + self.start_high_temperature_rule()?; + self.end_high_temperature_rule()?; self.start_charging_rule()?; self.end_charging_rule()?; self.lid_close_rule()?; @@ -326,6 +369,8 @@ impl Checker for Daemon { cpu.update()?; } + self.temp_max = get_highest_temp(&self.cpus) / 1000; + if self.should_graph { self.grapher.freqs.push(check_cpu_freq()? as f64); } @@ -480,10 +525,12 @@ pub fn daemon_init( already_charging: false, already_closed: false, already_under_powersave_under_percent: false, + already_high_temp: false, should_graph, graph: String::new(), grapher: Graph { freqs: vec![0.0] }, commit, + temp_max: 0, commit_hash: String::new(), timeout: time::Duration::from_millis(1), }; From 14975552a5e83516942f4f78d279e07946b5af94 Mon Sep 17 00:00:00 2001 From: Camerooooon Date: Fri, 11 Feb 2022 18:31:37 -0800 Subject: [PATCH 2/6] Remove unwrap that causes panic! --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index ee285d08..1d18287e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -52,7 +52,7 @@ fn parse_as_toml(config: String) -> Config { pub fn open_config() -> Result { let conf_path = config_path(); - let mut config_file: File = File::open(&conf_path).unwrap(); + let mut config_file: File = File::open(&conf_path)?; let config_string = read_as_string(&mut config_file); let config_toml = parse_as_toml(config_string); From e75ad5e2ca09a0e78c33b5423ced256122019176 Mon Sep 17 00:00:00 2001 From: Camerooooon Date: Fri, 11 Feb 2022 18:42:31 -0800 Subject: [PATCH 3/6] Cargo fmt --- src/daemon.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index 6200b01b..67ee6046 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -240,7 +240,6 @@ impl Checker for Daemon { fn end_high_temperature_rule(&mut self) -> Result<(), Error> { if self.already_high_temp && self.temp_max < 70 { - self.logger.log( "Governor set to powesave because CPU temperature is high", logger::Severity::Log, @@ -250,7 +249,6 @@ impl Checker for Daemon { Ok(()) } - fn lid_close_rule(&mut self) -> Result<(), Error> { if self.lid_state == LidState::Closed && !self.already_closed { self.logger.log( From 519713fd832e5fc8ef1aab925bccc807378a732b Mon Sep 17 00:00:00 2001 From: Camerooooon Date: Fri, 11 Feb 2022 18:55:19 -0800 Subject: [PATCH 4/6] Make the overheat threshold configurable --- src/config.rs | 2 ++ src/daemon.rs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1d18287e..4f4f2f55 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ pub fn config_dir_exists() -> bool { #[derive(Debug, Deserialize, Serialize)] pub struct Config { pub powersave_under: i8, + pub overheat_threshold: i8, // Future variables // pub charging_powersave_under: i32, } @@ -31,6 +32,7 @@ pub struct Config { pub fn default_config() -> Config { Config { powersave_under: 20, + overheat_threshold: 80, } } diff --git a/src/daemon.rs b/src/daemon.rs index 67ee6046..d8bc4b70 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -81,7 +81,7 @@ pub struct Daemon { pub graph: String, pub grapher: Graph, pub commit: bool, - pub temp_max: i32, + pub temp_max: i8, pub commit_hash: String, pub timeout: time::Duration, pub settings: Settings, @@ -227,7 +227,7 @@ impl Checker for Daemon { } fn start_high_temperature_rule(&mut self) -> Result<(), Error> { - if !self.already_high_temp && self.temp_max > 80 { + if !self.already_high_temp && self.temp_max > self.config.overheat_threshold { self.logger.log( "Governor set to powersave because CPU temperature is high", logger::Severity::Log, @@ -239,7 +239,7 @@ impl Checker for Daemon { } fn end_high_temperature_rule(&mut self) -> Result<(), Error> { - if self.already_high_temp && self.temp_max < 70 { + if self.already_high_temp && self.temp_max < self.config.overheat_threshold { self.logger.log( "Governor set to powesave because CPU temperature is high", logger::Severity::Log, @@ -393,7 +393,7 @@ impl Checker for Daemon { cpu.update()?; } - self.temp_max = get_highest_temp(&self.cpus) / 1000; + self.temp_max = (get_highest_temp(&self.cpus) / 1000) as i8; // Update the data in the graph and render it if self.settings.should_graph { From c92e5a2189ca47443529235c13206d16ee8a6062 Mon Sep 17 00:00:00 2001 From: Camerooooon Date: Fri, 11 Feb 2022 18:58:19 -0800 Subject: [PATCH 5/6] Remove unneccesary values that somehow sneaked in during merge --- src/daemon.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index d8bc4b70..a65738c0 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -77,10 +77,8 @@ pub struct Daemon { pub already_closed: bool, pub already_under_powersave_under_percent: bool, pub already_high_temp: bool, - pub should_graph: bool, pub graph: String, pub grapher: Graph, - pub commit: bool, pub temp_max: i8, pub commit_hash: String, pub timeout: time::Duration, @@ -557,10 +555,8 @@ pub fn daemon_init(settings: Settings, config: Config) -> Result already_closed: false, already_under_powersave_under_percent: false, already_high_temp: false, - should_graph: false, graph: String::new(), grapher: Graph { freqs: vec![0.0] }, - commit: false, temp_max: 0, commit_hash: String::new(), timeout: time::Duration::from_millis(1), From 00be6db4f2c50bc23994604ccd16b51a5aa2f60a Mon Sep 17 00:00:00 2001 From: Camerooooon Date: Fri, 11 Feb 2022 19:00:03 -0800 Subject: [PATCH 6/6] Add overheat threshold to default configuration --- acs.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/acs.toml b/acs.toml index 08d0eeea..ff18b70e 100644 --- a/acs.toml +++ b/acs.toml @@ -1,2 +1,3 @@ # acs.toml powersave_under = 20 +overheat_threshold = 80