Skip to content

Instantly share code, notes, and snippets.

@sylvainfaivre
Last active September 26, 2024 10:31
Show Gist options
  • Save sylvainfaivre/512fe8c171582caca3cabaed023188b4 to your computer and use it in GitHub Desktop.
Save sylvainfaivre/512fe8c171582caca3cabaed023188b4 to your computer and use it in GitHub Desktop.
CPU throttling and "lap mode" on Lenovo Thinkpad laptops

CPU throttling and "lap mode" on Lenovo Thinkpad laptops

Test setup

Hardware : Lenovo Thinkpad P14s, Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz

Software : Ubuntu 21.10, Gnome 40.4.0, Linux 5.13.0

Background

Lenovo has a "Lenovo Intelligent Thermal Solution" which is hardwired to some movement sensors that detect when the laptop has been moved. It then switches to "lap mode" so it throttles the CPU in order to lower the hardware temperature and allow safe use on your lap.

For months, this created problems on Linux where this feature was not supported, so the laptop was always stuck on lap mode, and performance was always throttled.

This has been fixed since mid-2020, details about this can be found in this document : https://web.archive.org/web/20190926163900if_/https://forums.lenovo.com/lnv/attachments/lnv/Special_Interest_Linux/13642/1/Linux%20Thermal%20throttling.pdf

Current situation

When moving the laptop, "lap mode" is triggered, so the "performance" power mode in disabled, and it is automatically set to "balanced power". After approximately 5 minutes, "lap mode" turns off, and you can turn the power mode back to "performance", but it is a manual action.

Detecting the problem

First, install the power-profiles-daemon package.

Here is the powerprofilesctl command output when set to performance mode :

$ powerprofilesctl
* performance:
    Driver:     platform_profile
    Inhibited:  no

  balanced:
    Driver:     platform_profile

  power-saver:
    Driver:     platform_profile

Here is the powerprofilesctl command output when "lap mode" is detected :

$ powerprofilesctl
  performance:
    Driver:     platform_profile
    Inhibited:  yes (lap-detected)

* balanced:
    Driver:     platform_profile

  power-saver:
    Driver:     platform_profile

Gnome setting's "power" page gives similar information.

How to get sensor info

/sys/devices/platform/thinkpad_acpi/dytc_lapmode is set to is 1 when lap mode is detected. It goes back to 0 after around 5 minutes without movement.

Workarounds

DKMS patch the kernel to disable lap mode

See https://github.com/JosiahBull/thinkpad_acpi

This is the best solution if it works with your setup. Tested by its developer on Fedora 34/35/36 and Ubuntu 20.04/22.04. Also tested by me on Ubuntu 21.10.

Use Gnome 41 or a more recent version

Upgrading Gnome (if you can) is the best solution. When Gnome 41/42 detects lap mode, it switches to a "degraded performance mode", which does not really seem to throttle the CPU. It doesn't switch to "balanced power" mode, so you don't need to restore performance mode after lap mode detection turns off.

Here is the powerprofilesctl command output when in "degraded performance mode" :

$ powerprofilesctl 
* performance:
    Driver:     platform_profile
    Degraded:   yes (lap-detected)

  balanced:
    Driver:     platform_profile

  power-saver:
    Driver:     platform_profile

Crontab to change power profile

You can run this script in a crontab every minute, to automatically turn power mode to "performance" as soon as possible :

p=$(powerprofilesctl) ; if echo "$p" | grep -qF "* balanced" && ! echo "$p" | grep -qF "Inhibited: yes" ; then powerprofilesctl set performance ; fi

WARNING : be sure to test your script, as any error will be repeated every minute !

Keyboard shortcut to switch to performance mode

When performance mode is inhibited, you can use the Fn + h shortcut to turn performance mode on. Of course it won't apply immediately, but it will apply as soon as lap mode is over. This is better than nothing...

Monkey patching the kernel to disable lap mode

See the "other solutions" paragraph in https://github.com/JosiahBull/thinkpad_acpi

In theory, this could be done, altough the proposed script is not functional (see JosiahBull/thinkpad_acpi#4)

Disable throttling (not recommended)

You can disable CPU thermal throttling altogether, but this is a "nuclear option", as described in https://wiki.archlinux.org/title/Lenovo_ThinkPad_X1_Extreme#Disabling_BDPROCHOT_to_prevent_throttling_on_battery

How to check CPU speed and temperature

Many tools are available for this. One of the easiest is to install the i7z package, then run sudo i7z in a terminal. It will display the actual frequency, temperature and voltage for each CPU core.

Then generate some load, for example using stress-ng :

stress-ng --cpu 8 --timeout 60s

WARNING : This will get your CPU very hot (more than 80 °C) !

WARNING : This will also hog for CPU for one minute, so make sure you have nothing important running at the same time !

You can watch i7z while stress-ng is running :

  • If your CPU is throttled, each core will run below 1 GHz to keep the temperature down.
  • If it is not throttled, each core will run between 3 and 5 GHz.

Other models, other Linux distributions and windows managers

If you have relevant info about other setups, please leave a comment and I will update this gist.

@CRAG666
Copy link

CRAG666 commented Jul 12, 2022

You know if this happens in P53, I want to assume that this related thing that in occasions while I hear music or I watch videos the audio just gets stuck for a few seconds?

@sylvainfaivre
Copy link
Author

You know if this happens in P53, I want to assume that this related thing that in occasions while I hear music or I watch videos the audio just gets stuck for a few seconds?

I don't know, but here's all the info you need in this gist to check it yourself. You should start by watching the powerprofilesctl command output when you experience this problem, and see if it contains lap-mode info.

@virgilhem
Copy link

Hello, maybe this could be of interest to you:
https://github.com/virgilhem/linux-patches/blob/main/thinkpad-acpi-disable-lapmode.patch
Or try : echo '_SB.PCI0.LPCB.EC.HKEY.DYTC 0x000F1001' > /proc/acpi/call
(Tested on a T490 20N2)

@sylvainfaivre
Copy link
Author

Hello, maybe this could be of interest to you: https://github.com/virgilhem/linux-patches/blob/main/thinkpad-acpi-disable-lapmode.patch Or try : echo '_SB.PCI0.LPCB.EC.HKEY.DYTC 0x000F1001' > /proc/acpi/call (Tested on a T490 20N2)

Thanks, in fact this doesn't annoy me too much now since with up to date Ubuntu, it automatically goes back to "performance mode" when going out of lap mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment