Coder Social home page Coder Social logo

throttled's Introduction

Fix Intel CPU Throttling on Linux

This tool was originally developed to fix Linux CPU throttling issues affecting Lenovo T480 / T480s / X1C6 as described here.

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 for more information)

Warning!

The latest commit (30 Oct 2021) switched from the legacy name lenovo_fix for the tool/config/system to a more uniform throttled. The install script was updated, but please report back if anything breaks.

Tested hardware

Other users have confirmed that the tool is also working for these laptops:

  • Lenovo T470s, T480, T480s, X1C5, X1C6, X1C8, T580, L590, L490, L480, T470, X280, X390, ThinkPad Anniversary Edition 25, E590 w/ RX 550X, P43s, E480, E580, T14 Gen 1, P14s Gen 1, T15 Gen 1, P15s Gen 1, E14 Gen 2, X1 Extreme Gen 4
  • Dell XPS 9365, 9370, 9550, 7390 2-in-1, Latitude 7390 2-in-1, Inspiron 16 Plus 7620
  • Microsoft Surface Book 2
  • HP Probook 470 G5, Probook 450 G5, ZBook Firefly 15 G7

I will keep this list updated.

Is this tool really doing something on my PC??

I suggest you to use the excellent s-tui tool to check and monitor the CPU usage, frequency, power and temperature under load!

Undervolt

The tool supports undervolting the CPU by configuring voltage offsets for CPU, cache, GPU, System Agent and Analog I/O planes. The tool will re-apply undervolt on resume from standby and hibernate by listening to DBus signals. You can now either use the UNDERVOLT key in config to set global values or the UNDERVOLT.AC and UNDERVOLT.BATTERY keys to selectively set undervolt values for the two power profiles.

===== Notice that undervolt is typically locked from 10th gen onwards! =====

IccMax (EXPERTS ONLY)

The tool now supports overriding the IccMax by configuring the maximum allowed current for CPU, cache and GPU planes. The tool will re-apply IccMax on resume from standby and hibernate. You can now either use the ICCMAX key in config to set global values or the ICCMAX.AC and ICCMAX.BATTERY keys to selectively set current values for the two power profiles. NOTE: the values specified in the config file are the actual current limit of your system, so those are not a offset from the default values as for the undervolt. As such, you should first find your system default values with the --monitor command.

HWP override (EXPERIMENTAL)

I have found that under load my CPU was not always hitting max turbo frequency, in particular when using one/two cores only. For instance, when running prime95 (1 core, test #1) my CPU is limited to about 3500 MHz over the theoretical 4000 MHz maximum. The reason is the value for the HWP energy performance hints. By default TLP sets this value to balance_performance on AC in order to reduce the power consumption/heat in idle. By setting this value to performance I was able to reach 3900 MHz in the prime95 single core test, achieving a +400 MHz boost. Since this value forces the CPU to full speed even during idle, a new experimental feature allows to automatically set HWP to performance under load and revert it to balanced when idle. This feature can be enabled (in AC mode only) by setting to True the HWP_Mode parameter in the throttled config file : https://github.com/erpalma/throttled/blob/master/etc/throttled.conf#L41 .

I have run Geekbench 4 and now I can get a score of 5391/17265! On balance_performance I can reach only 4672/16129, so 15% improvement in single core and 7% in multicore, not bad ;)

setting cTDP (EXPERIMENTAL)

On a lot of modern CPUs from Intel one can configure the TDP up or down based on predefined profiles. This is what this option does. For a i7-8650U normal would be 15W, up profile is setting it to 25W and down to 10W. You can lookup the values of your CPU at the Intel product website.

Requirements

A stripped down version of the python module python-periphery is now built-in and it is used for accessing the MCHBAR register by memory mapped I/O. You also need dbus and gobject python bindings for listening to dbus signals on resume from sleep/hibernate.

Writing to MSR and PCI BAR

Some time ago a feature called Kernel Lockdown was added to Linux. Kernel Lockdown automatically enables some security measures when Secure Boot is enabled, among them restricted access to MSR and PCI BAR via /dev/mem, which this tool requires. There are two ways to get around this: You can either disable Secure Boot in your firmware settings, or disable the Kernel Lockdown LSM.

The LSM can be disabled this way: Check the contents of the file /sys/kernel/security/lsm (example contents: capability,lockdown,yama). Take the contents of the file, remove lockdown and add the rest as a kernel parameter, like this: lsm=capability,yama. Reboot and Kernel Lockdown will be disabled!

As of Linux 5.9, kernel messages will be logged whenever the script writes to MSR registers. These aren't a problem for now, but there's some indication that future kernels may restrict MSR writes from userspace by default. This is being tracked by issue #215. The messages will look something like:

[  324.833543] msr: Write to unrecognized MSR 0x1a2 by python3
               Please report to [email protected]

Note that some kernels (e.g. linux-hardened) will prevent from writing to /dev/mem too. Specifically, you need a kernel with CONFIG_DEVMEM and CONFIG_X86_MSR set.

Thermald

