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.

DIGG THIS ARTICLE!

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:

GOVERNOR="ondemand"
MAX_SPEED="2128000"
MIN_SPEED="1596000"

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 > \
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

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 (404.g-net.pl). Translated by Adam Dziuba. Proof-read by: el es


Warning: include_once(/sites/polishlinux.org/wp-content/themes/jakilinuxorg/google_article_inside.php): failed to open stream: No such file or directory in /sites/polishlinux.org/wp-content/themes/jakilinuxorg/single.php on line 48

Warning: include_once(): Failed opening '/sites/polishlinux.org/wp-content/themes/jakilinuxorg/google_article_inside.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /sites/polishlinux.org/wp-content/themes/jakilinuxorg/single.php on line 48

Subscribe to RSS feed for this article!

14 Comments

fold this thread Marcin Trybus  Thursday, 17 April 2008 o godz. 10:57 am #  Add karma Subtract karma  +1

You don’t need sysfsutils. It works just as well without.

The ondemand governor is good for anything because the frequency switch is fast enough. I find conservative a bad option. Overall it is less efficient, contrary to what the documentation claims, as the CPU runs longer at speeds other then minimal. With a CPU with only two frequencies like my M-P3 there is no difference between ondemand and conservative.

In my opinion no GUI tool is necessary unless you fear CLI and you have a laptop. The only thing I use is the frequency monitor.

(Comments wont nest below this level)
 
fold this thread shabakeh  Thursday, 17 April 2008 o godz. 4:10 pm #  Add karma Subtract karma  +0

hi dear

how can i do this article in my desktop. my cpu name is Intel(R) Pentium(R) 4 CPU 1.80GHz.is it scalable?i use fedora and i like do this article in my fedora7.

(Comments wont nest below this level)
fold this thread Matt Woelfel  Saturday, 19 April 2008 o godz. 3:25 am #  Add karma Subtract karma  +1

Fedora 7 should have CPU scaling working out of box.

You can see your frequency using:
cat /proc/cpuinfo

To see your frequency change in the CLI:
watch “cat /proc/cpuinfo | grep MHz”

…and run/shutdown some apps.

Cheers

 
 
fold this thread nanon  Monday, 21 April 2008 o godz. 1:33 pm #  Add karma Subtract karma  +0

wonderful article…, though Ubuntu seems to do this out of the box with a nice graphical interface. Just click on the battery icon on the taskbar for a laptop.

(Comments wont nest below this level)
 
fold this thread Douglish  Monday, 21 April 2008 o godz. 5:37 pm #  Add karma Subtract karma  +0

Hi, for KDE there is very nice application into systray called kpowersave, it comunicates with powersaved daemon and works fine. It can manage also brightness, screensaver, suspend/hibernation, also displays battery status and when running on battery, it shows power consumtion.

(Comments wont nest below this level)
fold this thread rastos  Tuesday, 22 April 2008 o godz. 8:47 am #  Add karma Subtract karma  +0

When using KDE you can watch (though not change) the currently selected frequency in “Performence Monitor” aka ksysguard. Ksysguard also comes with “System Guard” applet on kicker panel that can be configured to show the frequency.

 
 
fold this thread hugis  Monday, 21 April 2008 o godz. 6:10 pm #  Add karma Subtract karma  --1

If you want to choose frequency or governor in gnome applet try run dpkg-reconfigure gnome-applets and set SUID bit.

(Comments wont nest below this level)
 
fold this thread enteon  Monday, 21 April 2008 o godz. 9:09 pm #  Add karma Subtract karma  +1

If you were crunching, you didn’t have to think about such things like clock scaling (except for upward scaling – hehe). I think crunching for a useful purpose makes my PC even more energy efficient than choosing a good PSU ever could. Just think about what we can achieve if every OS was crunching by default :)

Please, have a look at: http://www.worldcommunitygrid.org/

(Comments wont nest below this level)
 
fold this thread shabakeh  Monday, 21 April 2008 o godz. 10:06 pm #  Add karma Subtract karma  +0

what does “box” mean? because you said Fedora 7 should have CPU scaling working out of box.

(Comments wont nest below this level)
fold this thread response  Tuesday, 22 April 2008 o godz. 11:11 pm #  Add karma Subtract karma  +0

“out of the box” is an expression, it means that it does not require any additional installations or setup for it to do that specific task

 
 
fold this thread emanuele  Tuesday, 22 April 2008 o godz. 7:43 am #  Add karma Subtract karma  +0

Hi, debian testing user here.
Thus stuff works great, but only as long as I don’t reboot.
How can I keep it working for evey session?

thanks a lot
cheers

e.

(Comments wont nest below this level)
 
fold this thread dara  Tuesday, 22 April 2008 o godz. 9:20 am #  Add karma Subtract karma  +1

simply add cpufrequtils as a startup service. rcconf may come handy to configure this.

cheers

dara

(Comments wont nest below this level)
 
fold this thread Vladimir Kotal  Saturday, 17 January 2009 o godz. 4:20 pm #  Add karma Subtract karma  +0

In Fedora 10, it is sufficient to enable “cpuspeed” service. Works nicely on AMD Athlon X2 (4850e).

(Comments wont nest below this level)
 
fold this thread Richard  Tuesday, 16 June 2009 o godz. 1:30 pm #  Add karma Subtract karma  +0

I have a Pentium D 3GHz. The ondemand governor scales it down to 2.4GHz when it’s idle. Should the CPU drop any lower than 2.4GHz, or is this right for this Pentium D model?

Cheers,
Rich

(Comments wont nest below this level)
 
Name (required)
E-mail (required - never shown publicly)
URI

Adjust field size: shrink | enlarge)


You can use simple HTML in your comments. Some examples are as follows:
  • A hyperlink: <a href="polishlinux.org">GNU/Linux for everyone!</a>,
  • Strong text: <strong>Strong text</strong>,
  • Italic text: <em>italic text</em>,
  • Strike: <strike>strike</strike>,
  • Code: <code>printf("hello world");</code>,
  • Block quote: <blockquote>Block quote</blockquote>

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 404.g-net.pl.

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!

PolishLinux.org on Facebook

Follow PolishLinux on Twitter!

Follow polishlinux on Twitter

Google Ads