Basic Diagnostics for Hibernate and Sleep

This post was published 6 years, 7 months ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

(This article is written with particular reference to Windows operating systems, especially Windows 7, although, some points are applicable to other operating systems as well).

The current state of a computer is almost entirely dependent on the state of the computer’s RAM. That is to say, that the data stored in memory tells the computer everything about what is currently going on. (The processor’s state is also important, but contains far less data).

As long as the state of the RAM can be maintained or recalled, the computer can be returned to the same state.  This is the premise behind power saving modes such as hibernate and sleep (standby/suspend). Both of these modes are common on modern computers (and are prevalent in most machines going back almost a decade).

Remember that RAM is termed ‘volatile memory’. That is, its state is not retained when power is lost. It is only as long as there is power flowing through the RAM that the data is retained.

Sleep vs. Hibernate

In sleep mode, the power is cut to most unneeded devices (e.g. hard drives spin down, video cards stop outputting, etc.), while other devices will enter a low power mode. A small amount of power, however, is needed to maintain the contents of the RAM, in order for the computer to be able to return to the previous state. When the computer exits sleep mode, the devices will regain full power, and since the contents of RAM has been preserved unchanged, everything will remain as it was previously. If however, power is lost while the computer is in sleep mode, the contents of the RAM will be lost, and the computer will have to start-up from scratch.

In hibernate, the contents of the RAM is saved to a file on the hard drive (hiberfil.sys). Since this file now contains an exact copy of the contents of the RAM, the computer can be fully powered down, and when restarted, the contents of the file is loaded into memory to restore the previous state. Hibernate requires no more power than a computer that has been shut down.

Typically, a desktop will use about 150W powered up and idle, 5W in sleep, and under 1W in hibernate or when powered off. Most laptops use about a quarter to half the power of a desktop.

Sleep States

Computers and their devices typically have 5 ‘sleep states’ (S0 is not really a sleep state), although, not all are supported by every device.

  • S0 – Fully powered on – normal operating state
  • S1 – Processor cache is emptied, CPU stops executing commands, CPU and RAM receive power (requires most power of sleep states, not a commonly seen state)
  • S2 – Same as S1, but: CPU is powered down (not a commonly seen state)
  • S3 – Almost everything but the RAM is powered down – this is the typical ‘Sleep’ state
  • S4 – Memory saved to hard drive – this is the typical ‘Hibernate’ state
  • S5 – Machine powered down, with enough power to wake with input (i.e. wake on LAN, start by pressing the keyboard, etc), sometimes called ‘Soft Off’.

Why doesn’t it work?

These power saving features are excellent – as long as they work, unfortunately, it often seems that there are barriers to their functioning, the most common of which seems to be the inability for a computer to remain in the desired power-saving mode.

Presuming that a computer supports the necessary power-saving modes (ACPI specification on modern operating systems), and that the necessary resources are available (i.e. hard drive space for hibernate, no loss of power for standby), the question arises as to why these might not work as expected.

(From here on, the word ‘sleep’ denotes a sleep state (S1-S4) – encompassing both sleep and hibernate)

Devices and Device Manager

Firstly, each device has its own power saving settings. If a device is unable to enter a sleep state or is set to wake the computer, it might be the culprit behind a computer that fails to remain in a sleep state. These settings are accessible through device manager (accessible through the control panel).

Devices that are commonly troublesome are networking devices and USB devices. Right clicking a device in either of these categories and selecting Properties, should bring up a dialogue box. One of the tabs of this dialogue box should be Power Management.

There are typically two check boxes under the Power Management tab:

  • Allow the computer to turn of this device to save power: as this suggests, the computer will be able to cut power to this device, and the device should support a power saving mode. This box should generally be checked.
  • Allow this device to wake the computer: this box indicates that the computer can be brought out of a sleep state by this device. The common instances of this are to have a computer ‘Wake on LAN’ (be brought out of sleep when specific data is received over the network), or allowing a keyboard (or other peripheral) to bring the computer out of sleep. While this does have many uses, it is one of the common causes of a computer failing to remain in a sleep state (and at least for diagnostic purposes, should be unchecked).

Through device manager, it is also possible to look at the supported sleep states for a particular device. Under the Details tab, the ‘Power Data’ property will show both the supported sleep states (D0-D5) of the device, and how those states map to the machine’s sleep states (S0-S5)

