Capacity and lifetime of laptop batteries have improved much in the last years. Nevertheless modern processors consume much more energy than older ones and each laptop generation introduces more devices hungry for energy. That's why Power Management is more important than ever. Increasing battery run time doesn't necessarily mean buying another battery. Much can be achieved applying intelligent Power Management policies.
Please notice that this guide describes Power Management for
As this guide has become rather long, here's a short overview helping you to find your way through it.
The
Nearly every component can operate in different states - off, sleep, idle, active to name a few - consuming a different amount of energy. Major parts are consumed by the LCD display, CPU, chipset and hard drives. Often one is able to activate OS-independent Power Management in the BIOS, but an intelligent setup in the operating system adapting to different situations can achieve much more.
Before discussing the details of making individual devices Power Management
aware, make sure certain requirements are met. After controlling BIOS
settings, some kernel options want to be enabled - these are in short ACPI,
sleep states and CPU frequency scaling. As power saving most of the time comes
along with performance loss or increased latency, it should only be enabled
when running on batteries. That's where a new runlevel
First have a look into your BIOS Power Management settings. The best way is to combine BIOS and operating system policies, but for the moment it's better to disable most of the BIOS part. This makes sure it doesn't interfere with your policies. Don't forget to re-check BIOS settings after you configured everything else.
Please check that the
ACPI (Advanced Configuration and Power Interface) support in the kernel is still work in progress. Using a recent kernel will make sure you'll get the most out of it.
There are different kernel sources in Portage. I'd recommend using
Power Management Options --->
[*] Power Management Support
[ ] Software Suspend
ACPI( Advanced Configuration and Power Interface ) Support --->
[*] ACPI Support
[ ] Sleep States
[ ] /proc/acpi/sleep (deprecated)
[*] AC Adapter
[*] Battery
<M> Button
<M> Video
[ ] Generic Hotkey
<M> Fan
<M> Processor
<M> Thermal Zone
< > ASUS/Medion Laptop Extras
< > IBM ThinkPad Laptop Extras
< > Toshiba Laptop Extras
(0) Disable ACPI for systems before Jan 1st this year
[ ] Debug Statements
[*] Power Management Timer Support
< > ACPI0004,PNP0A05 and PNP0A06 Container Driver (EXPERIMENTAL)
CPU Frequency Scaling --->
[*] CPU Frequency scaling
[ ] Enable CPUfreq debugging
< > CPU frequency translation statistics
[ ] CPU frequency translation statistics details
Default CPUFreq governor (userspace)
<*> 'performance' governor
<*> 'powersave' governor
<*> 'ondemand' cpufreq policy governor
<*> 'conservative' cpufreq governor
<*> CPU frequency table helpers
<M> ACPI Processor P-States driver
<*> CPUFreq driver for your processor
Decide yourself whether you want to enable Software Suspend, and Sleep States (see below). If you own an ASUS, Medion, IBM Thinkpad or Toshiba laptop, enable the appropriate section.
The kernel has to know how to enable CPU frequency scaling on your processor. As
each type of CPU has a different interface, you've got to choose the right
driver for your processor. Be careful here - enabling
Compile your kernel, make sure the right modules get loaded at startup and boot
into your new ACPI-enabled kernel. Next run
# emerge sys-power/acpid # /etc/init.d/acpid start # rc-update add acpid default
The default policy will be to enable Power Management only when needed -
running on batteries. To make the switch between AC and battery convenient,
create a runlevel
# cd /etc/runlevels # cp -a default battery
Finished. Your new runlevel
Typical ACPI events are closing the lid, changing the power source or pressing the sleep button. An important event is changing the power source, which should cause a runlevel switch. A small script will take care of it.
First you need a script which changes the runlevel to
# emerge powermgmt-base
You are now able to determine the power source by executing
#!/bin/bash# BEGIN configuration RUNLEVEL_AC="default" RUNLEVEL_BATTERY="battery"# END configuration if [ ! -d "/etc/runlevels/${RUNLEVEL_AC}" ] then logger "${0}: Runlevel ${RUNLEVEL_AC} does not exist. Aborting." exit 1 fi if [ ! -d "/etc/runlevels/${RUNLEVEL_BATTERY}" ] then logger "${0}: Runlevel ${RUNLEVEL_BATTERY} does not exist. Aborting." exit 1 fi if on_ac_power then if [[ "$(cat /var/lib/init.d/softlevel)" != "${RUNLEVEL_AC}" ]] then logger "Switching to ${RUNLEVEL_AC} runlevel" /sbin/rc ${RUNLEVEL_AC} fi elif [[ "$(cat /var/lib/init.d/softlevel)" != "${RUNLEVEL_BATTERY}" ]] then logger "Switching to ${RUNLEVEL_BATTERY} runlevel" /sbin/rc ${RUNLEVEL_BATTERY} fi
Dont forget to run
# tail -f /var/log/acpid | grep "received event"
Run the command above and pull the power cable. You should see something like this:
[Tue Sep 20 17:39:06 2005] received event "ac_adapter AC 00000080 00000000" [Tue Sep 20 17:39:06 2005] received event "battery BAT0 00000080 00000001"
The interesting part is the quoted string after
# replace "ac_adapter" below with the event generated on your laptop # For example, ac_adapter.* will match ac_adapter AC 00000080 00000000 event=ac_adapter.* action=/etc/acpi/actions/pmg_switch_runlevel.sh %e
# replace "battery" below with the event generated on your laptop # For example, battery.* will match battery BAT0 00000080 00000001 event=battery.* action=/etc/acpi/actions/pmg_switch_runlevel.sh %e
Finally acpid has to be restarted to recognize the changes.
# /etc/init.d/acpid restart
Give it a try: Plug AC in and out and watch syslog for the "Switching to AC mode" or "Switching to battery mode" messages. See the Troubleshooting section if the script is not able to detect the power source correctly.
Due to the nature of the event mechanism, your laptop will boot into runlevel
# Fake acpi event to switch runlevel if running on batteries /etc/acpi/actions/pmg_switch_runlevel.sh "battery/battery"
Prepared like this you can activate Power Management policies for individual devices.
Mobile processors can operate at different frequencies. Some allow changing voltage as well. Most of the time your CPU doesn't need to run at full speed and scaling it down will save much energy - often without any performance decrease.
CPU frequency scaling brings up some technical terms that might be unknown to you. Here's a quick introduction.
First of all, the kernel has to be able to change the processor's frequency.
The
This doesn't sound like dynamic frequency changes yet and in fact it isn't.
Dynamics however can be accomplished with various approaches. For example,
the
Decreasing CPU speed and voltage has two advantages: On the one hand less energy is consumed, on the other hand there is thermal improvement as your system doesn't get as hot as running on full speed. The main disadvantage is obviously the loss of performance. Decreasing processor speed is a trade off between performance loss and energy saving.
It's time to test whether CPU frequency changing works. Let's install another
tool which is very handy for debugging purposes:
# emerge cpufrequtils # cpufreq-info
Here is an example output:
cpufrequtils 0.3: cpufreq-info (C) Dominik Brodowski 2004
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
driver: centrino
CPUs which need to switch frequency at the same time: 0
hardware limits: 600 MHz - 1.40 GHz
available frequency steps: 600 MHz, 800 MHz, 1000 MHz, 1.20 GHz, 1.40 GHz
available cpufreq governors: conservative, ondemand, powersave, userspace, performance
current policy: frequency should be within 924 MHz and 1.40 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency is 1.40 GHz.
Now play around with
The above is quite nice, but not doable in daily life. Better let your system
set the appropriate frequency automatically. There are many different
approaches to do this. The following table gives a quick overview to help you
decide on one of them. It's roughly seperated in three categories
| Name | Category | Switch decision | Kernel governors | Further governors | Comments |
|---|---|---|---|---|---|
While adjusting the frequency to the current load looks simple at a first glance, it's not such a trivial task. A bad algorithm can cause switching between two frequencies all the time or wasting energy when setting frequency to an unnecessary high level.
Which one to choose? If you have no idea about it, try
# emerge cpufreqd
[General] pidfile=/var/run/cpufreqd.pid poll_interval=3 enable_plugins=acpi_ac, acpi_battery verbosity=5 [/General] [Profile] name=ondemand minfreq=0% maxfreq=100% policy=ondemand [/Profile] [Profile] name=conservative minfreq=0% maxfreq=100% policy=conservative [/Profile] [Profile] name=powersave minfreq=0% maxfreq=100% policy=powersave [/Profile] [Profile] name=performance minfreq=0% maxfreq=100% policy=performance [/Profile] [Rule] name=battery ac=off profile=conservative [/Rule] [Rule] name=battery_low ac=off battery_interval=0-10 profile=powersave [/Rule] [Rule] name=ac ac=on profile=ondemand [/Rule]
Now you can start the cpufreqd daemon. Add it to the
# rc-update add cpufreqd default battery # rc
Sometimes it can be desirable to select another policy than the daemon chooses,
for example when battery power is low, but you know that AC will be available
soon. In that case you can turn on cpufreqd's manual mode with
The last thing to check is that your new policies do a good job. An easy way to do so is monitoring CPU speed while working with your laptop:
# watch grep \"cpu MHz\" /proc/cpuinfo
If
# watch x86info -mhz
Depending on your setup, CPU speed should increase on heavy load, decrease on
no activity or just stay at the same level. When using cpufreqd and verbosity
set to 5 or higher in
As you can see in
The first thing to check is the standby/suspend/off timings of the display. As
this depends heavily on your windowmanager, I'll let you figure it out
yourself. Just two common places: Blanking the terminal can be done with
Section "ServerLayout" Identifier [...] [...] Option "BlankTime" "5"# Blank the screen after 5 minutes (Fake) Option "StandbyTime" "10"# Turn off screen after 10 minutes (DPMS) Option "SuspendTime" "20"# Full suspend after 20 minutes Option "OffTime" "30"# Turn off after half an hour [...] EndSection [...] Section "Monitor" Identifier [...] Option "DPMS" "true" [...] EndSection
This is the same for XFree86 and
Probably more important is the backlight dimming. If you have access to the
dimming settings via a tool, write a small script that dims the backlight in
battery mode and place it in your
To be able to set the brightness level, the ibm_acpi module has to be loaded with the experimental parameter.
(Please read the warnings above before doing this!) # echo "options ibm_acpi experimental=1" >> /etc/modules.d/ibm_acpi # /sbin/modules-update # echo ibm_acpi >> /etc/modules.autoload.d/kernel-2.6 # modprobe ibm_acpi
This should work without error messages and a file
# See /proc/acpi/ibm/brightness for available values # Please read /usr/src/linux/Documentation/ibm-acpi.txt # brigthness level in ac mode. Default is 7. BRIGHTNESS_AC=7# brightness level in battery mode. Default is 4. BRIGHTNESS_BATTERY=4
#!/sbin/runscript
set_brightness() {
if on_ac_power
then
LEVEL=${BRIGHTNESS_AC:-7}
else
LEVEL=${BRIGHTNESS_BATTERY:-4}
fi
if [ -f /proc/acpi/ibm/brightness ]
then
ebegin "Setting LCD brightness"
echo "level ${LEVEL}" > /proc/acpi/ibm/brightness
eend $?
elif [[ -e /usr/bin/acpitool && -n $(acpitool -T | grep "LCD brightness") ]]
then
ebegin "Setting LCD brightness"
acpitool -l $LEVEL >/dev/null || ewarn "Unable to set lcd brightness"
eend $?
else
ewarn "Setting LCD brightness is not supported."
ewarn "For IBM Thinkpads, check that ibm_acpi is loaded into the kernel"
ewarn "For Toshiba laptops, you've got to install app-laptop/acpitool"
fi
}
start() {
set_brightness
}
stop () {
set_brightness
}
When done, make sure brightness is adjusted automatically by adding it to the battery runlevel.
# chmod +x /etc/init.d/lcd-brightness # rc-update add lcd-brightness battery # rc
Hard disks consume less energy in sleep mode. Therefore it makes sense to activate power saving features whenever the hard disk is not used for a certain amount of time. I'll show you two alternative possibilities to do it. First, laptop-mode will save most energy due to several measures which prevent or at least delay write accesses. The drawback is that due to the delayed write accesses a power outage or kernel crash will be more dangerous for data loss. If you don't like this, you have to make sure that there are no processes which write to your hard disk frequently. Afterwards you can enable power saving features of your hard disk with hdparm as the second alternative.
Recent kernels (2.6.6 and greater, recent 2.4 ones and others with patches)
include the so-called
# emerge laptop-mode-tools
Recent versions (1.11 and later) of laptop-mode-tools include a new tool
# lm-profiler Profiling session started. Time remaining: 600 seconds [4296896.602000] amarokapp Time remaining: 599 seconds [4296897.714000] sort [4296897.970000] mv Time remaining: 598 seconds Time remaining: 597 seconds [4296900.482000] reiserfs/0
After profiling your system for ten minutes, lm-profiler will present a list of services which might have caused disk accesses during that time.
Program: "atd" Reason: standard recommendation (program may not be running) Init script: /etc/init.d/atd (GUESSED) Do you want to disable this service in battery mode? [y/N]: n
To disable atd as suggested in the example above, you would run
If you don't want to use laptop-mode, you must take special care to disable
services that write to your disk frequently -
# rc-update del cupsd battery
You can also use
The second possibility is using a small script and hdparm. Skip this if you
are using laptop-mode. Otherwise, create
#!/sbin/runscript
depend() {
after hdparm
}
start() {
ebegin "Activating Power Management for Hard Drives"
hdparm -q -S12 /dev/hda
eend $?
}
stop () {
ebegin "Deactivating Power Management for Hard Drives"
hdparm -q -S253 /dev/hda
eend $?
}
See
# chmod +x /etc/init.d/pmg_hda # /sbin/depscan.sh # rc-update add pmg_hda battery
Another possibility is to deactivate swap in battery mode. Before writing a swapon/swapoff switcher, make sure there is enough RAM and swap isn't used heavily, otherwise you'll be in big problems.
If you don't want to use laptop-mode, it's still possible to minimize disk
access by mounting certain directories as
none /tmp tmpfs size=32m 0 0
In case you own an ATI graphics card supporting PowerPlay (dynamic clock
scaling for the the graphics processing unit GPU), you can activate this
feature in X.org. Open
Section "Device" [...] Option "DynamicClocks" "on" EndSection
Wireless LAN cards consume quite a bit of energy. Put them in Power Management mode in analogy to the pmg_hda script.
#!/sbin/runscript
start() {
ebegin "Activating Power Management for Wireless LAN"
iwconfig wlan0 power on
eend $?
}
stop () {
ebegin "Deactivating Power Management for Wireless LAN"
iwconfig wlan0 power off
eend $?
}
Starting this script will activate power saving features for wlan0. Save it as
# chmod +x /etc/init.d/pmg_wlan0 # /sbin/depscan.sh # rc-update add pmg_wlan0 battery
There are two problems with USB devices regarding energy consumption: First,
devices like USB mice, digital cameras or USB sticks consume energy while
plugged in. You cannot avoid this (nevertheless remove them in case they're not
needed). Second, when there are USB devices plugged in, the USB host controller
periodically accesses the bus which in turn prevents the CPU from going into
sleep mode. The kernel offers an experimental option to enable suspension of
USB devices through driver calls or one of the
Device Drivers
USB support
[*] Support for Host-side USB
[*] USB suspend/resume (EXPERIMENTAL)
ACPI defines different sleep states. The more important ones are
They can be called whenever the system is not in use, but a shutdown is not wanted due to the long boot time.
The ACPI support for these sleep states is marked experimental for good reason. APM sleep states seem to be more stable, however you can't use APM and ACPI together.
Power Management Options --->
[*] Power Management support
ACPI (Advanced Configuration and Power Interface) Support --->
[*] ACPI Support
[*] Sleep States
Once your kernel is properly configured, you can use the
# emerge hibernate-script
Some configuration has to be done in
To configure sleep, edit
Ready? Now is the last chance to backup any data you want to keep after
executing the next command. Notice that you probably have to hit a special key
like
# hibernate-ram
If you're still reading, it seems to work. You can also setup standby (S1) in
a similar way by copying
This section introduces hibernation, where a snapshot of the running system is written to disk before powering off. On resume, the snapshot is loaded and you can go on working at exactly the point you called hibernate before.
There are two different implementations for S4. The original one is swsusp,
then there is the newer suspend2 with a nicer interface (including
fbsplash support). A
Suspend2 is not included in the mainline kernel yet, therefore you either have
to patch your kernel sources with the patches provided by
The kernel part for both swusp and suspend2 is as follows:
Power Management Options --->(hibernate with swsusp) [*] Software Suspend(replace /dev/SWAP with your swap partition) (/dev/SWAP) Default resume partition(hibernate with suspend2) Software Suspend 2 --- Image Storage (you need at least one writer) [*] File Writer [*] Swap Writer --- General Options [*] LZF image compression(replace /dev/SWAP with your swap partition) (swap:/dev/SWAP) Default resume device name [ ] Allow Keep Image Mode
The configuration for swsusp is rather easy. If you didn't store the location
of your swap partition in the kernel config, you can also pass it as a
parameter with the
# rc-update add hibernate-cleanup boot
To activate hibernate with swsusp, use the hibernate script and set
If you experience kernel panics due to uhci or similar, try to compile USB
support as module and unload the modules before sending your laptop to sleep
mode. There are configuration options for this in
# nano -w /etc/hibernate.conf(Make sure you have a backup of your data) # hibernate
The following section discusses the setup of suspend2 including fbsplash support for a nice graphical progress bar during suspend and resume.
The first part of the configuration is similar to the configuration of
swsusp. In case you didn't store the location of your swap partition in the
kernel config, you have to pass it as a kernel parameter with the
# rc-update add hibernate-cleanup boot
Now edit
# nano -w /etc/hibernate.conf(Make sure you have a backup of your data) # hibernate
Please configure fbsplash now if you didn't do already. To enable fbsplash
support during hibernation, the
# mkdir -p /etc/portage # echo sys-apps/suspend2-userui fbsplash >> /etc/portage/package.use # emerge suspend2-userui
The ebuild tells you to make a symlink to the theme you want to use. For
example, to use the
# ln -sfn /etc/splash/livecd-2005.1 /etc/splash/suspend2
If you don't want a black screen in the first part of the resume process, you
have to add the
# mount /boot # mkdir ~/initrd.d # cp /boot/fbsplash-emergence-1024x768 ~/initrd.d/ # cd ~/initrd.d # gunzip -c fbsplash-emergence-1024x768 | cpio -idm --quiet -H newc # rm fbsplash-emergence-1024x768 # cp /usr/sbin/suspend2ui_fbsplash sbin/ # find . | cpio --quiet --dereference -o -H newc | gzip -9 > /boot/fbsplash-suspend2-emergence-1024x768
Afterwards adjust
# suspend2ui_fbsplash -t
Afterwards open
*) # logger "ACPI action $action is not defined"
$ grep capacity /proc/acpi/battery/BAT0/info design capacity: 47520 mWh last full capacity: 41830 mWh
If the "last full capacity" differs significantly from the design capacity, your battery is probably broken. Try to claim your warranty.