Ubuntu – CPU governor changes automatically to “performance” under load

cpugovernorperformancexubuntu

I have a Lenovo T570 with Xubuntu 18.04 LTS. My current issue is that my cpu speed stepping is kind of going nuts and does what ever it thinks its best.

Sample: when I run my IDE and cpu load increases during build time, the governor changes automatically. I caught the moment during compiling my project with the following call:

martin@martin-ThinkPad-T570:~$ while cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor; do sleep 1; done
powersave
powersave
performance
performance

cpufreq-info tells me this:

martin@martin-ThinkPad-T570:~$ 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: intel_pstate
  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 - 3.50 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 3.50 GHz and 3.50 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 3.25 GHz.
analyzing CPU 1:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 1
  CPUs which need to have their frequency coordinated by software: 1
  maximum transition latency: 4294.55 ms.
  hardware limits: 400 MHz - 3.50 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 3.50 GHz and 3.50 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 3.36 GHz.
analyzing CPU 2:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 2
  CPUs which need to have their frequency coordinated by software: 2
  maximum transition latency: 4294.55 ms.
  hardware limits: 400 MHz - 3.50 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 3.50 GHz and 3.50 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 3.26 GHz.
analyzing CPU 3:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 3
  CPUs which need to have their frequency coordinated by software: 3
  maximum transition latency: 4294.55 ms.
  hardware limits: 400 MHz - 3.50 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 3.50 GHz and 3.50 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 3.36 GHz.

Please take a look at

current policy: frequency should be within 3.50 GHz and 3.50 GHz.
The governor "performance" may decide which speed to use

Afterwards to go back to powersave I use my little script:

martin@martin-ThinkPad-T570:~$ cat cpu_freq_save.sh 
#!/bin/bash
sudo cpufreq-set -g powersave -c 0 --min 400MHz
sudo cpufreq-set -g powersave -c 1 --min 400MHz
sudo cpufreq-set -g powersave -c 2 --min 400MHz
sudo cpufreq-set -g powersave -c 3 --min 400MHz

Which resets the min frequency and the governor but as soon as I compile again with my IDE every time the governor and the min frequency changes again.

Any idea how I can disable that automatic change?

PS: If you need more details, just tell me where to find them and I will provide them

Best Answer

cpufreqd is a frequency management daemon installed with:

sudo apt install cpufreqd

A configuration file cpufreqd.conf is used to change frequencies. There are two sections where you can see it changing governor to "performance":

[Profile]
name=hi_boost
minfreq=0%
maxfreq=100%
policy=performance

# full power when AC
[Rule]
name=AC_on
ac=on                   # (on/off)
profile=hi_boost

It's harder to figure out when it changes to "powersave" unless the battery charger is unplugged.

Since kernel 3.4 cpufreq is built into the kernel and loaded automatically. It includes frequency management daemon called thermald. As such there isn't much a need for cpufreqd anymore and it may have conflicted on your system.

For even greater customization under battery power the tlp package is commonly used these days.

Related Question