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 su

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 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

Leave a comment

Leave a Reply