PowerManagement

Differences between revisions 1 and 34 (spanning 33 versions)
Revision 1 as of 2008-06-27 10:42:10
Size: 3317
Editor: szgt-d9b8e673
Comment: The different parts that make up the power management
Revision 34 as of 2009-03-25 16:44:50
Size: 8243
Editor: 208-151-246-43
Comment: wikilink reference to Hotkeys/Architecture
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; background-repeat: no-repeat; background-position: 98% 0.5ex; margin: 0 0 1em 1em; padding: 0.5em;"><<TableOfContents>>||

= Three tasks involved =

 1. Handling of hardware events
 1. Power state switching
 1. Letting disks idle

Though power management will deal with these, their objective does not solely lie in power management.

= Power management packages =
Line 8: Line 20:
They make those kind of hard events like the end of battery power or the pressing of the suspend button available to our software world. They make those kind of "hard" events like the end of battery power or the pressing of the suspend or other (laptop) buttons available to our software world.
Line 10: Line 22:
Then there are '''event manager deamons apmd and acpid''' Then there are '''event manager daemons apmd and acpid'''
Line 12: Line 24:
They provide means to execute commands on these external events. They run the scripts they find in their config directory tree unter /etc/acpi, or /etc/apm respectively. They provide means to execute commands on these external events. They run the scripts they find in their config directory tree under /etc/acpi, or /etc/apm respectively.
Line 14: Line 26:
The '''package acpi-support''' provides a set of such scripts under /etc/acpi that deal with handling special acpi keys on laptops. The package '''acpi-support''' provides a set of such scripts under /etc/acpi that deal with handling special acpi buttons on laptops.
Line 16: Line 28:
The package '''pm-tools''' provides the pm-action, pm-hibernate, pm-suspend and pm-suspend-hybrid commands. They allow to trigger hard power management events by software. The pm-tools also provide script directories to hook-in other software on their execution. The package '''pm-utils''' provides the pm-action, pm-hibernate, pm-suspend and pm-suspend-hybrid commands. They allow to trigger hard power management events by software. The pm-tools also provide script directories to hook-in other software when switching power (saving) states.

The '''gnome-power-manager''' is a program with a graphical user interface that subscribes itself to power events and acts on them. It shows you the battery status on laptops and dims down the screen if on battery for example. It will also shutdown or hibernate the computer after some idle time or before the battery runs out, if a user is logged in.

'''Disk idleing'''
 
A separate task is allowing harddisks to idle, so they can be parked and spun-down for long enough periods of time. This is done by a package that is a little bit misleadingly called '''laptop-mode-tools''' but not "disk-idle". Disk idleing has to deal with things like reading ahead and postponing disk activity. The program got its name from a kernel feature that is called laptop_mode and allows Linux to chunk up writes to filesystems and not write in between. But to really let a disk idle one has to manage other parts of the system that are relevant to letting disks idle also, like drive parameters, mount options, filesystem settings, cache sizes, sync logging programs etc. "laptop_mode" will do all that.

Disk idleing is commonly needed, thus laptop-mode enabled, when laptops operate on batteries to extend the battery times. But for example in vehicles with external power supply disk idleing may be needed even on AC. Not necessarily to leave the disk spun down, but to leave the heads parked for shock protection.

Disk spin-down and head parking should not be activated without controlled disk idleing. The regular uncoordinated logging or journaling activity may spin up the disks back up almost immediately after spinning down and lead to excessive load cycling.
Line 19: Line 41:
= Power (saving) states =
Line 20: Line 43:
The Common '''power (saving) states''' are awake, standby, suspend and hibernate. The Common power (saving) states are awake, standby, suspend and hibernate.
Line 28: Line 51:
During '''suspend''' however the CPU ist allways stoped. In modern PCs even all other components exept the RAM memory can be turned off. The RAM will hold the state. During '''suspend''' however the CPU is always stopped. In modern PCs even all other components except the RAM memory can be turned off. The RAM will hold the state.
Line 32: Line 55:
= Architecture =

This diagram shows how the kernel, hal, hal-info, pm-utils, and gnome-power-manager are plumbed together:

  {{attachment:power-management.png}}

([[attachment:power-management.dot|dot source]])

