6

I've been trying unsuccessfully to have the CPU governor default to Performance instead of Powersave at startup. Is there a tried-and-true method that currently works for Ubuntu 20.04? I tried the accepted solution for 18.04, but unfortunately, when I rebooted and looked at indicator-cpufreq, Powersave remained selected.

facialrecognition
  • 435
  • 2
  • 6
  • 12
  • 1
    Yes, disable the service that changes the governor during the boot process. Do: sudo systemctl disable ondemand and re-boot. For tons of detail see here.. – Doug Smythies Mar 10 '21 at 14:06
  • Unfortunately, it didn’t work for me. When I rebooted, and looked at indicator-cpufreq, Powersave remained selected. – facialrecognition Mar 10 '21 at 15:31
  • I observe that the default Ubuntu kernel configurations for this have changed. It will take me several hours (because I am busy with something else) to figure out an answer. – Doug Smythies Mar 10 '21 at 16:20
  • 1
    Thank you for your time!! Truly appreciate it :) – facialrecognition Mar 10 '21 at 16:23
  • meanwhile try this in /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT="cpufreq.default_governor=performance, still with that ondemand service disabled. make sure your system can handle it without overheating, as your throttling methods might not have started yet. – Doug Smythies Mar 10 '21 at 16:28
  • I get the following error when updating grub:

    Sourcing file /etc/default/grub' /usr/sbin/grub-mkconfig: 10: /etc/default /grub: cpufreq.default_governor=performance: not found

    – facialrecognition Mar 10 '21 at 17:19
  • so sorry, typo. needs closing ". – Doug Smythies Mar 10 '21 at 19:57
  • This older answer I wrote might help: https://askubuntu.com/a/1021174/307523 – WinEunuuchs2Unix Mar 11 '21 at 01:49
  • No such file (/etc/init.d/cpufrequtils) exists in Ubuntu 20.04 :( – facialrecognition Mar 11 '21 at 02:19
  • Note that some recent CPUs handle power management themselves, and the performance setting has no effect. – Simon Richter Mar 11 '21 at 09:56
  • @SimonRichter not in this case, nor any processor I am familiar with. the OP has HWP (HardWare Pstate) control, but one can still set the governor. – Doug Smythies Mar 11 '21 at 15:10
  • 1
    @DougSmythies, I just tested on an E5-2630v4, which uses the intel_pstate driver, compiling the same program twice, once with "powersave" and once with "performance" governor active on all CPUs, and got no difference in CPU time spent. I, too, can set a governor, but it doesn't do anything. – Simon Richter Mar 11 '21 at 15:58
  • @SimonRichter: the default EPP (Energy Performance Preference) for the performance governor is 0 and for the powersave governor is 128. This effect is on the rise time rate for the CPU frequency. You should also observe slightly higher idle power consumption, albeit small. – Doug Smythies Mar 11 '21 at 18:32
  • Yes, thank you very much, now it works!! – facialrecognition Mar 13 '21 at 18:28

5 Answers5

4

On Ubuntu21.10: powerprofilesctl set performance

You can add it as a startup script.

More info here: Power-profiles-daemon Download for Linux (deb, eopkg, rpm, xbps, xz, zst)

[EDIT - got a message to add additional references - see additional link with more information]

power-profiles-daemon

Not sure if you want me to copy and paste the README.md file on the power-profiles-daemon page.

ATutorMe
  • 141
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Error404 Nov 19 '21 at 02:31
  • This does not change the cpu governor from powersave to performance. It only changes the performance hint for the processor. – Ferdi May 28 '23 at 20:00
  • Thanks @Ferdi. Any further reading or reference for that? I'm keen to find out more. – ATutorMe May 29 '23 at 04:33
  • Well, actually the power-profiles-daemon depends on the powersave governor to function on systems with intel processors. The reason is the documentation of the daemon. In short, the different performance profiles (Performance/Balanced/Powersave) are not supported by the Performance governor. The profiles set the "/sys/devices/system/cpu/cpuX/cpufreq/energy_performance_preference" and "/sys/devices/system/cpu/cpuX/power/energy_perf_bias" with predetermined values – Ferdi May 29 '23 at 19:59
3

If your processor is defaulting to using the powersave CPU frequency scaling governor, then it is probably using the intel_pstate CPU frequency scaling driver. Check via:

$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_driver
/sys/devices/system/cpu/cpufreq/policy0/scaling_driver:intel_pstate
...
/sys/devices/system/cpu/cpufreq/policy5/scaling_driver:intel_pstate

Ubuntu has changed the default kernel configuration as for the default governor. It used to be performance and now it is schedutil, which will fall through to powersave if schedutil is not available. Therefore, some of the older answers no longer apply.

Method 1 The ondemand service just calls /lib/systemd/set-cpufreq, which could be edited to set the governor to performance instead of what it currently does. This old answer indicates a method, repeated and modified herein:

doug@s18:~/config/lib/systemd$ diff -u set-cpufreq.original set-cpufreq
--- set-cpufreq.original        2021-03-10 14:07:32.036863542 -0800
+++ set-cpufreq 2021-03-10 14:10:05.313627963 -0800
@@ -10,6 +10,10 @@

read governors < $AVAILABLE case $governors in

  •    *performance*)
    
  •            GOVERNOR=&quot;performance&quot;
    
  •            break
    
  •            ;;
       *interactive*)
               GOVERNOR=&quot;interactive&quot;
               break
    

