I'd like to set the CPU frequency scaling governor for all cores at once instead of doing it individually for each core. Is there a way to do this?
(I know it would be easy to echo the governor to /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
, but I'm not looking for a custom solution.)
I googled a lot and I think it's just not possible, so I added the following one-liner to my
.bashrc
:Now I can run something like
setgov ondemand
and all cores will switch to the ondemand governor.I'm still a linux noob but don't you think cpufrequtils lets u do it by using (its not bundled in the Ubuntu OS but is there in the repository)
-r
flag is used to set the change for all ("all hardware related") coresthe shortest command to change governor of all cores is the following:
You could add it to .bashrc like htorque mentioned
setgov performance
:You can do this for all cores at once by running
Might as well add bash code completion, while we're at it:
The way I set this to stick since the governor defaults back to powersave after about 30 seconds now as of Ubuntu 16.04 or more recent (I'm on Ubuntu Mate);
Put this (one line of) code (thank you, courtesy of switch87 in the previous answer)
into the file in the directory
Mine is a line above "exit 0" and uncommented, under the commented ones.
"rc.local" for those who do not know, it runs the command as sudo. Any command it seems, to change the governor, needs to be run as sudo.
It lets the governor reset back to powersave and runs the code as sudo after 60 seconds to change it back to performance.
Change the "60" (in the code you copy) to whatever time (in seconds. 60 = 60 seconds= 1 minute) you need to delay the command and "performance" (in the command part) to what governor you want it to change to.
Out of my hours and hours of searching I have not found a more permanent fix for this than this. I figure what's a couple of minutes that it's on powersave if this is the best fix I've found, right? Right.
Not the best fix, but it makes it somewhat permanent after it does it's little switch to powersave thing. If you want to boot right up and jump into a game or something you're going to have to wait a minute for the code you just put in to switch it back from powersave or lower the timing on it (depending on how long it takes everything to start up so it'll switch back to performance correctly).
And, as always, to revert back to default (I've seen some issues with people's PCs overheating which is why they might have defaulted it to powersave in the first place) just remove the code from rc.local and reboot or switch it back manually with your cpu icon indicator switcher or run;
in the terminal and or reboot.
Basing on switch87's answer, I made a simple script
cpufreq-set-all
, which will allow to do othercpufreq-set
things with all CPUs:Now it can be invoked(after
chmod +x
, of course) like this:or
sometimes setting the governor isn't enough. I had to set the MAX and MIN variables for frequency as well, because the scaling policies had them set to minimum, so what I do is 1. Get the min and max scaling frequencies from CPU 0 2. Divide them by a million to get the frequency in GHz 3. Pipe the result through bc so I can get the result in floating point(BASH can only handle integers) - scale=1 is how many decimals 4. Check if a scaling governor is supplied on the command line 5. If not, set ONDEMAND - save some money when idling 6. Run the cpufreq-set command in a loop on all CPU-s