How to set as default Performance mode on Ubuntu 20.04 instead of Powersave?
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.
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.