Difference between revisions of "Suspend to RAM"

From ArchWiki
Jump to: navigation, search
(Pm-utils Internals: Move to Pm-utils)
m (ACPI_OS_NAME)
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Power management (English)]]
+
[[Category:Power management]]
[[Category:Laptops (English)]]
+
{{i18n|Suspend to RAM}}
+
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|Describes the operation of the pm-utils suspend framework and supported backend methods}}
 
{{Article summary text|Describes the operation of the pm-utils suspend framework and supported backend methods}}
Line 13: Line 11:
  
 
There is a variety of mechanisms to enable your operating system to suspend to memory or to disk. To understand the difference between these systems, you need to know that there exists a suspend/resume implementation in the kernel (swsusp) and (typically) a set of additional tweaks to handle specific drivers/modules/hardware (ex: video card re-initialization).  
 
There is a variety of mechanisms to enable your operating system to suspend to memory or to disk. To understand the difference between these systems, you need to know that there exists a suspend/resume implementation in the kernel (swsusp) and (typically) a set of additional tweaks to handle specific drivers/modules/hardware (ex: video card re-initialization).  
 +
 +
* [[systemd]] provides commands for suspend to RAM, hibernate and a hybrid suspend using the kernel's native suspend/resume functionality. There are also mechanisms to add hooks to customize pre- and post-suspend actions.
  
 
* [[pm-utils]] is a set of shell scripts that encapsulate the kernel's suspend/resume functionality. It comes with a set of pre- and post-suspend tweaks and various hooks to customize the process.
 
* [[pm-utils]] is a set of shell scripts that encapsulate the kernel's suspend/resume functionality. It comes with a set of pre- and post-suspend tweaks and various hooks to customize the process.
  
* [[uswsusp]] also aims to provide programs that encapsulate the kernel's suspend/resume functionality with the additional tweaks necesarry. It also aims to provide a suspend-to-both functionality - this allows resuming from memory if battery is not depleted and resuming from disk if battery is completely depleted.  
+
* [[uswsusp]] also aims to provide programs that encapsulate the kernel's suspend/resume functionality with the additional tweaks necessary. It also aims to provide a suspend-to-both functionality - this allows resuming from memory if battery is not depleted and resuming from disk if battery is completely depleted.  
  
 
* [[TuxOnIce]] differs from pm-utils and uswsusp in that it attempts to directly patch the kernel's suspend/resume functionality to add more functionality than the default implementation. It therefore requires a custom kernel.
 
