diff options
author | Victor Lowther <victor.lowther@gmail.com> | 2008-12-03 13:09:46 -0600 |
---|---|---|
committer | Victor Lowther <victor.lowther@gmail.com> | 2008-12-03 13:09:46 -0600 |
commit | 2c253a933218e5256427bf84460e1060b3dc0f0e (patch) | |
tree | 9093a30095236817c9c49ce280ca260d63f3bc77 /pm | |
parent | f0cf3adb37fd06e7cbb882c9ab4ba35da28a3531 (diff) | |
parent | 89c71b6e409194cb18a5a6cf6b358d2f36957ffd (diff) |
Merge branch 'master' into pm-utils-1.2
Conflicts:
configure.ac
Diffstat (limited to 'pm')
-rw-r--r-- | pm/HOWTO.hooks | 16 | ||||
-rw-r--r-- | pm/HOWTO.modules | 65 | ||||
-rw-r--r-- | pm/defaults | 3 | ||||
-rw-r--r-- | pm/functions.in | 21 | ||||
-rwxr-xr-x | pm/module.d/uswsusp | 25 | ||||
-rwxr-xr-x | pm/sleep.d/50ntpd | 28 | ||||
-rwxr-xr-x | pm/sleep.d/55NetworkManager | 6 | ||||
-rwxr-xr-x | pm/sleep.d/55battery | 20 | ||||
-rwxr-xr-x | pm/sleep.d/65alsa | 19 | ||||
-rwxr-xr-x | pm/sleep.d/90clock | 2 | ||||
-rwxr-xr-x | pm/sleep.d/99video | 4 | ||||
-rw-r--r-- | pm/sleep.d/Makefile.am | 1 |
12 files changed, 79 insertions, 131 deletions
diff --git a/pm/HOWTO.hooks b/pm/HOWTO.hooks index bf68813..a506759 100644 --- a/pm/HOWTO.hooks +++ b/pm/HOWTO.hooks @@ -75,6 +75,19 @@ At or before 50, you can assume that all services are still enabled. At or before 75, you can assume that all modules are still loaded. +SUSPEND FAST PATH + +When suspending the system to memory, most of the time is used to synchronize +the disks and perform the actual sleep process in kernel space. +On modern systems, these steps generally only take 1 - 3 seconds. Since +just about every laptop user wants their system to sleep and wake up as fast +as possible, you should minimize the amount of work done during suspend and +during resume before we switch vts back to the original vt. + +If you have something to do that will take lots of time, try to run it during +resume after the 90chvt hook runs -- that will minimize the impact we have on +resume time. + CONVENIENCE FUNCTIONS If your hook is a shell script that supports POSIX/SuS compatible syntax, you @@ -115,3 +128,6 @@ the hook. This will make the following convenience functions available: hibernate the system after this function is called. 13: inhibited Test to see if inhibit has been called. +14: dbus_send + Just like regular dbus-send, but return $NA if the command fails for + any reason. diff --git a/pm/HOWTO.modules b/pm/HOWTO.modules index 09c3d78..a1b1306 100644 --- a/pm/HOWTO.modules +++ b/pm/HOWTO.modules @@ -3,38 +3,39 @@ How to write a sleep module: OVERVIEW: Sleep modules are POSIX-compatible shell scripts designed to be sourced by the pm-utils machinery in order to check that the machine supports a sleep -method and to actually enter that method. +method and to actually enter that method. Sleep modules can be stacked, which +means that some care must be taken to write a sleep module. The basic rules +are as follows: + +1: Check to see if someone else has already implemented your sleep method. + If they have, you should do nothing. + +2: Check to see if your sleep method is applicable to this system. If it + is not, you should do nothing. + +3: If no other module has claimed your sleep method and this system is capable + of performing your sleep method, then go ahead and define the function that + implements your sleep method. + +As an example of how to do things, take a look at pm/module.d/uswsusp, which +implements all three sleep methods and shows how to use the module helper +functions add_before_hooks and add_module_help. + Currently, three sleep methods are supported: SUSPEND: Suspend (also known as suspend-to-ram) is the sleep mode equivalent to ACPI S3 -- state is saved in system memory, and all other hardware is either -powered off or in power-saving mode. If your sleep module supports suspend, -it MUST define 2 functions: - -* check_suspend, which checks to see that the system provides a suspend-to-ram - mechanism, returns 0 if it does, and 1 if it does not. +powered off or in power-saving mode. -* do_suspend, which performs just the task of putting the system in suspend. +Your sleep module must implement do_suspend if you support suspend to ram. HIBERNATE: Hibernate (also know as suspend-to-disk) is the sleep mode equivalent to ACPI S4 -- the system state is saved to permanent media (like a hard drive), -and the system is iether in a very low-power use mode or completly powered off. -If your sleep module supports hibernate, it MUST define 2 functions: - -* check_hibernate, which checks to see if the system provides a suspend-to-disk - mechanism, and returns 0 if it does, and 1 if it does not. +and the system is either in a very low-power use mode or completly powered off. -* do_hibernate, which performs just the task of putting the system in hibernate. - -Hibernate can optionally provide a third function: -* hibernate_might_work, which should return 0 if the minimum prerequisites - for a sucessful hibernate/thaw cycle are met (ensuring that there is an - active swap device, etc), and 1 otherwise. If your system provides this - method, your do_hibernate function SHOULD check it and: - * emit an error message, and - * return without hibernating the system. +Your sleep module must implement do_hibernate if you support suspend to disk. SUSPEND_HYBRID: suspend_hybrid is a blend of suspend and hibernate. It performs all @@ -45,24 +46,4 @@ of suspend with the assurance that your state is saved to the hard drive if you run out of power. If your sleep module supports suspend_hybrid, it MUST define 2 functions: -* check_suspend_hybrid, which checks to see that the system provides hybrid - suspend functionality, and returns 0 if it dies and 1 if it does not. - -* do_suspend_hybrid, which just performs the task of putting the system into - suspend_hybrid sleep. - -do_suspend_hybrid SHOULD utilize hibernate_might_work if it is present. - -OTHER STUFF: - -If you define a function named "before_hook", that function will be executed -just before the sleep/resume hooks are executed. If you need to disable a hook, -this is the place to do it. - -If you define a function named "sleep_method_help", that function will be -executed whenever any of the pm-utils scripts is called with the "--help" -option. If the behaviour of your sleep method can be changes by command-line -parameters passed to pm-action or by a configuration file setting, you -SHOULD define a sleep_method_help function and that function SHOULD explain -how the command-line paramaters and configuration file settings can change its -behaviour. +Your sleep module must implement do_suspend_hybrid if you support hybrid suspend. diff --git a/pm/defaults b/pm/defaults index c0063c5..db4d59a 100644 --- a/pm/defaults +++ b/pm/defaults @@ -47,3 +47,6 @@ # If you want to ignore commandline parameters, add them here. # DROP_PARAMETERS="" +# If you need to synchronize the system clock across a suspend/resume or +# hibernate/thaw cycle, set this variable. +# NEED_CLOCK_SYNC="true" diff --git a/pm/functions.in b/pm/functions.in index 110282e..70740cb 100644 --- a/pm/functions.in +++ b/pm/functions.in @@ -129,14 +129,13 @@ modreload() if ! command_exists service; then service() { - if [ -x "/etc/init.d/$1" ]; then - svc="$1" - shift - "/etc/init.d/$svc" "$@" - else - log "${1}: unrecognized service" - return 1 - fi + for svc in "/etc/init.d/$1" "/etc/rc.d/rc.$1"; do #lsb, then slack + [ -x "$svc" ] && { shift; "$svc" "$@"; return $?; } + done + # this only happens if we did not find the service + log "${1}: unrecognized service" + return 1 + } fi @@ -240,3 +239,9 @@ has_parameter() done return 1 } + +# Like regular dbus-send, but returns $NA if the command fails for any reason. +dbus_send () +{ + command dbus-send "$@" 2>/dev/null || return $NA +} diff --git a/pm/module.d/uswsusp b/pm/module.d/uswsusp index 9da30c9..b9778af 100755 --- a/pm/module.d/uswsusp +++ b/pm/module.d/uswsusp @@ -1,12 +1,16 @@ #!/bin/sh -# disable processing of 99video +# disable processing of 90chvt and 99video. +# s2ram and s2disk handle all this stuff internally. uswsusp_hooks() { disablehook 90chvt "disabled by uswsusp" disablehook 99video "disabled by uswsusp" } +# Since we disabled 99video, we need to take responsibility for proper +# quirk handling. s2ram handles all common video quirks internally, +# so all we have to do is translate the HAL standard options to s2ram options. uswsusp_get_quirks() { OPTS="" @@ -30,28 +34,37 @@ uswsusp_get_quirks() done [ $ACPI_SLEEP -ne 0 ] && OPTS="$OPTS --acpi_sleep $ACPI_SLEEP" # if we were told to ignore quirks, do so. + # This is arguably not the best way to do things, but... [ "$QUIRK_NONE" = "true" ] && OPTS="" } +# Since we disabled 99video, we also need to handle displaying +# help info for the quirks we handle. uswsusp_help() { echo # first echo makes it look nicer. - echo "Video quirk handler options:" + echo "s2ram video quirk handler options:" echo - echo " --quirk-dpms-on" - echo " --quirk-dpms-suspend" echo " --quirk-radeon-off" - echo " --quirk-reset-brightness" echo " --quirk-s3-bios" echo " --quirk-s3-mode" echo " --quirk-vbe-post" echo " --quirk-vbemode-restore" echo " --quirk-vbestate-restore" - echo " --quirk-vga-mode3" echo " --quirk-save-pci" echo " --quirk-none" } +# This idiom is used for all sleep methods. Only declare the actual +# do_ method if: +# 1: some other sleep module has not already done so, and +# 2: this sleep method can actually work on this system. +# +# For suspend, if SUSPEND_MODULE is set then something else has already +# implemented do_suspend. We could just check to see of do_suspend was +# already declared using command_exists, but using a dedicated environment +# variable makes it easier to debug when we have to know what sleep module +# ended up claiming ownership of a given sleep method. if [ -z "$SUSPEND_MODULE" ] && command_exists s2ram && \ ( grep -q mem /sys/power/state || \ ( [ -c /dev/pmu ] && pm-pmu --check; ); ); then diff --git a/pm/sleep.d/50ntpd b/pm/sleep.d/50ntpd deleted file mode 100755 index 96ad3d4..0000000 --- a/pm/sleep.d/50ntpd +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -. "${PM_FUNCTIONS}" - -NTPD_LOCK="pm-ntpd.lock" - -stop_ntp() -{ - if try_lock "${NTPD_LOCK}"; then - trap 'release_lock "${NTPD_LOCK}"' 0 - stopservice ntpd - fi -} - -start_ntp() -{ - # Bring back ntpd _after_ NetworkManager and such come back... - ( spin_lock "${NTPD_LOCK}"; - trap 'release_lock "${NTPD_LOCK}"' 0 - sleep 20 - restartservice ntpd; ) & -} - -case "$1" in - hibernate|suspend) stop_ntp ;; - thaw|resume) start_ntp ;; - *) exit $NA ;; -esac diff --git a/pm/sleep.d/55NetworkManager b/pm/sleep.d/55NetworkManager index 244e2c7..bc0cf5a 100755 --- a/pm/sleep.d/55NetworkManager +++ b/pm/sleep.d/55NetworkManager @@ -8,12 +8,10 @@ . "${PM_FUNCTIONS}" -command_exists dbus-send || exit $NA - suspend_nm() { # Tell NetworkManager to shut down networking - dbus-send --system \ + dbus_send --system \ --dest=org.freedesktop.NetworkManager \ /org/freedesktop/NetworkManager \ org.freedesktop.NetworkManager.sleep @@ -22,7 +20,7 @@ suspend_nm() resume_nm() { # Wake up NetworkManager and make it do a new connection - dbus-send --system \ + dbus_send --system \ --dest=org.freedesktop.NetworkManager \ /org/freedesktop/NetworkManager \ org.freedesktop.NetworkManager.wake diff --git a/pm/sleep.d/55battery b/pm/sleep.d/55battery deleted file mode 100755 index 1944e98..0000000 --- a/pm/sleep.d/55battery +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -# Have HAL rescan batteries on resume. -# TODO: Merge this code back into HAL, it should not be in pm-utils. - -. "${PM_FUNCTIONS}" - -resume_batteries() -{ - for x in $(hal-find-by-capability --capability battery 2>/dev/null); do - dbus-send --system --reply-timeout=2000 \ - --dest=org.freedesktop.Hal "$x" \ - org.freedesktop.Hal.Device.Rescan "string:$x" - done -} - -case "$1" in - resume|thaw) - resume_batteries - ;; -esac diff --git a/pm/sleep.d/65alsa b/pm/sleep.d/65alsa deleted file mode 100755 index 37ba3fe..0000000 --- a/pm/sleep.d/65alsa +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# Ensure that ALSA state is saved and restored correctly. -# TODO: Modern ALSA does not need this hack. Is it worth trying to detect -# that and disable this hook if we do not need it? - -. "${PM_FUNCTIONS}" - -command_exists alsactl || exit $NA - -case "$1" in - hibernate|suspend) - alsactl store 0 >/dev/null 2>&1 - ;; - thaw|resume) - alsactl restore 0 >/dev/null 2>&1 - ;; - *) exit $NA - ;; -esac diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock index d824778..5df6e8e 100755 --- a/pm/sleep.d/90clock +++ b/pm/sleep.d/90clock @@ -15,6 +15,8 @@ resume_clock() /sbin/hwclock --hctosys >/dev/null 2>&1 0<&1 } +[ "$NEED_CLOCK_SYNC" ] || exit $NA + case "$1" in hibernate|suspend) suspend_clock ;; thaw|resume) resume_clock ;; diff --git a/pm/sleep.d/99video b/pm/sleep.d/99video index 0beb360..1fe54c2 100755 --- a/pm/sleep.d/99video +++ b/pm/sleep.d/99video @@ -144,7 +144,7 @@ suspend_video() local acpi_flag=0 quirk "${QUIRK_S3_BIOS}" && acpi_flag=$(($acpi_flag + 1)) quirk "${QUIRK_S3_MODE}" && acpi_flag=$(($acpi_flag + 2)) - [ 0 -ne $acpi_flag ] && sysctl -w kernel.acpi_video_flags=$acpi_flag + sysctl -w kernel.acpi_video_flags=$acpi_flag quirk "${QUIRK_NOFB}" && die_if_framebuffer quirk "${QUIRK_VBESTATE_RESTORE}" && vbe_savestate @@ -166,8 +166,6 @@ resume_video() quirk "${QUIRK_RADEON_OFF}" && radeon_on quirk "${QUIRK_DPMS_ON}" && vbe dpms on quirk "${QUIRK_RESET_BRIGHTNESS}" && reset_brightness - # always reset acpi_video_flag -- makes quirk testing more reliable. - sysctl -w kernel.acpi_video_flags=0 return 0 # avoid spurious hook exit failure message. } diff --git a/pm/sleep.d/Makefile.am b/pm/sleep.d/Makefile.am index 2972d20..960a7b5 100644 --- a/pm/sleep.d/Makefile.am +++ b/pm/sleep.d/Makefile.am @@ -7,7 +7,6 @@ sleep_SCRIPTS = \ 01grub \ 49bluetooth \ 50ntpd \ - 55battery \ 55NetworkManager \ 65alsa \ 75modules \ |