As discovered by DEvil0000 the Linux Thermal Monitor (thermald) can conflict with the purpose of this tool. In particular, thermald might be pre-installed (e.g. on Ubuntu) and configured in such a way to keep the CPU temperature below a certain threshold (~80 'C) by applying throttling or messing up with RAPL or other CPU-specific registers. I strongly suggest to either disable/uninstall it or to review its default configuration.

Update

The tool is now running with Python3 by default (tested w/ 3.6) and a virtualenv is automatically created in /opt/throttled. Python2 should probably still work.

Installation

Arch Linux community package:

pacman -S throttled
sudo systemctl enable --now throttled.service

Thanks to felixonmars for creating and maintaining this package.

Artix Linux

makepkg -si
sudo rc-update add throttled default
sudo rc-service throttled start

Debian/Ubuntu

sudo apt install git build-essential python3-dev libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev python3-cairo-dev python3-venv python3-wheel
git clone https://github.com/erpalma/throttled.git
sudo ./throttled/install.sh

If you own a X1C6 you can also check a tutorial for Ubuntu 18.04 here.

You should make sure that thermald is not setting it back down. Stopping/disabling it will do the trick:

sudo systemctl stop thermald.service
sudo systemctl disable thermald.service

If you want to keep it disabled even after a package update you should also run:

sudo systemctl mask thermald.service

In order to check if the service is well started, you could run:

systemctl status throttled

Fedora

A copr repository is available and can be used as detailed below. You can find the configuration installed at /etc/throttled.conf. The issue tracker for this packaging is available here.

sudo dnf copr enable abn/throttled
sudo dnf install -y throttled

sudo systemctl enable --now throttled

If you prefer to install from source, you can use the following commands.

sudo dnf install python3-cairo-devel cairo-gobject-devel gobject-introspection-devel dbus-glib-devel python3-devel make libX11-devel
git clone https://github.com/erpalma/throttled.git
sudo ./throttled/install.sh

Feedback about Fedora installation is welcome.

Fedora Silverblue

Download the .repo file matching your Fedora on the copr repository page then copy it to /etc/yum.repos.d/.

You can then install the package:

rpm-ostree override remove thermald
rpm-ostree install throttled
systemctl reboot

sudo systemctl enable --now throttled

openSUSE

User brycecordill reported that the following dependencies are required for installing in openSUSE, tested on openSUSE 15.0 Leap.

sudo zypper install gcc make python3-devel dbus-1-glib-devel python3-cairo-devel cairo-devel python3-gobject-cairo gobject-introspection-devel
git clone https://github.com/erpalma/throttled.git
sudo ./throttled/install.sh

Gentoo

The ebuild is now in the official tree!

sudo emerge -av sys-power/throttled
# when using OpenRC:
rc-update add throttled default
/etc/init.d/throttled start
# when using systemd:
systemctl enable --now throttled.service

Solus

sudo eopkg it -c system.devel
sudo eopkg it git python3-devel dbus-glib-devel python3-cairo-devel libcairo-devel python3-gobject-devel
git clone https://github.com/erpalma/throttled.git
sudo ./throttled/install.sh

Void

The installation itself will create a runit service as throttled, enable it and start it. Before installation, make sure dbus is running sv up dbus.

sudo xbps-install -Sy gcc git python3-devel dbus-glib-devel libgirepository-devel cairo-devel python3-wheel pkg-config make

git clone https://github.com/erpalma/throttled.git

sudo ./throttled/install.sh

Uninstall

To permanently stop and disable the execution just issue:

systemctl stop throttled.service
systemctl disable throttled.service

If you're running runit instead of systemd:

sv down throttled
rm /var/service/throttled

If you're using OpenRC instead of systemd:

rc-service throttled stop
rc-update del throttled default

If you also need to remove the tool from the system:

rm -rf /opt/throttled /etc/systemd/system/throttled.service
# to purge also the config file
rm /etc/throttled.conf

On Arch you should probably use pacman -R lenovo-throttling-fix-git instead.

Update

If you update the tool you should manually check your config file for changes or additional features and modify it accordingly. The update process is then as simple as:

cd throttled
git pull
sudo ./install.sh
sudo systemctl restart throttled.service
OpenRC: sudo rc-service throttled restart

Configuration

The configuration has moved to /etc/throttled.conf. Makefile does not overwrite your previous config file, so you need to manually check for differences in config file structure when updating the tool. If you want to overwrite the config with new defaults just issue sudo cp etc/throttled.conf /etc. There exist two profiles AC and BATTERY and the tool can be totally disabled by setting Enabled: False in the GENERAL section. Undervolt is applied if any voltage plane in the config file (section UNDERVOLT) was set. Notice that the offset is in mV and only undervolting (i.e. negative values) is supported. All fields accept floating point values as well as integers.

My T480s with i7-8550u is stable with:

[UNDERVOLT]
# CPU core voltage offset (mV)
CORE: -105
# Integrated GPU voltage offset (mV)
GPU: -85
# CPU cache voltage offset (mV)
CACHE: -105
# System Agent voltage offset (mV)
UNCORE: -85
# Analog I/O voltage offset (mV)
ANALOGIO: 0

IMPORTANT: Please notice that my system is stable with these values. Your notebook might crash even with slight undervolting! You should test your system and slowly incresing undervolt to find the maximum stable value for your CPU. You can check this tutorial if you don't know where to start.

Monitoring

With the flag --monitor the tool constantly monitors the throttling status, indicating the cause among thermal limit, power limit, current limit or cross-origin. The last cause is often related to an external event (e.g. by the GPU). The update rate can be adjusted and defaults to 1 second. Example output:

./throttled.py --monitor
[I] Detected CPU architecture: Intel Kaby Lake (R)
[I] Loading config file.
[I] Starting main loop.
[D] Undervolt offsets: CORE: -105.00 mV | GPU: -85.00 mV | CACHE: -105.00 mV | UNCORE: -85.00 mV | ANALOGIO: 0.00 mV
[D] IccMax: CORE: 64.00 A | GPU: 31.00 A | CACHE: 6.00 A
[D] Realtime monitoring of throttling causes:

[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+). 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:

# /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:

./throttled.py --debug
[D] cpu platform info: maximum non turbo ratio = 20
[D] cpu platform info: maximum efficiency ratio = 4
[D] cpu platform info: minimum operating ratio = 4
[D] cpu platform info: feature ppin cap = 0
[D] cpu platform info: feature programmable turbo ratio = 1
[D] cpu platform info: feature programmable tdp limit = 1
[D] cpu platform info: number of additional tdp profiles = 2
[D] cpu platform info: feature programmable temperature target = 1
[D] cpu platform info: feature low power mode = 1
[D] TEMPERATURE_TARGET - write 0xf - read 0xf
[D] Undervolt plane CORE - write 0xf2800000 - read 0xf2800000
[D] Undervolt plane GPU - write 0xf5200000 - read 0xf5200000
[D] Undervolt plane CACHE - write 0xf2800000 - read 0xf2800000
[D] Undervolt plane UNCORE - write 0xf5200000 - read 0xf5200000
[D] Undervolt plane ANALOGIO - write 0x0 - read 0x0
[D] MSR PACKAGE_POWER_LIMIT - write 0xcc816000dc80e8 - read 0xcc816000dc80e8
[D] MCHBAR PACKAGE_POWER_LIMIT - write 0xcc816000dc80e8 - read 0xcc816000dc80e8
[D] TEMPERATURE_TARGET - write 0xf - read 0xf
[D] core 0 thermal status: thermal throttle status = 0
[D] core 0 thermal status: thermal throttle log = 1
[D] core 0 thermal status: prochot or forcepr event = 0
[D] core 0 thermal status: prochot or forcepr log = 0
[D] core 0 thermal status: crit temp status = 0
[D] core 0 thermal status: crit temp log = 0
[D] core 0 thermal status: thermal threshold1 status = 0
[D] core 0 thermal status: thermal threshold1 log = 1
[D] core 0 thermal status: thermal threshold2 status = 0
[D] core 0 thermal status: thermal threshold2 log = 1
[D] core 0 thermal status: power limit status = 0
[D] core 0 thermal status: power limit log = 1
[D] core 0 thermal status: current limit status = 0
[D] core 0 thermal status: current limit log = 0
[D] core 0 thermal status: cross domain limit status = 0
[D] core 0 thermal status: cross domain limit log = 0
[D] core 0 thermal status: cpu temp = 44
[D] core 0 thermal status: temp resolution = 1
[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 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.

throttled's People

Contributors

ann1kab avatar boytunp avatar cassidyjames avatar cedws avatar ckcr4lyf avatar conjfrnk avatar devil0000 avatar dragetd avatar erpalma avatar felixonmars avatar flejz avatar g3n35i5 avatar hbriese avatar juuuuuu avatar kikislater avatar lakotamm avatar laquay avatar m-kuhn avatar marcwittke avatar mkogan1 avatar moldabekov avatar nariox avatar pdelteil avatar precupstefan avatar r0x57n avatar rborer avatar shbach avatar tejaskale avatar thomwiggers avatar troyhy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

throttled's Issues

Undervolting Linux vs Windows, AC vs Battery

First of all: thanks for the great work and the awesome tool! Filling one of the gaps that the multi million dollar company that claims to be linux friendly should not have left open ;)

First question is regarding undervolting differences between windows and linux: is it normal to find a (big) difference in possible undervolting settings between the two OS's? In windows I can run prime95 a day with -120mV on core and cache. In linux (using this script) -100mV is unstable (many firefox crashes). Theoretically this should not be the case I assume? How is your experience regarding this difference?

Second question is regarding undervolting differences between running plugged-in vs on battery. I found that I can run stable with a certain undervolt setting on AC, but this crashes the desktop (regardless the OS) when running on battery. I assume this has to do with the lowering of the default voltage bsy energy saving processes when on battery. The threshold is now too low and the system becomes unstable. Does this make sense? And in this case: would it be an idea to add different undervolting settings for plugged-in and on battery?

Thanks.

Instruction infelicities

The instructions could use

cd lenovo-throttling-fix

Also, the pip install could perhaps use a -H.

Mention python2 explicit

Hi, i needed some time to figure out why the script was not working for me. Turns out it uses python2, maybe you could mention that somewhere in the readme. Afaik python3 is default on basically all distros nowadays.

the script improves the situation but there is something limiting still L480 with i7-8550U

I have an L480 with a i7-8550U. (latest bios)
The script improves the situation (due to the thermal limits) but there is still something throtteling the CPU without need and limiting the potential. When I start stress with c of 1,2 or 8 I first get a period of high CPU performance (like I would expect it) of about 14 to 28 secodns. Then it gos with the following pattern: it drops very drastically for about 3 seconds followed by a higher (but not as high as at the beginning) utilisation for about 3 seconds. This pattern then repeats as long as cpu stress is there. Even if the temperature is 10°C below the thermal threshold (stress with c of 1 or 2) the performance goes down every 3 seconds for 3 seconds. When it goes down the temperature drops imeadiately to about 55 to 63°C. As I understand it there should be no need to throttle that long, much and offten. I guess there is some other magic register in the CPU involved.
I can see similar patterns on the machines of colleges using the s version.

Beside that lenovo does let the fan only run 2/3 of its max speed (which gets quit loud). Thinkfan solves this for me but the effect on performance is low anyway. Seems like lenovo did not design the laptops properly to get the heat away.

Let me know if I should send you some MSR values.

Script crashes on Ubuntu 18.04

I tried using the lenovo_fix service on T480s running Ubuntu 18.04 (Linux kernel 4.15) but it fails when starting:

user@t480s:~$ systemctl status lenovo_fix.service
● lenovo_fix.service - Fix Lenovo T480/T480s/X1C6 throttling on Linux
   Loaded: loaded (/etc/systemd/system/lenovo_fix.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-05-13 14:35:56 CEST; 7min ago
  Process: 1399 ExecStart=/opt/lenovo_fix/venv/bin/python3 /opt/lenovo_fix/lenovo_fix.py (code=exited, status=1/FAILURE)
 Main PID: 1399 (code=exited, status=1/FAILURE)

May 13 14:35:56 t480s python3[1399]:     main()
May 13 14:35:56 t480s python3[1399]:   File "/opt/lenovo_fix/lenovo_fix.py", line 141, in main
May 13 14:35:56 t480s python3[1399]:     undervolt(config)
May 13 14:35:56 t480s python3[1399]:   File "/opt/lenovo_fix/lenovo_fix.py", line 61, in undervolt
May 13 14:35:56 t480s python3[1399]:     writemsr(0x150, calc_undervolt_msr(plane, config.getfloat('UNDERVOLT', plane)))
May 13 14:35:56 t480s python3[1399]:   File "/opt/lenovo_fix/lenovo_fix.py", line 37, in writemsr
May 13 14:35:56 t480s python3[1399]:     os.write(f, struct.pack('Q', val))
May 13 14:35:56 t480s python3[1399]: PermissionError: [Errno 1] Operation not permitted
May 13 14:35:56 t480s systemd[1]: lenovo_fix.service: Main process exited, code=exited, status=1/FAILURE
May 13 14:35:56 t480s systemd[1]: lenovo_fix.service: Failed with result 'exit-code'.

The full error messages is as follows:

root@t480s:~# source /opt/lenovo_fix/venv/bin/activate
(venv) root@t480s:~# /opt/lenovo_fix/venv/bin/python3 /opt/lenovo_fix/lenovo_fix.py
Traceback (most recent call last):
  File "/opt/lenovo_fix/lenovo_fix.py", line 169, in <module>
    main()
  File "/opt/lenovo_fix/lenovo_fix.py", line 141, in main
    undervolt(config)
  File "/opt/lenovo_fix/lenovo_fix.py", line 61, in undervolt
    writemsr(0x150, calc_undervolt_msr(plane, config.getfloat('UNDERVOLT', plane)))
  File "/opt/lenovo_fix/lenovo_fix.py", line 37, in writemsr
    os.write(f, struct.pack('Q', val))
PermissionError: [Errno 1] Operation not permitted
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/opt/lenovo_fix/venv/lib/python3.6/site-packages/periphery/mmio.py", line 61, in _open
    fd = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
PermissionError: [Errno 1] Operation not permitted: '/dev/mem'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/lenovo_fix/lenovo_fix.py", line 113, in power_thread
    mchbar_mmio = MMIO(0xfed159a0, 8)
  File "/opt/lenovo_fix/venv/lib/python3.6/site-packages/periphery/mmio.py", line 36, in __init__
    self._open(physaddr, size)
  File "/opt/lenovo_fix/venv/lib/python3.6/site-packages/periphery/mmio.py", line 63, in _open
    raise MMIOError(e.errno, "Opening /dev/mem: " + e.strerror)
periphery.mmio.MMIOError: [Errno 1] Opening /dev/mem: Operation not permitted

crash after stop stress immediately

Hi, thanks very much for your code.

i have a question, i setup my t480s, use ~ -90mv undervoltage, and ~92oC temp wall.

it can run stress(in s-tui) very long time, but crash after stress stop immediately, i can watch CPU freq down from 3.xG to 800Mhz in seconds, then system crash..

some suggestion?

question regarding updates

Just a short question regarding script updates to a newer version. Is it sufficient to just do a git pull of the script repo and then probably re-run the script? Or do I have to do something else like maybe first stop the service an/or uninstall a previous version of the script?

[improvement] Install guide for openSUSE

Since there isn't an installation guide for openSUSE systems, I have made a list of the required packages and attached them at the bottom. I don't know if all of the packages are necessary (going off guess and check), but having them all installed worked on my system.
deps.txt

T460P support planned?

I own a T460P with i7-6700HQ 3.5 GHz CPU and a GTX 940MX GPU.
Using this tool to undervolt my cpu and its cache by -150mV lowers the max temp from 90 to 80°C
But the throttling issue still exists.

Even if only one core reaches 100% while the others are doing nothing the throttling will be activated.
But it won't be deactivated after the ThinkPad is getting colder.
Means my OS lags and stutters every 2-3 Seconds (Video/Mouse Movement/Windows/Animations).
But not the sound.

PS:
It is weird that the max clock is 3.2GHz on only one Core instead of 3.5GHz turbo.
The s-tui tool is telling me, that power limit is 28 Watt without throttling and 25, 20 or 15 Watt after throttling.

Thinkpad X1 Carbon 6th Gen - still throttling issue

Hi,
I own a Lenovo Thinkpad X1 witbh Intel i7 8550u. Running Kubuntu with kernel 4.17.2-041702-generic #201806160433.
I installed the fixapparently without issues and tried to play a bit the configuration file. However, no matter what i change I always get message about CPU throttling:

> [ 5285.052945] CPU2: Core temperature above threshold, cpu clock throttled (total events = 8)
> [ 5285.052945] CPU6: Core temperature above threshold, cpu clock throttled (total events = 8)
> [ 5285.052947] CPU3: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052948] CPU5: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052949] CPU4: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052950] CPU7: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052951] CPU0: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052951] CPU1: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052953] CPU6: Package temperature above threshold, cpu clock throttled (total events = 72)
> [ 5285.052959] CPU2: Package temperature above threshold, cpu clock throttled (total events = 72)

