xref: /OK3568_Linux_fs/kernel/Documentation/admin-guide/pm/sleep-states.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun.. include:: <isonum.txt>
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun===================
5*4882a593SmuzhiyunSystem Sleep States
6*4882a593Smuzhiyun===================
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun:Copyright: |copy| 2017 Intel Corporation
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunSleep states are global low-power states of the entire system in which user
14*4882a593Smuzhiyunspace code cannot be executed and the overall system activity is significantly
15*4882a593Smuzhiyunreduced.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunSleep States That Can Be Supported
19*4882a593Smuzhiyun==================================
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunDepending on its configuration and the capabilities of the platform it runs on,
22*4882a593Smuzhiyunthe Linux kernel can support up to four system sleep states, including
23*4882a593Smuzhiyunhibernation and up to three variants of system suspend.  The sleep states that
24*4882a593Smuzhiyuncan be supported by the kernel are listed below.
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun.. _s2idle:
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunSuspend-to-Idle
29*4882a593Smuzhiyun---------------
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunThis is a generic, pure software, light-weight variant of system suspend (also
32*4882a593Smuzhiyunreferred to as S2I or S2Idle).  It allows more energy to be saved relative to
33*4882a593Smuzhiyunruntime idle by freezing user space, suspending the timekeeping and putting all
34*4882a593SmuzhiyunI/O devices into low-power states (possibly lower-power than available in the
35*4882a593Smuzhiyunworking state), such that the processors can spend time in their deepest idle
36*4882a593Smuzhiyunstates while the system is suspended.
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunThe system is woken up from this state by in-band interrupts, so theoretically
39*4882a593Smuzhiyunany devices that can cause interrupts to be generated in the working state can
40*4882a593Smuzhiyunalso be set up as wakeup devices for S2Idle.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThis state can be used on platforms without support for :ref:`standby <standby>`
43*4882a593Smuzhiyunor :ref:`suspend-to-RAM <s2ram>`, or it can be used in addition to any of the
44*4882a593Smuzhiyundeeper system suspend variants to provide reduced resume latency.  It is always
45*4882a593Smuzhiyunsupported if the :c:macro:`CONFIG_SUSPEND` kernel configuration option is set.
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun.. _standby:
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunStandby
50*4882a593Smuzhiyun-------
51*4882a593Smuzhiyun
52*4882a593SmuzhiyunThis state, if supported, offers moderate, but real, energy savings, while
53*4882a593Smuzhiyunproviding a relatively straightforward transition back to the working state.  No
54*4882a593Smuzhiyunoperating state is lost (the system core logic retains power), so the system can
55*4882a593Smuzhiyungo back to where it left off easily enough.
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunIn addition to freezing user space, suspending the timekeeping and putting all
58*4882a593SmuzhiyunI/O devices into low-power states, which is done for :ref:`suspend-to-idle
59*4882a593Smuzhiyun<s2idle>` too, nonboot CPUs are taken offline and all low-level system functions
60*4882a593Smuzhiyunare suspended during transitions into this state.  For this reason, it should
61*4882a593Smuzhiyunallow more energy to be saved relative to :ref:`suspend-to-idle <s2idle>`, but
62*4882a593Smuzhiyunthe resume latency will generally be greater than for that state.
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunThe set of devices that can wake up the system from this state usually is
65*4882a593Smuzhiyunreduced relative to :ref:`suspend-to-idle <s2idle>` and it may be necessary to
66*4882a593Smuzhiyunrely on the platform for setting up the wakeup functionality as appropriate.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunThis state is supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration
69*4882a593Smuzhiyunoption is set and the support for it is registered by the platform with the
70*4882a593Smuzhiyuncore system suspend subsystem.  On ACPI-based systems this state is mapped to
71*4882a593Smuzhiyunthe S1 system state defined by ACPI.
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun.. _s2ram:
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunSuspend-to-RAM
76*4882a593Smuzhiyun--------------
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunThis state (also referred to as STR or S2RAM), if supported, offers significant
79*4882a593Smuzhiyunenergy savings as everything in the system is put into a low-power state, except
80*4882a593Smuzhiyunfor memory, which should be placed into the self-refresh mode to retain its
81*4882a593Smuzhiyuncontents.  All of the steps carried out when entering :ref:`standby <standby>`
82*4882a593Smuzhiyunare also carried out during transitions to S2RAM.  Additional operations may
83*4882a593Smuzhiyuntake place depending on the platform capabilities.  In particular, on ACPI-based
84*4882a593Smuzhiyunsystems the kernel passes control to the platform firmware (BIOS) as the last
85*4882a593Smuzhiyunstep during S2RAM transitions and that usually results in powering down some
86*4882a593Smuzhiyunmore low-level components that are not directly controlled by the kernel.
87*4882a593Smuzhiyun
88*4882a593SmuzhiyunThe state of devices and CPUs is saved and held in memory.  All devices are
89*4882a593Smuzhiyunsuspended and put into low-power states.  In many cases, all peripheral buses
90*4882a593Smuzhiyunlose power when entering S2RAM, so devices must be able to handle the transition
91*4882a593Smuzhiyunback to the "on" state.
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunOn ACPI-based systems S2RAM requires some minimal boot-strapping code in the
94*4882a593Smuzhiyunplatform firmware to resume the system from it.  This may be the case on other
95*4882a593Smuzhiyunplatforms too.
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunThe set of devices that can wake up the system from S2RAM usually is reduced
98*4882a593Smuzhiyunrelative to :ref:`suspend-to-idle <s2idle>` and :ref:`standby <standby>` and it
99*4882a593Smuzhiyunmay be necessary to rely on the platform for setting up the wakeup functionality
100*4882a593Smuzhiyunas appropriate.
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunS2RAM is supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration option
103*4882a593Smuzhiyunis set and the support for it is registered by the platform with the core system
104*4882a593Smuzhiyunsuspend subsystem.  On ACPI-based systems it is mapped to the S3 system state
105*4882a593Smuzhiyundefined by ACPI.
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun.. _hibernation:
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunHibernation
110*4882a593Smuzhiyun-----------
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunThis state (also referred to as Suspend-to-Disk or STD) offers the greatest
113*4882a593Smuzhiyunenergy savings and can be used even in the absence of low-level platform support
114*4882a593Smuzhiyunfor system suspend.  However, it requires some low-level code for resuming the
115*4882a593Smuzhiyunsystem to be present for the underlying CPU architecture.
116*4882a593Smuzhiyun
117*4882a593SmuzhiyunHibernation is significantly different from any of the system suspend variants.
118*4882a593SmuzhiyunIt takes three system state changes to put it into hibernation and two system
119*4882a593Smuzhiyunstate changes to resume it.
120*4882a593Smuzhiyun
121*4882a593SmuzhiyunFirst, when hibernation is triggered, the kernel stops all system activity and
122*4882a593Smuzhiyuncreates a snapshot image of memory to be written into persistent storage.  Next,
123*4882a593Smuzhiyunthe system goes into a state in which the snapshot image can be saved, the image
124*4882a593Smuzhiyunis written out and finally the system goes into the target low-power state in
125*4882a593Smuzhiyunwhich power is cut from almost all of its hardware components, including memory,
126*4882a593Smuzhiyunexcept for a limited set of wakeup devices.
127*4882a593Smuzhiyun
128*4882a593SmuzhiyunOnce the snapshot image has been written out, the system may either enter a
129*4882a593Smuzhiyunspecial low-power state (like ACPI S4), or it may simply power down itself.
130*4882a593SmuzhiyunPowering down means minimum power draw and it allows this mechanism to work on
131*4882a593Smuzhiyunany system.  However, entering a special low-power state may allow additional
132*4882a593Smuzhiyunmeans of system wakeup to be used  (e.g. pressing a key on the keyboard or
133*4882a593Smuzhiyunopening a laptop lid).
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunAfter wakeup, control goes to the platform firmware that runs a boot loader
136*4882a593Smuzhiyunwhich boots a fresh instance of the kernel (control may also go directly to
137*4882a593Smuzhiyunthe boot loader, depending on the system configuration, but anyway it causes
138*4882a593Smuzhiyuna fresh instance of the kernel to be booted).  That new instance of the kernel
139*4882a593Smuzhiyun(referred to as the ``restore kernel``) looks for a hibernation image in
140*4882a593Smuzhiyunpersistent storage and if one is found, it is loaded into memory.  Next, all
141*4882a593Smuzhiyunactivity in the system is stopped and the restore kernel overwrites itself with
142*4882a593Smuzhiyunthe image contents and jumps into a special trampoline area in the original
143*4882a593Smuzhiyunkernel stored in the image (referred to as the ``image kernel``), which is where
144*4882a593Smuzhiyunthe special architecture-specific low-level code is needed.  Finally, the
145*4882a593Smuzhiyunimage kernel restores the system to the pre-hibernation state and allows user
146*4882a593Smuzhiyunspace to run again.
147*4882a593Smuzhiyun
148*4882a593SmuzhiyunHibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel
149*4882a593Smuzhiyunconfiguration option is set.  However, this option can only be set if support
150*4882a593Smuzhiyunfor the given CPU architecture includes the low-level code for system resume.
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun
153*4882a593SmuzhiyunBasic ``sysfs`` Interfaces for System Suspend and Hibernation
154*4882a593Smuzhiyun=============================================================
155*4882a593Smuzhiyun
156*4882a593SmuzhiyunThe power management subsystem provides userspace with a unified ``sysfs``
157*4882a593Smuzhiyuninterface for system sleep regardless of the underlying system architecture or
158*4882a593Smuzhiyunplatform.  That interface is located in the :file:`/sys/power/` directory
159*4882a593Smuzhiyun(assuming that ``sysfs`` is mounted at :file:`/sys`) and it consists of the
160*4882a593Smuzhiyunfollowing attributes (files):
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun``state``
163*4882a593Smuzhiyun	This file contains a list of strings representing sleep states supported
164*4882a593Smuzhiyun	by the kernel.  Writing one of these strings into it causes the kernel
165*4882a593Smuzhiyun	to start a transition of the system into the sleep state represented by
166*4882a593Smuzhiyun	that string.
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun	In particular, the "disk", "freeze" and "standby" strings represent the
169*4882a593Smuzhiyun	:ref:`hibernation <hibernation>`, :ref:`suspend-to-idle <s2idle>` and
170*4882a593Smuzhiyun	:ref:`standby <standby>` sleep states, respectively.  The "mem" string
171*4882a593Smuzhiyun	is interpreted in accordance with the contents of the ``mem_sleep`` file
172*4882a593Smuzhiyun	described below.
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun	If the kernel does not support any system sleep states, this file is
175*4882a593Smuzhiyun	not present.
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun``mem_sleep``
178*4882a593Smuzhiyun	This file contains a list of strings representing supported system
179*4882a593Smuzhiyun	suspend	variants and allows user space to select the variant to be
180*4882a593Smuzhiyun	associated with the "mem" string in the ``state`` file described above.
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun	The strings that may be present in this file are "s2idle", "shallow"
183*4882a593Smuzhiyun	and "deep".  The "s2idle" string always represents :ref:`suspend-to-idle
184*4882a593Smuzhiyun	<s2idle>` and, by convention, "shallow" and "deep" represent
185*4882a593Smuzhiyun	:ref:`standby <standby>` and :ref:`suspend-to-RAM <s2ram>`,
186*4882a593Smuzhiyun	respectively.
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun	Writing one of the listed strings into this file causes the system
189*4882a593Smuzhiyun	suspend variant represented by it to be associated with the "mem" string
190*4882a593Smuzhiyun	in the ``state`` file.  The string representing the suspend variant
191*4882a593Smuzhiyun	currently associated with the "mem" string in the ``state`` file is
192*4882a593Smuzhiyun	shown in square brackets.
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun	If the kernel does not support system suspend, this file is not present.
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun``disk``
197*4882a593Smuzhiyun	This file controls the operating mode of hibernation (Suspend-to-Disk).
198*4882a593Smuzhiyun	Specifically, it tells the kernel what to do after creating a
199*4882a593Smuzhiyun	hibernation image.
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun	Reading from it returns a list of supported options encoded as:
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun	``platform``
204*4882a593Smuzhiyun		Put the system into a special low-power state (e.g. ACPI S4) to
205*4882a593Smuzhiyun		make additional wakeup options available and possibly allow the
206*4882a593Smuzhiyun		platform firmware to take a simplified initialization path after
207*4882a593Smuzhiyun		wakeup.
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun		It is only available if the platform provides a special
210*4882a593Smuzhiyun		mechanism to put the system to sleep after creating a
211*4882a593Smuzhiyun		hibernation image (platforms with ACPI do that as a rule, for
212*4882a593Smuzhiyun		example).
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun	``shutdown``
215*4882a593Smuzhiyun		Power off the system.
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun	``reboot``
218*4882a593Smuzhiyun		Reboot the system (useful for diagnostics mostly).
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun	``suspend``
221*4882a593Smuzhiyun		Hybrid system suspend.  Put the system into the suspend sleep
222*4882a593Smuzhiyun		state selected through the ``mem_sleep`` file described above.
223*4882a593Smuzhiyun		If the system is successfully woken up from that state, discard
224*4882a593Smuzhiyun		the hibernation image and continue.  Otherwise, use the image
225*4882a593Smuzhiyun		to restore the previous state of the system.
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun		It is available if system suspend is supported.
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun	``test_resume``
230*4882a593Smuzhiyun		Diagnostic operation.  Load the image as though the system had
231*4882a593Smuzhiyun		just woken up from hibernation and the currently running kernel
232*4882a593Smuzhiyun		instance was a restore kernel and follow up with full system
233*4882a593Smuzhiyun		resume.
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun	Writing one of the strings listed above into this file causes the option
236*4882a593Smuzhiyun	represented by it to be selected.
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun	The currently selected option is shown in square brackets, which means
239*4882a593Smuzhiyun	that the operation represented by it will be carried out after creating
240*4882a593Smuzhiyun	and saving the image when hibernation is triggered by writing ``disk``
241*4882a593Smuzhiyun	to :file:`/sys/power/state`.
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun	If the kernel does not support hibernation, this file is not present.
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun``image_size``
246*4882a593Smuzhiyun	This file controls the size of hibernation images.
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun	It can be written a string representing a non-negative integer that will
249*4882a593Smuzhiyun	be used as a best-effort upper limit of the image size, in bytes.  The
250*4882a593Smuzhiyun	hibernation core will do its best to ensure that the image size will not
251*4882a593Smuzhiyun	exceed that number, but if that turns out to be impossible to achieve, a
252*4882a593Smuzhiyun	hibernation image will still be created and its size will be as small as
253*4882a593Smuzhiyun	possible.  In particular, writing '0' to this file causes the size of
254*4882a593Smuzhiyun	hibernation images to be minimum.
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun	Reading from it returns the current image size limit, which is set to
257*4882a593Smuzhiyun	around 2/5 of the available RAM size by default.
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun``pm_trace``
260*4882a593Smuzhiyun	This file controls the "PM trace" mechanism saving the last suspend
261*4882a593Smuzhiyun	or resume event point in the RTC memory across reboots.  It helps to
262*4882a593Smuzhiyun	debug hard lockups or reboots due to device driver failures that occur
263*4882a593Smuzhiyun	during system suspend or resume (which is more common) more effectively.
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun	If it contains "1", the fingerprint of each suspend/resume event point
266*4882a593Smuzhiyun	in turn will be stored in the RTC memory (overwriting the actual RTC
267*4882a593Smuzhiyun	information), so it will survive a system crash if one occurs right
268*4882a593Smuzhiyun	after storing it and it can be used later to identify the driver that
269*4882a593Smuzhiyun	caused the crash to happen.
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun	It contains "0" by default, which may be changed to "1" by writing a
272*4882a593Smuzhiyun	string representing a nonzero integer into it.
273*4882a593Smuzhiyun
274*4882a593SmuzhiyunAccording to the above, there are two ways to make the system go into the
275*4882a593Smuzhiyun:ref:`suspend-to-idle <s2idle>` state.  The first one is to write "freeze"
276*4882a593Smuzhiyundirectly to :file:`/sys/power/state`.  The second one is to write "s2idle" to
277*4882a593Smuzhiyun:file:`/sys/power/mem_sleep` and then to write "mem" to
278*4882a593Smuzhiyun:file:`/sys/power/state`.  Likewise, there are two ways to make the system go
279*4882a593Smuzhiyuninto the :ref:`standby <standby>` state (the strings to write to the control
280*4882a593Smuzhiyunfiles in that case are "standby" or "shallow" and "mem", respectively) if that
281*4882a593Smuzhiyunstate is supported by the platform.  However, there is only one way to make the
282*4882a593Smuzhiyunsystem go into the :ref:`suspend-to-RAM <s2ram>` state (write "deep" into
283*4882a593Smuzhiyun:file:`/sys/power/mem_sleep` and "mem" into :file:`/sys/power/state`).
284*4882a593Smuzhiyun
285*4882a593SmuzhiyunThe default suspend variant (ie. the one to be used without writing anything
286*4882a593Smuzhiyuninto :file:`/sys/power/mem_sleep`) is either "deep" (on the majority of systems
287*4882a593Smuzhiyunsupporting :ref:`suspend-to-RAM <s2ram>`) or "s2idle", but it can be overridden
288*4882a593Smuzhiyunby the value of the ``mem_sleep_default`` parameter in the kernel command line.
289*4882a593SmuzhiyunOn some systems with ACPI, depending on the information in the ACPI tables, the
290*4882a593Smuzhiyundefault may be "s2idle" even if :ref:`suspend-to-RAM <s2ram>` is supported in
291*4882a593Smuzhiyunprinciple.
292