After the edit and after re-booting, check it:

$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_governor
/sys/devices/system/cpu/cpufreq/policy0/scaling_governor:performance
...
/sys/devices/system/cpu/cpufreq/policy5/scaling_governor:performance

And check the status of the service, which should be dead by now:

$ sudo systemctl status ondemand
[sudo] password for doug:
● ondemand.service - Set the CPU Frequency Scaling governor
     Loaded: loaded (/lib/systemd/system/ondemand.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Wed 2021-03-10 14:13:02 PST; 1min 18s ago
    Process: 667 ExecStart=/lib/systemd/set-cpufreq (code=exited, status=0/SUCCESS)
   Main PID: 667 (code=exited, status=0/SUCCESS)

Mar 10 14:12:57 s18 systemd[1]: Started Set the CPU Frequency Scaling governor. Mar 10 14:13:02 s18 set-cpufreq[667]: Setting performance scheduler for all CPUs Mar 10 14:13:02 s18 systemd[1]: ondemand.service: Succeeded.

If something later on during boot is overriding the governor setting it would be by far best to figure out what and get rid of it. However, and just as a temporary workaround try introducing a sleep delay into this service (note the older ondemand startup script used to delay 1 minute, then change the governor). Untested example:

doug@s18:~/config/lib/systemd$ diff -u set-cpufreq.original set-cpufreq.doug.test
--- set-cpufreq.original        2021-03-10 14:07:32.036863542 -0800
+++ set-cpufreq.doug.test       2021-03-10 16:24:13.088946203 -0800
@@ -10,6 +10,10 @@

read governors < $AVAILABLE case $governors in

  •    *performance*)
    
  •            GOVERNOR=&quot;performance&quot;
    
  •            break
    
  •            ;;
       *interactive*)
               GOVERNOR=&quot;interactive&quot;
               break
    

@@ -34,6 +38,8 @@

[ -n "${GOVERNOR:-}" ] || exit 0

+sleep 60

echo "Setting $GOVERNOR scheduler for all CPUs"

for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Method 2 Now, if you prefer to run with that service disabled:

$ sudo systemctl disable ondemand
Removed /etc/systemd/system/multi-user.target.wants/ondemand.service.

then the preference can be set on the grub command line, by adding cpufreq.default_governor=performance to what is already present. Keep a copy of /etc/default/grub before you start and in case you want to revert later. This example includes other stuff already in my command line. So, in my case, I changed this:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 consoleblank=450 msr.allow_writes=on cpuidle.governor=teo intel_idle.states_off=4"

to this:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 consoleblank=450 cpufreq.default_governor=performance msr.allow_writes=on cpuidle.governor=teo intel_idle.states_off=4"

Run sudo update-grub afterwards and re-boot. Then check:

doug@s18:~$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_governor
/sys/devices/system/cpu/cpufreq/policy0/scaling_governor:performance
...
/sys/devices/system/cpu/cpufreq/policy5/scaling_governor:performance

Caution: Be sure your computer can run in performance mode without creating to much heat, because whatever thermal throttling methods are used might not be operating yet during the boot process.