* [[TuxOnIce]] differs from pm-utils and uswsusp in that it attempts to directly patch the kernel's suspend/resume functionality to add more functionality than the default implementation. It therefore requires a custom kernel.
Line 56: Line 56:
  
 
In general, it is possible that just installing pm-utils and invoking pm-suspend (which uses the kernel backend by default) just works for you. In some cases, you may need to force specific modules to be unloaded to make this work, as described in [[pm-utils#Advanced Configuration]].
 
In general, it is possible that just installing pm-utils and invoking pm-suspend (which uses the kernel backend by default) just works for you. In some cases, you may need to force specific modules to be unloaded to make this work, as described in [[pm-utils#Advanced Configuration]].
   
+
 
 +
=== systemd ===
 +
 
 +
Systemd provides native commands for suspend, hibernate and a hybrid suspend.
 +
 
 +
  # systemctl suspend
 +
# systemctl hibernate
 +
# systemctl hybrid-sleep
 +
 
 +
See [[Systemd#ACPI_power_management]] for additional information on configuring suspend/resume hooks. Also see {{ic|man systemctl}}, {{ic|man systemd-sleep}}, and {{ic|man systemd.special}}.
 +
 
 
=== uswsusp ===
 
=== uswsusp ===
  
Line 105: Line 115:
 
It just fools the BIOS about the real OS used, and work-around custom behavior; i.e. the BIOS/ACPI is broken for everything but Windows.
 
It just fools the BIOS about the real OS used, and work-around custom behavior; i.e. the BIOS/ACPI is broken for everything but Windows.
  
You might want to try other string if this one does not work.
+
You might want to try another string if this one does not work.
  
 
== Other Resources ==
 
== Other Resources ==
Line 111: Line 121:
 
*[http://suspend.sourceforge.net/ Uswsusp Home Page]
 
*[http://suspend.sourceforge.net/ Uswsusp Home Page]
 
*[http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface Advanced Configuration and Power Interface]
 
*[http://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface Advanced Configuration and Power Interface]
*{{Filename|/usr/share/doc/suspend/README}} Uswsusp Documentation
+
*{{ic|/usr/share/doc/suspend/README}} Uswsusp Documentation
*{{Filename|/usr/share/doc/suspend/README.s2ram-whitelist}} s2ram-whitelist README
+
*{{ic|/usr/share/doc/suspend/README.s2ram-whitelist}} s2ram-whitelist README
*{{Filename|/usr/src/linux-2.6.38-ARCH/Documentation/power/interface.txt}} Kernel Power Management Interface
+
*{{ic|/usr/src/linux-2.6.38-ARCH/Documentation/power/interface.txt}} Kernel Power Management Interface
*{{Filename|/usr/src/linux-2.6.38-ARCH/Documentation/power/states.txt}} System Power Management States
+
*{{ic|/usr/src/linux-2.6.38-ARCH/Documentation/power/states.txt}} System Power Management States

Revision as of 05:20, 4 January 2013

Summary help replacing me
Describes the operation of the pm-utils suspend framework and supported backend methods
Related
Pm-utils
Uswsusp
TuxOnIce

Sleep mode can go by many different names, including Stand By, Sleep, and Suspend. When placed in this sleep mode, aside from the RAM which is required to restore the machine's state, the computer attempts to cut power to all unneeded parts of the machine. Because of the large power savings, most laptops automatically enter this mode when the computer is running on batteries and the lid is closed. (from Wikipedia:Sleep mode)

There is a variety of mechanisms to enable your operating system to suspend to memory or to disk. To understand the difference between these systems, you need to know that there exists a suspend/resume implementation in the kernel (swsusp) and (typically) a set of additional tweaks to handle specific drivers/modules/hardware (ex: video card re-initialization).

  • systemd provides commands for suspend to RAM, hibernate and a hybrid suspend using the kernel's native suspend/resume functionality. There are also mechanisms to add hooks to customize pre- and post-suspend actions.
  • pm-utils is a set of shell scripts that encapsulate the kernel's suspend/resume functionality. It comes with a set of pre- and post-suspend tweaks and various hooks to customize the process.
  • uswsusp also aims to provide programs that encapsulate the kernel's suspend/resume functionality with the additional tweaks necessary. It also aims to provide a suspend-to-both functionality - this allows resuming from memory if battery is not depleted and resuming from disk if battery is completely depleted.
  • TuxOnIce differs from pm-utils and uswsusp in that it attempts to directly patch the kernel's suspend/resume functionality to add more functionality than the default implementation. It therefore requires a custom kernel.

Note that the end goal of these packages is to provide binaries/scripts that can be invoked to perform suspend/resume. Actually hooking them up to power buttons or menu clicks or laptop lid events is left to other mechanisms. To automatically suspend/resume on certain power events, such as laptop lid close or battery depletion percentage, you may want to look into running Acpid.

Suspend methods

These methods can be used to suspend/resume directly. pm-utils is also fairly generic, so its pm-suspend and pm-hibernate scripts can be configured to use any of these methods.

kernel

The most straightforward approach is to directly inform the in-kernel software suspend code (swsusp) to enter a suspended state; the exact method and state depends on the level of hardware support. On modern kernels, writing appropriate strings to /sys/power/state is the primary mechanism to trigger this suspend. For example, let us study out how pm-utils does this.

/usr/lib/pm-utils/pm-functions::294 (comments added):

if grep -q mem /sys/power/state; then
    SUSPEND_MODULE="kernel"
    # Suspend-to-RAM
    # ACPI State S3
    # Device State D3
    # Greatest power savings, slower resume
    do_suspend() { echo -n "mem" >/sys/power/state; }
elif [ -c /dev/pmu ] && pm-pmu --check; then
    SUSPEND_MODULE="kernel"
    # Suspend using Macintosh-style PMU
    # Fallback for older kernels in which the sysfs interface does not support this hardware
    do_suspend() { pm-pmu --suspend; }
elif grep -q standby /sys/power/state; then
    SUSPEND_MODULE="kernel"
    # Power-On-Suspend
    # ACPI State S1
    # Device State D1 (supported devices)
    # Minimal power savings, fast resume
    do_suspend() { echo -n "standby" >/sys/power/state; }
fi

In general, it is possible that just installing pm-utils and invoking pm-suspend (which uses the kernel backend by default) just works for you. In some cases, you may need to force specific modules to be unloaded to make this work, as described in pm-utils#Advanced Configuration.

systemd

Systemd provides native commands for suspend, hibernate and a hybrid suspend.

# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep

See Systemd#ACPI_power_management for additional information on configuring suspend/resume hooks. Also see man systemctl, man systemd-sleep, and man systemd.special.

uswsusp

The uswsusp ('Userspace Software Suspend') package provides s2ram, a wrapper around the kernel's suspend-to-RAM mechanism which perform some graphics adapter manipulations from userspace before suspending and after resuming. This includes:

  • passing acpi_sleep=s3_bios to the kernel
  • passing acpi_sleep=s3_mode to the kernel
  • passing both of the above (acpi_sleep=s3_bios,s3_mode) to the kernel
  • POSTing the video card from userspace after resume using vbetool
  • saving the VBE state before suspend and restoring it after resume using vbetool

This is accomplished by a hardware whitelist maintained by HAL - s2ram translates the HAL database options into s2ram parameters.

Since HAL is deprecated and KMS drivers can save the state of the grahic card directly without userspace quirks, s2ram development is discontinued and no further whitelist entries are accepted. If a KMS driver is in use, s2ram will directly suspend the machine.

tuxonice

TuxOnIce is a fork of the kernel implementation of suspend/resume that provides kernel patches to improve the default implementation. It requires a custom kernel to achieve this purpose. Since pm-utils is a set of shell scripts with a variety of hooks, it can be configured to use TuxOnIce as well.

pm-utils configuration

See pm-utils.

Deciding between these options

Pm-utils framework or not?

Directly calling the kernel backend method is significantly faster than calling pm-suspend, since running all the hooks provided by the pm-utils framework invariable takes time. Even uswsusp is faster than pm-suspend. However, the recommended approach is to use pm-utils as it can properly:

  • set hardware clock
  • restore wireless
  • etc...

In fact, only the pm-utils approach can be called without special privileges, see pm-utils#Suspend.2FHibernate as regular user

Selecting the backend/method

  • kernel - hooks provided by pm-utils (including video quirks) with kernel method. This is the recommended mechanism. It may require specific kernel modules to be unloaded before it will work properly. Searching on the arch linux bbs for your specific laptop is a good idea to discover these modules.
  • uswsusp - hooks provided by pm-utils except video99 with s2ram assuming responsibility for video quirks. Not necessary unless the kernel method explicitly fails to work.
  • tuxonice - since it requires a kernel recompile, make sure you are getting a specific feature out of it that is not supported by the default kernel implementation.

ACPI_OS_NAME

You might want to tweak your DSDT table to make it work. See DSDT article

However, you could try simply to use a acpi_os_name parameter, like:

acpi_os_name="Microsoft Windows NT"

Add this to your kernel boot option. For example, for grub legacy:

kernel /boot/vmlinuz-linux root=/dev/sdx resume=/dev/sdy ro quiet acpi_os_name="Microsoft Windows NT"

It just fools the BIOS about the real OS used, and work-around custom behavior; i.e. the BIOS/ACPI is broken for everything but Windows.

You might want to try another string if this one does not work.

Other Resources

  • Uswsusp Home Page
  • Advanced Configuration and Power Interface
  • /usr/share/doc/suspend/README Uswsusp Documentation
  • /usr/share/doc/suspend/README.s2ram-whitelist s2ram-whitelist README
  • /usr/src/linux-2.6.38-ARCH/Documentation/power/interface.txt Kernel Power Management Interface
  • /usr/src/linux-2.6.38-ARCH/Documentation/power/states.txt System Power Management States