Moreover when running command rdmsr -f 29:24 -d 0x1a2 I cannot get better values than 10 when plugged in AC and 20 when using battery.

Do you think there could be something wrong with my setup or anything I can do to improve?
Thanks

Question about PL2_Tdp_W and BATTERY values in general

Hello and good day,

this is not an issue but a question about the BATTERY value of PL2_Tdp_W.

On default it's also set to 44. Shouldn't this also be set to 29 like PL1_Tdp_W?

And another question in general:
When I have an i7-8550U the normal TLP is 15 watts right? So it's still lower than the default battery value of 29 here?
Is it possible to set the BATTERY values of PL1_Tdp_W and PL2_Tdp_W to 15 to even save more juice?

Thank you in advance and all the best

T580 with dGPU (too hot)

Hi there,

firstly let me thank you for your work on this regard!

I've got multiple questions and some problems, you could help me with:

1.) If I disable systemd service, it seems the PL1/2 settings aren't reverted to the original values, correct?
Even after stopping the service and rebooting, turbostat reports them still as what I last have set them with lenovo-fix?

Ok, tested again. I explicitly set PL1_Tdp=17 and after disable systemd service and rebooting, this is what turbostat reports:

cpu0: PKG Limit #1: ENabled (29.000000 Watts, 28.000000 sec, clamp ENabled)                                    
cpu0: PKG Limit #2: ENabled (44.000000 Watts, 0.002441* sec, clamp DISabled)  