Doug Smythies
  • 15,448
  • 5
  • 44
  • 61
  • Unfortunately, even after running sudo systemctl disable ondemand and adding the performance string to grub, it keeps defaulting back to powersave after restart. john@john:~$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_governor /sys/devices/system/cpu/cpufreq/policy0/scaling_governor:powersave /sys/devices/system/cpu/cpufreq/policy1/scaling_governor:powersave /sys/devices/system/cpu/cpufreq/policy2/scaling_governor:powersave /sys/devices/system/cpu/cpufreq/policy3/scaling_governor:powersave – facialrecognition Mar 10 '21 at 20:39
  • are you running any daemon that might be overriding things? Like tlp or one of those cpufreq things? (I never ever use any of that stuff, so don't know much about it.) – Doug Smythies Mar 10 '21 at 20:55
  • Nope, not running any cpufreq utilities, besides indicator-cpufreq, which I uninstalled for the sake of controlling for it. The grep command keeps returning powersave, not performance. So frustrating, why!? Not sure why, but using indicator-cpufreq, when I switch to performance, the grep command spits out performance, which is a step forward. How to make that default remains a mystery. – facialrecognition Mar 10 '21 at 21:21
  • well, let's go back to basics. this comment thing will ask us to move to a chat eventually, which I am willing to to, if you are. Step 1 confirm intel_pstate CPU frequency scaling driver: grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_driver. and what CPU? do: grep "model name" /proc/cpuinfo – Doug Smythies Mar 10 '21 at 21:46
  • /sys/devices/system/cpu/cpufreq/policy0/scaling_driver:intel_pstate model name : Intel(R) Core(TM) i3-7130U CPU @ 2.70GHz – facialrecognition Mar 10 '21 at 23:12
  • Forgot to ask which kernel version. uname -a. I still think something else must be changing it again. I'll edit my answer, yet again, with another suggestion for the ondemand service Method 1 suggestion. When I get time... – Doug Smythies Mar 11 '21 at 00:14
  • 5.8.0-44-generic – facialrecognition Mar 11 '21 at 01:47
  • did you try Method 1 part 2 - introduce a sleep delay? – Doug Smythies Mar 11 '21 at 15:52
  • Hi! I'm a bit confused on how to do that. What do I add exactly and in what file? Thank you :) – facialrecognition Mar 12 '21 at 09:09
  • the file is /lib/systemd/set-cpufreq and the difference file, as in my local configuration directory is in my answer. You would edit as per the lines starting with "+" signs, but not including the actual "+" sign. By the way, the comments from @SimonRichter are somewhat valid in that typical users can not tell the system response difference between the two governors. – Doug Smythies Mar 12 '21 at 13:53
0

On my Ubuntu 20.04 I have done the following to have full flexibility in which frequency scaling governor to use. The default CPU frequency scaling driver is intel pstate driver, but this only allows ondemand and performance governors (at least on my older intel CPU). If you disable intel pstate driver then the default CPU frequency scaling driver will change to acpi driver which support the following governors: cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors conservative ondemand userspace powersave performance schedutil

To disable the intel pstate driver add "intel_pstate=disable" to the line:

GRUB_CMDLINE_LINUX_DEFAULT= in /etc/default/grub and run "sudo update-grub" to let it take effect on next reboot.

Reboot the machine.

With that done, disable the existing service "ondemand.service" by issuing command: sudo systemctl disable ondemand.service sudo systemctl stop ondemand.service

Now, create a new service file /etc/systemd/system/mygovernor.service owned by root, with the following contents:

[Unit]
Description=Set CPU Frequency Scaling governor
ConditionVirtualization=no
ConditionPathExists=/sys/devices/system/cpu/online

[Service] Type=idle EnvironmentFile=/etc/default/mygovernor ExecCondition=/bin/bash -xc '/bin/systemctl is-enabled --quiet ondemand.service && exit 1 || exit 0' ExecStart=/etc/systemd/set-mygovernor ${GOVERNOR}

[Install] WantedBy=multi-user.target


Also create a file /etc/systemd/set-mygovernor with the folowing contents:


#! /bin/bash
# This script is called by script /etc/systemd/system/mygovernor.service
# It will set the CPU Frequency Scaling governor to the value passed in
# the first command line argument "$1"

set -eu

FIRSTCPU=$(cut -f1 -d- /sys/devices/system/cpu/online) AVAILABLE=$(/bin/cat /sys/devices/system/cpu/cpu${FIRSTCPU}/cpufreq /scaling_available_governors)

Check if the specified commandline governor ID is supported on this PC

GOVERNOR=""

for gov in ${AVAILABLE}; do if [[ "${gov}" == "${1}" ]]; then GOVERNOR="${gov}" break fi done

if [ -z ${GOVERNOR} ]; then echo "Unknown governor =" &quot;${1}&quot; exit 1 fi

echo "Setting CPUFreq Scaling governor = &quot;$GOVERNOR&quot; for all CPUs"

for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor do [ -f "${CPUFREQ}" ] || continue echo -n "${GOVERNOR}" > ${CPUFREQ} done


Make sure it is owned by root and is executable: sudo chown root:root /etc/systemd/set-mygovernor sudo chmod +x /etc/systemd/set-mygovernor

Create a file /etc/default/mygovernor with the following contents:

# Environment file for systemd service /etc/systemd/system/mygovernor.service
# which set the cpufreq governor to be used by the system.  A list of supported
# governors may be found by the following command:
# "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
# conservative ondemand userspace powersave performance schedutil

GOVERNOR=schedutil


Now you have to tell systemd that you have added a new service:

sudo systemctl daemon-reload

and enable and start the new service:

sudo systemctl enable mygovernor.service
sudo systemctl start mygovernor.service

To see the result, issue the following command:

cpupower frequency-info

You can easily change the governor :

  1. edit /etc/default/mygovernor to choose one of the supported governors
  2. sudo systemctl restart mygovernor.service
0

check if cpupower is installed then:

# cat<<EOF > /etc/systemd/system/cpupower.service 
[Unit]
Description=CPU powersave
[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower -c all frequency-set --governor powersave  -d 400MHz -u 1000MHz
[Install]
WantedBy=multi-user.target

systemctl daemon-reload

systemcl enable cpupower

it sets :

  • "powersave" governer
  • lower frequency to 400MHz
  • upper frequency to 1000MHz
Alex
  • 139
0

Many answers on this issue require installing new applications like cpufreq, cpupower or powerprofilesctl. New applications are NOT necessary.

As this GitHub post states:

For some reason in Ubuntu 20.04 a default CPU governor (even on stationary PCs) is powersave.

You can enable performance CPU governor with the following command:

$ sudo systemctl disable ondemand.service
$ echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Reboot your computer, and performance governer should be the default one.

To test if the default governor has changed to the desired performance enter the following and observe if the governor is set correctly

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