Search This Blog

A script to disable and enable intel cpu turbo boost on Linux

I have a Thinkpad T410 laptop with i5 cpu. The computer turns off when compiling GWT code because of cpu overheating. The cpu temperature increases to 100 degrees in about 3 minutes even if I set the fan speed to maximum 5000rpm.

So I looked for resolution and found disabling turbo boost can help.
  1. First, you need to install msr-tools:
    sudo apt-get install msr-tools
  2. To disable turbo boost on all your cpu cores:
    sudo wrmsr -pi 0x1a0 0x4000850089
    where i is the cpu core number, e.g. 0, 1, 2, 3..., you can get those number by running
    cat /proc/cpuinfo | grep processor
    .
    Note: you need to run the wrmsr command for each cpu core.
  3. To re-enable turbo boost on all your cpu cores:
    sudo wrmsr -pi 0x1a0 0x850089
    where i is the cpu core number, e.g. 0, 1, 2, 3..., you can get those number by running
    cat /proc/cpuinfo | grep processor
    .
    Note: you need to run the wrmsr command for each cpu core.
After disabling turbo boost, I am able to complete my GWT compilation altough the temperature still goes as high as 90 degrees.

A script to disable/enable turbo boost

The following script can be used to turn off/on turbo boost:
#!/bin/bash

if [[ -z $(which rdmsr) ]]; then
    echo "msr-tools is not installed. Run 'sudo apt-get install msr-tools' to install it." >&2
    exit 1
fi

if [[ ! -z $1 && $1 != "enable" && $1 != "disable" ]]; then
    echo "Invalid argument: $1" >&2
    echo ""
    echo "Usage: $(basename $0) [disable|enable]"
    exit 1
fi

cores=$(cat /proc/cpuinfo | grep processor | awk '{print $3}')
for core in $cores; do
    if [[ $1 == "disable" ]]; then
        sudo wrmsr -p${core} 0x1a0 0x4000850089
    fi
    if [[ $1 == "enable" ]]; then
        sudo wrmsr -p${core} 0x1a0 0x850089
    fi
    state=$(sudo rdmsr -p${core} 0x1a0 -f 38:38)
    if [[ $state -eq 1 ]]; then
        echo "core ${core}: disabled"
    else
        echo "core ${core}: enabled"
    fi
done

Usage:
You can copy the above script and save it into a file named turbo-boost then set it to be executable:
sudo chmod +x turbo-boost
you can then use it to disable/enable turbo boost:
  • turbo-boost disable
  • turbo-boost enable


See also

2 comments:

  1. Brilliant. This script works perfectly on my laptop's poor, overheating Sandy Bridge i7-2760QM quad core CPU that was routinely hitting 92°C while doing WCG/BOINC cancer gene marker research 24/7/365 (cores 0-4 ranging between 87°-92°C). Now at a much more reasonable 76°C - 85°C. Ubuntu Linux 18.04. CPU is on rails at its rated 2.4 GHz base clock speed, which is what I want. It kept trying to go higher w/Turbo mode. I was desperate, and this is the only solution on the entire web I could find that was clear, direct, simple and 100% effective. Just brilliant. Many thanks!

    ReplyDelete
  2. Thanks for this. I noticed that running the disable option turns the turbo boost off, but also sets the governor to powersave mode. I would like to simply turn off the the turbo boost, keeping my cpu governor set to performance. Any suggestions?

    ReplyDelete