Setting anything with lenovo-fix then, shows up with turbostat then. Stopping lenovo-fix again, does not reset the values!

Btw, from the above:
So 29 & 44 are system's defaults and safe to be set in conf as these are system's defaults?

2.) As my Laptop has a dedicated Nvidia GPU, too, there's a heat problem, when using your script with installation standards. The system is running stable and fast, but the dGPU has a fall-off temperature of 76°C. As soon as the GPU reaches this value, it gets throttled to a 3rd of it's frequency (around 400MHz, instead of 1600). Strange thing here is, the GPU only levels its frequency within a range of 100MHz (1600-1700) when running glxspheres64 for instance.
So, what happens is, the GPU (as not able to throttle itself down more in multiple steps) reaches the 76° quite fast, as the machine's cooling system isn't able to vent off the heat resulting from higher performance with lenovo-fix.

I stumble upon this, as phoronix/openarena gets from app. 120FPS to app. 35FPS.

The GPU is clocked with around 400MHz until it gets down below 60° again, which doesn't happenm when CPU is producing heat.

So, the installation standards do not fit this machine when used with dGPU.
I tried undervolting, which makes the system last longer until the GPU's fall-off is reached, but system still gets too hot!

Using this config:

[GENERAL]
Enabled: True

## Settings to apply while connected to AC power
[AC]
# Update the registers every this many seconds
Update_Rate_s: 5
# Max package power for time window #1
PL1_Tdp_W: 15
# Time window #1 duration
PL1_Duration_s: 28
# Max package power for time window #2
PL2_Tdp_W: 44
# Time window #2 duration
PL2_Duration_S: 0.002
# Max allowed temperature before throttling
Trip_Temp_C: 93
# Set HWP energy performance hints to 'performance' on high load (EXPERIMENTAL)
HWP_Mode: False
# Set cTDP to normal=0, down=1 or up=2 (EXPERIMENTAL)
cTDP: 0

