Power Management in OS X

Macs have long had the ability to put some or all of their hardware to ‘sleep’, a state in which they are not exactly turned off, but which uses much less power. Waking a sleeping Mac is then far faster than starting up after a period shut down, and can impose less wear and tear on its components. Sleep and its resulting low power consumption are most important for laptops (and iOS devices), in optimising battery endurance – the period of use without mains power supply.

As with so many features of Macs and OS X, what started off as a relatively simple system has become much more sophisticated, and inevitably far more complex. It is quite possible now to configure the settings in the Energy Saver pane to permit hard drives, display, and system sleep, but for only one of those to actually happen. It is also sadly uncommon for Macs to crash or freeze when being woken up, and sometimes even when going to sleep.

Understanding Power Management in OS X is important when you are puzzled by sleep behaviour, befuddled by the complexities of the Energy Saver pane, or are trying to prevent crashes and freezes which occur on waking or sleeping. The only general-purpose tool which might help you understand what is going on or wrong is Console, with its log browser. However, your logs are likely to be full of many confusing messages, and using them to solve such problems is not easy.

Tools

Users are supposed to interact with Power Management through the Energy Saver pane, which has become simpler in design, but more confounding in its operation, over the years. Back in the Classic days of Mac OS 9, there were three separate slider controls to allow you to set the time delay before the system (CPU), display, and drives went to sleep, when not being used.

energysaver9

Now, in El Capitan, the appearance of, and controls available in, the Energy Saver pane vary according to model, and in many cases offer just a single slider, to control the time to display sleep.

energysaver1011

energysavermacpilot

Third-party tools such as MacPilot offer more controls, but may not have any different effect. This is because the settings from Energy Saver are effectively implemented through the pmset command line tool. If you want to do anything more sophisticated than the gross controls in Energy Saver, you need to use pmset in Terminal.

Power Management, and the Power Manager, work through what Apple terms the I/O Kit, part of OS X which is particularly important to those developing drivers and other support software for peripherals and other hardware devices. The Power Manager’s role is to manage the transition between different power states – awake and running, sleep, and off – so as to make the most efficient use of power.

There is another tool which used to be of vital importance to driver developers, IORegistryExplorer, which was supplied as part of Apple’s Xcode development environment. My copy from 2012 still seems to run fine despite its age, but it is no longer a part of Xcode. This allows you to browse the hierarchy of controllers, ports, and devices in what Apple terms the ‘power plane’. Its value for those not developing hardware drivers is probably very small indeed.

pmset

pmset gives you full access to the Power Manager powerd, and can be used to inspect its settings, browse its logs, and to control Power Management in much greater detail than offered even by the full controls in MacPilot. It can, like many command line tools, get you into serious trouble requiring SMC and NVRAM resetting, so you must be cautious before making any changes to its settings. Full information is, as ever, available in its man page, viewed in Terminal by typing
man pmset

A good way to start understanding the Power Manager is to ask for a list of the current settings, using
pmset -g

Here is a typical response from my iMac, with intercalated comments:

System-wide power settings:
DestroyFVKeyOnStandby 0

This relates to behaviour when File Vault is configured; if set to 1, then the keys to File Vault will be destroyed when going to standby mode, requiring you to enter the password in order to wake up.

Active Profiles:
UPS Power -1
AC Power -1*

These refer to custom profiles as stored in the Energy Saver pane settings file. The asterisk marks the currently active profile, that to be used when running on mains power.

Currently in use:
The following are the current Power Manager settings, which should match those in the active profile.

standby 0
Sleep On Power Button 0

Standby is disabled, as is forcing sleep using the Power Button.

womp 1
‘womp’ is wake on ethernet magic packet. In other words, this Mac will wake up for network access (in the Energy Saver pane).

halfdim 1
Display sleep is set to use a half-bright setting. I am not sure that this works on iMacs at present, as when this display sleeps, it goes fully black.

hibernatefile /private/var/vm/sleepimage
When hibernating, a current system image will be saved to this location. Don’t change this.

powernap 0
Whether Power Nap will be used, on those Macs which support it.

gpuswitch 2
This is currently undocumented, but appears to refer to sleep state in the GPU of graphics cards which support this feature.

autorestart 0
This determines whether your Mac restarts automatically when power is restored, after an outage.

networkoversleep 0
This is platform-specific, and determines how shared network services are provided during sleep. Don’t alter it.

disksleep 0
The time, in minutes, before hard drives are put to sleep, 0 meaning never sleep.

sleep 0 (sleep prevented by com.apple.serverd, xcsbuildd)
The time, in minutes, to system sleep. Here, two services – OS X Server and the Xcode build service – are preventing system sleep, even though the Energy Saver pane may allow it.

autopoweroffdelay 0
Supported by certain models only, after this delay in seconds (not minutes), the system will hibernate by writing an image to the drive and powering down memory.

hibernatemode 0
On desktops, set to 0, and will not hibernate, but only sleep. On portables, normally set to 3, which stores a hibernation image but does not power down memory. When set to 25, using pmset, will go into full hibernation, with memory powered down.

autopoweroff 0
After the period set in autopoweroffdelay, certain models will hibernate, when set.

ttyskeepawake 1
When set to 1, this prevents sleep when a remote login session remains active.

displaysleep 60
The delay, in minutes, before putting the display to sleep.

standbydelay 10800
The delay, in seconds, before hibernating, when supported.

So although my custom profile, as set in the Energy Saver pane, allows system sleep but not disk sleep, because OS X Server and Xcode’s build service are running, system sleep is prevented.

If you have been experiencing problems with the battery in a portable, then the command
pmset -g pslog
displays the power source log. This can be used to detect sudden discontinuities in battery power remaining which often occur with ageing batteries, for instance.

pmset -g log
displays the full Power Management log, which can be quite long and hard to decipher. However, if you suspect there are problems with waking, sleeping, or other functions, this can be a valuable tool. You will then see timed entries like
2016-06-06 01:19:28 +0100 Notification Display is turned off
when the display goes to sleep, and
2016-06-06 01:19:28 +0100 Assertions PID 80(com.apple.serverd) Summary PreventUserIdleSystemSleep "com.apple.service.xcode" 183:50:21 id:0x0x10000013b [System: PrevIdle]
when OS X Server and Xcode are preventing sleep.

Conclusion

With awake, Power Nap, asleep, semi-hibernating, and full hibernation, Power Management has become very complex – all the more so when you bear in mind that different models support quite different features. Getting to the bottom of problems can be tricky, but pmset is a valuable tool to help. Unfortunately the settings shown in the Energy Saver pane, and in its settings file, often do not reflect the Power Management settings in force. That is bad interface design, and requires re-engineering to ensure that the user can understand what is going on, without having to resort to pmset.