power-management-in-Ubuntu

Differences between revisions 6 and 26 (spanning 20 versions)
Revision 6 as of 2007-05-20 13:48:41
Size: 3875
Editor: a81-197-130-222
Comment:
Revision 26 as of 2008-08-06 16:22:27
Size: 9636
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
 * '''Packages affected''':   * '''Packages affected''':
Line 15: Line 15:
 * Be able to watch 3-4 hours of DVD on a flight without an extended battery  * Jane wants to be able to watch a couple of DVD movies on a cross-Atlantic flight
 * Robert wants to be able to attend one full day of a conference taking notes on his laptop without having to carry a power supply and searching for power sockets.
Line 18: Line 19:
 * Any package in the default install which can cause excessive battery usage: accessing the harddrive, polling for WLAN AP, keeps HW awake, etc. === Hardy ===
 * Tickless on x64
 * Use ''cpuidle'' infrastructure to idle processors
 * Develop a library that allows timer wake ups to be synchronized for non-real time apps. Get KDE and Gnome communities to use these libraries e.g. gtimeout_at_secs in glib, deferred timers in kernel,
Line 22: Line 26:
 * Enable a tickless (dynamic tick) kernel to allow processor to stay sleep for longer periods
 * Profile userspace with a ''powertop'' from Intel that lists offending processes that poll or set '''frequent''' timers and get them fixed
 * Develop a library that allows timer wake ups to be synchronized for non-real time apps. Get KDE and Gnome communities to use these libraries
 * Profile userspace for unexpected block I/O accesses while idling. This wakes up the block devices and ATA buses from power saving modes, but PowerTOP doesn't track I/O. Tools : sysctl vm.block_dump=1 (then dmesg will show every block access), blktrace, systemtap.
 * Profile userspace with ''powertop'' from Intel (www.linuxpowertop.org) that lists offending processes that poll or set '''frequent''' timers and get them fixed
 * Includes patches from powertop website that fix application issues
 * Fix packages in the default install which can cause excessive battery usage: accessing the harddrive, polling for WLAN AP, keeps HW awake, etc.
Line 30: Line 34:
 * We get the following for free with 2.6.24:
  * Tickless on x64
  * cpuidle
  * Force-enable HPET patches are merged and on by default for documented chipsets (even when hidden by BIOS), present but off for some undocumented chipsets
  * SATA ALPM (AHCI link power management) and AN (asynchronous notifications)
  * Intel HDA audio powersaving rework
  * USB autosuspend for a few devices, like HID
  * USB URB statistics exported to userland (Sarah Sharp patches), exploited in powertop >= 1.9
Line 31: Line 43:
From https://wiki.ubuntu.com/ReducedPowerUsage so that we don't lose these optimizations.

'''acpi scripts'''

'''/etc/acpi/ac.d/10-vm_settings.sh'''
{{{
#!/bin/bash
# Tweak virtual memory for running on AC.

echo 60 > /proc/sys/vm/swappiness
echo 3000 > /proc/sys/vm/dirty_expire_centisecs
echo 500 > /proc/sys/vm/dirty_writeback_centisecs
echo 10 > /proc/sys/vm/dirty_background_ratio
echo 40 > /proc/sys/vm/dirty_ratio}}}

'''/etc/acpi/battery.d/10-vm_settings.sh'''
{{{
#!/bin/bash
# Tweak virtual memory to conserve power when running on batteries.

echo 10 > /proc/sys/vm/swappiness
echo 0 > /proc/sys/vm/dirty_expire_centisecs
echo 0 > /proc/sys/vm/dirty_writeback_centisecs
echo 60 > /proc/sys/vm/dirty_background_ratio
echo 95 > /proc/sys/vm/dirty_ratio}}}

'''/etc/acpi/ac.d/20-wireless_power.sh'''
{{{
#!/bin/bash
# Change the wireless power mode to AC.
# This works for ipw3945, not sure about other chipsets
# Make sure eth1 is your wireless.

/sbin/iwpriv eth1 set_power 6}}}

'''/etc/acpi/battery.d/20-wireless_power.sh'''
{{{
#!/bin/bash
# Change the wireless power mode to Battery.

/sbin/iwpriv eth1 set_power 7}}}


'''video card low power mode'''

The following is a nasty hack for the fglrx driver. It sets the video card to low power mode on boot.

https://help.ubuntu.com/community/BinaryDriverHowto/Fglrx_lowpower

The need for this hack points to the usefulness there would be of an acpi event generated upon user login/display activation. (perhaps this event already exists). The event could then trigger an acpi script which sets the video card to low power mode.
 * Need to check KDE libs for deferred timer implementation
