Capacity and lifetime of laptop batteries have improved much over the years. On the other hand, modern processors consume exponentially more energy than older generations. Expanding displays and integration of more components lets power consumption raise even more. That's why Power Management is more important than ever. Increasing battery run time doesn't necessarily mean getting another battery. Much can be achieved applying intelligent Power Management policies.
Please notice that this guide describes Power Management for
Nearly every component can operate in different states - off, sleep, idle, active and sometimes more - 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 going in the details on making individual devices Power Management aware, make sure certain requirements are met. After controlling the 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.
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. ACPI-patches need to be included, so the plain
In kernel config, activate at least these options (kernel 2.6):
Power Management Options ---> [*] Power Management Support [ ] Software Suspend [ ] Suspend-to-Disk Support ACPI( Advanced Configuration and Power Interface ) Support ---> [*] ACPI Support [ ] Sleep States <M> AC Adapter <M> Battery <M> Button <M> Fan <M> Processor <M> Thermal Zone < > ASUS/Medion Laptop Extras < > Toshiba Laptop Extras [ ] Debug Statements CPU Frequency Scaling ---> [*] CPU Frequency scaling Default CPUFreq governor (userspace) <*> 'performance' governor <*> 'powersave' governor <*> CPU frequency table helpers <M> ACPI Processor P-States driver <*>Decide yourself whether you want to enable Software Suspend, Suspend-to-Disk and Sleep States (see below). If you own an ASUS, Medion or Toshiba laptop, enable the appropriate section.CPUFreq driver for your processor
Compile your kernel, make sure the right modules get loaded at startup and boot into your new ACPI-enabled kernel. Next run
emerge sys-apps/acpid modprobe button /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 batteryFinished. Your new runlevel
Typical ACPI events are closing the lid, changing the power source or pressing the sleep button. Every acpi event recognized by the kernel is catched by acpid which calls
#!/bin/sh set $* group=${1/\/*/} action=${1/*\//} # runlevel to use in AC mode RLVL_AC="default" # runlevel to use in battery mode RLVL_BATTERY="battery" # file indicating the AC state AC_STATE="/proc/acpi/ac_adapter/AC/state" # this string means running on AC AC_ON="on-line" # this string means running on batteries AC_OFF="off-line" function SwitchRunlevel() { if [[ "$(grep ${AC_OFF} ${AC_STATE})" != "" && "$(cat /var/lib/init.d/softlevel)" != "${RLVL_BATTERY}" ]] then logger "Switching to ${RLVL_BATTERY} runlevel" /sbin/rc ${RLVL_BATTERY} elif [[ "$(grep ${AC_ON} ${AC_STATE})" != "" && "$(cat /var/lib/init.d/softlevel)" != "${RLVL_AC}" ]] then logger "Switching to ${RLVL_AC} runlevel" /sbin/rc ${RLVL_AC} fi } case "$group" in battery) case "$action" in battery) SwitchRunlevel ;; *) logger "ACPI group battery / action $action is not defined" ;; esac ;; ac_adapter) case "$action" in ac_adapter) SwitchRunlevel ;; *) logger "ACPI group ac_adapter / action $action is not defined" ;; esac ;; *) logger "ACPI group $group / action $action is not defined" ;; esacTry it out: Plug AC in and out and watch syslog for the "Switching to AC mode" or "Switching to battery mode" messages.
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/default.sh "battery/battery"
So prepared you can activate Power Management policies for individual devices.
Decreasing CPU speed 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.
To get comfortable with the CPU frequency scaling interface to the kernel, first do some manual speed modifications. To set another CPU speed, use
cat /proc/cpuinfo | grep "cpu MHz" cd /sys/devices/system/cpu/cpu0/cpufreq/ echo -n userspace > scaling_governor echo -n 1000000 > scaling_setspeed cat /proc/cpuinfo | grep "cpu MHz"The first line informs you about the current CPU frequency. Writing "userspace" to
The above is quite nice, but not doable in daily life. Better let your system set the appropriate frequency automatically.
Two daemons will take control over CPU speed:
Which one to choose?
Let's get our hands dirty. First get
// if you want cpufreq emerge cpufreqd rc-update add cpufreqd battery // to get speedfreq emerge speedfreq rc-update add speedfreq battery // only if you prefer cpudyn emerge cpudyn rc-update add cpudyn battery
[General] pidfile=/var/run/cpufreqd.pid poll_interval=2 pm_type=acpi # Uncomment the following line to enable ACPI workaround (see cpufreqd.conf(5)) # acpi_workaround=1 verbosity=4 #(if you want a minimal logging set to 5) # Full performance [Profile] name=ac minfreq=600000 maxfreq=1400000 policy=performance # Maximum power saving [Profile] name=battery minfreq=600000 maxfreq=900000 policy=powersave # Constant frequency [Profile] name=dvd minfreq=900000 maxfreq=1100000 policy=powersave # Full performance when running on AC [Rule] name=ac_on ac=on profile=ac # Compiling should be fast if battery state is ok [Rule] name=compiling ac=off battery_interval=30-100 programs=emerge,make,gcc,cpp cpu_interval=0-100 profile=ac # watching DVD's gets sluggish with slow CPU frequency # Can also be used for games etc. [Rule] name=dvd_watching ac=off battery_interval=15-100 programs=xine,mplayer,avidemux,kaffeine,kmplayer cpu_interval=0-100 profile=dvd # If above doesn't apply, maximise power saving [Rule] name=battery_on ac=off battery_interval=0-100 cpu_interval=0-100 profile=battery
For
/etc/init.d/cpufreqd start /etc/init.d/cpudyn start /etc/init.d/speedfreq start
The last thing to check is that your new policies do a good job. An easy way to do so is monitoring the CPU speed while working with your laptop:
watch -n 1 cat /proc/cpuinfo | grep "cpu MHz"If
watch -n 1 x86info -mhzDepending on your setup, CPU speed should increase on heavy load, decrease on no activity or just stay at the same level.
As you can see in figure 1.1, the LCD display consumes the biggest part of energy (might not be the case for non-mobile CPU's). That makes it quite important not only to shut the display off when not needed, but also to reduce it's backlight if possible. Most laptops offer the possibility to control the backlight dimming.
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" [...] EndSectionThis 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
The idea is, as always, to bring the hard disk to sleep as early as possible whenever it is not needed. I'll show you two possibilities to do it. First
################################################ # DISK OPTIONS # (disabled by default) ################################################ # # Timeout to put the disk in standby mode if there was no # io during that period (in seconds) # TIMEOUT=60 # # Specified disks to spindown (comma separated devices) # DISKS=/dev/hdaThe second possibility is to use a small script and hdparm. Create
#!/sbin/runscript start() { ebegin "Activating Power Management for Hard Drives" hdparm -q -B128 -q -S12 /dev/hda eend $? } stop () { ebegin "Deactivating Power Management for Hard Drives" hdparm -q -B192 -q -S0 /dev/hda eend $? } # vim:ts=4See
/sbin/depscan.sh rc-update add pm.hda battery
Andrew Mortons's kernel (or
Once your laptop-mode supporting kernel is running, you need a script for starting/stopping laptop mode. Don't forget to add it to your battery runlevel.
mkdir -p /etc/portage echo "~app-laptop/laptop-mode-20040403 ~x86" >> /etc/portage/package.keywords emerge laptop-mode rc-update add laptop-mode battery
Besides putting your disk to sleep state as early as possible, it is a good idea to minimize disk accesses. Have a look at processes that write to your disk frequently - the syslogd is a good candidate. You probably don't want to shut it down completely, but it's possible to modify the config file so that "unnecessary" things don't get logged and thus don't create disk traffic. Cups writes to disk periodically, so consider shutting it down and only enable it manually when needed.
rc-update del cupsd batteryAnother 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.
none /tmp tmpfs size=32m 0 0
Wireless LAN cards consume quite a few energy. Put them in Power Management mode in analogy to the pm.hda script.
#!/sbin/runscript start() { ebegin "Activating Power Management for Wireless LAN" iwconfig wlan0 power on power max period 3 eend $? } stop () { ebegin "Deactivating Power Management for Wireless LAN" iwconfig wlan0 power off eend $? } # vim:ts=4Starting this script will put wlan0 in Power Management mode, going to sleep at the latest three seconds after no traffic. Save it as
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 C3/4 sleep mode. The OS answer to this problem is the so called "USB selective suspend", which has not yet been implemented in the kernel. USB selective suspend only allows bus accesses in case the device is in use. The cruel workaround until it's implemented is as following: Compile USB support and devices as modules and remove them via a script while they are not in use (e.g. when closing the lid).
ACPI defines different sleep states. The more important ones are
The ACPI support for these sleep states is marked as experimental for good reason. APM sleep states seem to be more stable, however you can't use APM and ACPI together.
If this confused you, have a look at a
The kernel part for this is as following:
Power Management Options ---> // sleep and standby ACPI( Advanced Configuration and Power Interface ) Support ---> [*] ACPI Support [*] Sleep States // hibernate with swsusp [*] Software Suspend (EXPERIMENTAL) // hibernate with swsusp2 Software Suspend 2 --- Image Storage (you need at least one writer) [*] Swap Writer --- Page Transformers [*] LZF image compression (/dev/"your-swap-here") Default resume device name // hibernate with Suspend-to-Disk [*] Suspend-to-Disk Suport (/dev/"your-swap-here") Default resume partitionCompile your kernel with the appropriate options enabled and issue
To put your system in one of the sleep states, use
// kernel 2.4 series echo 1 > /proc/acpi/sleep // standby echo 3 > /proc/acpi/sleep // sleep // kernel 2.6 series echo -n standby > /sys/power/state // standby echo -n mem > /sys/power/state // sleep // swsusp echo 4 > /proc/acpi/sleep // hibernate // Suspend-to-Disk echo -n disk > /sys/power/state // hibernate // swsusp2 echo > /proc/swsusp/activate
emerge swsusp2Edit
$ grep capacity /proc/acpi/battery/BAT0/info design capacity: 47520 mWh last full capacity: 41830 mWhIf the "last full capacity" differs significantly from the design capacity, your battery is probably broken. Try to claim your warranty.