Differences between revisions 1 and 7 (spanning 6 versions)
Revision 1 as of 2005-10-20 22:53:21
Size: 1626
Editor: MartinWilck
Comment:
Revision 7 as of 2005-10-25 13:36:04
Size: 4967
Editor: MartinWilck
Comment:
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
There are several aspects to power management: The battery lifetime numbers Samsung publishes (6h) are marketing exaggerations. The normal battery in my notebook lasts about 2h when I'm working normally.
Line 7: Line 7:
 1. React to "battery low" events by shutting down gracefully or suspending. {{{acpid}}} can do it (it works), but the actions must be written by hand.
 1. React to "critical temperature" events. Should be possible with {{{acpid}}}, too. Not tested.
 1. Do a graceful shutdown when the power button is pressed. OK with {{{acpid}}}.
 1. Carry out suspend-to-disk or suspend-to-RAM. Requires kernel recompilation on Debian. Not yet tested.
 1. Regulate the power consumption of different subsystems. This can be done in several ways.
   * The most powerful approach is using ACPI power states, but this is hardly implemented in Linux right now (2005).
   * "laptop-mode-tools" for regulating disk activity (unfortunately pointless with SATA, see [/SamsungX50/HDDandCDrom])
   * CPU frequency control: There are many tools for this ([http://www.gentoo.de/doc/de/power-management-guide.xml see here for a comparison]). I opted for {{{cpufrequtils}}} because it's lightweight, easy to use in scripts, and powerful enough for my purposes.
   
   I am using the kernel "performance" governor with AC connected, the "ondemand" governor on battery,
   and the "powersave" governor in "etiquette mode" (see [wiki:../InputDevices].
== Emergency power off ==
Line 19: Line 9:
   I put the following into {{{/etc/modules}}} to enable power control: React to "battery low" events by shutting down gracefully or suspending. Works with {{{acpid}}}. Action must be written by hand on Debian. Here is mine:

~-{{{
#! /bin/sh
# /etc/acpid/actions/mw_battery.sh

# Don't forget to define an event in /etc/acpi/events that calls
# /etc/acpi/actions/mw_battery.sh %e on battery events

export LC_ALL=C

# dont bother if shutdown is already running
[ -f /var/run/shutdown.pid ] && exit 0

minutes=$(/usr/local/bin/minutes_to_go $2)
[ -z "$minutes" ] && exit 0 # charging or full

if [ $minutes -le 3 ]; then
   /sbin/shutdown -h now "battery running low ($minutes minutes)"
fi

}}}

The {{{minutes_to_go}}} command is here:
Line 21: Line 34:
#! /bin/sh
# /usr/local/bin/minutes_to_go BATTERY

BAT=$1
[ -r /proc/acpi/battery/$BAT/state ] || exit 2

awk '
/^charging state:/ { if ($3 !~ /^discharging/) { r=0; exit (0); }}
/^present rate:/ {r=$3}
/^remaining capacity/ {c=$3}
END { if (r) print int(60*c/r); }
' /proc/acpi/battery/$BAT/state
}}}
-~
Instead of poweroff, one could as well do a suspend-to-disk (see below).

Likewise, it should be possible to react to "critical temperature" events. Should be possible with {{{acpid}}} on the X50, too. Not tested (I didn't reach critical temperatures:-).


== ACPI sleep states and software suspend ==

This requires a kernel recompilation. Make the following selections in the kernel configuration:
~-{{{
 -> Power management options (ACPI, APM)
   [*] Software Suspend [EXPERIMENTAL]
   -> ACPI (Advanced Configuration and Power Interface) Support
     -> ACPI Support
     [*] ACPI Sleep States [EXPERIMENTAL]
 }}}-~

Suspend-to-disk ({{{echo disk >/sys/power/state}}}) works fine on the X50 as long as the proprietary ATI graphics driver isn't used.

Suspend-to-RAM didn't work for me yet.


== Power saving ==

'''CPU frequency adjustment''' works very well. There is a large number of tools available ([http://www.gentoo.de/doc/de/power-management-guide.xml see here for a comparison]). My personal favorite under Debian are the light-weight {{{cpufrequtils}}}. They rely mostly on the kernel {{{cpufreq}}} driver to do the adjustments. I am using the {{{ondemand}}} governor under normal conditions and the {{{powersave}}} governor when I really want to save battery.
I put the following into {{{/etc/modules}}} to enable power control:
~-{{{
Line 25: Line 78:
}}} }}}-~
{{{cpufrequtils}}} must be enabled by editing {{{/etc/default/cpufrequtils}}}. I call {{{cpufreq-set}}} upon {{{acpid}}} AC adapter events and etiquette mode keys (see ../InputDevices).

There are also power saving modes for other components besides the CPU. Onfortunately, the {{{hdparm}}} commands to put the disk to sleep don't work with SATA disks underr libata (yet), so the {{{laptop-mode-tools}}} package is currently mostly useless.

== Power button and sleep button ==

The default {{{acpid}}} setup in Etch has a script for the '''power button''' that
 1. If a user is logged in under KDE, logs him out;
 1. Otherwise, initiates a graceful shutdown.
Thus, the power button needs to be pressed twice if someone is logged on under KDE.
All of this works out of the box on the X50.

