Difference between revisions of "How to reduce power consumption"

From ThinkWiki
Jump to: navigation, search
m (Useful sysctls)
m (Bluetooth)
Line 323: Line 323:
  
 
==Bluetooth==
 
==Bluetooth==
When you don't need bluetooth, disable it. Because of it's radio,  
+
When you don't need bluetooth, disable it. Because of its radio,  
 
bluetooth is not power friendly.
 
bluetooth is not power friendly.
  

Revision as of 03:38, 9 October 2007

Reducing system power consumption will extend battery life, reduce system temperature and (on some models) reduce system fan noise. Power consumption can be greatly improved from a stock distribution configuration to a fine tuned system. The general rules are :

  • Unload drivers for unused devices (ie. USB 1.1, Yenta/PCMCIA, Wireless, IRDA, Bluetooth, ...)
  • Reduce polling on devices (drives, USB subsystem, nvram, ...)
  • Reduce hard drive activity
  • Reduce LCD brightness to the minimum you can stand
  • Reduce CPU wakeups, so it can stay longer in deep power saving c-states

Tools

Arjan van de Ven's PowerTOP utility is a gold mine to improve energy efficiency. This tool helps to easily detect the top power offenders, both userland and kernel modules, and sometime suggest fixes accordingly. PowerTOP users collected some tips & tricks and an informative faq.

Alternatively (or complementary) to PowerTOP, running strace -p $(pidof yourapp) for all your favourite or background running applications while they are expected to be idle, will show the misbehaviours.

Beside CPU wakeups, disks spins are also power angry. To detect what make your disk spinning,

sysctl vm.block_dump=1

will list all applications causing disks wakeups on the kernel's dmesg. Other useful tools for this purpose are blktrace, iostat and lm-profiler (from laptop-mode-tools suite).

BIOS settings

Some Thinkpad BIOS (like 2.08 BIOS on X40) offer two very lame options, with a very misleading online help (saying "Usually not needed"). That's

CPU power management: (default disabled)
PCI bus power management: (default disabled)

You should indeed enable them, else the deepest C3 and C4 ACPI C-states are disabled.

CPU

Look at:

A good thing to keep in mind is that every CPU wakeup, even if it's for a trivial light job, reduce the time the CPU stays on a deep power saving C-state (like C3 or C4). Therefore you should ensure your applications stay really idle when they meant to be idle (track shorts select timeouts in loop, etc. with powertop).

Also note that manually locking the CPU in the lowest P-state (frequency) available is not an efficient way to improve battery lifetime. This will cause the CPU to stay longer in C0 (power angry C-state) doing hard work when there is something to do, while it could have done this work faster by augmenting the CPU freq, and returned back faster to a deeper, economic, C-state and to a lower frequency (P-state). The best is to let the kernel select the appropriates CPU frequencies by itself with the help of in kernel CPU governors. Have a look at this explanation from Intel's kernel developer Arjan van de Ven.

Kernel settings and patches

General settings

The 2.6.21 kernel brought some very effective changes (like dynticks). If it's not already on your distribution and you value power efficiency, you may think about compiling it (or a more recent one) yourself.

Here are a few options (beside the ACPI and APM related one) that matter to reduce power consumption or to help diagnosing consumers:

# From PowerTOP's FAQ:
CONFIG_NO_HZ
CONFIG_HIGH_RES_TIMERS
CONFIG_HPET
CONFIG_CPU_FREQ_GOV_ONDEMAND
CONFIG_USB_SUSPEND
CONFIG_SND_AC97_POWER_SAVE
CONFIG_TIMER_STATS
CONFIG_ACPI_BATTERY
CONFIG_CPU_FREQ_STAT
# Not from the PowerTOP FAQ:
CONFIG_BLK_DEV_IO_TRACE
CONFIG_X86_ACPI_CPUFREQ
CONFIG_X86_SPEEDSTEP_CENTRINO
CONFIG_X86_SPEEDSTEP_ICH
CONFIG_X86_SPEEDSTEP_SMI
CONFIG_X86_ACPI_CPUFREQ

Those options are already in Fedora Core 7 and Ubuntu Gutsy (not Feisty) default i686 kernels. PowerTOP FAQ also suggest to disable CONFIG_IRQBALANCE et CONFIG_ACPI_DEBUG.

