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

>>> Read the full article

Friday, January 26, 2007

Debian HOW-TO : CPU power management

Last revision : February 5th, 2007

CPU frequency management is one of the keys to power preservation.

The Linux kernel now provides all the necessary tools to properly manage CPU frequency : no need to use a daemon (like cpufreqd or powernowd) to take care of your CPU.

Of course the benefits of such power management are obvious for a laptop, but most desktop users should also consider this.

In this tutorial, I use sudo to get root privileges.


  • Prerequisites


Debian Etch (and Sid) should automatically configure CPU frequency management on most processors that supports it, so it might very well be already enabled. You can verify if that is the case using this command :

cpufreq-info


and analyze the output regarding the current policy.

If CPU frequency management is off (or the command is not found), then you can go on with this tutorial.

In order to make this work, you need to install the required packages:

sudo apt-get install cpufrequtils sysfsutils


Next, verify your exact CPU model :

cat /proc/cpuinfo | grep "model name"


Which should output something like that :

model name      : Intel(R) Pentium(R) M processor 1.73GHz


Once you know your exact CPU type, the next step is to load the proper modules : the CPU frequency driver and the CPU frequency policy governor.


  • CPU frequency driver


As you may guess the CPU frequency driver will differ depending on your type of CPU. For example, my laptop is equipped with a Pentium M, so I type :

sudo modprobe speedstep_centrino


to load the proper driver.

Some of the other common drivers (or modules) are :

AMD K6 processors : powernow_k6
AMD K7 processors (Athlon, Duron, Sempron 32 bits) : powernow_k7
AMD K8 processors (Athlon 64, Turion 64, Sempron 64, Opteron 64) : powernow_k8

Pentium 4, Celeron D, Pentium D, Celeron M : p4_clockmod
Pentium M, Core Duo, Core 2 Duo : speedstep_centrino

There are of course other CPU frequency drivers. In doubt, you can use the generic driver : acpi_cpufreq


  • CPU policy governor


Once the proper driver is loaded, you need to choose the desired CPU policy governor. This policy governor will manage the actual behavior of your CPU. Here is some policy governors and their module names :

performance, which sets the CPU statically to the highest possible frequency : cpufreq_performance
powersave, which is the opposite, clocks the CPU statically to the lowest frequency : cpufreq_powersave
ondemand, which sets the CPU speed dynamically depending on the work load (ideal for desktops) : cpufreq_ondemand
conservative, which also sets the CPU dynamically, but less aggressively then the ondemand governor (ideal for laptops) : cpufreq_conservative

For example, my machine has a Pentium M processor, so I type :

sudo modprobe speedstep_centrino
sudo modprobe cpufreq_ondemand


to load both the CPU frequency driver and the CPU policy governor.


  • CPU configuration


Once the modules are loaded, you need to configure the policy governor. For example, I use the ondemand governor, so :

echo ondemand | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor


will enable it.

You can verify that everything went well with this command :

cpufreq-info


It should output your actual frequency, as well as the governor presently in use.


  • System configuration


If everything is good, then you can make this configuration permanent. First make sure the proper modules are loaded at startup (in /etc/modules).

So in my case :


echo speedstep_centrino | sudo tee -a /etc/modules
echo cpufreq_ondemand | sudo tee -a /etc/modules


Finally, ensure that the CPU uses your policy governor of choice by default. Simply edit the file /etc/sysfs.conf with a line like this one :

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


That's it !

>>> Read the full article