10c0b6b7bSRafael J. Wysocki=================== 20c0b6b7bSRafael J. WysockiSystem Sleep States 30c0b6b7bSRafael J. Wysocki=================== 40c0b6b7bSRafael J. Wysocki 50c0b6b7bSRafael J. Wysocki:: 60c0b6b7bSRafael J. Wysocki 70c0b6b7bSRafael J. Wysocki Copyright (c) 2017 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com> 80c0b6b7bSRafael J. Wysocki 90c0b6b7bSRafael J. WysockiSleep states are global low-power states of the entire system in which user 100c0b6b7bSRafael J. Wysockispace code cannot be executed and the overall system activity is significantly 110c0b6b7bSRafael J. Wysockireduced. 120c0b6b7bSRafael J. Wysocki 130c0b6b7bSRafael J. Wysocki 140c0b6b7bSRafael J. WysockiSleep States That Can Be Supported 150c0b6b7bSRafael J. Wysocki================================== 160c0b6b7bSRafael J. Wysocki 170c0b6b7bSRafael J. WysockiDepending on its configuration and the capabilities of the platform it runs on, 18c72a0dedSJonathan Neuschäferthe Linux kernel can support up to four system sleep states, including 190c0b6b7bSRafael J. Wysockihibernation and up to three variants of system suspend. The sleep states that 200c0b6b7bSRafael J. Wysockican be supported by the kernel are listed below. 210c0b6b7bSRafael J. Wysocki 220c0b6b7bSRafael J. Wysocki.. _s2idle: 230c0b6b7bSRafael J. Wysocki 240c0b6b7bSRafael J. WysockiSuspend-to-Idle 250c0b6b7bSRafael J. Wysocki--------------- 260c0b6b7bSRafael J. Wysocki 270c0b6b7bSRafael J. WysockiThis is a generic, pure software, light-weight variant of system suspend (also 280c0b6b7bSRafael J. Wysockireferred to as S2I or S2Idle). It allows more energy to be saved relative to 290c0b6b7bSRafael J. Wysockiruntime idle by freezing user space, suspending the timekeeping and putting all 300c0b6b7bSRafael J. WysockiI/O devices into low-power states (possibly lower-power than available in the 310c0b6b7bSRafael J. Wysockiworking state), such that the processors can spend time in their deepest idle 320c0b6b7bSRafael J. Wysockistates while the system is suspended. 330c0b6b7bSRafael J. Wysocki 340c0b6b7bSRafael J. WysockiThe system is woken up from this state by in-band interrupts, so theoretically 350c0b6b7bSRafael J. Wysockiany devices that can cause interrupts to be generated in the working state can 360c0b6b7bSRafael J. Wysockialso be set up as wakeup devices for S2Idle. 370c0b6b7bSRafael J. Wysocki 380c0b6b7bSRafael J. WysockiThis state can be used on platforms without support for :ref:`standby <standby>` 390c0b6b7bSRafael J. Wysockior :ref:`suspend-to-RAM <s2ram>`, or it can be used in addition to any of the 400c0b6b7bSRafael J. Wysockideeper system suspend variants to provide reduced resume latency. It is always 410c0b6b7bSRafael J. Wysockisupported if the :c:macro:`CONFIG_SUSPEND` kernel configuration option is set. 420c0b6b7bSRafael J. Wysocki 430c0b6b7bSRafael J. Wysocki.. _standby: 440c0b6b7bSRafael J. Wysocki 450c0b6b7bSRafael J. WysockiStandby 460c0b6b7bSRafael J. Wysocki------- 470c0b6b7bSRafael J. Wysocki 480c0b6b7bSRafael J. WysockiThis state, if supported, offers moderate, but real, energy savings, while 490c0b6b7bSRafael J. Wysockiproviding a relatively straightforward transition back to the working state. No 500c0b6b7bSRafael J. Wysockioperating state is lost (the system core logic retains power), so the system can 510c0b6b7bSRafael J. Wysockigo back to where it left off easily enough. 520c0b6b7bSRafael J. Wysocki 530c0b6b7bSRafael J. WysockiIn addition to freezing user space, suspending the timekeeping and putting all 540c0b6b7bSRafael J. WysockiI/O devices into low-power states, which is done for :ref:`suspend-to-idle 550c0b6b7bSRafael J. Wysocki<s2idle>` too, nonboot CPUs are taken offline and all low-level system functions 560c0b6b7bSRafael J. Wysockiare suspended during transitions into this state. For this reason, it should 570c0b6b7bSRafael J. Wysockiallow more energy to be saved relative to :ref:`suspend-to-idle <s2idle>`, but 580c0b6b7bSRafael J. Wysockithe resume latency will generally be greater than for that state. 590c0b6b7bSRafael J. Wysocki 600c0b6b7bSRafael J. WysockiThe set of devices that can wake up the system from this state usually is 610c0b6b7bSRafael J. Wysockireduced relative to :ref:`suspend-to-idle <s2idle>` and it may be necessary to 620c0b6b7bSRafael J. Wysockirely on the platform for setting up the wakeup functionality as appropriate. 630c0b6b7bSRafael J. Wysocki 640c0b6b7bSRafael J. WysockiThis state is supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration 650c0b6b7bSRafael J. Wysockioption is set and the support for it is registered by the platform with the 660c0b6b7bSRafael J. Wysockicore system suspend subsystem. On ACPI-based systems this state is mapped to 670c0b6b7bSRafael J. Wysockithe S1 system state defined by ACPI. 680c0b6b7bSRafael J. Wysocki 690c0b6b7bSRafael J. Wysocki.. _s2ram: 700c0b6b7bSRafael J. Wysocki 710c0b6b7bSRafael J. WysockiSuspend-to-RAM 720c0b6b7bSRafael J. Wysocki-------------- 730c0b6b7bSRafael J. Wysocki 740c0b6b7bSRafael J. WysockiThis state (also referred to as STR or S2RAM), if supported, offers significant 750c0b6b7bSRafael J. Wysockienergy savings as everything in the system is put into a low-power state, except 760c0b6b7bSRafael J. Wysockifor memory, which should be placed into the self-refresh mode to retain its 770c0b6b7bSRafael J. Wysockicontents. All of the steps carried out when entering :ref:`standby <standby>` 780c0b6b7bSRafael J. Wysockiare also carried out during transitions to S2RAM. Additional operations may 790c0b6b7bSRafael J. Wysockitake place depending on the platform capabilities. In particular, on ACPI-based 800c0b6b7bSRafael J. Wysockisystems the kernel passes control to the platform firmware (BIOS) as the last 810c0b6b7bSRafael J. Wysockistep during S2RAM transitions and that usually results in powering down some 820c0b6b7bSRafael J. Wysockimore low-level components that are not directly controlled by the kernel. 830c0b6b7bSRafael J. Wysocki 840c0b6b7bSRafael J. WysockiThe state of devices and CPUs is saved and held in memory. All devices are 850c0b6b7bSRafael J. Wysockisuspended and put into low-power states. In many cases, all peripheral buses 860c0b6b7bSRafael J. Wysockilose power when entering S2RAM, so devices must be able to handle the transition 870c0b6b7bSRafael J. Wysockiback to the "on" state. 880c0b6b7bSRafael J. Wysocki 890c0b6b7bSRafael J. WysockiOn ACPI-based systems S2RAM requires some minimal boot-strapping code in the 900c0b6b7bSRafael J. Wysockiplatform firmware to resume the system from it. This may be the case on other 910c0b6b7bSRafael J. Wysockiplatforms too. 920c0b6b7bSRafael J. Wysocki 930c0b6b7bSRafael J. WysockiThe set of devices that can wake up the system from S2RAM usually is reduced 940c0b6b7bSRafael J. Wysockirelative to :ref:`suspend-to-idle <s2idle>` and :ref:`standby <standby>` and it 950c0b6b7bSRafael J. Wysockimay be necessary to rely on the platform for setting up the wakeup functionality 960c0b6b7bSRafael J. Wysockias appropriate. 970c0b6b7bSRafael J. Wysocki 980c0b6b7bSRafael J. WysockiS2RAM is supported if the :c:macro:`CONFIG_SUSPEND` kernel configuration option 990c0b6b7bSRafael J. Wysockiis set and the support for it is registered by the platform with the core system 1000c0b6b7bSRafael J. Wysockisuspend subsystem. On ACPI-based systems it is mapped to the S3 system state 1010c0b6b7bSRafael J. Wysockidefined by ACPI. 1020c0b6b7bSRafael J. Wysocki 1030c0b6b7bSRafael J. Wysocki.. _hibernation: 1040c0b6b7bSRafael J. Wysocki 1050c0b6b7bSRafael J. WysockiHibernation 1060c0b6b7bSRafael J. Wysocki----------- 1070c0b6b7bSRafael J. Wysocki 1080c0b6b7bSRafael J. WysockiThis state (also referred to as Suspend-to-Disk or STD) offers the greatest 1090c0b6b7bSRafael J. Wysockienergy savings and can be used even in the absence of low-level platform support 1100c0b6b7bSRafael J. Wysockifor system suspend. However, it requires some low-level code for resuming the 1110c0b6b7bSRafael J. Wysockisystem to be present for the underlying CPU architecture. 1120c0b6b7bSRafael J. Wysocki 1130c0b6b7bSRafael J. WysockiHibernation is significantly different from any of the system suspend variants. 1140c0b6b7bSRafael J. WysockiIt takes three system state changes to put it into hibernation and two system 1150c0b6b7bSRafael J. Wysockistate changes to resume it. 1160c0b6b7bSRafael J. Wysocki 1170c0b6b7bSRafael J. WysockiFirst, when hibernation is triggered, the kernel stops all system activity and 1180c0b6b7bSRafael J. Wysockicreates a snapshot image of memory to be written into persistent storage. Next, 1190c0b6b7bSRafael J. Wysockithe system goes into a state in which the snapshot image can be saved, the image 1200c0b6b7bSRafael J. Wysockiis written out and finally the system goes into the target low-power state in 1210c0b6b7bSRafael J. Wysockiwhich power is cut from almost all of its hardware components, including memory, 1220c0b6b7bSRafael J. Wysockiexcept for a limited set of wakeup devices. 1230c0b6b7bSRafael J. Wysocki 1240c0b6b7bSRafael J. WysockiOnce the snapshot image has been written out, the system may either enter a 1250c0b6b7bSRafael J. Wysockispecial low-power state (like ACPI S4), or it may simply power down itself. 1260c0b6b7bSRafael J. WysockiPowering down means minimum power draw and it allows this mechanism to work on 1270c0b6b7bSRafael J. Wysockiany system. However, entering a special low-power state may allow additional 1280c0b6b7bSRafael J. Wysockimeans of system wakeup to be used (e.g. pressing a key on the keyboard or 1290c0b6b7bSRafael J. Wysockiopening a laptop lid). 1300c0b6b7bSRafael J. Wysocki 1310c0b6b7bSRafael J. WysockiAfter wakeup, control goes to the platform firmware that runs a boot loader 1320c0b6b7bSRafael J. Wysockiwhich boots a fresh instance of the kernel (control may also go directly to 1330c0b6b7bSRafael J. Wysockithe boot loader, depending on the system configuration, but anyway it causes 1340c0b6b7bSRafael J. Wysockia fresh instance of the kernel to be booted). That new instance of the kernel 1350c0b6b7bSRafael J. Wysocki(referred to as the ``restore kernel``) looks for a hibernation image in 1360c0b6b7bSRafael J. Wysockipersistent storage and if one is found, it is loaded into memory. Next, all 1370c0b6b7bSRafael J. Wysockiactivity in the system is stopped and the restore kernel overwrites itself with 1380c0b6b7bSRafael J. Wysockithe image contents and jumps into a special trampoline area in the original 1390c0b6b7bSRafael J. Wysockikernel stored in the image (referred to as the ``image kernel``), which is where 1400c0b6b7bSRafael J. Wysockithe special architecture-specific low-level code is needed. Finally, the 1410c0b6b7bSRafael J. Wysockiimage kernel restores the system to the pre-hibernation state and allows user 1420c0b6b7bSRafael J. Wysockispace to run again. 1430c0b6b7bSRafael J. Wysocki 1440c0b6b7bSRafael J. WysockiHibernation is supported if the :c:macro:`CONFIG_HIBERNATION` kernel 1450c0b6b7bSRafael J. Wysockiconfiguration option is set. However, this option can only be set if support 1460c0b6b7bSRafael J. Wysockifor the given CPU architecture includes the low-level code for system resume. 1470c0b6b7bSRafael J. Wysocki 1480c0b6b7bSRafael J. Wysocki 1490c0b6b7bSRafael J. WysockiBasic ``sysfs`` Interfaces for System Suspend and Hibernation 1500c0b6b7bSRafael J. Wysocki============================================================= 1510c0b6b7bSRafael J. Wysocki 1520c0b6b7bSRafael J. WysockiThe following files located in the :file:`/sys/power/` directory can be used by 1530c0b6b7bSRafael J. Wysockiuser space for sleep states control. 1540c0b6b7bSRafael J. Wysocki 1550c0b6b7bSRafael J. Wysocki``state`` 1560c0b6b7bSRafael J. Wysocki This file contains a list of strings representing sleep states supported 1570c0b6b7bSRafael J. Wysocki by the kernel. Writing one of these strings into it causes the kernel 1580c0b6b7bSRafael J. Wysocki to start a transition of the system into the sleep state represented by 1590c0b6b7bSRafael J. Wysocki that string. 1600c0b6b7bSRafael J. Wysocki 1610c0b6b7bSRafael J. Wysocki In particular, the strings "disk", "freeze" and "standby" represent the 1620c0b6b7bSRafael J. Wysocki :ref:`hibernation <hibernation>`, :ref:`suspend-to-idle <s2idle>` and 1630c0b6b7bSRafael J. Wysocki :ref:`standby <standby>` sleep states, respectively. The string "mem" 1640c0b6b7bSRafael J. Wysocki is interpreted in accordance with the contents of the ``mem_sleep`` file 1650c0b6b7bSRafael J. Wysocki described below. 1660c0b6b7bSRafael J. Wysocki 1670c0b6b7bSRafael J. Wysocki If the kernel does not support any system sleep states, this file is 1680c0b6b7bSRafael J. Wysocki not present. 1690c0b6b7bSRafael J. Wysocki 1700c0b6b7bSRafael J. Wysocki``mem_sleep`` 1710c0b6b7bSRafael J. Wysocki This file contains a list of strings representing supported system 1720c0b6b7bSRafael J. Wysocki suspend variants and allows user space to select the variant to be 1730c0b6b7bSRafael J. Wysocki associated with the "mem" string in the ``state`` file described above. 1740c0b6b7bSRafael J. Wysocki 1750c0b6b7bSRafael J. Wysocki The strings that may be present in this file are "s2idle", "shallow" 1760c0b6b7bSRafael J. Wysocki and "deep". The string "s2idle" always represents :ref:`suspend-to-idle 1770c0b6b7bSRafael J. Wysocki <s2idle>` and, by convention, "shallow" and "deep" represent 1780c0b6b7bSRafael J. Wysocki :ref:`standby <standby>` and :ref:`suspend-to-RAM <s2ram>`, 1790c0b6b7bSRafael J. Wysocki respectively. 1800c0b6b7bSRafael J. Wysocki 1810c0b6b7bSRafael J. Wysocki Writing one of the listed strings into this file causes the system 1820c0b6b7bSRafael J. Wysocki suspend variant represented by it to be associated with the "mem" string 1830c0b6b7bSRafael J. Wysocki in the ``state`` file. The string representing the suspend variant 1840c0b6b7bSRafael J. Wysocki currently associated with the "mem" string in the ``state`` file 1850c0b6b7bSRafael J. Wysocki is listed in square brackets. 1860c0b6b7bSRafael J. Wysocki 1870c0b6b7bSRafael J. Wysocki If the kernel does not support system suspend, this file is not present. 1880c0b6b7bSRafael J. Wysocki 1890c0b6b7bSRafael J. Wysocki``disk`` 1900c0b6b7bSRafael J. Wysocki This file contains a list of strings representing different operations 1910c0b6b7bSRafael J. Wysocki that can be carried out after the hibernation image has been saved. The 1920c0b6b7bSRafael J. Wysocki possible options are as follows: 1930c0b6b7bSRafael J. Wysocki 1940c0b6b7bSRafael J. Wysocki ``platform`` 1950c0b6b7bSRafael J. Wysocki Put the system into a special low-power state (e.g. ACPI S4) to 1960c0b6b7bSRafael J. Wysocki make additional wakeup options available and possibly allow the 1970c0b6b7bSRafael J. Wysocki platform firmware to take a simplified initialization path after 1980c0b6b7bSRafael J. Wysocki wakeup. 1990c0b6b7bSRafael J. Wysocki 2000c0b6b7bSRafael J. Wysocki ``shutdown`` 2010c0b6b7bSRafael J. Wysocki Power off the system. 2020c0b6b7bSRafael J. Wysocki 2030c0b6b7bSRafael J. Wysocki ``reboot`` 2040c0b6b7bSRafael J. Wysocki Reboot the system (useful for diagnostics mostly). 2050c0b6b7bSRafael J. Wysocki 2060c0b6b7bSRafael J. Wysocki ``suspend`` 2070c0b6b7bSRafael J. Wysocki Hybrid system suspend. Put the system into the suspend sleep 2080c0b6b7bSRafael J. Wysocki state selected through the ``mem_sleep`` file described above. 2090c0b6b7bSRafael J. Wysocki If the system is successfully woken up from that state, discard 2100c0b6b7bSRafael J. Wysocki the hibernation image and continue. Otherwise, use the image 2110c0b6b7bSRafael J. Wysocki to restore the previous state of the system. 2120c0b6b7bSRafael J. Wysocki 2130c0b6b7bSRafael J. Wysocki ``test_resume`` 2140c0b6b7bSRafael J. Wysocki Diagnostic operation. Load the image as though the system had 2150c0b6b7bSRafael J. Wysocki just woken up from hibernation and the currently running kernel 2160c0b6b7bSRafael J. Wysocki instance was a restore kernel and follow up with full system 2170c0b6b7bSRafael J. Wysocki resume. 2180c0b6b7bSRafael J. Wysocki 2190c0b6b7bSRafael J. Wysocki Writing one of the listed strings into this file causes the option 2200c0b6b7bSRafael J. Wysocki represented by it to be selected. 2210c0b6b7bSRafael J. Wysocki 2220c0b6b7bSRafael J. Wysocki The currently selected option is shown in square brackets which means 2230c0b6b7bSRafael J. Wysocki that the operation represented by it will be carried out after creating 2240c0b6b7bSRafael J. Wysocki and saving the image next time hibernation is triggered by writing 2250c0b6b7bSRafael J. Wysocki ``disk`` to :file:`/sys/power/state`. 2260c0b6b7bSRafael J. Wysocki 2270c0b6b7bSRafael J. Wysocki If the kernel does not support hibernation, this file is not present. 2280c0b6b7bSRafael J. Wysocki 2290c0b6b7bSRafael J. WysockiAccording to the above, there are two ways to make the system go into the 2300c0b6b7bSRafael J. Wysocki:ref:`suspend-to-idle <s2idle>` state. The first one is to write "freeze" 2310c0b6b7bSRafael J. Wysockidirectly to :file:`/sys/power/state`. The second one is to write "s2idle" to 2320c0b6b7bSRafael J. Wysocki:file:`/sys/power/mem_sleep` and then to write "mem" to 2330c0b6b7bSRafael J. Wysocki:file:`/sys/power/state`. Likewise, there are two ways to make the system go 2340c0b6b7bSRafael J. Wysockiinto the :ref:`standby <standby>` state (the strings to write to the control 2350c0b6b7bSRafael J. Wysockifiles in that case are "standby" or "shallow" and "mem", respectively) if that 2360c0b6b7bSRafael J. Wysockistate is supported by the platform. However, there is only one way to make the 2370c0b6b7bSRafael J. Wysockisystem go into the :ref:`suspend-to-RAM <s2ram>` state (write "deep" into 2380c0b6b7bSRafael J. Wysocki:file:`/sys/power/mem_sleep` and "mem" into :file:`/sys/power/state`). 2390c0b6b7bSRafael J. Wysocki 2400c0b6b7bSRafael J. WysockiThe default suspend variant (ie. the one to be used without writing anything 2410c0b6b7bSRafael J. Wysockiinto :file:`/sys/power/mem_sleep`) is either "deep" (on the majority of systems 2420c0b6b7bSRafael J. Wysockisupporting :ref:`suspend-to-RAM <s2ram>`) or "s2idle", but it can be overridden 2430c0b6b7bSRafael J. Wysockiby the value of the "mem_sleep_default" parameter in the kernel command line. 2440c0b6b7bSRafael J. WysockiOn some ACPI-based systems, depending on the information in the ACPI tables, the 2450c0b6b7bSRafael J. Wysockidefault may be "s2idle" even if :ref:`suspend-to-RAM <s2ram>` is supported. 246