From b5e52c03f4b221a012fe0e0c791c0e6869106f3d Mon Sep 17 00:00:00 2001 From: Pedro Nariyoshi Date: Wed, 29 Jan 2020 09:53:21 -0500 Subject: [PATCH 1/6] Parse Disable BDPROCHOT option --- lenovo_fix.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lenovo_fix.py b/lenovo_fix.py index 16c6d14..da9bcf9 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -379,6 +379,10 @@ def load_config(): value = config.set(power_source, option, str(max(0.001, value))) elif option == 'Update_Rate_s': fatal('The mandatory "Update_Rate_s" parameter is missing.') + for option in ('Disable_BDPROCHOT'): + value = config.boolean(power_source, option, fallback=None) + if value is None: + value = config.set(power_source, option, 0) trip_temp = config.getfloat(power_source, 'Trip_Temp_C', fallback=None) if trip_temp is not None: From f2ee9ed38d11deeefcd70dea62f872f7c00e207c Mon Sep 17 00:00:00 2001 From: Pedro Nariyoshi Date: Wed, 29 Jan 2020 10:27:05 -0500 Subject: [PATCH 2/6] Implement Disable_BDPROCHOT --- lenovo_fix.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lenovo_fix.py b/lenovo_fix.py index da9bcf9..d3389ad 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -379,10 +379,6 @@ def load_config(): value = config.set(power_source, option, str(max(0.001, value))) elif option == 'Update_Rate_s': fatal('The mandatory "Update_Rate_s" parameter is missing.') - for option in ('Disable_BDPROCHOT'): - value = config.boolean(power_source, option, fallback=None) - if value is None: - value = config.set(power_source, option, 0) trip_temp = config.getfloat(power_source, 'Trip_Temp_C', fallback=None) if trip_temp is not None: @@ -517,6 +513,7 @@ def calc_reg_values(platform_info, config): else: valid_c_tdp_target_value = max(0, c_tdp_target_value) regs[power_source]['MSR_CONFIG_TDP_CONTROL'] = valid_c_tdp_target_value + return regs @@ -532,6 +529,18 @@ def set_hwp(): log('[D] HWP - write "{:#02x}" - read "{:#02x}" - match {}'.format(HWP_VALUE, read_value, match)) +def set_disable_bdprochot(): + # Disable BDPROCHOT + cur_val = readmsr(0x1FC,flatten=True) + new_val = (cur_val & 0xFFFFFFFFFFFFFFFE) + + writemsr(0x1FC, new_val) + if args.debug: + read_value = readmsr(0x1FC, from_bit=31, to_bit=31)[0] + match = OK if ~read_value else ERR + log('[D] BDPROCHOT - write "{:#02x}" - read "{:#02x}" - match {}'.format(0, read_value, match)) + + def power_thread(config, regs, exit_event): try: mchbar_mmio = MMIO(0xFED159A0, 8) @@ -603,6 +612,11 @@ def power_thread(config, regs, exit_event): ) ) + # Disable BDPROCHOT + disable_bdprochot = config.getboolean(power['source'], 'Disable_BDPROCHOT', fallback=None) + if disable_bdprochot is not None: + set_disable_bdprochot() + wait_t = config.getfloat(power['source'], 'Update_Rate_s') enable_hwp_mode = config.getboolean('AC', 'HWP_Mode', fallback=False) # set HWP less frequently. Just to be safe since (e.g.) TLP might reset this value From 3cf2f1aa0ff2689aa51a084972ccb281eeb1cbca Mon Sep 17 00:00:00 2001 From: Pedro Nariyoshi Date: Wed, 29 Jan 2020 10:28:22 -0500 Subject: [PATCH 3/6] Add default values for Disable_BDPROCHOT --- etc/lenovo_fix.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/lenovo_fix.conf b/etc/lenovo_fix.conf index 2b66d64..da5a39b 100644 --- a/etc/lenovo_fix.conf +++ b/etc/lenovo_fix.conf @@ -20,6 +20,8 @@ PL2_Duration_S: 0.002 Trip_Temp_C: 85 # Set cTDP to normal=0, down=1 or up=2 (EXPERIMENTAL) cTDP: 0 +# Disable BDPROCHOT (EXPERIMENTAL) +Disable_BDPROCHOT: False ## Settings to apply while connected to AC power [AC] @@ -39,6 +41,8 @@ Trip_Temp_C: 95 HWP_Mode: False # Set cTDP to normal=0, down=1 or up=2 (EXPERIMENTAL) cTDP: 0 +# Disable BDPROCHOT (EXPERIMENTAL) +Disable_BDPROCHOT: False [UNDERVOLT.BATTERY] # CPU core voltage offset (mV) From d118ddc0a3770789be403aa03088a698919a1efa Mon Sep 17 00:00:00 2001 From: Pedro Nariyoshi Date: Wed, 29 Jan 2020 10:29:56 -0500 Subject: [PATCH 4/6] Remove extra line to make PR cleaner --- lenovo_fix.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lenovo_fix.py b/lenovo_fix.py index d3389ad..9967246 100755 --- a/lenovo_fix.py +++ b/lenovo_fix.py @@ -513,7 +513,6 @@ def calc_reg_values(platform_info, config): else: valid_c_tdp_target_value = max(0, c_tdp_target_value) regs[power_source]['MSR_CONFIG_TDP_CONTROL'] = valid_c_tdp_target_value - return regs From b1d887c167f403eeb929f5edb27deece73f5438e Mon Sep 17 00:00:00 2001 From: nariox Date: Wed, 12 Feb 2020 11:27:30 -0500 Subject: [PATCH 5/6] Move static fix down The static fix takes quite a bit of space, but doesn't really relate to throttled. Moved it down, so readme is a bit cleaner. --- README.md | 81 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 8ce69a5..f7cd9e2 100644 --- a/README.md +++ b/README.md @@ -3,45 +3,7 @@ This tool was originally developed to fix Linux CPU throttling issues affecting The CPU package power limit (PL1/2) is forced to a value of **44 W** (29 W on battery) and the temperature trip point to **95 'C** (85 'C on battery) by overriding default values in MSR and MCHBAR every 5 seconds (30 on battery) to block the Embedded Controller from resetting these values to default. -On systems where the EC doesn't reset the values (ex: ASUS Zenbook UX430UNR), the power limit can be altered by using the official intel_rapl driver (note: [5.3](https://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git/commit/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c?h=for-5.4&id=555c45fe0d04bd817e245a125d242b6a86af4593) or newer is required, if you want to change the MCHBAR values): -``` -# MSR -# PL1 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw # 44 watt -echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us # 28 sec -# PL2 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw # 44 watt -echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us # 0.00244 sec - -# MCHBAR -# PL1 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw # 44 watt -# ^ Only required change on a ASUS Zenbook UX430UNR -echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us # 28 sec -# PL2 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw # 44 watt -echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us # 0.00244 sec -``` -If you want to change the values automatic on boot you can use [systemd-tmpfiles](https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html): -``` -# /etc/tmpfiles.d/power_limit.conf -# MSR -# PL1 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw - - - - 44000000 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us - - - - 28000000 -# PL2 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw - - - - 44000000 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us - - - - 2440 - -# MCHBAR -# PL1 -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw - - - - 44000000 -# ^ Only required change on a ASUS Zenbook UX430UNR -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us - - - - 28000000 -# PL2 -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw - - - - 44000000 -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us - - - - 2440 -``` +On systems where the EC doesn't reset the values (ex: ASUS Zenbook UX430UNR), the power limit can be altered by using the official intel_rapl driver (see [Static fix](#static-fix) for more information) ### Tested hardware Other users have confirmed that the tool is also working for these laptops: @@ -219,6 +181,47 @@ With the flag `--monitor` the tool *constantly* monitors the throttling status, [AC] Thermal: OK - Power: OK - Current: OK - Cross-domain (e.g. GPU): OK || VCore: 549 mV - Package: 2.6 W - Graphics: 0.4 W - DRAM: 1.2 W ``` +## Static Fix +You can alternatively set the power limits using intel_rapl driver (modifying MCHBAR values requires [Linux 5.3+](https://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git/commit/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c?h=for-5.4&id=555c45fe0d04bd817e245a125d242b6a86af4593)). Bear in mind, some embedded controllers (EC) control the power limit values and will reset them from time to time): +``` +# MSR +# PL1 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw # 44 watt +echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us # 28 sec +# PL2 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw # 44 watt +echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us # 0.00244 sec + +# MCHBAR +# PL1 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw # 44 watt +# ^ Only required change on a ASUS Zenbook UX430UNR +echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us # 28 sec +# PL2 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw # 44 watt +echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us # 0.00244 sec +``` +If you want to change the values automatic on boot you can use [systemd-tmpfiles](https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html): +``` +# /etc/tmpfiles.d/power_limit.conf +# MSR +# PL1 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw - - - - 44000000 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us - - - - 28000000 +# PL2 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw - - - - 44000000 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us - - - - 2440 + +# MCHBAR +# PL1 +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw - - - - 44000000 +# ^ Only required change on a ASUS Zenbook UX430UNR +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us - - - - 28000000 +# PL2 +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw - - - - 44000000 +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us - - - - 2440 +``` + ## Debug You can enable the `--debug` option to read back written values and check if the tool is working properly. At the statup it will also show the CPUs platform info which contains information about multiplier values and features present for this CPU. Additionally the tool will print the thermal status per core which is handy when it comes to figuring out the reason for CPU throttle. Status fields stands for the current throttle reason or condition and log shows if this was a throttle reason since the last interval. This is an example output: From 919b61f3c9e59bda56d86b3d7d2fc2db7bd31ed5 Mon Sep 17 00:00:00 2001 From: Pedro Nariyoshi Date: Wed, 12 Feb 2020 11:36:14 -0500 Subject: [PATCH 6/6] Revert "Move static fix down" This reverts commit b1d887c167f403eeb929f5edb27deece73f5438e. --- README.md | 81 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index f7cd9e2..8ce69a5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,45 @@ This tool was originally developed to fix Linux CPU throttling issues affecting The CPU package power limit (PL1/2) is forced to a value of **44 W** (29 W on battery) and the temperature trip point to **95 'C** (85 'C on battery) by overriding default values in MSR and MCHBAR every 5 seconds (30 on battery) to block the Embedded Controller from resetting these values to default. -On systems where the EC doesn't reset the values (ex: ASUS Zenbook UX430UNR), the power limit can be altered by using the official intel_rapl driver (see [Static fix](#static-fix) for more information) +On systems where the EC doesn't reset the values (ex: ASUS Zenbook UX430UNR), the power limit can be altered by using the official intel_rapl driver (note: [5.3](https://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git/commit/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c?h=for-5.4&id=555c45fe0d04bd817e245a125d242b6a86af4593) or newer is required, if you want to change the MCHBAR values): +``` +# MSR +# PL1 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw # 44 watt +echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us # 28 sec +# PL2 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw # 44 watt +echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us # 0.00244 sec + +# MCHBAR +# PL1 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw # 44 watt +# ^ Only required change on a ASUS Zenbook UX430UNR +echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us # 28 sec +# PL2 +echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw # 44 watt +echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us # 0.00244 sec +``` +If you want to change the values automatic on boot you can use [systemd-tmpfiles](https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html): +``` +# /etc/tmpfiles.d/power_limit.conf +# MSR +# PL1 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw - - - - 44000000 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us - - - - 28000000 +# PL2 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw - - - - 44000000 +w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us - - - - 2440 + +# MCHBAR +# PL1 +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw - - - - 44000000 +# ^ Only required change on a ASUS Zenbook UX430UNR +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us - - - - 28000000 +# PL2 +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw - - - - 44000000 +w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us - - - - 2440 +``` ### Tested hardware Other users have confirmed that the tool is also working for these laptops: @@ -181,47 +219,6 @@ With the flag `--monitor` the tool *constantly* monitors the throttling status, [AC] Thermal: OK - Power: OK - Current: OK - Cross-domain (e.g. GPU): OK || VCore: 549 mV - Package: 2.6 W - Graphics: 0.4 W - DRAM: 1.2 W ``` -## Static Fix -You can alternatively set the power limits using intel_rapl driver (modifying MCHBAR values requires [Linux 5.3+](https://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux.git/commit/drivers/thermal/intel/int340x_thermal/processor_thermal_device.c?h=for-5.4&id=555c45fe0d04bd817e245a125d242b6a86af4593)). Bear in mind, some embedded controllers (EC) control the power limit values and will reset them from time to time): -``` -# MSR -# PL1 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw # 44 watt -echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us # 28 sec -# PL2 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw # 44 watt -echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us # 0.00244 sec - -# MCHBAR -# PL1 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw # 44 watt -# ^ Only required change on a ASUS Zenbook UX430UNR -echo 28000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us # 28 sec -# PL2 -echo 44000000 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw # 44 watt -echo 2440 | sudo tee /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us # 0.00244 sec -``` -If you want to change the values automatic on boot you can use [systemd-tmpfiles](https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html): -``` -# /etc/tmpfiles.d/power_limit.conf -# MSR -# PL1 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_power_limit_uw - - - - 44000000 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_0_time_window_us - - - - 28000000 -# PL2 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_power_limit_uw - - - - 44000000 -w /sys/devices/virtual/powercap/intel-rapl/intel-rapl:0/constraint_1_time_window_us - - - - 2440 - -# MCHBAR -# PL1 -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_power_limit_uw - - - - 44000000 -# ^ Only required change on a ASUS Zenbook UX430UNR -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_0_time_window_us - - - - 28000000 -# PL2 -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_power_limit_uw - - - - 44000000 -w /sys/devices/virtual/powercap/intel-rapl-mmio/intel-rapl-mmio:0/constraint_1_time_window_us - - - - 2440 -``` - ## Debug You can enable the `--debug` option to read back written values and check if the tool is working properly. At the statup it will also show the CPUs platform info which contains information about multiplier values and features present for this CPU. Additionally the tool will print the thermal status per core which is handy when it comes to figuring out the reason for CPU throttle. Status fields stands for the current throttle reason or condition and log shows if this was a throttle reason since the last interval. This is an example output: