Green PCs: CPU frequency scaling in Linux

[ Wednesday, 16 April 2008, dhor ]

Electricity bills got higher again? Does your computer waste too many power cycles? Or perpahs you just don’t feel green enough? In any case, this article is for you! You’ll learn how to save energy and CPU cycles with your Linux box, no matter how old it is.


Short introduction

Somehow, I’ve always had bad luck to new technologies. The world introduces more and more sophisticated methods of using the human knowledge each day, and I was always in the long tail of progress. Or simply, something didn’t want to work for me on Linux. It was similar when I tried to scale the CPU frequency. I didn’t pay much attention to this before, because the laptops I used, simply didn’t provide such a feature. Yes, I realize it was my bad luck to buy laptops like that — different Durons and Athlons, which didn’t allow economical scaling, visited my poor desktop computer. So I classified this topic as: ‘I don’t know, nor am I interested, I’m overworked’. And then, recently, I purchased a new laptop and installed Ubuntu on it, where such things as CPU scaling work out of the box. I would have got over this like “Well, because it’s a laptop, and they’re made to do this by default”, if not the fact, that the electricity price is rising, or that I feel responsible for the ozone depletion — well… I’ve developed a guilty conscience. Does my tiny desktop PC have to heat like a crazy one?

The Playground

My Debian desktop is so aged, that it remembers the time of capturing Saddam. Of course, the whole time I’ve been feeding him ‘unstable’ updates, but I didn’t even try to suspect, that in a ‘magical’ way, all the conveniences of Linux will start to work by themselves. So I’ve made a little look-around, and this is what we need to control the wild powers of the CPU:

  • kernel 2.6.X — the newer the better – I’ve tested everything on 2.6.22 (reportedly, from 2.6.20 on, there shouldn’t be any problems with scaling),
  • the cpufrequtils, sysfsutils packages (installed the way you like it – apt-get, aptitude, synaptic, and so on.),
  • a computer with a scalable CPU (well, it’s a must).

Beat the Bossy one

So we’ve got the proper packages and the kernel, and we believe that we can save the world from the heat pouring from inside of our computer.

We can start gaining speed now – because we have to figure out, what kind of CPU do we have? The onanists hardware lovers surely remember even the serial number of their component, but if someone doesn’t know the type, then:

cat /proc/cpuinfo | grep name

Why do we need that? To load the proper driver, which manage the frequency scaling of our CPU. We can choose between the following modules:

  • Pentium 4, Celeron D, Pentium D, Celeron M : p4_clockmod Pentium M, Core Duo, Core 2 Duo: speedstep_centrino
  • AMD K6: powernow_k6
  • AMD K7 (Athlon, Duron, Sempron 32): powernow_k7
  • AMD K8 (Athlon 64, Turion 64, Sempron 64, Opteron 64): powernow_k8
  • None of above: acpi_cpufreq (with NO warranty that it works, whatsoever!)

Inside the /lib/modules/`uname -r`/kernel/arch/i386/kernel/cpu/cpufreq/ directory you can also find different modules – if none of above drivers works, you can try other drivers placed in this directory (modinfo module_name will give us a hint, which models we can use).

We now load the chosen module:

modprobe module_name

Policy, handcuffs for unruly individuals

Except for the already loaded scaling driver, we also need another module (or multiple modules), which define a — so called — policy governor. Again, whenever we browse through the appropriate directories, we will find out, that we can use the following rules:

  • ondemand: my favorite rule, which adjusts the CPU spee dynamically, depending on the usage. The cpufreq_ondemand module.
  • performance: sets the frequency to the highest possible value, statically. The cpufreq_performance module.
  • powersave: this one sets the frequency statically to the lowest possible value. The cpufreq_powersave module.
  • conservative: similar to ‘ondemand’, adjusts the frequency dynamically, but works better on laptops. The cpufreq_conservative module.

Now, whichever policy we have chosen, we type:

modprobe policy_module

Go to sleep, go to sleep…

We’ve got the driver and the policy governor, so what’s next? They must be aware of the way we want the CPU frequency to be scaled. For this purpose we have to edit the /etc/init.d/cpufrequtils file and we need to find the lines:


The smarty ones will notice, that in the place of “ondemand” they can (or even should) type in their chosen policy name. What to assign to MAX_SPEED and MIN_SPEED? Theoretically, you can leave it without any value (empty “”), but just to be sure, put there the maximum and minimum values, that I could select for my Core2Duo CPU. And how do you find those values out? You just have to run the command cpufreq-info -l:

1596000 2128000

These are the values for MIN_SPEED and MAX_SPEED, respectively.

OK, so we’ve configured the required stuff. Now we need to only restart the cpufrequtils (/etc/init.d/cpufrequtils restart). And…

Does it work?

… now we’re checking, what have we have achieved, by typing cpufreq-info -p:

1596000 2128000 ondemand

If the result is the same as the policy set before, and the same as MIN_SPEED and MAX_SPEED, then we can party. Almost. We yet have to add the module names we’ve modprobed before, to /etc/modules:

echo "driver_module_name" >> /etc/modules
echo "policy_module_name" >> /etc/modules

Are we happy now?

Theoretically, it should be enough, and everything should behave the way that we wanted it to. But in case of older versions of cpufrequtils, there could be a need of setting the policy governor to a ‘stiff’ value in such a weird way (you can check it on-the-fly):

echo ondemand > \

And add the following line to /etc/sysfs.conf:

devices/system/cpu/cpu0/cpufreq/scaling_governor \
= ondemand

Maybe there is a different (GUI?) way to do that, but the terminal is more comfortable and, apparently, my system only reacts to such gore-mangling.

Anyway, those who like indicators or graphs, can go on installing gnome-applets packages (for GNOME) or xfce4-cpufreq-plugin (for XFCE) (btw. the panel plugins are the ugliest elements of XFCE ever). You can try to add a suitable applet to the panel, and see if or how the CPU is scaling now. Unfortunately, I can’t name such a plugin name for KDE, because I’m not familiar with that environment. An additional feature is the cpufreqd package, which allows to create profiles for saving power – for example, to turn on conservative when we use the battery, then ondemand when we use the power supply, and so on.

And this way we became the fully conscious inhabitants of our planet, who do take care of limiting the heat amount, and the used electricity. And we also pay lower bills. Yay!.

Original text can be found (in Polish) at: Zielone procesorki ( Translated by Adam Dziuba. Proof-read by: el es

About the Author

Dariusz Duma

Debian user. Age: undefined. Cannot swim. Likes biking and hiking but has no time for it. Blogs on Linux and life on

New AdTaily ads!

Are you a film buff?

film buffs community, movie recommendations and reviews

RSS: Comments

You can follow the comments to this article through a special channel RSS 2.0 .

Related articles: Apps

 more »

Related articles: Debian

 more »

PolishLinux Top Content

Become our fan on Facebook! on Facebook

Follow PolishLinux on Twitter!

Follow polishlinux on Twitter

Google Ads