The '''sleep button''' is detected on the X50 but there is no default action. Here is mine:
~-{{{
#! /bin/sh
# /etc/acpi/actions/mw_sleep.sh
# Create an acpi event that calls this script!

# The resume partition
RESUME=8:10

export LC_ALL=C

# Security: be sure that no console is directly accessible after wake-up
kill_console_sessions() {
        wall <<EOF
 *** SLEEP BUTTON PRESSED ***
EOF
        sleep 2
        [ -n "$(dcop --all-users --list-sessions)" ] && {
                dcop --all-users kdesktop KScreensaverIface lock
        }
        ps -eo tty,comm,pid | \
                awk '/tty[0-9]* *login /{print $3}' | \
                xargs -r kill -TERM
}

### CAREFUL! Does this also work with fglrx (ATI proprietary X driver)??
grep -q fglrx /proc/modules && exit 0

## set resume partition
grep -q $RESUME /sys/power/resume || echo $RESUME >/sys/power/resume

kill_console_sessions

chvt 1 # change to text terminal to avoid problems with X
[ -w /sys/power/state ] && {
        /sbin/hwclock --systohc
        echo disk >/sys/power/state
        /sbin/hwclock --hctosys
}
chvt 7 # change back to the console you want activated after wake-up (X Windows)
}}}-~

Power Management and ACPI

Most of this works out-of-the-box. [http://faq.pathfinderteam.org/index.php/Samsung_X20 this page on the Samsung X20 (in German)] has many good hints.

The battery lifetime numbers Samsung publishes (6h) are marketing exaggerations. The normal battery in my notebook lasts about 2h when I'm working normally.

Emergency power off

React to "battery low" events by shutting down gracefully or suspending. Works with acpid. Action must be written by hand on Debian. Here is mine:

# /etc/acpid/actions/mw_battery.sh

# Don't forget to define an event in /etc/acpi/events that calls 
# /etc/acpi/actions/mw_battery.sh %e on battery events

export LC_ALL=C

# dont bother if shutdown is already running
[ -f /var/run/shutdown.pid ] && exit 0

minutes=$(/usr/local/bin/minutes_to_go $2)
[ -z "$minutes" ] && exit 0 # charging or full

if [ $minutes -le 3 ]; then
   /sbin/shutdown -h now "battery running low ($minutes minutes)"
fi

The minutes_to_go command is here:

# /usr/local/bin/minutes_to_go BATTERY

BAT=$1
[ -r /proc/acpi/battery/$BAT/state ] || exit 2

awk '
/^charging state:/ { if ($3 !~ /^discharging/) { r=0; exit (0); }}
/^present rate:/ {r=$3}
/^remaining capacity/ {c=$3}
END { if (r) print int(60*c/r); }
' /proc/acpi/battery/$BAT/state

Instead of poweroff, one could as well do a suspend-to-disk (see below).

Likewise, it should be possible to react to "critical temperature" events. Should be possible with acpid on the X50, too. Not tested (I didn't reach critical temperatures:-).

ACPI sleep states and software suspend

This requires a kernel recompilation. Make the following selections in the kernel configuration:

 -> Power management options (ACPI, APM)
   [*] Software Suspend [EXPERIMENTAL]     
   -> ACPI (Advanced Configuration and Power Interface) Support                                                                  
     -> ACPI Support 
     [*] ACPI Sleep States [EXPERIMENTAL]

Suspend-to-disk (echo disk >/sys/power/state) works fine on the X50 as long as the proprietary ATI graphics driver isn't used.

Suspend-to-RAM didn't work for me yet.

Power saving

CPU frequency adjustment works very well. There is a large number of tools available ([http://www.gentoo.de/doc/de/power-management-guide.xml see here for a comparison]). My personal favorite under Debian are the light-weight cpufrequtils. They rely mostly on the kernel cpufreq driver to do the adjustments. I am using the ondemand governor under normal conditions and the powersave governor when I really want to save battery. I put the following into /etc/modules to enable power control:

freq_table
speedstep_centrino
cpufreq_ondemand
cpufreq_powersave

cpufrequtils must be enabled by editing /etc/default/cpufrequtils. I call cpufreq-set upon acpid AC adapter events and etiquette mode keys (see ../InputDevices).

There are also power saving modes for other components besides the CPU. Onfortunately, the hdparm commands to put the disk to sleep don't work with SATA disks underr libata (yet), so the laptop-mode-tools package is currently mostly useless.

Power button and sleep button

The default acpid setup in Etch has a script for the power button that

  1. If a user is logged in under KDE, logs him out;
  2. Otherwise, initiates a graceful shutdown.

Thus, the power button needs to be pressed twice if someone is logged on under KDE. All of this works out of the box on the X50.

The sleep button is detected on the X50 but there is no default action. Here is mine:

# /etc/acpi/actions/mw_sleep.sh
# Create an acpi event that calls this script!

# The resume partition
RESUME=8:10

export LC_ALL=C

# Security: be sure that no console is directly accessible after wake-up
kill_console_sessions() {
        wall <<EOF
 *** SLEEP BUTTON PRESSED ***
EOF
        sleep 2
        [ -n "$(dcop --all-users --list-sessions)" ] && {
                dcop --all-users kdesktop KScreensaverIface lock
        }
        ps -eo tty,comm,pid | \
                awk '/tty[0-9]* *login /{print $3}' | \
                xargs -r kill -TERM
}

### CAREFUL! Does this also work with fglrx (ATI proprietary X driver)??
grep -q fglrx /proc/modules && exit 0

## set resume partition
grep -q $RESUME /sys/power/resume || echo $RESUME >/sys/power/resume

kill_console_sessions

chvt 1 # change to text terminal to avoid problems with X
[ -w /sys/power/state ] && {
        /sbin/hwclock --systohc
        echo disk >/sys/power/state
        /sbin/hwclock --hctosys
}
chvt 7 # change back to the console you want activated after wake-up (X Windows)