Wednesday, January 31, 2007

Debian HOW-TO : Power Management

Last revision : Mai 5th, 2007

This article is intended to give general tips on how to properly manage power consumption and its different aspects (CPU frequency management, suspend/resume, and other common functionalities).

While most laptop users should care, any desktop user concerned with the environment (or their electricity bill) might want to put some efforts in this.


  • Prerequisites


Keep in mind that the present tutorial contains only general guidelines and examples : the exact procedure will most likely differ on your machine.

To higher your chances of success, I suggest the use of a recent Linux distribution (like Debian Etch or Ubuntu Edgy), based on a recent Linux kernel (Etch will ship with a 2.6.18 kernel, Ubuntu Edgy ships with a 2.6.17 one : that's about what you need). The instructions posted here have been tested on Debian & Ubuntu.


  • CPU frequency management


This is perhaps the main area where you can save energy. Please refer to this tutorial for more.


  • X server


The X server configuration is equally important. I shall divide this question in 2 aspects : first, optimizations related to CPU/GPU consumption, and second, modifications concerning your machine's ability to suspend/resume properly.

The file to edit here is /etc/X11/xorg.conf (or /etc/X11/XF86Config-4 for Debian Sarge users).


About power


For the energy conservation minded laptop user, a few general guidelines are to be followed. First, always use 16 bit color depth instead of the default 24 (it will render 3D and images about 50% faster, or consume that much less power for about the same visual result). So in Section "Screen", make sure you have this line :

   DefaultDepth 16


Also, to make proper use of your graphic card memory (as a buffer of images), one might want to use :

   Option   "backingstore"   "true"


in Section "Device".

Also, to make sure hardware rendering is enabled, the line :

   Option   "RenderAccel"   "true"


should be present in Section "Device".

ATI cards users have an extra trick on hands (given the ATI proprietary driver is installed), as this line of code in Section "Device" activates GPU frequency management on their video card :

   Option   "DynamicClocks"   "true"


This option refer to a feature called powerplay (by ATI), which allows you to change GPU clocking of your card on-the-fly (see the Notes section of the present tutorial for more details).


About suspend/resume


A specific option can help your laptop properly resume from suspend to RAM. The code is :

   Option   "VBERestore"   "true"


which should be included in Section "Device" (again in your /etc/X11/xorg.conf).


  • Suspend to RAM


For suspend to RAM to work properly, you will need a bit of luck and a bit work.

I personally use Powersave in conjunction with a collection of little subsidiary tools like laptop-mode-tools, hdparm, and others.


Installation


So minimally you would need to install those packages :

sudo apt-get install acpi acpid acpi-tools hdparm sdparm laptop-detect laptop-mode-tools powersaved


Also, many users will prefer a graphical front end to manage those utilities : the recommended one for KDE is kpowersave, while GNOME fans have gnome-power-manager.

It is to be noted that for powersaved to work correctly, you need to make your user part of the group powerdev :

sudo adduser your_username powerdev



Configuration


Obviously this is the tricky part, though in my experience it does work without too much effort on most recent laptops.

The main configuration file for powersaved is /etc/powersave/sleep. Fortunately only a few lines need to be changed, if any.

For example, on my Asus Z63A laptop, 5 lines needed to be changed :

UNLOAD_MODULES_BEFORE_SUSPEND2RAM="sdhci"
SUSPEND2RAM_FORCE="yes"
SUSPEND2RAM_ACPI_SLEEP="1"
SUSPEND2RAM_VBE_SAVE="yes"
SUSPEND2DISK_METHOD="uswsusp"


In ideal conditions, no changes at all should be required for the file discussed here (/etc/powersave/sleep). So you might as well try it before hacking it.

You can put your machine in suspend to RAM state by clicking on the battery icon in your system tray, and choosing "suspend". You can resume by (quickly) pressing the power button of your machine.

That's it folks !


  • Notes


If you hesitated on any aspects of the X server configuration, you can check out some working examples I prepared (and tested) :

INTEL card xorg.conf
ATI card xorg.conf using proprietary drivers
NVIDIA card xorg.conf using proprietary drivers


You can verify that a certain feature related to the X server is enabled by looking at the output of

cat /var/log/Xorg.0.log


For example, on a properly configured ATI card, the output of

cat /var/log/Xorg.0.log | grep -i dynamic

should look like that :

(**) RADEON(0): Option "DynamicClocks" "on"
(II) RADEON(0): Dynamic Clock Scaling Enabled


As stated earlier, machines equipped with ATI video cards can make use of the powerplay feature, provided the official ATI drivers are installed.

Several powerstates might be available depending of the card's model. This command will give you the complete list :

aticonfig --list-powerstates


You can find out more about this specific feature at thinkwiki.org

4 comments:

Anonymous said...

Holy smokes, I cannot believe how much snappier my system is after ditching powernowd and moving to a kernel-based frequency governor! Thank you thank you thank you, Antidrugue, for giving my laptop new life.
This is the third time I've seen you reference one of your HOWTOs on LinuxForums.org, and each one has been a gold mine. I'm going to have to check out all your articles, so that I can get the most out of my Debian system.
Again a big THANK YOU!!!

joffa said...

Your articles have helped me to install beryl and network-manager-gnome. They both worked a treat. I have tried previously installing gnome-power-manager and added my user to powerdev. As the screen didn't resume I tried your instructions using powersaved - same thing, screen didn't resume. I tried searching google but either what I tried didn't work or it was too technical for me. So are you able to give me plain english help as to what to tweak? I have an nvidia geforce4 mx440 agp8x graphics card if that helps.
PS I tried sending this message before but it seems not to have been added, so if you get this again I apologise.

Hugues said...

Hi Joffa,

Some video cards are a bit problematic with suspend to RAM.

Specifically, my guess is that you should try the different options available regarding the variable SUSPEND2RAM_ACPI_SLEEP=... (which relates to values like "s3_bios", "s3_mode", and more)in the file /etc/powersaved/sleep.

Good luck with that. If you struggle, I suggest you start a thread about this issue on LinuxForums.org.

Thanks for reading, and thank you for your comments,

Hugues

free ps3 said...

Thanks for the nice post!