[UNDERVOLT]
# CPU core voltage offset (mV)
CORE: -120
# Integrated GPU voltage offset (mV)
GPU: -100
# CPU cache voltage offset (mV)
CACHE: -120
# System Agent voltage offset (mV)
UNCORE: -120
# Analog I/O voltage offset (mV)
ANALOGIO: 0

With glxspehere64 CPU is running around 3800MHz, 15W & 80°, which is nice. But dGPU is constantly heating up, as not clocked further down than 1657MHz and reached it's thermal limit of 76° with hard fall-off.

So, I somehow need a way, to solve this, as once I bring in the dGPU into the mix, I need less power, for to to overpower the cooling system, whereas performance withou dGPU heavy working, is nice'n stable...

2a)
When heating up, the touchpad gets irresponsive until I end glxsphere!? No entries in journal about that!?

3.) Is my following assumption correct?
The I7-8550U is declared with 15W TDP. cTDP_up would be 25W. So if setting PL1_Tdp=25, I need to set cTDP=2?

And, with having a TDP of 15W, setting 44W in conf is quite high above the TDP? Or am I missing something?

Tests with s-tui & mprime -t showed, that even when setting cTDP=1, system is using app. 30W while around 3.300MHz and around 88° with s-tui stress test. So that's double the TDP and 3 times cTDP (10W when down).

4.) I need a little help regarding PL1/2. If I set 29/44W PL1/2, using stress from s-tui, I get 3700MHz for about haf a minute, then Power drops to around 3400MHz and 28W Power. Expected, as PL1 is 29W. The stress is running continously with this power and frequency then. No further throttling to 15W is experienced?!
System is undervolted:

[UNDERVOLT]
# CPU core voltage offset (mV)
CORE: -120
# Integrated GPU voltage offset (mV)
GPU: -100
# CPU cache voltage offset (mV)
CACHE: -120
# System Agent voltage offset (mV)
UNCORE: -120
# Analog I/O voltage offset (mV)
ANALOGIO: 0

My system is: T580, I7-8550U, dGPU, 16GB Ram, Bionic 18.04, nvidia-396

Just a question

Sorry to use issues for this - i cant find how to message on github
I'm new to linux in genereal and I'd like to know what this fix actually performs.

I tried to make sense of the code and installer ... Does this fix keep an instance of python running continually to set the values every couple of seconds? or does it kill it and restarts it ? or is it a cron job or something else?
sorry if this is innapropriate...
thank in advance

Installation failed: No package 'dbus-1' found

First of all, thank you for this fix :-)

Unfortunately the installation according to readme failed on my system:
`
configure: error: Package requirements (dbus-1 >= 1.6) were not met:

No package 'dbus-1' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables DBUS_CFLAGS
and DBUS_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-install-va9i90_i/dbus-python/setup.py", line 106, in <module>
    'build_ext': BuildExt,
  File "/opt/lenovo_fix/venv/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/opt/lenovo_fix/venv/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
    return orig.install.run(self)
  File "/usr/lib/python3.6/distutils/command/install.py", line 589, in run
    self.run_command('build')
  File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/tmp/pip-install-va9i90_i/dbus-python/setup.py", line 62, in run
    cwd=builddir)
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/tmp/pip-install-va9i90_i/dbus-python/configure', '--disable-maintainer-mode', 'PYTHON=/opt/lenovo_fix/venv/bin/python3', '--prefix=/tmp/pip-install-va9i90_i/dbus-python/build/temp.linux-x86_64-3.6/prefix']' returned non-zero exit status 1.
`

---------------------------------------- Command "/opt/lenovo_fix/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-va9i90_i/dbus-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-jp1pmzfa/install-record.txt --single-version-externally-managed --compile --install-headers /opt/lenovo_fix/venv/include/site/python3.6/dbus-python" failed with error code 1 in /tmp/pip-install-va9i90_i/dbus-python/
Can you help me?

Note about C-states on XPS 9370.

