Setting CPU to performance mode

Started by finotti, 2025/03/21, 13:36:52

Previous topic - Next topic

finotti

I am trying to set up all my CPU cores to performance mode at boot.

I've installed cpufrequtils and have set up /etc/init.d/cpufrequtils as (note GOVERNOR)


#!/bin/sh
### BEGIN INIT INFO
# Provides:       cpufrequtils
# Required-Start: $remote_fs loadcpufreq
# Required-Stop:
# Default-Start:  2 3 4 5
# Default-Stop:
# Short-Description: set CPUFreq kernel parameters
# Description: utilities to deal with CPUFreq Linux
#       kernel support
### END INIT INFO
#

DESC="CPUFreq Utilities"

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
CPUFREQ_SET=/usr/bin/cpufreq-set
CPUFREQ_INFO=/usr/bin/cpufreq-info
CPUFREQ_OPTIONS=""

# use lsb-base
. /lib/lsb/init-functions

# Which governor to use. Must be one of the governors listed in:
#   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
#
# and which limits to set. Both MIN_SPEED and MAX_SPEED must be values
# listed in:
#   cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
# a value of 0 for any of the two variables will disabling the use of
# that limit variable.
#
# WARNING: the correct kernel module must already be loaded or compiled in.
#
# Set ENABLE to "true" to let the script run at boot time.
#
# eg:   ENABLE="true"
#       GOVERNOR="ondemand"
#       MAX_SPEED=1000
#       MIN_SPEED=500

ENABLE="true"
#GOVERNOR="ondemand"
GOVERNOR="performance"
MAX_SPEED="0"
MIN_SPEED="0"

check_governor_avail() {
        info="/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
        if [ -f $info ] && grep -q "\<$GOVERNOR\>" $info ; then
                return 0;
        fi
        return 1;
}

[ -x $CPUFREQ_SET ] || exit 0

if [ -f /etc/default/cpufrequtils ] ; then
        . /etc/default/cpufrequtils
fi

# if not enabled then exit gracefully
[ "$ENABLE" = "true" ] || exit 0

if [ -n "$MAX_SPEED" ] && [ $MAX_SPEED != "0" ] ; then
        CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --max $MAX_SPEED"
fi

if [ -n "$MIN_SPEED" ] && [ $MIN_SPEED != "0" ] ; then
        CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --min $MIN_SPEED"
fi

if [ -n "$GOVERNOR" ] ; then
        CPUFREQ_OPTIONS="$CPUFREQ_OPTIONS --governor $GOVERNOR"
fi

CPUS=$(cat /proc/stat|sed -ne 's/^cpu\([[:digit:]]\+\).*/\1/p')
RETVAL=0
case "$1" in
        start|force-reload|restart|reload)
                log_action_begin_msg "$DESC: Setting $GOVERNOR CPUFreq governor"
                if check_governor_avail ; then
                        for cpu in $CPUS ; do
                                log_action_cont_msg "CPU${cpu}"
                                $CPUFREQ_SET --cpu $cpu $CPUFREQ_OPTIONS 2>&1 > /dev/null || \
                                        RETVAL=$?
                        done
                        log_action_end_msg $RETVAL ""
                else
                        log_action_cont_msg "disabled, governor not available"
                        log_action_end_msg $RETVAL
                fi
                ;;
        stop)
                ;;
        *)
                echo "Usage: $0 {start|stop|restart|reload|force-reload}"
                exit 1
esac

exit 0


It seems that the governor was changed at boot:


# service cpufrequtils status
● cpufrequtils.service - LSB: set CPUFreq kernel parameters
     Loaded: loaded (/etc/init.d/cpufrequtils; generated)
     Active: active (exited) since Fri 2025-03-21 08:18:51 EDT; 13min ago
Invocation: a2f6ec03da2e4525949e64454acabed8
       Docs: man:systemd-sysv-generator(8)
    Process: 1098 ExecStart=/etc/init.d/cpufrequtils start (code=exited, status=0/SUCCESS)
   Mem peak: 2.1M
        CPU: 8ms

Mar 21 08:18:51 debian systemd[1]: Starting cpufrequtils.service - LSB: set CPUFreq kernel parameters...
Mar 21 08:18:51 debian cpufrequtils[1098]: CPUFreq Utilities: Setting performance CPUFreq governor...CPU0...CPU1...CPU2...CPU3...CP>
Mar 21 08:18:51 debian systemd[1]: Started cpufrequtils.service - LSB: set CPUFreq kernel parameters.


But as soon as I log in, even in a virtual terminal, it is changed to "powersave".


# cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave


I also tried a script to manually change the governor on boot, which ran successfully, but it was also reverted to powersave every time.  (But if I run it after login, it seems to stick.)

Does anyone have any idea what is changing the governor to powersave?

Some info about the system:


$ inxi -v3
System:
  Host: debian Kernel: 6.13.7-1-siduction-amd64 arch: x86_64 bits: 64
    compiler: gcc v: 14.2.0
  Desktop: KDE Plasma v: 6.3.2 Distro: siduction 2024.1.0 shine-on - kde -
    (202412261719) base: Debian GNU/Linux trixie/sid
Machine:
  Type: Desktop System: ASUS product: N/A v: N/A serial: <superuser required>
  Mobo: ASUSTeK model: TUF GAMING B850-PLUS WIFI v: Rev 1.xx
    serial: <superuser required> UEFI: American Megatrends v: 0237
    date: 09/20/2024
Battery:
  Device-1: hidpp_battery_0 model: Logitech Wireless Mouse B330/M330/M331
    charge: 55% (should be ignored) status: discharging
CPU:
  Info: 8-core model: AMD Ryzen 7 9700X bits: 64 type: MT MCP arch: N/A rev: 0
    cache: L1: 640 KiB L2: 8 MiB L3: 32 MiB
  Speed (MHz): avg: 2991 min/max: 600/5581 boost: enabled cores: 1: 2991
    2: 2991 3: 2991 4: 2991 5: 2991 6: 2991 7: 2991 8: 2991 9: 2991 10: 2991
    11: 2991 12: 2991 13: 2991 14: 2991 15: 2991 16: 2991 bogomips: 121364
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm
Graphics:
  Device-1: Advanced Micro Devices [AMD/ATI] Navi 23 [Radeon RX 6600/6600
    XT/6600M] vendor: ASRock driver: amdgpu v: kernel arch: RDNA-2
    bus-ID: 03:00.0
  Device-2: Advanced Micro Devices [AMD/ATI] Granite Ridge [Radeon Graphics]
    vendor: ASUSTeK driver: amdgpu v: kernel bus-ID: 0e:00.0 temp: 26.0 C
  Display: x11 server: X.Org v: 21.1.16 with: Xwayland v: 24.1.6 driver: X:
    loaded: amdgpu unloaded: fbdev,modesetting,radeon,vesa dri: radeonsi
    gpu: amdgpu resolution: 1920x1080~60Hz
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: amd mesa v: 25.0.2-1 glx-v: 1.4
    direct-render: yes renderer: AMD Radeon RX 6600 (radeonsi navi23 LLVM
    19.1.7 DRM 3.61 6.13.7-1-siduction-amd64)
  Info: Tools: api: clinfo, eglinfo, glxinfo, vulkaninfo
    de: kscreen-console,kscreen-doctor gpu: amdgpu_top wl: wayland-info
    x11: xdriinfo, xdpyinfo, xprop, xrandr
Network:
  Device-1: Realtek RTL8125 2.5GbE vendor: ASUSTeK driver: r8169 v: kernel
    port: e000 bus-ID: 0a:00.0
  IF: eno1 state: down mac: 60:cf:84:cc:9d:90
  Device-2: MEDIATEK vendor: AzureWave driver: mt7925e v: kernel port: N/A
    bus-ID: 0b:00.0
  IF: wlan0 state: up mac: c0:bf:be:70:10:58
  IF-ID-1: tailscale0 state: unknown speed: -1 duplex: full mac: N/A
Drives:
  Local Storage: total: 3.64 TiB used: 45.6 GiB (1.2%)
Info:
  Memory: total: 60 GiB note: est. available: 60.48 GiB used: 5.15 GiB (8.5%)
  Processes: 493 Uptime: 17m Init: systemd
  Packages: 4264 Compilers: gcc: 14.2.0 Shell: Bash v: 5.2.37 inxi: 3.3.37

whistler_mb

Regardless of the name, the governor powersave lets the CPU decide on the frequency.

Maybe it's just a naming problem

cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: amd-pstate-epp
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 4294.55 ms.
  hardware limits: 400 MHz - 4.45 GHz
  available cpufreq governors: powersave
  current policy: frequency should be within 2.38 GHz and 4.45 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 2.38 GHz.

finotti

Thanks for the reply!

I don't think that "performance" and "powersave" are the same: https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt

It's recommended to set the governor to "performance" for recording music, as any small interruption can cause artifacts with the recording in real time.  (See, for instance, https://wiki.linuxaudio.org/wiki/system_configuration#cpu_frequency_scaling.)