How to set as default Performance mode on Ubuntu 20.04 instead of Powersave?

7,477

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

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

Share:
7,477

Related videos on Youtube

facialrecognition
Author by

facialrecognition

Updated on September 18, 2022

Comments

  • facialrecognition
    facialrecognition over 1 year

    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.

    • Doug Smythies
      Doug Smythies about 3 years
      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..
    • facialrecognition
      facialrecognition about 3 years
      Unfortunately, it didn’t work for me. When I rebooted, and looked at indicator-cpufreq, Powersave remained selected.
    • Doug Smythies
      Doug Smythies about 3 years
      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.
    • facialrecognition
      facialrecognition about 3 years
      Thank you for your time!! Truly appreciate it :)
    • Doug Smythies
      Doug Smythies about 3 years
      meanwhile try this in /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT="cpufreq.default_governor=perform‌​ance, still with that ondemand service disabled. make sure your system can handle it without overheating, as your throttling methods might not have started yet.
    • facialrecognition
      facialrecognition about 3 years
      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
    • Doug Smythies
      Doug Smythies about 3 years
      so sorry, typo. needs closing ".
    • WinEunuuchs2Unix
      WinEunuuchs2Unix about 3 years
      This older answer I wrote might help: askubuntu.com/a/1021174/307523
    • facialrecognition
      facialrecognition about 3 years
      No such file (/etc/init.d/cpufrequtils) exists in Ubuntu 20.04 :(
    • Simon Richter
      Simon Richter about 3 years
      Note that some recent CPUs handle power management themselves, and the performance setting has no effect.
    • Doug Smythies
      Doug Smythies about 3 years
      @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.
    • Simon Richter
      Simon Richter about 3 years
      @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.
    • Doug Smythies
      Doug Smythies about 3 years
      @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.
    • facialrecognition
      facialrecognition about 3 years
      Yes, thank you very much, now it works!!
  • facialrecognition
    facialrecognition about 3 years
    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:pow‌​ersave /sys/devices/system/cpu/cpufreq/policy1/scaling_governor:pow‌​ersave /sys/devices/system/cpu/cpufreq/policy2/scaling_governor:pow‌​ersave /sys/devices/system/cpu/cpufreq/policy3/scaling_governor:pow‌​ersave
  • Doug Smythies
    Doug Smythies about 3 years
    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.)
  • facialrecognition
    facialrecognition about 3 years
    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.
  • Doug Smythies
    Doug Smythies about 3 years
    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
  • facialrecognition
    facialrecognition about 3 years
    /sys/devices/system/cpu/cpufreq/policy0/scaling_driver:intel‌​_pstate model name : Intel(R) Core(TM) i3-7130U CPU @ 2.70GHz
  • Doug Smythies
    Doug Smythies about 3 years
    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...
  • facialrecognition
    facialrecognition about 3 years
    5.8.0-44-generic
  • Doug Smythies
    Doug Smythies about 3 years
    did you try Method 1 part 2 - introduce a sleep delay?
  • facialrecognition
    facialrecognition about 3 years
    Hi! I'm a bit confused on how to do that. What do I add exactly and in what file? Thank you :)
  • Doug Smythies
    Doug Smythies about 3 years
    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.
  • Error404
    Error404 over 2 years
    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.