This isn't a bug with the repo, but might be useful information to have for anyone passing by.
On my XPS 9370, I've been seeing a lot of kernel messages complaining about thermal throttling (package/core above temperature), despite it being only 40-50 degrees. One of the widgets in my window manager was reporting the CPU temperature as 90 degrees even though it wasn't.
For some reason, disabling C-states in the UEFI fixes this. I'm inclined to say it's a firmware bug.

PermissionError when trying to write to voltage MSRs

This great little program doesn't work in its current version on Ubuntu 18.04 and T480. It seems the script is unable to write voltage configuration.

I'm not interested in undervolt so I commented out the call to undervolt, so the rest of the script works fine.

Relevant log below, kernel is 4.15.0-23-generic.

ul 19 18:32:05 steve-ThinkPad-T480 kernel: [ 2115.556629] msr: Direct access to MSR 150
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: Traceback (most recent call last):
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/lenovo_fix.py", line 226, in <module>
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     main()
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/lenovo_fix.py", line 186, in main
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: Exception in thread Thread-1:
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: Traceback (most recent call last):
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/mmio.py", line 58, in _open
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     fd = os.open("/dev/mem", os.O_RDWR | os.O_SYNC)
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: PermissionError: [Errno 1] Operation not permitted: '/dev/mem'
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: During handling of the above exception, another exception occurred:
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: Traceback (most recent call last):
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     self.run()
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/usr/lib/python3.6/threading.py", line 864, in run
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     self._target(*self._args, **self._kwargs)
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/lenovo_fix.py", line 143, in power_thread
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     mchbar_mmio = MMIO(0xfed159a0, 8)
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/mmio.py", line 33, in __init__
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     self._open(physaddr, size)
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/mmio.py", line 60, in _open
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     raise MMIOError(e.errno, "Opening /dev/mem: " + e.strerror)
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: mmio.MMIOError: [Errno 1] Opening /dev/mem: Operation not permitted
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     undervolt(config)
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/lenovo_fix.py", line 67, in undervolt
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     writemsr(0x150, calc_undervolt_msr(plane, config.getfloat('UNDERVOLT', plane)))
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:   File "/opt/lenovo_fix/lenovo_fix.py", line 43, in writemsr
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]:     os.write(f, struct.pack('Q', val))
Jul 19 18:32:05 steve-ThinkPad-T480 python3[23214]: PermissionError: [Errno 1] Operation not permitted
Jul 19 18:32:05 steve-ThinkPad-T480 systemd[1]: lenovo_fix.service: Main process exited, code=exited, status=1/FAILURE
Jul 19 18:32:05 steve-ThinkPad-T480 systemd[1]: lenovo_fix.service: Failed with result 'exit-code'.

Is there a chance that this practically voids waranty?

I.e. is there a chance that the writes to MSR are detected by the BIOS/Firmware and
"noted down" leading to lenovos customer service rejecting repairs...?

If you buy a T480s through lenovo campus you get 36M VOS and adding
accident protection isn't expensive either. It would be sad to lose this
by "fixing" something which could be said to be a firmware bug...

Max boost and fall back on T480 with i7-8650U

Hi there,

thx so much for the fix it helped me to avoid to run into a total throttling where the CPU get stuck with 0.2 Ghz until a reboot.

Two particular issues I saw now with the default config of the lenovo-throttling-fix.

  1. The boost seems so be set on default to 4.0 Ghz which I can monitor, but the specs mention a max tubo of 4.2 Ghz.
  2. when enabled the fix the CPU seems slightly slow on longer workload even though the boost is there. I have the feeling that the base frequencies are maybe different to the default settings of Lenevo.

Any comments on that or how I can measure or monitor my observation to have some objective evidence?

Regards
Valentin

Additional installation requirement--Fedora 28

Attempted install on a brand new Fedora 28 system (Thinkpad T480s) after installing all listed dependencies. Installation failed sighting "No module named 'cairo'. Adding the python3-cairo-devel package resolved this issue.

Use on Qubes

Hello,

anyone has successfully used this fix on Qubes?

Thanks

Lenovo T470: seems to work?

I've got a T470 with an i7-7600U CPU. Right after bootup, it goes frequently into throttling so I decided to give this fix a try.

What I observed using s-tui is that it can stay way longer in Turbo Boost with the fix applied. The temperature raises to 96C and Power to about 23W (it stays at 19W without the fix).

I'm currently experimenting whether the EC resets the values periodically as well...

Problem re-appeared after second boot

There were several throttling warnings during boot before I installed the script and gone once after the installation. However, those warnings re-appeared after I boot my laptop again, any idea what might be the problem?

My laptop is T480 with i7-8650u
System: Arch Linux
Systemd version: 238

Thanks!

X1C6 hangs with lenovo-throttling-fix

I'm using Linux Mint 19 on one of my laptop (X1C6) and after going through all steps and uninstalling thermald, laptop hangs spontaneous during first 2-3 mins after starting, deinstalling throttling fix helps to fix it.

Is it a known issue with Mint?

file path problems

Working on Asus UX430UN(R).

Os info: 4.18.5-arch1-1-ARCH #1 SMP PREEMPT Fri Aug 24 12:48:58 UTC 2018 x86_64 GNU/Linux

  1. SYSFS_POWER_PATH should be parametric and should be read from the config file. In my laptop this path is /sys/class/power_supply/AC0/online.
  2. virtualenv command in install.sh script is not necessary. I don't have it installed on my laptop and calling pip directly with python such as python3 -m pip install -r requirements.txt
  3. /opt/lenovo_fix/venv/bin/python3 is a bit odd in service file. Can be replaced with /usr/bin/python3 without hesitation.

Pip failed during installation process

install.sh script doesn't install dependencies via pip (log) on Fedora 28. I've installed all dependencies using dnf command and added —system-site-packages to virtualenv command in order to complete installation.

We should try to reduce dependencies

The script has quite some dependencies beside python3. I am quite sure we could get rid of some by getting the information a bit differently.

Installation fails on Ubuntu 18.04 amd64

