How do I set the CPU frequency scaling governor for all cores at once?

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


Solution 1:

I googled a lot and I think it's just not possible, so I added the following one-liner to my .bashrc:

function setgov ()
{
    echo "$1" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 
}

Now I can run something like setgov ondemand and all cores will switch to the ondemand governor.

Solution 2:

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)

sudo apt-get install cpufrequtils
sudo cpufreq-set -r -g performance
  • The -r flag is used to set the change for all ("all hardware related") cores

Solution 3:

the shortest command to change governor of all cores is the following:

sudo bash -c 'for ((i=0;i<$(nproc);i++)); do cpufreq-set -c $i -g performance; done'

You could add it to .bashrc like htorque mentioned setgov performance:

function setgov ()
{
     for i in {0..7}; 
     do 
         sudo  cpufreq-set -c $i -g $1; # run cpufreq-set with root
     done
}