From dfdda3b1b7f834027dc4ea111ab6c9253970c12d Mon Sep 17 00:00:00 2001 From: hbriese Date: Fri, 7 Aug 2020 16:58:36 +1000 Subject: [PATCH 1/5] Reload config when modified --- lenovo_fix.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lenovo_fix.py b/lenovo_fix.py index 6b2a896..f92d0cc 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -541,6 +541,10 @@ def set_disable_bdprochot(): log('[D] BDPROCHOT - write "{:#02x}" - read "{:#02x}" - match {}'.format(0, read_value, match)) +def get_config_write_time(): + return os.stat(args.config).st_mtime + + def power_thread(config, regs, exit_event): try: mchbar_mmio = MMIO(0xFED159A0, 8) @@ -550,6 +554,7 @@ def power_thread(config, regs, exit_event): mchbar_mmio = None next_hwp_write = 0 + last_config_write_time = get_config_write_time() while not exit_event.is_set(): # log thermal status if args.debug: @@ -558,6 +563,13 @@ def power_thread(config, regs, exit_event): for key, value in core_thermal_status.items(): log('[D] core {} thermal status: {} = {}'.format(index, key.replace("_", " "), value)) + # Reload config when modified + config_write_time = get_config_write_time() + if last_config_write_time != config_write_time: + last_config_write_time = config_write_time + config = load_config() + log('[I] Reloading changes.') + # switch back to sysfs polling if power['method'] == 'polling': power['source'] = 'BATTERY' if is_on_battery(config) else 'AC' From 46a062e14d92a2d04c3c0ded55749e37f5f9ffeb Mon Sep 17 00:00:00 2001 From: hbriese Date: Fri, 7 Aug 2020 17:12:18 +1000 Subject: [PATCH 2/5] Don't reload changes when the config file has been deleted --- lenovo_fix.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lenovo_fix.py b/lenovo_fix.py index f92d0cc..ce65310 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -542,7 +542,10 @@ def set_disable_bdprochot(): def get_config_write_time(): - return os.stat(args.config).st_mtime + try: + return os.stat(args.config).st_mtime + except FileNotFoundError: + return None def power_thread(config, regs, exit_event): @@ -563,9 +566,9 @@ def power_thread(config, regs, exit_event): for key, value in core_thermal_status.items(): log('[D] core {} thermal status: {} = {}'.format(index, key.replace("_", " "), value)) - # Reload config when modified + # Reload config when modified (unless it no longer exists) config_write_time = get_config_write_time() - if last_config_write_time != config_write_time: + if config_write_time and last_config_write_time != config_write_time: last_config_write_time = config_write_time config = load_config() log('[I] Reloading changes.') From 8d598f524ce98d684b3771671705defc49e9719e Mon Sep 17 00:00:00 2001 From: hbriese Date: Sun, 9 Aug 2020 14:18:51 +1000 Subject: [PATCH 3/5] Set undervolt & icc max on reload --- lenovo_fix.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lenovo_fix.py b/lenovo_fix.py index ce65310..aa672f9 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -548,6 +548,15 @@ def get_config_write_time(): return None +def reload_config(): + config = load_config() + regs = calc_reg_values(get_cpu_platform_info(), config) + undervolt(config) + set_icc_max(config) + log('[I] Reloading changes.') + return config, regs + + def power_thread(config, regs, exit_event): try: mchbar_mmio = MMIO(0xFED159A0, 8) @@ -570,8 +579,7 @@ def power_thread(config, regs, exit_event): config_write_time = get_config_write_time() if config_write_time and last_config_write_time != config_write_time: last_config_write_time = config_write_time - config = load_config() - log('[I] Reloading changes.') + config, regs = reload_config() # switch back to sysfs polling if power['method'] == 'polling': From 7b20337840bb14a03c231a0d13861c21480fff2d Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Tue, 11 Aug 2020 10:07:27 +1000 Subject: [PATCH 4/5] Set HWP mode when reloading --- lenovo_fix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lenovo_fix.py b/lenovo_fix.py index 1348285..d406c32 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -555,6 +555,7 @@ def reload_config(): regs = calc_reg_values(get_cpu_platform_info(), config) undervolt(config) set_icc_max(config) + set_hwp(config.getboolean('AC', 'HWP_Mode', fallback=False)) log('[I] Reloading changes.') return config, regs From 320243dafe4e03b0b1cb11423b7c7c0f34b7e73d Mon Sep 17 00:00:00 2001 From: Hayden Briese Date: Tue, 11 Aug 2020 16:16:20 +1000 Subject: [PATCH 5/5] Added 'Autoreload' config option --- README.md | 10 +++++++++- etc/lenovo_fix.conf | 2 ++ lenovo_fix.py | 14 ++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 01ac7bb..056ea05 100644 --- a/README.md +++ b/README.md @@ -291,11 +291,19 @@ This is an example output: [D] core 0 thermal status: reading valid = 1 ..... ``` + +## Autoreload +Auto reload config on changes (unless it's deleted) can be enabled/disabled in the config + +``` +[General] +Autoreload = True +``` + ## A word about manufacturer provided tooling Tools provided by your notebook manufacturer like [Dell Power Manager](https://www.dell.com/support/contents/us/en/04/article/product-support/self-support-knowledgebase/software-and-downloads/dell-power-manager) tend to persist their settings to the system board. If you ever had it running under Windows and activated a cool/quiet/silent/saving profile, this setting will still be active when running linux, throttling your system. > On my Dell Latitude 5591, not even a BIOS reset to manufacturar default killed the active `Quiet` profile - ## Disclaimer This script overrides the default values set by Lenovo. I'm using it without any problem, but it is still experimental so use it at your own risk. diff --git a/etc/lenovo_fix.conf b/etc/lenovo_fix.conf index 9082579..6821fa0 100644 --- a/etc/lenovo_fix.conf +++ b/etc/lenovo_fix.conf @@ -3,6 +3,8 @@ Enabled: True # SYSFS path for checking if the system is running on AC power Sysfs_Power_Path: /sys/class/power_supply/AC*/online +# Auto reload config on changes +Autoreload: True ## Settings to apply while connected to Battery power [BATTERY] diff --git a/lenovo_fix.py b/lenovo_fix.py index d406c32..5437254 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -569,7 +569,8 @@ def power_thread(config, regs, exit_event): mchbar_mmio = None next_hwp_write = 0 - last_config_write_time = get_config_write_time() + last_config_write_time = get_config_write_time() \ + if config.getboolean('GENERAL', 'Autoreload', fallback=False) else None while not exit_event.is_set(): # log thermal status if args.debug: @@ -578,11 +579,12 @@ def power_thread(config, regs, exit_event): for key, value in core_thermal_status.items(): log('[D] core {} thermal status: {} = {}'.format(index, key.replace("_", " "), value)) - # Reload config when modified (unless it no longer exists) - config_write_time = get_config_write_time() - if config_write_time and last_config_write_time != config_write_time: - last_config_write_time = config_write_time - config, regs = reload_config() + # Reload config on changes (unless it's deleted) + if config.getboolean('GENERAL', 'Autoreload', fallback=False): + config_write_time = get_config_write_time() + if config_write_time and last_config_write_time != config_write_time: + last_config_write_time = config_write_time + config, regs = reload_config() # switch back to sysfs polling if power['method'] == 'polling':