It looks like the install script needs the i386 version of the dependencies. I was able to install most of them by appending :i386 to the apt-get command from the readme. But Ubuntu won't install libgirepository1.0-dev:i386 at the moment.

sudo apt install libgirepository1.0-dev:i386
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.       
Statusinformationen werden eingelesen.... Fertig
Einige Pakete konnten nicht installiert werden. Das kann bedeuten, dass
Sie eine unmögliche Situation angefordert haben oder, wenn Sie die
Unstable-Distribution verwenden, dass einige erforderliche Pakete noch
nicht erstellt wurden oder Incoming noch nicht verlassen haben.
Die folgenden Informationen helfen Ihnen vielleicht, die Situation zu lösen:

Die folgenden Pakete haben unerfüllte Abhängigkeiten:
 libgirepository1.0-dev:i386 : Hängt ab von: gobject-introspection:i386 (= 1.56.1-1) soll aber nicht installiert werden
E: Probleme können nicht korrigiert werden, Sie haben zurückgehaltene defekte Pakete.

This is the output of the install script:

Copying config file...
Config file already exists, skipping.
Copying systemd service file...
Building virtualenv...
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /opt/lenovo_fix/venv/bin/python3
Not overwriting existing python script /opt/lenovo_fix/venv/bin/python (you must use /opt/lenovo_fix/venv/bin/python3)
Installing setuptools, pkg_resources, pip, wheel...done.
Requirement already satisfied: configparser==3.5.0 in ./venv/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (3.5.0)
Requirement already satisfied: dbus-python==1.2.8 in ./venv/lib/python3.6/site-packages (from -r requirements.txt (line 2)) (1.2.8)
Requirement already satisfied: psutil==5.4.7 in ./venv/lib/python3.6/site-packages (from -r requirements.txt (line 3)) (5.4.7)
Collecting PyGObject==3.30.0 (from -r requirements.txt (line 4))
  Using cached https://files.pythonhosted.org/packages/40/12/071e113583e826c9c06b06779730f2b5c3aae1d1a2cf715f25daa8f62ec6/PyGObject-3.30.0.tar.gz
Requirement already satisfied: pycairo>=1.11.1 in ./venv/lib/python3.6/site-packages (from PyGObject==3.30.0->-r requirements.txt (line 4)) (1.17.1)
Building wheels for collected packages: PyGObject
  Running setup.py bdist_wheel for PyGObject ... error
  Complete output from command /opt/lenovo_fix/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-hfnpk6p1/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-aca1qxbq --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/__init__.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/generictreemodel.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/pygtkcompat.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  creating build/lib.linux-x86_64-3.6/gi
  copying gi/_propertyhelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/__init__.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/types.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_signalhelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/importer.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_constants.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_gtktemplate.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_option.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_compat.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_ossighelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/pygtkcompat.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_error.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/docstring.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/module.py -> build/lib.linux-x86_64-3.6/gi
  creating build/lib.linux-x86_64-3.6/gi/repository
  copying gi/repository/__init__.py -> build/lib.linux-x86_64-3.6/gi/repository
  creating build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/__init__.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gdk.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GObject.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/keysyms.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gtk.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GIMarshallingTests.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GLib.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Pango.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GdkPixbuf.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gio.py -> build/lib.linux-x86_64-3.6/gi/overrides
  running build_ext
  Package gobject-introspection-1.0 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'gobject-introspection-1.0', required by 'world', not found
  Command '('pkg-config', '--print-errors', '--exists', 'gobject-introspection-1.0 >= 1.46.0')' returned non-zero exit status 1.
  
  Try installing it with: 'sudo apt install libgirepository1.0-dev'
  
  ----------------------------------------
  Failed building wheel for PyGObject
  Running setup.py clean for PyGObject
Failed to build PyGObject
Installing collected packages: PyGObject
  Running setup.py install for PyGObject ... error
    Complete output from command /opt/lenovo_fix/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-hfnpk6p1/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-p64nygsx/install-record.txt --single-version-externally-managed --compile --install-headers /opt/lenovo_fix/venv/include/site/python3.6/PyGObject:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/pygtkcompat
    copying pygtkcompat/__init__.py -> build/lib.linux-x86_64-3.6/pygtkcompat
    copying pygtkcompat/generictreemodel.py -> build/lib.linux-x86_64-3.6/pygtkcompat
    copying pygtkcompat/pygtkcompat.py -> build/lib.linux-x86_64-3.6/pygtkcompat
    creating build/lib.linux-x86_64-3.6/gi
    copying gi/_propertyhelper.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/__init__.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/types.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_signalhelper.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/importer.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_constants.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_gtktemplate.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_option.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_compat.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_ossighelper.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/pygtkcompat.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_error.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/docstring.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/module.py -> build/lib.linux-x86_64-3.6/gi
    creating build/lib.linux-x86_64-3.6/gi/repository
    copying gi/repository/__init__.py -> build/lib.linux-x86_64-3.6/gi/repository
    creating build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/__init__.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Gdk.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GObject.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/keysyms.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Gtk.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GIMarshallingTests.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GLib.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Pango.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GdkPixbuf.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Gio.py -> build/lib.linux-x86_64-3.6/gi/overrides
    running build_ext
    Package gobject-introspection-1.0 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
    to the PKG_CONFIG_PATH environment variable
    Package 'gobject-introspection-1.0', required by 'world', not found
    Command '('pkg-config', '--print-errors', '--exists', 'gobject-introspection-1.0 >= 1.46.0')' returned non-zero exit status 1.
    
    Try installing it with: 'sudo apt install libgirepository1.0-dev'
    
    ----------------------------------------
Command "/opt/lenovo_fix/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-hfnpk6p1/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-p64nygsx/install-record.txt --single-version-externally-managed --compile --install-headers /opt/lenovo_fix/venv/include/site/python3.6/PyGObject" failed with error code 1 in /tmp/pip-install-hfnpk6p1/PyGObject/

