2

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.

14
  • 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.. Mar 10, 2021 at 14:06
  • Unfortunately, it didn’t work for me. When I rebooted, and looked at indicator-cpufreq, Powersave remained selected. Mar 10, 2021 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. Mar 10, 2021 at 16:20
  • 1
    Thank you for your time!! Truly appreciate it :) Mar 10, 2021 at 16:23
  • 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. Mar 11, 2021 at 15:58

3 Answers 3

2

On Ubuntu21.10: powerprofilesctl set performance

You can add it as a startup script.

More info here: power-profiles-daemon_0.8.1-1_amd64.deb

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

1
  • 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. Nov 19, 2021 at 2:31
1

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="performance"
+                break
+                ;;
         *interactive*)
                 GOVERNOR="interactive"
                 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="performance"
+                break
+                ;;
         *interactive*)
                 GOVERNOR="interactive"
                 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.

10
  • 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 Mar 10, 2021 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.) Mar 10, 2021 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. Mar 10, 2021 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 Mar 10, 2021 at 21:46
  • /sys/devices/system/cpu/cpufreq/policy0/scaling_driver:intel_pstate model name : Intel(R) Core(TM) i3-7130U CPU @ 2.70GHz Mar 10, 2021 at 23:12
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 =" \"${1}\"
       exit 1
fi

echo "Setting CPUFreq Scaling governor = \"$GOVERNOR\" 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.