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

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

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.


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, you will have to run it as root sudo setgov performance:

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

Tags:

Cpufreq