Changing CPU Scaling Governor on Linux

Through “Scaling Governor”, you can choose the optimal CPU frequency control scheme, which affects power consumption and performance.

On highly loaded access servers, acquaintances had cases of server hangup during “ondemand”, although I did not have such cases, but still I recommend changing it to “performance”.
On laptops and lightly loaded servers, you can leave “ondemand” to save energy.

On HPE servers in the BIOS, you must enable Collaborative Power Control (CPC); otherwise, processor performance cannot be controlled from the operating system and there won’t be these files:

find / -name scaling_governor
find / -name scaling_max_freq

Let’s see the current value of all processor cores:

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
ls /sys/devices/system/cpu/

In my case, the default value for all eight cores is “ondemand”.

Let’s look at possible schemes:

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

Switch to root user:

sudo -i

And we indicate for all kernels “performance”:

echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor
echo performance > /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor

Either way:

apt install cpufrequtils
for i in 0 1 2 3 4 5 6 7 8 9 10 11; do cpufreq-set -c $i -g performance; done


cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
egrep '(MHz)' /proc/cpuinfo

If the previous methods did not help, then for the Intel CPU, you can also specify “intel_idle.max_cstate” in the grub:

nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="intel_idle.max_cstate=1 ..."
dmesg -T | grep intel_idle

Or you can completely disable the energy-saving features of the CPU and PCIe:

intel_idle.max_cstate=0 processor.max_cstate=1 pcie_aspm=off quiet mitigations=off

As a last resort with idle=poll:

intel_idle.max_cstate=0 processor.max_cstate=1 pcie_aspm=off quiet mitigations=off idle=poll

I note that if you specify idle=poll, then in the BIOS or iLo for example, it may appear that the CPU is used at 100%, although this is not so.

We will also disable the already unnecessary energy saving service:

systemctl is-enabled ondemand
systemctl disable ondemand

See also my article:
Changing the processor core frequency in Linux
PCI Express ASPM

Join the Conversation

1 Comment

Leave a Reply

  1. Trying to scrape up a few more FPS in gaming I went ahead and tried this, expected a small to moderate boost.

    I don’t seem to hit higher FPS numbers at the top end, but at the low end? Under powersave I’d sometimes crater from as much as 60 or so in Mass Effect Legendary Edition(more if I’m uncapped) down to single digits, I’ve seen it hit 1 and slow down further.

    Now? Mass Effect Legendary Edition does not drop below 56FPS. Ever. No matter what is or is not happening. Set the cap to 60 and I basically never notice FPS stutters unless I’m looking at the FPS counter in the corner.

    This is *huge*. I expected it to help, especially on the low end, but I did not expect “basically new hardware” levels of improvement.