Limit CPU Frequency on Linux
Limit or Set CPU Frequency on Linux
I got a Linux home server to run some background tasks, do the occasional streaming, experiment with some things and so on. The idea is to keep it running 24/7 while keeping power consumption as little as possible. That’s super easy with a Mac (just turn it on, and you’re good to go) and I guess to a certain extent also with the Raspberry Pi, since there’s just so much energy the small pc can draw. However, from time to time I need a bit more power than the Raspberry Pi can provide.
Unfortunately, I find it quite cumbersome to get the Linux power consumption right. It seems very complex, never does really work and there are just too many options. There might very well be an easy solution to all of this, it’s just super hard to find, and I’m just adding another entry to all the search results. 🤷♂️ Please let me know!
Usually, there are a few CPU governors available to set the CPU frequency. There’s performance, powersave and ondemand for example. The Arch Linux Wiki provides some explanation.
| governor | description |
|-------------|----------------------------------------------|
| performance | run at the maximum speed |
| powersave | run at the minimum speed provided by the CPU |
| ondemand | scale dynamically |
In an ideal world, you’d just go with ondemand, and you’re off to the races. In my experience, the ondemand governor scaled up to the maximum speed for nearly any tasks. Perhaps that’s what this thing is destined to do, but I just wanted to keep it at a lower clock rate.
Let’s get to it. I’m on an Ubuntu system.
Install cpufrequtils:
sudo apt-get install cpufrequtils
With these CPU utilities installed, you can now pick and set your CPU favorite CPU governor and even configure the minimum and maximum CPU frequency as well to customize it to your liking.
To update your settings, add or edit the following file: /etc/default/cpufrequtils. Here are two examples, you can also remove the MIN_SPEED and MAX_SPEED lines to just set the governor configuration.
powersave:
ENABLE="true"
GOVERNOR="powersave"
MIN_SPEED="800000" # 800 MHz
MAX_SPEED="2800000" # 2800 MHz
performance:
ENABLE="true"
GOVERNOR="performance"
MIN_SPEED="800000" # 800 MHz
MAX_SPEED="4900000" # 4900 MHz
Now, ensure that the service is enabled and running:
sudo systemctl enable cpufrequtils.service
These settings should also be applied when you reboot the system from now on.