Line 85: Line 47:
 * laptop-mode
 * take care of these patches by Intel too!!! [http://www.linuxpowertop.org/known.php #patches-by-intel]
 * laptop-mode (should enable patented laptop-drive-killing mode by default).
 * take care of these patches by Intel too!!! [[http://www.linuxpowertop.org/known.php|#patches-by-intel]] <- yes, all of those should be checked that we either ship recent enough upstream version or add a patch
 * evaluate the best frequency scaling method (which userspace governor is best presently, is the recently reworked in kernel cpuidle/ondemand better than an userland daemon, ...)
 * Start a whitelist for USB devices that support autosuspend (for already supported in kernel, grep supports_autosuspend in kernel sources)
 * AHCI link level PM to be pulled in - will lose hotswap support on desktop and server.
 * detect and disable hardware when not needed (ie. NetworkManager could be made to kill wireless radio when running on ethernet, we may disable Wake-on-Lan by default, ensure xorg 7.3 detects and disable TV-out or CRT outputs when no external monitor is plugged, etc.)
 * ensure other (non-CPU) hardware power saving modes are really activated when on battery (like AC97's /sys/module/snd_ac97_codec/parameters/power_save and HDA codec, hard drives APM and spindown timeouts, SATA ALPM, wireless powersaving mode, USB autosuspend, fglrx, ...)
 * Pulse audio (better-than-esd(tm) "drop-in" replacement with extensions). Allows multi-application access at a high-level than direct ALSA
 * Ensure HPET (High Precision Event Timer) is enabled on platforms that support it.
 * NetworkManager general issues:
  * NetworkManager has aggressive scanning.
  * NetworkManager keeps eth0 up even when no cable is plugged in. Needs syncing with kernel about up/down states for the interface.
  * If NIC disappears, should accept that rather than going AWOL.
  * Switch to NM 0.7 as 0.6 (Ubuntu is shipping) has been dropped by upstream.
  * Scan on event (screen unlock, icon-click) rather than on timer (which is too slow for user-experience and too fast for good power saving).
 * MID: Nokia routes all network connection through a connection tracker. So they can disable network interface and when an application tries to access the network, they can start a new connection quickly. It needs to be reimplemented in open source.
  * Netfilter connection tracking (better than LD_PRELOAD grabbing of `connect()`).
  * Investigate `dummy` network interface used with PPP bring up.

=== Notes for benchmarking ===

 * Remounting an `ext3` filesystem as `ext2` will attribute the block I/O requests directly to a process rather than to `kjournald`.

== References and See also ==
 * ReducedPowerUsage
 * EnableLaptopPowerFeatures
 * [[MobileAndEmbedded/PowerPolicyManagement]]
 * Note http://lwn.net/Articles/240253/ and the tips for "Getting more from tickless", regarding usage of deferable timers and hardware timers. Could the deferrable timers patch put in Ubuntu?
 * Red Hat hackers and Arjan van de Ven have set up a "Why userspace sucks (wakeups)" bugzilla entry to follow and fix power related bugs on Fedora. We should ensure we've integrated the relevant fixes from there. https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=213042
 * On the thinkpad thinkwiki : http://www.thinkwiki.org/wiki/How_to_reduce_power_consumption
 * Intel LessWatts site : http://www.lesswatts.org/
  * Intel PowerTOP : http://www.linuxpowertop.org/
 * OLS talks bout frequency scaling governors, cpuidle frameworks etc. : http://kernel.org/pub/linux/kernel/people/lenb/acpi/doc/OLS2006-ondemand-presentation.pdf , https://ols2006.108.redhat.com/2007/Reprints/siddha-Reprint.pdf , https://ols2006.108.redhat.com/2007/Reprints/pallipadi-Reprint.pdf
 * http://www.phoronix.com/scan.php?page=article&item=880&num=2 Ubuntu 7.10 consumes more than Fedora 8 and Windows XP and Vista
 * http://phc.athousandnights.de/ Linux Processor Hardware Control is a patch for the Linux kernel that provides a userspace interface to control the core voltage of a computer processor(s).
Line 90: Line 85:
== FAQs ==
  * Enable "usbcore.autosuspend=1" by default? Done! Drivers need to enable it - whitelisting could fix it.
 * Some important aspects (mostly: available and supported hardware power saving features) has been somehow tested, but may need a larger scale testing before we can confidently choose to use or not use them by default in a released Ubuntu version. So it'd make sense to have this soon enabled during Gutsy+1 testing phase. On the other hand, some of those features had just been merged in 2.6.24-rc1, therefore may not be released soon enough (if we wait for 2.6.24 official release). Some power saving related decisions to be made ASAP:
  * Enable Alsa's AC97 and HDA codec power saving features on by default?
  * Enable laptop mode by default when running on battery? (ie. are the suspend/resume problems been fixed as of now (let alone the "hdparm -B" thinggy) ? or would more exposure help to finally fix them ?).
  * Enable "hpet=force" by default? Would enable hpet for supported but undocumented hpet timers, ie. on ICH4, VT8235/8237, nVidia chipsets. 2.6.24 upstream only enables it officially documented (ICH5 upwards) platforms, but it would be also supported on eg. the mentioned chipsets in 2.6.24.
  * Enable Intel's "ondemand" kernel scaling governor by default? Done (Why is the CPU still attributed to the setter---`powernowd.sh`).
  * Disable "aggressive scanning when not associated on pre-mac80211 wireless drivers"? (as per Intel's [[http://www.lesswatts.org/tips/wireless.php|lesswatts]] recommendation)?
  * Running Ubuntu desktop is down to ~40 wake ups per second, which is acceptable for the moment.
    * This really depends on the hardware and drivers (and setup, launched softwares, ...), and could still be much more than 40 for many users.
    * Uhci_hcd still causes 100 wakeups per second on many computers, effectively disabling deeper sleep states
    * Vertical refresh causes eg. 60 wakeups per second on many chipsets, also effectively disabling deeper sleep states. Intel is going to be fixed, but should be made sure it makes to hardy (drm kernel driver). ATI drm driver has a vblank branch but it's not merged yet, should be considered for hardy. Nouveau?
  * kernel's round_jiffies and gnome's g_timeout_add_seconds() already round to next plain second (so gnome and kernel grouped timers are already in sync)
Line 91: Line 100:
CategorySpec CategorySpec CategoryLaptop

Please check the status of this specification in Launchpad before editing it. If it is Approved, contact the Assignee or another knowledgeable person before making changes.

Summary

The Ubuntu Mobile Distribution will run on battery-powered devices. This makes power management critical. This specification lists the things that need to be addressed.

Rationale

Currently, Ubuntu is popular on laptops. With the increasing interest in mobile computing with the advent of Nokia´s internet tablets, Microsoft-Intel UMPCs and Intel´s MID initiative, battery life is becoming increasingly important. To be successful on these mobile platforms, significant work needs to be addressed toward increasing battery life. This work spans the whole stack from kernel to user-space.

Use Cases

  • Jane wants to be able to watch a couple of DVD movies on a cross-Atlantic flight
  • Robert wants to be able to attend one full day of a conference taking notes on his laptop without having to carry a power supply and searching for power sockets.

Scope

Hardy

  • Tickless on x64
  • Use cpuidle infrastructure to idle processors

  • Develop a library that allows timer wake ups to be synchronized for non-real time apps. Get KDE and Gnome communities to use these libraries e.g. gtimeout_at_secs in glib, deferred timers in kernel,
  • Fix drivers to automatically put hardware to increasing levels of power save states based on multiple timeouts
  • Fix bus drivers to automatically put buses into power save modes when no devices on the bus are active e.g. pci, usb, pcmcia
  • Improve Linux driver model to allow control power control of individual devices to allow userspace to override the default policy of the driver
  • Profile userspace for unexpected block I/O accesses while idling. This wakes up the block devices and ATA buses from power saving modes, but PowerTOP doesn't track I/O. Tools : sysctl vm.block_dump=1 (then dmesg will show every block access), blktrace, systemtap.
  • Profile userspace with powertop from Intel (www.linuxpowertop.org) that lists offending processes that poll or set frequent timers and get them fixed

  • Includes patches from powertop website that fix application issues
  • Fix packages in the default install which can cause excessive battery usage: accessing the harddrive, polling for WLAN AP, keeps HW awake, etc.

Design

Implementation

  • We get the following for free with 2.6.24:
    • Tickless on x64
    • cpuidle
    • Force-enable HPET patches are merged and on by default for documented chipsets (even when hidden by BIOS), present but off for some undocumented chipsets
    • SATA ALPM (AHCI link power management) and AN (asynchronous notifications)
    • Intel HDA audio powersaving rework
    • USB autosuspend for a few devices, like HID
    • USB URB statistics exported to userland (Sarah Sharp patches), exploited in powertop >= 1.9

  • Need to check KDE libs for deferred timer implementation

Outstanding Issues

  • laptop-mode (should enable patented laptop-drive-killing mode by default).
  • take care of these patches by Intel too!!! #patches-by-intel <- yes, all of those should be checked that we either ship recent enough upstream version or add a patch

  • evaluate the best frequency scaling method (which userspace governor is best presently, is the recently reworked in kernel cpuidle/ondemand better than an userland daemon, ...)
  • Start a whitelist for USB devices that support autosuspend (for already supported in kernel, grep supports_autosuspend in kernel sources)
  • AHCI link level PM to be pulled in - will lose hotswap support on desktop and server.
  • detect and disable hardware when not needed (ie. NetworkManager could be made to kill wireless radio when running on ethernet, we may disable Wake-on-Lan by default, ensure xorg 7.3 detects and disable TV-out or CRT outputs when no external monitor is plugged, etc.)

  • ensure other (non-CPU) hardware power saving modes are really activated when on battery (like AC97's /sys/module/snd_ac97_codec/parameters/power_save and HDA codec, hard drives APM and spindown timeouts, SATA ALPM, wireless powersaving mode, USB autosuspend, fglrx, ...)
  • Pulse audio (better-than-esd(tm) "drop-in" replacement with extensions). Allows multi-application access at a high-level than direct ALSA
  • Ensure HPET (High Precision Event Timer) is enabled on platforms that support it.
  • NetworkManager general issues:

    • NetworkManager has aggressive scanning.

    • NetworkManager keeps eth0 up even when no cable is plugged in. Needs syncing with kernel about up/down states for the interface.

    • If NIC disappears, should accept that rather than going AWOL.
    • Switch to NM 0.7 as 0.6 (Ubuntu is shipping) has been dropped by upstream.
    • Scan on event (screen unlock, icon-click) rather than on timer (which is too slow for user-experience and too fast for good power saving).
  • MID: Nokia routes all network connection through a connection tracker. So they can disable network interface and when an application tries to access the network, they can start a new connection quickly. It needs to be reimplemented in open source.
    • Netfilter connection tracking (better than LD_PRELOAD grabbing of connect()).

    • Investigate dummy network interface used with PPP bring up.

Notes for benchmarking

  • Remounting an ext3 filesystem as ext2 will attribute the block I/O requests directly to a process rather than to kjournald.

References and See also

BoF agenda and discussion

FAQs

  • Enable "usbcore.autosuspend=1" by default? Done! Drivers need to enable it - whitelisting could fix it.
  • Some important aspects (mostly: available and supported hardware power saving features) has been somehow tested, but may need a larger scale testing before we can confidently choose to use or not use them by default in a released Ubuntu version. So it'd make sense to have this soon enabled during Gutsy+1 testing phase. On the other hand, some of those features had just been merged in 2.6.24-rc1, therefore may not be released soon enough (if we wait for 2.6.24 official release). Some power saving related decisions to be made ASAP:
    • Enable Alsa's AC97 and HDA codec power saving features on by default?
    • Enable laptop mode by default when running on battery? (ie. are the suspend/resume problems been fixed as of now (let alone the "hdparm -B" thinggy) ? or would more exposure help to finally fix them ?).
    • Enable "hpet=force" by default? Would enable hpet for supported but undocumented hpet timers, ie. on ICH4, VT8235/8237, nVidia chipsets. 2.6.24 upstream only enables it officially documented (ICH5 upwards) platforms, but it would be also supported on eg. the mentioned chipsets in 2.6.24.
    • Enable Intel's "ondemand" kernel scaling governor by default? Done (Why is the CPU still attributed to the setter---powernowd.sh).

    • Disable "aggressive scanning when not associated on pre-mac80211 wireless drivers"? (as per Intel's lesswatts recommendation)?

    • Running Ubuntu desktop is down to ~40 wake ups per second, which is acceptable for the moment.
      • This really depends on the hardware and drivers (and setup, launched softwares, ...), and could still be much more than 40 for many users.
      • Uhci_hcd still causes 100 wakeups per second on many computers, effectively disabling deeper sleep states
      • Vertical refresh causes eg. 60 wakeups per second on many chipsets, also effectively disabling deeper sleep states. Intel is going to be fixed, but should be made sure it makes to hardy (drm kernel driver). ATI drm driver has a vblank branch but it's not merged yet, should be considered for hardy. Nouveau?
    • kernel's round_jiffies and gnome's g_timeout_add_seconds() already round to next plain second (so gnome and kernel grouped timers are already in sync)


CategorySpec CategoryLaptop

power-management-in-Ubuntu (last edited 2008-08-06 16:22:27 by localhost)