0

I would like to throttle my CPU, I have an i5-8265U and it has frequencies up to 3.9GHz, but I rarely need the speed.

Now if something causes a high load, the CPU goes up and the fan gets noisy.

It is already set to powersave

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
powersave

And userspace is not available, when I try

sudo cpufreq-set -f 2.0

How do I throttle such a CPU to max 2GHz?

rubo77
  • 28,966

1 Answers1

1

If you don't have such a setting in your BIOS, the solution is solved quite well here for Linux: http://notepad2.blogspot.com/2014/11/a-script-to-turn-off-intel-cpu-turbo.html

I created an enhanced version of that script to toggle the turbo boost here on GitHub:
https://github.com/rubo77/intel-turbo-boost


Old version:

just create a /usr/local/sbin/turbo-boost.sh script:

#!/bin/bash

is_root () {
    return $(id -u)
}

has_sudo() {
    local prompt

    prompt=$(sudo -nv 2>&1)
    if [ $? -eq 0 ]; then
        # has_sudo__pass_set
        return 0
    elif echo $prompt | grep -q '^sudo:'; then
        # has_sudo__needs_pass"
        return 0
    else
        echo "no_sudo"
        return 1
    fi
}

if ! is_root && ! has_sudo; then
    echo "Error: need to call this script with sudo or as root!"         
    exit 1
fi

modprobe msr
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" != "toggle" && "$1" != "enable" && "$1" != "disable" ]]; then
    echo "Invalid argument: $A" >&2
    echo ""
    echo "Usage: $(basename $0) [disable|enable|toggle]"
    exit 1
fi

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

give it

chmod +x /usr/local/sbin/turbo-boost.sh

Now you can call

sudo turbo-boost.sh disable
sudo turbo-boost.sh enable
sudo turbo-boost.sh toggle

automatically disable turbo-boost on startup

If you want to autostart this one minute after boot, you can allow the execution without password in /etc/sudoers with:

# Allow command for my user without password         
my_username_here ALL = NOPASSWD: /usr/local/sbin/turbo-boost.sh

Then create a systemd startup script with a delay of 60 seconds:

Create the script /etc/systemd/system/turbo-boost-disable.service:

[Unit]
Description=disables turbo-boost

[Service]
TimeoutStartSec=infinity
ExecStartPre=/bin/sleep 60
ExecStart=/usr/local/sbin/turbo-boost.sh disable

[Install]
WantedBy=default.target

Update systemd with:

sudo systemctl daemon-reload
sudo systemctl enable turbo-boost-disable

Add toggle button on desktop

If you more often want to control the turbo-boost manually, you can add a Button to your desktop:

  1. sudo gedit /usr/share/applications/toggle-turbo-boost.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Name=toggle turbo-boost
Icon=/usr/share/icons/Humanity/apps/64/gkdebconf-icon.svg
Exec=sudo /usr/local/sbin/turbo-boost.sh toggle
X-MultipleArgs=false
Categories=GNOME;GTK;
StartupNotify=true
GenericName=Toggle Turbo-Boost
Path=/tmp/
  1. press SUPER and search for "Toggle Turbo Boost", you will see the icon.
  2. press ENTER to execute, or right click to "Add to Favorites" which will add a button in the quick-start bar.
rubo77
  • 28,966
  • I don't know...I control this through BIOS. Your link is to a distro package. BIOS can prohibit changing this, for a reason. You should at least make that more clear. Otherwise: important Q! –  Oct 17 '19 at 12:22