PyGIDeprecationWarning

Not sure if this is known or useful to you guys, but --debug now and then spits out the following:

/usr/lib/lenovo-throttling-fix/lenovo_fix.py:420: PyGIDeprecationWarning: Since version 3.11, calling threads_init is no longer needed. See: https://wiki.gnome.org/PyGObject/Threading
  GObject.threads_init()
/usr/lib/lenovo-throttling-fix/lenovo_fix.py:421: PyGIDeprecationWarning: GObject.MainLoop is deprecated; use GLib.MainLoop instead
  loop = GObject.MainLoop()

Some systeminfo:

λ python --version
Python 3.7.0
λ yay -Q |grep Pyg
pygmentize 2.2.0-2
pygobject-devel 3.28.3-2
python-pygments 2.2.0-2

Seems harmless, still I wanted to report this.

Why isn't it event driven?

Instead of writing to the registers every X seconds, I believe it should be enough to just write to them at specific events, ie. after boot and after waking from sleep. Am I missing something?

Is 44W necessary?

Where does the 44W default come from? If I read your posts correctly you said you have a 8550U, but according to the 8550U Intel website its maximum TDP-up is 25W. Or am I misreading it?

Hardened kernel

Hey guys, nice tool you've got here, works on my X1C5. I was just playing with it and discovered that this does not work with linux-hardened kernel (I am on ArchLinux). Running it with --debug will log an error related to /dev/mem. Perhaps it would be great to update README...

Add an 'in between' throttle setting.

97'C thermal limit may get uncomfortable on the lap.

Something like 29w / 90'C might be a good compromise,

Or maybe even read in arbitrary values from a variable set in script for the brave. ex. if someone wants a 4.5w cTDP

Expand support / documentation for other laptops

Thanks for your work on this. I just wanted to let you know that it also works on laptops from other manufacturers, e.g. Dell XPS 9370 with the same cpu. Perhaps the documentation could be updated to include this? I am also interested to know if the undervolting would work (I felt it best not to try it)?

On my XPS it now manages to sustain between 2.8 and 3.0 Ghz with temp between 97-99C depending on ambient. It no longer scales back to 2.2-2.4 Ghz with temps of 80C.

However I did note that the service fails if a temp of more than 97C is specified. In my case, although pushing the limits, it seems to be OK with the value manually set at 98 using wrmsr and it eeks out a further 50-100Mhz.

Fix issues on Ubuntu and make script portable across different shells

So, I tried running this script on my Kubuntu 17.10 install (ThinkPad T480) and was met with failure when the script failed to source the python venv. Here is the output:

$ sudo ./install.sh
Copying config file...
Copying systemd service file...
Building virtualenv...
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /opt/lenovo_fix/venv/bin/python3
Also creating executable in /opt/lenovo_fix/venv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
./install.sh: 26: ./install.sh: source: not found

The reason for this is pretty trivial, though it took me some time to figure it out: On Ubuntu-based systems /bin/sh is a symlink to /bin/dash, which doesn't understand the source command. source is a bashism, so there is no guarantee that other shells such as sh or dash support it.

Solution:

  • Either change the shebang from #!/bin/sh to #!/bin/bash to explicitly call bash instead of a similar shell (dash, ksh, zsh, whatever)
  • Or (the more elegant solution imo) make the source command POSIX-portable by using the standard . command instead of source. This should allow the script to work on almost any other shell. For your reference

Oh, and thanks for the script - now that everything is set up things are working wonderfully :)

Arch Install - Incorrect vitrualenv location in readme.md & virtualenv not including dbus (module import error)

The scripts is now running with Python3 by default (tested w/ 3.6) and a virtualenv is automatically created in /opt/lenovo_fix. Python2 should probably still work.

Installed using:

yaourt -S lenovo-throttling-fix-git

virtualenv location was /usr/bin/env, not in /opt/


Also had module import error (ModuleNotFoundError: No module named 'dbus') for dbus, python-dbus was installed.

Changed the script to use my python install instead of the virtualenv and had no issues.

From:
#!/usr/bin/env python
To:
#!/usr/bin/python3

Trying to access non-existent cores

When trying to run this fix on an X1 Carbon 6th gen I get the following error:

Traceback (most recent call last):
File "/usr/lib/lenovo-throttling-fix/lenovo_fix.py", line 245, in
main()
File "/usr/lib/lenovo-throttling-fix/lenovo_fix.py", line 205, in main
undervolt(config)
File "/usr/lib/lenovo-throttling-fix/lenovo_fix.py", line 78, in undervolt
writemsr(0x150, calc_undervolt_msr(plane, config.getfloat('UNDERVOLT', plane)))
File "/usr/lib/lenovo-throttling-fix/lenovo_fix.py", line 60, in writemsr
raise e
File "/usr/lib/lenovo-throttling-fix/lenovo_fix.py", line 51, in writemsr
f = os.open(c, os.O_WRONLY)
OSError: [Errno 6] No such device or address: '/dev/cpu/15/msr'

The skript was installed from the AUR and I am running it on an X1 Carbon i7-8550U, Manjaro Kernel 4.17.9-1-MANJARO

It seems like the skript tries to access the msr register for cpu core number 15, which should not exist on a 8 core machine.
If I can help in any way, please let me know!

Does this also work for the T580?

I got a T580 and I tried this script but it doesn't seem to fix the symptoms that I currently see. Is this supposed to work with T580?

should we rename the tool

The tool is more targeting general cpu settings and is not related to lenovo in any other way beside their BIOS defaults are bad.
I think we should think about a new name for it which reflects this better.

KDE Neon broken completely after trying this fix

System was stable and I ran some benchmark, then I rebooted, still stable, Suddenly GPU started to show artifacts in very specific scenarios (some shaders in opengl) and then system became unstable, lagging for seconds every 30 seconds or so. I tried editing the config but filesystem became readonly, I forced a reboot and the system is now unbootable completely, shows only initramfs sheel at boot. Well I guess I should have made a backup :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.