Also, you need to properly set APM and ACPI. Look at:

Useful Patchs

Thomas Gleixner High Resolution Timers (hrt) patchset brings many improvements, like the cpuidle work and Udo A. Steinberg and Venki Pallipadi "force enable HPET" patches (non HPET timers causes about 20-40 CPU wakeups/second, but HPET is often hidden by the BIOS due to Windows XP deficiencies). See http://www.tglx.de/projects/hrtimers/

Kristen Carlson Accardi from Intel has a patchset to turn on "Aggressive Link Power Management" (ALPM) for the AHCI driver (for SATA bus). See: http://www.kernel.org/pub/linux/kernel/people/kristen/patches/SATA/alpm/

The HDAPS disk protection systems can reduce battery life. Matthew Garrett provides a patch that prevents hdaps kernel module to generate interrupts when this feature isn't used.

Useful sysctls

The meaning of those settings is explained case by case on the relevant sections of this document. But for convenience sake, we group them here too.

Note that the "ondemand" scaling governor is recommended by Intel developers for energy efficiency: it's expected to be more efficient than the "powersave" governor, or than userspace daemons (like cpufreq-utils, cpufreqd, powernowd...). Look here, here, or here for a kernel developer explanation about "ondemand" being better on modern Intel CPUs.

The "link_power_management_policy" tunable won't be available unless you run Kirsten patchset, have an Intel AHCI compatible chipset, and use SATA drives.

echo 5 > /proc/sys/vm/laptop_mode
echo 0 > /proc/sys/kernel/nmi_watchdog
echo Y > /sys/module/snd_ac97_codec/parameters/power_save
echo 1 > /sys/devices/system/cpu/sched_mc_power_savings
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
echo min_power > /sys/class/scsi_host/host1/link_power_management_policy
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

If you're running a kernel older than 2.6.22 do this. Not needed for kernels 2.6.22 onward:

cd /sys/devices/system/cpu/cpu0/cpufreq
cat ondemand/sampling_rate_max > ondemand/sampling_rate

ATA drives

Hard drives and CDRom drives spinning is very costly. To improve battery lifetime, you should reduce disks access (or devices polling) the more you can.

Hard Drives

The files access time update, while mandated by POSIX, is causing lots of disks access; even accessing files on disk cache may wake the ATA or USB bus. If you don't use this feature, disable it via:

mount -o remount,noatime /  # and so on for all mounted fs

The laptop_mode reduce disk usage by regrouping writes. You should enable it, at least while on battery. See Laptop-mode for more details:

echo 5 > /proc/sys/vm/laptop_mode

The default kernel dirty page writeback frequency is very conservative. On a laptop running on battery, one might find more appropriate to reduce it:

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

Some power saving hard drives features can be activated with hdparm. For more details look at How to make use of Power Management features :

hdparm -B 1 -S 12 /dev/sda # and/or any other disk device

Optical drive

The optical drive is reported to consume power even when not accessed. See

The hald daemon polling tends to maintain the ATA buses out of power saving modes, and to wakeup CDROM drive. If you have a recent hald version, you can stop this polling when on battery:

hal-disable-polling /dev/scd0 # or whatever your CD drive is

If your hald is not recent enough, consider stopping it on battery.

LCD Backlight/Brightness

The LCD backlight is one of the very major power drain. Reducing brightness to the lowest readable level will save a lot of battery lifetime. Also, don't forget to configure your screen saver to shutdown the screen backlight (rather than displaying some eye candy), when no activity for a few minutes.

You can also let the system automatically reduce brightness after a period of inactivity.

If you're choosing your Thinkpad laptop model, keep in mind that the screen size affect the battery time greatly: more power needed for larger screens.

Graphic controllers

All xorg Thinkpad graphics chipsets drivers (ati, radeon, fglrx, i810) have the same bug causing very frequent CPU wakeups when DRI is activated, even when you don't use any 3D application. This problem is partly fixed on xorg git tree but not released as of xorg 7.2. If you value more battery than 3D, you should disable DRI: put this on the /etc/X11/xorg.conf "Device" of you graphic controller:

Option          "NoDRI"

Also be sure that DPMS is working: grep DPMS /var/log/Xorg.0.log should output "DPMS enabled". If not, put Option "DPMS" in your config.

