Read more

Installing throttled to fix Lenovo laptops with nvidia graphics running Ubuntu losing performance after a while

Florian Heinle
May 19, 2021Software engineer at makandra GmbH

We have observed Lenovo laptops with nvidia graphics losing performance after they have been in use for a few minutes. While we have not been able to pinpoint exactly what triggered the performance loss, we have found it mostly correlated with high load or during video calls (i.e. GPU usage), possibly related to temperature sensors picking up rising temps.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

What happens is that the CPU clock falls to e.g. 400 MHz and will stay there, rendering the system unusable. This problem can be mitigated by using throttled Show archive.org snapshot on affected systems.

Tested systems

We have so far found this fix necessary and tested it on

  • Lenovo P14s Gen 1
  • Lenovo T14 Gen 1

Observing the situation

To get a good overview about load, cpu frequency, temperature sensors, etc. we found s-tui Show archive.org snapshot quite useful. It's included in Ubuntu's default repositories:

$ sudo apt install s-tui
$ s-tui

While it's possible to run s-tui as root for even more information and optionally also make use of stress for benchmarking, those methods did not provide any additional useful information for the current problem.

throttled fix

Disable Secure Boot

For this fix to work it's necessary to disable secure boot on the affected laptop. This cannot be avoided by providing a machine owner key (MOK) since it's not about signed kernel images or modules but rather about the tool accessing functionality which is locked down by the Kernel Lockdown that is enabled when Secure Boot is active.

To disable Secure Boot on Lenovo Laptops, access the Setup Utility.

  • Press F1 when the Lenovo Logo appears after turning on the laptop
  • Click Security, click Secure Boot on the right
  • Switch Secure Boot to Disabled.

Install throttled

Boot back into the regular Ubuntu system and install throttled:

$ 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

as per the documentation Show archive.org snapshot , you should also disable thermald:

$ sudo systemctl stop thermald.service
$ sudo systemctl disable thermald.service
$ sudo systemctl mask thermald.service

Verify setup

After installing throttled, reboot your systemd and make sure the lenovo_fix service is running:

$ sudo systemctl status throttled
● lenovo_fix.service - Stop Intel throttling
     Loaded: loaded (/etc/systemd/system/lenovo_fix.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-05-18 13:13:15 CEST; 1 day 1h ago
   Main PID: 1454 (python3)
      Tasks: 2 (limit: 37987)
     Memory: 16.6M
     CGroup: /system.slice/lenovo_fix.service
             └─1454 /opt/lenovo_fix/venv/bin/python3 /opt/lenovo_fix/lenovo_fix.py
Mai 18 13:13:15 ThinkPad-P14s-Gen-1 systemd[1]: Started Stop Intel throttling.
Mai 18 13:13:15 ThinkPad-P14s-Gen-1 python3[1454]: [I] Detected CPU architecture: Intel Comet Lake-U
Mai 18 13:13:15 ThinkPad-P14s-Gen-1 python3[1454]: [I] Trying to unlock MSR allow_writes.
Mai 18 13:13:15 ThinkPad-P14s-Gen-1 python3[1454]: [I] Loading config file.
Mai 18 13:13:15 ThinkPad-P14s-Gen-1 python3[1454]: [I] Starting main loop.
Florian Heinle
May 19, 2021Software engineer at makandra GmbH
Posted by Florian Heinle to makandra Operations (2021-05-19 14:13)