System Power Management Sleep States

来源:互联网 发布:苹果手机检测软件 编辑:程序博客网 时间:2024/05/28 18:43
https://www.kernel.org/doc/Documentation/power/states.txt
System Power Management Sleep States(C) 2014 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com>The kernel supports up to four system sleep states generically, although threeof them depend on the platform support code to implement the low-level detailsfor each state.The states are represented by strings that can be read or written to the/sys/power/state file.  Those strings may be "mem", "standby", "freeze" and"disk", where the last three always represent Power-On Suspend (if supported),Suspend-To-Idle and hibernation (Suspend-To-Disk), respectively.The meaning of the "mem" string is controlled by the /sys/power/mem_sleep file.It contains strings representing the available modes of system suspend that maybe triggered by writing "mem" to /sys/power/state.  These modes are "s2idle"(Suspend-To-Idle), "shallow" (Power-On Suspend) and "deep" (Suspend-To-RAM).The "s2idle" mode is always available, while the other ones are only availableif supported by the platform (if not supported, the strings representing themare not present in /sys/power/mem_sleep).  The string representing the suspendmode to be used subsequently is enclosed in square brackets.  Writing one ofthe other strings present in /sys/power/mem_sleep to it causes the suspend modeto be used subsequently to change to the one represented by that string.Consequently, there are two ways to cause the system to go into theSuspend-To-Idle sleep state.  The first one is to write "freeze" directly to/sys/power/state.  The second one is to write "s2idle" to /sys/power/mem_sleepand then to write "mem" to /sys/power/state.  Similarly, there are two waysto cause the system to go into the Power-On Suspend sleep state (the strings towrite to the control files in that case are "standby" or "shallow" and "mem",respectively) if that state is supported by the platform.  In turn, there isonly one way to cause the system to go into the Suspend-To-RAM state (write"deep" into /sys/power/mem_sleep and "mem" into /sys/power/state).The default suspend mode (ie. the one to be used without writing anything into/sys/power/mem_sleep) is either "deep" (if Suspend-To-RAM is supported) or"s2idle", but it can be overridden by the value of the "mem_sleep_default"parameter in the kernel command line.The properties of all of the sleep states are described below.State:Suspend-To-IdleACPI state:S0Label:"s2idle" ("freeze")This state is a generic, pure software, light-weight, system sleep state.It allows more energy to be saved relative to runtime idle by freezing userspace and putting all I/O devices into low-power states (possiblylower-power than available at run time), such that the processors canspend more time in their idle states.This state can be used for platforms without Power-On Suspend/Suspend-to-RAMsupport, or it can be used in addition to Suspend-to-RAM to provide reducedresume latency.  It is always supported.State:Standby / Power-On SuspendACPI State:S1Label:"shallow" ("standby")This state, if supported, offers moderate, though real, power savings, whileproviding a relatively low-latency transition back to a working system.  Nooperating state is lost (the CPU retains power), so the system easily starts upagain where it left off. In addition to freezing user space and putting all I/O devices into low-powerstates, which is done for Suspend-To-Idle too, nonboot CPUs are taken offlineand all low-level system functions are suspended during transitions into thisstate.  For this reason, it should allow more energy to be saved relative toSuspend-To-Idle, but the resume latency will generally be greater than for thatstate.State:Suspend-to-RAMACPI State:S3Label:"deep"This state, if supported, offers significant power savings as everything in thesystem is put into a low-power state, except for memory, which should be placedinto the self-refresh mode to retain its contents.  All of the steps carried outwhen entering Power-On Suspend are also carried out during transitions to STR.Additional operations may take place depending on the platform capabilities.  Inparticular, on ACPI systems the kernel passes control to the BIOS (platformfirmware) as the last step during STR transitions and that usually results inpowering down some more low-level components that aren't directly controlled bythe kernel.System and device state is saved and kept in memory.  All devices are suspendedand put into low-power states.  In many cases, all peripheral buses lose powerwhen entering STR, so devices must be able to handle the transition back to the"on" state.For at least ACPI, STR requires some minimal boot-strapping code to resume thesystem from it.  This may be the case on other platforms too.State:Suspend-to-diskACPI State:S4Label:"disk"This state offers the greatest power savings, and can be used even inthe absence of low-level platform support for power management. Thisstate operates similarly to Suspend-to-RAM, but includes a final stepof writing memory contents to disk. On resume, this is read and memoryis restored to its pre-suspend state. STD can be handled by the firmware or the kernel. If it is handled bythe firmware, it usually requires a dedicated partition that must besetup via another operating system for it to use. Despite theinconvenience, this method requires minimal work by the kernel, sincethe firmware will also handle restoring memory contents on resume. For suspend-to-disk, a mechanism called 'swsusp' (Swap Suspend) is usedto write memory contents to free swap space. swsusp has some restrictiverequirements, but should work in most cases. Some, albeit outdated,documentation can be found in Documentation/power/swsusp.txt.Alternatively, userspace can do most of the actual suspend to disk work,see userland-swsusp.txt.Once memory state is written to disk, the system may either enter alow-power state (like ACPI S4), or it may simply power down. Poweringdown offers greater savings, and allows this mechanism to work on anysystem. However, entering a real low-power state allows the user totrigger wake up events (e.g. pressing a key or opening a laptop lid).