I'm trying to set the CPU governor to performance in 18.04, the problem is that it never survives reboots.
I've tried following these steps in an answer to this question How to set "Performance" instead of "Powersave" as default? but when I reboot the computer the CPU governor switches back to powersaver.
I've also tried creating a file called /etc/rc.local
with the line:
cpupower frequency-set --governor performance
That also doesn't survive reboots.
How can I do this?
Short Answer
In
/etc/rc.local
put in these commands:1 minute after boot automatic switch to Powersave
For whatever reasons my Skylake Intel CPU always starts up in Performance mode and then switches to Powersave mode at the 1 minute mark automatically.
If you set the mode to Performance on startup it will be overridden around the 1 minute Up Time mark to Powersave mode.
In the GIF below, the 3000+ MHz CPU speed at start up appears near the top. The up time appears near the bottom. When up time hits about 1 minute you see CPU MHz drop off. :
Program to monitor exact second Powersave invoked
Create this script in
/usr/local/bin/watch-gov.sh
:Call the script in
/etc/rc.local
before theexit 0
command (explained in detail below).One minute after logging in look at the output:
Confirmation from this answer states this 1 minute force to
powersave
governor is controlled by/etc/init.d/ondemand
.Sleep 120 seconds before setting Performance Mode
The simplest way to stay in Performance mode is to edit
/etc/rc.local
and insert these lines before the last line containingexit 0
:Save the file and reboot.
If you insert the new lines after
exit 0
it will never be executed.To setup
/etc/rc.local
in 18.04 see: How to Enable/etc/rc.local
with SystemdCaveats
Your machine will probably run 10 to 15 degrees C hotter.
You may need to remove other programs that change CPU frequency if they override your Performance settings in
/etc/rc.local
Default Ubuntu kernel configurations are such that the performance CPU frequency scaling governor will be used during boot. The relevant section of the kernel configuration file (
/boot/config-4.15.0-36-generic
, in this example) is:But also by default during boot up the
ondemand
service is executed. It sleeps for 1 minutes and then changes the scaling governor to eitherinteractive
,ondemand
orpowersave
, depending on availability. In turn availability depends on which CPU frequency scaling driver you are using. The code is (in multiple locations, search forondemand
):Why is it called "ondemand", but it sets other governors (for example with the intel_pstate driver it will set the powersave governor)? Because this tool pre-dates the intel_pstate driver, back to a time when, by far, the dominant frequency scaling driver was the acpi-cpufreq driver, and "ondemand" was the preferred Ubuntu default governor.
So, one way to boot and stay using the performance CPU frequency scaling governor is to disable the service that changes away from it (which was also mentioned in another answer):
Before:
Disable the service:
re-boot, then check again (being sure to wait a minute after the re-boot):
Note: the examples in this answer are from a computer that uses the acpi-cpufreq CPU frequency scaling driver. If you are using the intel_pstate driver, with no ondemand governor, the powersave governor will be used by default.
Anticipated question: Why do my CPU frequencies scale, even when using the performance governor?
Answer: Modern processors scale the CPU frequency, even in performance mode and as a function of the depth of the idle state they go into. If you really want to lock the CPU frequency then disable all idle states deeper than 0. However, note that it will cost a huge huge amount of power.
Personally, and as mentioned in another answer, I use the performance governor or the powersave governor as a function of whatever work I am doing. My scripts are a little different:
and:
example usage (on a computer using the intel_pstate driver):
What I did was use the file /etc/rc.local
To help you find your paths, use:
This works for my setup, but you just need to edit it for your setup
I added to /etc/rc.local using nano:
directly under the shebang line. Close nano with Ctrl-X and Y to save
Then for 18.04 (may not work on 16.04) on the command line run:
Then on the command line - read /etc/rc.local and then reboot:
if /etc/rc.local chokes and errors then make sure it's chmod +x /etc/rc.local
I am using this bash script to set the
performance
governor:Make is executable
chmod +x cpu.sh
and run at any time You need (ever right after every computer start/reboot).I had a similar problem. In my case I wanted to set the governor to 'schedutil', but after a reboot I would always find the governor to be 'ondemand'. I read and did try most solutions presented here to no avail.
What did the trick for me, and I am using Ubuntu Mate 18.04.2 was finding the file:
/lib/systemd/set-cpufreq
editing it to insert the lines:
so now the file reads:
and now when I boot my computer it starts with the 'schedutil' governor!
You'll first need to install cpufrequtils;
then, perform a restart and set cpufrequency to performance,
Note: If you ran the above command without restarting, then you'd have to edit edit the file in
/etc/init.d/cpufrequtils
and change the line that saysto
then run;
it'd probably prompt you to restart your systemctl daemon, so do it like this;
this should do the work. then view your cpufrequency with;
A simple script to switch between powersave and performance mode. You can try with any of the 'wrmsr' commenting out one in below script. I don't know why, but writing 0 to register worked well for me.