Another common cause of computers failing to enter the sleep state is software running on the machine. An example of would be a media player, which disables sleep modes so that a user can watch a movie uninterrupted. While a cursory review of the software running might be helpful, in many cases, one will fail to identify the software that is preventing the machine from entering a sleep state. Luckily there is a solution.

PowerCfg

One of the most useful tools for diagnosing sleep state problems on a computer is built into windows – powercfg. This is a command line tool, and must be run as an administrator.

To start, you must open an administrative command prompt.

  • Start > All Programs > Accessories
  • Right click Command Prompt, and select Run as Administrator
  • The window that opens will be titled Administrator: Command Prompt

Power Requests

In order to determine what applications and drivers are requesting power, we can run: powercfg –requests

From the help for powercfg: “Power Requests prevent the computer from automatically powering off the display or entering a low-power sleep mode”.

A typical output might look like the following (I am running VLC at the moment):

C:\>powercfg -requests
DISPLAY:
[PROCESS] \Device\HarddiskVolume1\Program Files (x86)\VideoLAN\VLC\vlc.exe

SYSTEM:
[DRIVER] High Definition Audio Device (HDAUDIO\FUNC_01&VEN_10EC&DEV_0662&SUBSYS_14621033&REV_1001\4&bb96953&0&0001)
An audio stream is currently in use.

AWAYMODE:
None.

If I was experiencing trouble entering a sleep state, the above output would suggest that I should consider looking at VLC as a starting point.

In a scenario where a computer is unexpectedly waking from a sleep state, it is helpful to know a) what devices are setup to wake the computer from sleep and b) what was the last cause of the computer waking from sleep.

Devices that can wake the computer

We previously mentioned how device manager could be used to look at which devices were set to wake the computer from a sleep state. The same task can be accomplished by using powercfg:

powercfg -devicequery wake_armed

This command will output a list of devices that are currently configured to wake the system from any sleep state. (If no devices are setup this way, the command will not output anything).

Last cause of waking

powercfg will also tell us the cause of the last sleep transition:

powercfg -lastwake

A typical output might resemble the following:

C:\>powercfg -lastwake
Wake History Count - 1
Wake History [0]
    Wake Source Count - 1
    Wake Source [0]
          Type: Fixed Feature
          Power Button

(My computer was last brought out of sleep by using the power button)

Timed Wakeup

Another way for a computer to exit a sleep state is due to a timer (some scheduled tasks will wake the computer at a specified time). In order to find out if there are any ‘wake timers’ set, we can run:

powercfg -waketimers

Energy Summary

If one still has not managed to determine the cause of their sleep state problems, powercfg has one more handy function – an energy analysis. This will attempt to determine what is using excessive resources, and what is preventing the computer from entering a sleep state. There is a good bit of overlap in the output of this command and the commands listed above. This command, however, will produce an HTML file as its output. The command to run is:

powercfg -energy

This command will run a 60 second trace, and will create an output file (energy-report.html), in the current directory (typically C:\Windows\System32, unless you changed it with cd). Keep in mind that some browsers might not be able to open a file in System32, so you may need to copy the file to a more accessible location.

There are two more features of powercfg that merit a mention.

Disabling Hibernate

Firstly, to disable hibernate on Windows 7, one can run:

powercfg -H off

(to enable hibernate, one would run powercfg -H on)

Supported Sleep States

Secondly, powercfg will show you the sleep states that are supported by your machine:

powercfg -A

A typical output might resemble the following:

C:\>powercfg -A
The following sleep states are available on this system: Standby ( S3 ) Hibernate Hybrid Sleep
The following sleep states are not available on this system:
Standby (S1)
         The system firmware does not support this standby state.
Standby (S2)
         The system firmware does not support this standby state.

While by no means comprehensive, hopefully you have, at least a starting point, maybe a solution, and perhaps a different insight into the states of sleep.

3 thoughts on “Basic Diagnostics for Hibernate and Sleep

  1. Good article. It described a number of causes on leaving the power saving modes.

    There is not much information on how to diagnose a failure to enter the sleep mode, however. Hope you can add this information (not just to ‘setup’ as mentioned).

Leave a Reply

Your email address will not be published. Required fields are marked *