sleep-states.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. ===================
  2. System Sleep States
  3. ===================
  4. ::
  5. Copyright (c) 2017 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  6. Sleep states are global low-power states of the entire system in which user
  7. space code cannot be executed and the overall system activity is significantly
  8. reduced.
  9. Sleep States That Can Be Supported
  10. ==================================
  11. Depending on its configuration and the capabilities of the platform it runs on,
  12. the Linux kernel can support up to four system sleep states, including
  13. hibernation and up to three variants of system suspend. The sleep states that
  14. can be supported by the kernel are listed below.
  15. .. _s2idle:
  16. Suspend-to-Idle
  17. ---------------
  18. This is a generic, pure software, light-weight variant of system suspend (also
  19. referred to as S2I or S2Idle). It allows more energy to be saved relative to
  20. runtime idle by freezing user space, suspending the timekeeping and putting all
  21. I/O devices into low-power states (possibly lower-power than available in the
  22. working state), such that the processors can spend time in their deepest idle
  23. states while the system is suspended.
  24. The system is woken up from this state by in-band interrupts, so theoretically
  25. any devices that can cause interrupts to be generated in the working state can
  26. also be set up as wakeup devices for S2Idle.
  27. This state can be used on platforms without support for :ref:`standby <standby>`
  28. or :ref:`suspend-to-RAM <s2ram>`, or it can be used in addition to any of the
  29. deeper system suspend variants to provide reduced resume latency. It is always
  30. supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration option is set.
  31. .. _standby:
  32. Standby
  33. -------
  34. This state, if supported, offers moderate, but real, energy savings, while
  35. providing a relatively straightforward transition back to the working state. No
  36. operating state is lost (the system core logic retains power), so the system can
  37. go back to where it left off easily enough.
  38. In addition to freezing user space, suspending the timekeeping and putting all
  39. I/O devices into low-power states, which is done for :ref:`suspend-to-idle
  40. <s2idle>` too, nonboot CPUs are taken offline and all low-level system functions
  41. are suspended during transitions into this state. For this reason, it should
  42. allow more energy to be saved relative to :ref:`suspend-to-idle <s2idle>`, but
  43. the resume latency will generally be greater than for that state.
  44. The set of devices that can wake up the system from this state usually is
  45. reduced relative to :ref:`suspend-to-idle <s2idle>` and it may be necessary to
  46. rely on the platform for setting up the wakeup functionality as appropriate.
  47. This state is supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration
  48. option is set and the support for it is registered by the platform with the
  49. core system suspend subsystem. On ACPI-based systems this state is mapped to
  50. the S1 system state defined by ACPI.
  51. .. _s2ram:
  52. Suspend-to-RAM
  53. --------------
  54. This state (also referred to as STR or S2RAM), if supported, offers significant
  55. energy savings as everything in the system is put into a low-power state, except
  56. for memory, which should be placed into the self-refresh mode to retain its
  57. contents. All of the steps carried out when entering :ref:`standby <standby>`
  58. are also carried out during transitions to S2RAM. Additional operations may
  59. take place depending on the platform capabilities. In particular, on ACPI-based
  60. systems the kernel passes control to the platform firmware (BIOS) as the last
  61. step during S2RAM transitions and that usually results in powering down some
  62. more low-level components that are not directly controlled by the kernel.
  63. The state of devices and CPUs is saved and held in memory. All devices are
  64. suspended and put into low-power states. In many cases, all peripheral buses
  65. lose power when entering S2RAM, so devices must be able to handle the transition
  66. back to the "on" state.
  67. On ACPI-based systems S2RAM requires some minimal boot-strapping code in the
  68. platform firmware to resume the system from it. This may be the case on other
  69. platforms too.
  70. The set of devices that can wake up the system from S2RAM usually is reduced
  71. relative to :ref:`suspend-to-idle <s2idle>` and :ref:`standby <standby>` and it
  72. may be necessary to rely on the platform for setting up the wakeup functionality
  73. as appropriate.
  74. S2RAM is supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration option
  75. is set and the support for it is registered by the platform with the core system
  76. suspend subsystem. On ACPI-based systems it is mapped to the S3 system state
  77. defined by ACPI.
  78. .. _hibernation:
  79. Hibernation
  80. -----------
  81. This state (also referred to as Suspend-to-Disk or STD) offers the greatest
  82. energy savings and can be used even in the absence of low-level platform support
  83. for system suspend. However, it requires some low-level code for resuming the
  84. system to be present for the underlying CPU architecture.
  85. Hibernation is significantly different from any of the system suspend variants.
  86. It takes three system state changes to put it into hibernation and two system
  87. state changes to resume it.
  88. First, when hibernation is triggered, the kernel stops all system activity and
  89. creates a snapshot image of memory to be written into persistent storage. Next,
  90. the system goes into a state in which the snapshot image can be saved, the image
  91. is written out and finally the system goes into the target low-power state in
  92. which power is cut from almost all of its hardware components, including memory,
  93. except for a limited set of wakeup devices.
  94. Once the snapshot image has been written out, the system may either enter a
  95. special low-power state (like ACPI S4), or it may simply power down itself.
  96. Powering down means minimum power draw and it allows this mechanism to work on
  97. any system. However, entering a special low-power state may allow additional
  98. means of system wakeup to be used (e.g. pressing a key on the keyboard or
  99. opening a laptop lid).
  100. After wakeup, control goes to the platform firmware that runs a boot loader
  101. which boots a fresh instance of the kernel (control may also go directly to
  102. the boot loader, depending on the system configuration, but anyway it causes
  103. a fresh instance of the kernel to be booted). That new instance of the kernel
  104. (referred to as the ``restore kernel``) looks for a hibernation image in
  105. persistent storage and if one is found, it is loaded into memory. Next, all
  106. activity in the system is stopped and the restore kernel overwrites itself with
  107. the image contents and jumps into a special trampoline area in the original
  108. kernel stored in the image (referred to as the ``image kernel``), which is where
  109. the special architecture-specific low-level code is needed. Finally, the
  110. image kernel restores the system to the pre-hibernation state and allows user
  111. space to run again.
  112. Hibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel
  113. configuration option is set. However, this option can only be set if support
  114. for the given CPU architecture includes the low-level code for system resume.
  115. Basic ``sysfs`` Interfaces for System Suspend and Hibernation
  116. =============================================================
  117. The following files located in the :file:`/sys/power/` directory can be used by
  118. user space for sleep states control.
  119. ``state``
  120. This file contains a list of strings representing sleep states supported
  121. by the kernel. Writing one of these strings into it causes the kernel
  122. to start a transition of the system into the sleep state represented by
  123. that string.
  124. In particular, the strings "disk", "freeze" and "standby" represent the
  125. :ref:`hibernation <hibernation>`, :ref:`suspend-to-idle <s2idle>` and
  126. :ref:`standby <standby>` sleep states, respectively. The string "mem"
  127. is interpreted in accordance with the contents of the ``mem_sleep`` file
  128. described below.
  129. If the kernel does not support any system sleep states, this file is
  130. not present.
  131. ``mem_sleep``
  132. This file contains a list of strings representing supported system
  133. suspend variants and allows user space to select the variant to be
  134. associated with the "mem" string in the ``state`` file described above.
  135. The strings that may be present in this file are "s2idle", "shallow"
  136. and "deep". The string "s2idle" always represents :ref:`suspend-to-idle
  137. <s2idle>` and, by convention, "shallow" and "deep" represent
  138. :ref:`standby <standby>` and :ref:`suspend-to-RAM <s2ram>`,
  139. respectively.
  140. Writing one of the listed strings into this file causes the system
  141. suspend variant represented by it to be associated with the "mem" string
  142. in the ``state`` file. The string representing the suspend variant
  143. currently associated with the "mem" string in the ``state`` file
  144. is listed in square brackets.
  145. If the kernel does not support system suspend, this file is not present.
  146. ``disk``
  147. This file contains a list of strings representing different operations
  148. that can be carried out after the hibernation image has been saved. The
  149. possible options are as follows:
  150. ``platform``
  151. Put the system into a special low-power state (e.g. ACPI S4) to
  152. make additional wakeup options available and possibly allow the
  153. platform firmware to take a simplified initialization path after
  154. wakeup.
  155. ``shutdown``
  156. Power off the system.
  157. ``reboot``
  158. Reboot the system (useful for diagnostics mostly).
  159. ``suspend``
  160. Hybrid system suspend. Put the system into the suspend sleep
  161. state selected through the ``mem_sleep`` file described above.
  162. If the system is successfully woken up from that state, discard
  163. the hibernation image and continue. Otherwise, use the image
  164. to restore the previous state of the system.
  165. ``test_resume``
  166. Diagnostic operation. Load the image as though the system had
  167. just woken up from hibernation and the currently running kernel
  168. instance was a restore kernel and follow up with full system
  169. resume.
  170. Writing one of the listed strings into this file causes the option
  171. represented by it to be selected.
  172. The currently selected option is shown in square brackets which means
  173. that the operation represented by it will be carried out after creating
  174. and saving the image next time hibernation is triggered by writing
  175. ``disk`` to :file:`/sys/power/state`.
  176. If the kernel does not support hibernation, this file is not present.
  177. According to the above, there are two ways to make the system go into the
  178. :ref:`suspend-to-idle <s2idle>` state. The first one is to write "freeze"
  179. directly to :file:`/sys/power/state`. The second one is to write "s2idle" to
  180. :file:`/sys/power/mem_sleep` and then to write "mem" to
  181. :file:`/sys/power/state`. Likewise, there are two ways to make the system go
  182. into the :ref:`standby <standby>` state (the strings to write to the control
  183. files in that case are "standby" or "shallow" and "mem", respectively) if that
  184. state is supported by the platform. However, there is only one way to make the
  185. system go into the :ref:`suspend-to-RAM <s2ram>` state (write "deep" into
  186. :file:`/sys/power/mem_sleep` and "mem" into :file:`/sys/power/state`).
  187. The default suspend variant (ie. the one to be used without writing anything
  188. into :file:`/sys/power/mem_sleep`) is either "deep" (on the majority of systems
  189. supporting :ref:`suspend-to-RAM <s2ram>`) or "s2idle", but it can be overridden
  190. by the value of the "mem_sleep_default" parameter in the kernel command line.
  191. On some ACPI-based systems, depending on the information in the ACPI tables, the
  192. default may be "s2idle" even if :ref:`suspend-to-RAM <s2ram>` is supported.