On recent xrandr/xorg versions, you can disable the TV output when you're not using it (it's known to consume power) :

xrandr --output TV -off

When you don't have an external monitor plugged, disable CRT and DVI output (for some, this can make a difference in power usage) :

echo crt_disable > /proc/acpi/ibm/video
echo dvi_disable > /proc/acpi/ibm/video

Some drivers have specials power saving mode, and/or allows underclocking the GPU. See also:

USB Subsystem

The kernel support an efficient USB 2.0 power saving feature if you enabled CONFIG_USB_SUSPEND. This may not trigger in when you have an USB device plugged (and beside, USB devices tends to suck power on their own), so avoid using such devices when on battery.

USB 1.1 is worst. It needs polling the bus frequently, hence can't really go in a low power mode when you enabled it, even if you don't have any device plugged. You'd better remove it when you don't use a 1.1 device:

rmmod uhci_hcd

If you don't intend to use any USB 1.1 device (unfortunately, the built-in bluetooth and fingerprint-reader are USB 1.1 devices), the USB 1.1 support can also be totaly avoided. On Debian and derivatives, just do:

echo "blacklist uhci_hcd" >> /etc/modprobe.d/blacklist

Sound

ALSA has a power saving feature that should be enabled on your kernel (CONFIG_SND_AC97_POWER_SAVE). Note that this low power mode won't trigger in unless you muted all sound inputs (micro, line in etc.). This feature has to be activated with:

amixer set Line mute nocap
amixer set Mic mute nocap
echo Y > /sys/module/snd_ac97_codec/parameters/power_save

More radical: you can unload all sound related modules when you are on battery, or mute the sound system (echo mute > /proc/acpi/ibm/volume).

Seel also How to enable AC97 power saving.

Wireless Interface

Wireless network consume a lot of power. To save power on ipw adapters, you can kill the Wi-Fi radio when it's not in use:

echo 1 > /sys/bus/pci/drivers/ipw*/*/rf_kill

If you need Wi-Fi, you can also reduce power consumption (at the price of performances) by activating the power saving modes:

iwpriv eth1 set_power 5

Reducing beacon intervals on your Access Point to 1 per second will also reduce network card interrupts, therefore power savings. This shouldn't have negatives side effects.

See also, to activate power saving on the wireless network card:

Ethernet Controler

If you don't use Wake-on-LAN, you should disable it for your network card, because it sucks a lot of power:

ethtool -s eth0 wol d

If you can, try to reduce useless network activity on your ethernet segment, coming to your NIC (ie. uneeded broadcasts), those cause interrupts and CPU wakeups.

Bluetooth

When you don't need bluetooth, disable it. Because of its radio, bluetooth is not power friendly.

hciconfig hci0 down ; rmmod hci_usb
echo disable > /proc/acpi/ibm/bluetooth

Modem

When was the last time you used your analog modem? If you can't remember, you probably just don't need it. If it is on a separate module in your laptop, simply remove it. Store it in a ESD safe place (like the bag in which your last addon card or hard drive was packed), in case you should need it again. This won't save you a lot of power and weight, but why carry something around you never use.

System Fans

Fans consumes power when running, so you may look at the ACPI fan control script.

Misbehaving Userland

You should avoid using Beagle, Compiz, Beryl, XMMS, gnome-power-manager and Evolution while on battery. Look at the PowerTOP's known problems list.

Deactivate desktop animations (blinking cursor on the terms, animated wallpapers, ...): they cause regular X (therefore kernel and CPU) wakeups.

In short, while on battery, you should stop all applications that don't really stay idle when you're not using them. This means applications that:

  • Wakes up the CPU too often (by polling something, because of too short select() timeouts, ...)
  • Access the disks at regular intervals
  • Access an hardware bus (USB, ATA, ...) at regular intervals

To find those offenders run:

  • strace -p $(pidof yourapp) # for all your running applications
  • powertop
  • sysctl vm.block_dump=1 # and look at dmesg
  • ps aux | awk '{print$10,$11}' | sort -n # will list all running softs sorted by used cpu time

Please, don't forget to fill a bug when you find such a misbehaving software.

NOTE!
Not all software is evil, buggy or badly written. Some produce regular activity because they have to and the purpose of the software is doing it like this. Just think twice before fill bugs like this.

See Also

External resources