From c8c000b1873f341410e89931d62b6265693dd944 Mon Sep 17 00:00:00 2001 From: erpalma Date: Thu, 14 Jun 2018 10:39:31 +0200 Subject: [PATCH] double check if we are still in AC before writing HWP value --- lenovo_fix.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lenovo_fix.py b/lenovo_fix.py index be94454..2550472 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -139,9 +139,11 @@ def power_thread(config, regs, exit_event): enable_hwp_mode = config.getboolean('AC', 'HWP_Mode', fallback=False) if power_source == 'AC' and enable_hwp_mode: cpu_usage = float(psutil.cpu_percent(interval=wait_t)) - # set the full performance mode only when load is greater than this threshold (~ at least 1 core full speed) + # set full performance mode only when load is greater than this threshold (~ at least 1 core full speed) performance_mode = cpu_usage > 100. / (cpu_count() * 1.25) - set_hwp('performance' if performance_mode else 'balance_performance') + # check again if we are on AC, since in the meantime we might have switched to BATTERY + if not is_on_battery(): + set_hwp('performance' if performance_mode else 'balance_performance') else: exit_event.wait(wait_t)