Please see [[Hotkeys/Architecture]] about the details of "Hotkey handling".

= How to get disks idleing correctly (without excessive load cycling) =

== 8.10 (Intrepid) ==

Many of the previous issues have been addressed in Intrepid. All you need to do is:
 * "ENABLE_LAPTOP_MODE=true" in /etc/default/laptop-mode (Bug Bug:244838 fixed in acpi-support 0.111?)

== 8.04 (Hardy) ==

Unfortunately, ubuntu has mangled disk idleing into event handling and power state switching in the past. And this did not deliver idle disks but break disk idleing (laptop-mode) features by leaving undefined (factory default) apm settings in place.

To correct disk-idleing in Ubuntu Hardy you need to adjust the following:

 * Enable CONTROL_HD_POWERMGMT=1 in /etc/laptop-mode/laptop-mode.conf
  (Bug Bug:244832 missing hdparm -B setting during boot (fixed in intrepid Bug:250935))

 * ENABLE_LAPTOP_MODE=true in /etc/default/acpi-support (another package's conffile), even if you do not ENABLE_LAPTOP_MODE_ON_BATTERY or _ON_AC in laptop-mode.conf. So that laptop-mode-tools can control the harddisk power management settings.
  (Bug:244838 laptop-mode needs to be activated in two places)

 * Delete or #comment the four $HDPARM blocks (for...done) in /etc/acpi/power.sh and change the two $LAPTOP_MODE start/stop lines to "$LAPTOP_MODE auto"
  (Bug:244836 /etc/acpi/power.sh overrides user settings (fixed in intrepid Bug:250938))<<BR>>
  (Bug:244831 /etc/acpi/power.sh overrides user scripts (fixed in intrepid Bug:250938))<<BR>>
  (Bug:244844 Adapt laptop-mode-tools invocation to ubuntu's acpi-support / pm-utils packages (fixed in intrepid Bug:250935))

 * Create an empty "laptop-tools" file (touch /etc/pm/power.d/laptop-tools) to override /usr/lib/pm-utils/power.d/laptop-tools.
  (Bug:239419 pm-utils has laptop-tools script which conflicts with laptop-mode-tools (not so in intrepid))

With the above changes hardy (ubuntu 8.04) will set the hdparm -B value to 254 when booting and thus override inadequately aggressive hardware defaults that cause load cycling. Not all harddisks will stop head parking with value 255 and some may even overheat. (hdparm -B255 turns off the disk's apm feature, but this only turns off the spin down timer in many disks and doesn't increase the head parking timer at all, which is the issue here.)

Other issues/adjustuments are related to have the hdparm -B value also reset after a suspend/resume cycle (fixed in intrepid Bug:250935).
  Bug:244833 missing hdparm -B setting during resume<<BR>>
  Bug:244839 /etc/acpi/start.d and resume.d scripts are not run.<<BR>>
  Bug:244844 Adapt laptop-mode-tools invocation to ubuntu's acpi-support / pm-tools packages
  also:<<BR>>
  Bug:238555 pm-utils doesn't reload hdparm.conf after a suspend

= Comments =
Line 34: Line 104:
The '''gnome-power-manager''' is a program with a graphical user interface that subscribes itself to power events and acts on them. It shows you the battery status on laptops and dimms down the screen if on battery for example. But it will also shutdown or hibernate the computer after some idle time or before the battery runns out. I searched around and it seems I am not the only one with this problem and unfortunately, I could not find a good answer in the forums. Consequently, could someone explain in a little more detail how one would go about creating "a bogus /etc/pm/power.d/laptop-tools script to override /usr/lib/pm-utils/power.d/laptop-tools." Does it entail just making a new file the in the directory or is there actual code that has to go in the file. Thanks - Ali
 * Ali, just copy /usr/lib/pm-utils/power.d/laptop-tools to /etc/pm/power.d/laptop-tools and insert the code near line 26 following guidelines in Bug:239419
  * Actually, to disabe this yet another "laptop-tools" script from pm-utils you just need to create an empty file (touch /etc/pm/power.d/laptop-tools). (Info also added above)

----
The issues described here are pointed out in the interesting bug Bug:59695: "High frequency of load/unload cycles on some hard disks may shorten lifetime"
Line 37: Line 112:
'''Disk idleing'''
 
A rather complex task is allowing harddisks to idle, so they can be parked and spun-down for long enough periods of time. This is done by a program that is a little bit misleadingly called "laptop_mode" but not "disk-idle". Disk idleing has to deal with things like reading ahead and postponeing disk activity. The program got its name from a kernel feature that is called laptop_mode and allows linux to chunk up writes to filesystems and not write in between. But to really let a disk idle one has to manage other parts of the system that are relevant to letting disks idle also, like drive parameters, mount options, filsystem settings, cache sizes, sync logging programs etc. "laptop_mode" will do all that.
----
Line 41: Line 114:
Disk idling is commonly needed, thus laptop-mode enabled, when laptops operate on batteries to extend the battery times. But for example in vehicles with external power supply disk idling may be needed even on AC. Not nessecarily to leave the disk spun down, but to leave the heads parked for shock protection. [[http://en.opensuse.org/Disk_Power_Management|This opensuse wiki page]] might be useful for creating a proper solution for pm-utils - -- AzraelNightwalker <<DateTime(2008-07-14T15:32:11Z)>>
Line 43: Line 116:
Disk spin-down and head parking should never be activated without disk idling. The regular uncoordinated logging or journaling activity may spin up the disks back up almost imediately after spinning down and lead to excessive load cycling. [[http://ubuntuforums.org/showthread.php?p=5564900|This page]] shows a simple script that successfully activates laptop-mode after resuming from suspend in Hardy. --AbtZ

Three tasks involved

  1. Handling of hardware events
  2. Power state switching
  3. Letting disks idle

Though power management will deal with these, their objective does not solely lie in power management.

Power management packages

Foremost there is the apm and acpi support in the linux kernel.

They make those kind of "hard" events like the end of battery power or the pressing of the suspend or other (laptop) buttons available to our software world.

Then there are event manager daemons apmd and acpid

They provide means to execute commands on these external events. They run the scripts they find in their config directory tree under /etc/acpi, or /etc/apm respectively.

The package acpi-support provides a set of such scripts under /etc/acpi that deal with handling special acpi buttons on laptops.

The package pm-utils provides the pm-action, pm-hibernate, pm-suspend and pm-suspend-hybrid commands. They allow to trigger hard power management events by software. The pm-tools also provide script directories to hook-in other software when switching power (saving) states.

The gnome-power-manager is a program with a graphical user interface that subscribes itself to power events and acts on them. It shows you the battery status on laptops and dims down the screen if on battery for example. It will also shutdown or hibernate the computer after some idle time or before the battery runs out, if a user is logged in.

Disk idleing

A separate task is allowing harddisks to idle, so they can be parked and spun-down for long enough periods of time. This is done by a package that is a little bit misleadingly called laptop-mode-tools but not "disk-idle". Disk idleing has to deal with things like reading ahead and postponing disk activity. The program got its name from a kernel feature that is called laptop_mode and allows Linux to chunk up writes to filesystems and not write in between. But to really let a disk idle one has to manage other parts of the system that are relevant to letting disks idle also, like drive parameters, mount options, filesystem settings, cache sizes, sync logging programs etc. "laptop_mode" will do all that.

Disk idleing is commonly needed, thus laptop-mode enabled, when laptops operate on batteries to extend the battery times. But for example in vehicles with external power supply disk idleing may be needed even on AC. Not necessarily to leave the disk spun down, but to leave the heads parked for shock protection.

Disk spin-down and head parking should not be activated without controlled disk idleing. The regular uncoordinated logging or journaling activity may spin up the disks back up almost immediately after spinning down and lead to excessive load cycling.

Power (saving) states

The Common power (saving) states are awake, standby, suspend and hibernate.

During the awake state all components of the computer are running.

During standby the CPU keeps running your programs but some components like the monitor and harddisks may be turned off. When you touch the mouse or keyboard or a harddisk is accessed by software they quickly wake up again.

In both the awake and the standby state the speed of modern CPUs may be throttled down,though. For example if not in use.

During suspend however the CPU is always stopped. In modern PCs even all other components except the RAM memory can be turned off. The RAM will hold the state.

During hibernation the state is written to harddisk and the whole computer is turned off.

Architecture

This diagram shows how the kernel, hal, hal-info, pm-utils, and gnome-power-manager are plumbed together:

  • power-management.png

(dot source)

Please see Hotkeys/Architecture about the details of "Hotkey handling".

How to get disks idleing correctly (without excessive load cycling)

8.10 (Intrepid)

Many of the previous issues have been addressed in Intrepid. All you need to do is:

  • "ENABLE_LAPTOP_MODE=true" in /etc/default/laptop-mode (Bug 244838 fixed in acpi-support 0.111?)

8.04 (Hardy)

Unfortunately, ubuntu has mangled disk idleing into event handling and power state switching in the past. And this did not deliver idle disks but break disk idleing (laptop-mode) features by leaving undefined (factory default) apm settings in place.

To correct disk-idleing in Ubuntu Hardy you need to adjust the following:

  • Enable CONTROL_HD_POWERMGMT=1 in /etc/laptop-mode/laptop-mode.conf
    • (Bug 244832 missing hdparm -B setting during boot (fixed in intrepid 250935))

  • ENABLE_LAPTOP_MODE=true in /etc/default/acpi-support (another package's conffile), even if you do not ENABLE_LAPTOP_MODE_ON_BATTERY or _ON_AC in laptop-mode.conf. So that laptop-mode-tools can control the harddisk power management settings.
    • (244838 laptop-mode needs to be activated in two places)

  • Delete or #comment the four $HDPARM blocks (for...done) in /etc/acpi/power.sh and change the two $LAPTOP_MODE start/stop lines to "$LAPTOP_MODE auto"
    • (244836 /etc/acpi/power.sh overrides user settings (fixed in intrepid 250938))
      (244831 /etc/acpi/power.sh overrides user scripts (fixed in intrepid 250938))
      (244844 Adapt laptop-mode-tools invocation to ubuntu's acpi-support / pm-utils packages (fixed in intrepid 250935))

  • Create an empty "laptop-tools" file (touch /etc/pm/power.d/laptop-tools) to override /usr/lib/pm-utils/power.d/laptop-tools.
    • (239419 pm-utils has laptop-tools script which conflicts with laptop-mode-tools (not so in intrepid))

With the above changes hardy (ubuntu 8.04) will set the hdparm -B value to 254 when booting and thus override inadequately aggressive hardware defaults that cause load cycling. Not all harddisks will stop head parking with value 255 and some may even overheat. (hdparm -B255 turns off the disk's apm feature, but this only turns off the spin down timer in many disks and doesn't increase the head parking timer at all, which is the issue here.)

Other issues/adjustuments are related to have the hdparm -B value also reset after a suspend/resume cycle (fixed in intrepid 250935).

  • 244833 missing hdparm -B setting during resume
    244839 /etc/acpi/start.d and resume.d scripts are not run.
    244844 Adapt laptop-mode-tools invocation to ubuntu's acpi-support / pm-tools packages also:
    238555 pm-utils doesn't reload hdparm.conf after a suspend

Comments

I searched around and it seems I am not the only one with this problem and unfortunately, I could not find a good answer in the forums. Consequently, could someone explain in a little more detail how one would go about creating "a bogus /etc/pm/power.d/laptop-tools script to override /usr/lib/pm-utils/power.d/laptop-tools." Does it entail just making a new file the in the directory or is there actual code that has to go in the file. Thanks - Ali

  • Ali, just copy /usr/lib/pm-utils/power.d/laptop-tools to /etc/pm/power.d/laptop-tools and insert the code near line 26 following guidelines in 239419

    • Actually, to disabe this yet another "laptop-tools" script from pm-utils you just need to create an empty file (touch /etc/pm/power.d/laptop-tools). (Info also added above)


The issues described here are pointed out in the interesting bug 59695: "High frequency of load/unload cycles on some hard disks may shorten lifetime"


This opensuse wiki page might be useful for creating a proper solution for pm-utils - -- AzraelNightwalker 2008-07-14 15:32:11

This page shows a simple script that successfully activates laptop-mode after resuming from suspend in Hardy. --AbtZ

PowerManagement (last edited 2010-04-15 11:28:39 by 62-2-76-204)