Thursday, August 4, 2022

CPU frequency scaling in Ubuntu

Changing CPU frequencies can be interesting to measure certain energy efficiency aspects. To manually change the CPU frequency in Ubuntu, first install cpufrequtils to get the additional commands:

sudo apt-get install cpufrequtils
See the available CPU frequencies, the current frequency and governor per core.

$ cpufreq-info
 cpufrequtils 007: cpufreq-info (C) Dominik Brodowski 2004-2009
 Report errors and bugs to cpufreq@vger.kernel.org, please.
 analyzing CPU 0:
 driver: powernow-k8
 ...
 available frequency steps: 2.60 GHz, 2.30 GHz, 1.80 GHz, 1.30 GHz, 800 MHz
 available cpufreq governors: conservative, ondemand, userspace, powersave, performance
 current policy: frequency should be within 800 MHz and 2.60 GHz.
 The governor "ondemand" may decide which speed to use
 within this range.
 current CPU frequency is 800 MHz.
 cpufreq stats: 2.60 GHz:1.77%, 2.30 GHz:0.33%, 1.80 GHz:0.20%, 1.30 GHz:0.34%, 800 MHz:97.35% (63965465)
To be able to change the frequency, we have to change to the userspace frequency.

sudo cpufreq-set -g userspace
Finally, we can switch the actual frequency to one of the available values with:

sudo cpufreq-set -f 2.6GHz
This happend per-core on the server I tested the procedure on. You can select e.g. CPU 2 using the -c2 option. Also, don’t forget to change back to the default ondemand governor once you’re done – you wanna stay green 😉

References:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.