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




No comments:

Post a Comment