Sleep, Wake, and Startup: Hardware and ACPI

Our Macs, their firmware and software, normally take care to protect us from knowing much about the innards of their hardware. If the hardware is playing up, we run a hardware test or diagnostics, and may get an error code to suggest how expensive the repair bill will be.

But there are times when hardware plays up and diagnosis is more tricky. This is most common in problems with sleep, wake, and startup. This article dives a bit deeper into what happens then, and what diagnostic help is available.

Causes and reasons

When your Mac starts up, one of the early entries in its log records the reason for its last shutdown – the cause code:
kernel AppleSMC Previous shutdown cause: 5

You can find a partial listing of cause codes here, but so long as you see the number 5, indicating a normal shutdown initiated by the user, you can be happy.

Prior to a sleep, and sometimes on waking, you may see a Wake reason given, which uses a completely different set of codes, e.g.
16:31:41.017148 Default 115 0 kernel AppleACPIPlatform ACPI SLEEP
16:31:41.030198 Default 115 0 kernel AppleACPIPlatform ACPI S3 WAKE
16:31:41.038419 Default 115 0 kernel AppleACPIPlatform Wake reason: XHC1
16:31:41.038420 Default 115 0 kernel AppleACPIPlatform Wake reason: XHC1

You can also sometimes see a sleep cause code given on waking, using the standard cause codes which are given on startup.

Wake reasons become most apparent when you browse the log following problems with maintaining sleep, for example a laptop model which won’t stay asleep for more than a couple of minutes and keeps waking up, or one which keeps falling asleep.

Wake reasons which are reported include:

  • XHC1, which some claim relates to USB3 devices, but is normally the result of a Bluetooth device such as a wireless keyboard, mouse, or trackpad;
  • EC.SleepTimer, which is the expiry of a sleep timer;
  • (HibernateError), which occurs when problems are encountered trying to enter Hibernate mode;
  • EC.LidOpen (User) or EC LID0, when the lid of a laptop is opened;
  • EHC2, PWRB (User), and others, whose meanings are obscure.

A more healthy wake may just record ‘reason 1’ in a short series of entries from the kernel:
PMRD: System Wake
then slightly later
PMRD: full wake promotion (reason 1) 125 ms
full wake promotion (reason 1) 125 ms

ACPI

Unless you’re into serious hardware hacking, such as configuring non-Mac hardware to run macOS (a hackintosh, see this site), you almost certainly won’t have come across ACPI and its hardware controls.

The Advanced Configuration and Power Interface, ACPI, is the open standard used by Intel-based Macs (and most other computers) to discover their internal hardware components and manage their power states, including sleep. This is very low-level stuff which Mac users hardly ever get concerned with, but which posts potentially useful (or confusing) entries in the log.

Early on during startup, the AppleACPIPlatform kernel extension is loaded, and the ACPI tables are built, over a series of duplicated log entries. For example, here is the sequence for my iMac17,1 with spacers and duplicates removed:
RSDP 0x000000008AFFE014 000024 (v02 APPLE ) – the Root System Description Pointer, listing the rest of the tables
XSDT 0x000000008AFB9188 0000CC (v01 APPLE Apple00 00000000 01000013) – Apple’s Extended System Description Table
FACP 0x000000008AFF8000 0000F4 (v05 APPLE Apple00 00000000 Loki 0000005F)
DSDT 0x000000008AFEE000 005D4E (v03 APPLE iMac 00150001 INTL 20140424) – Differentiated System Description Table
FACS 0x000000008AF95000 000040
UEFI 0x000000008AF97000 000042 (v01 INTEL EDK2 00000002 01000013) – Intel Unified Extensible Firmware Interface (UEFI)
ECDT 0x000000008AFFA000 000053 (v01 APPLE Apple00 00000001 Loki 0000005F)
HPET 0x000000008AFF7000 000038 (v01 APPLE Apple00 00000001 Loki 0000005F)
APIC 0x000000008AFF6000 0000BC (v02 APPLE Apple00 00000001 Loki 0000005F)
MCFG 0x000000008AFF5000 00003C (v01 APPLE Apple00 00000001 Loki 0000005F)
SBST 0x000000008AFF4000 000030 (v01 APPLE Apple00 00000001 Loki 0000005F)
SSDT 0x000000008AFED000 000024 (v01 APPLE SmcDppt 00001000 INTL 20140424) – Secondary System Description Table for SMC
SSDT 0x000000008AFEA000 000024 (v01 APPLE PEG0SSD0 00001000 INTL 20140424)
SSDT 0x000000008AFE7000 000031 (v01 APPLE SsdtS3 00001000 INTL 20140424)
SSDT 0x000000008AFE6000 000293 (v01 APPLE SataAhci 00001000 INTL 20140424) – Secondary System Description Table for SATA
SSDT 0x000000008AFE5000 0000B8 (v01 APPLE Sdxc 00001000 INTL 20140424)
SSDT 0x000000008AFE1000 003E1B (v02 APPLE PcieTbt 00001000 INTL 20140424) – Secondary System Description Table for PCIE
SSDT 0x000000008AFD0000 0006B8 (v02 APPLE Xhci 00001000 INTL 20140424)
SSDT 0x000000008AFCF000 000696 (v02 PmRef Cpu0Ist 00003000 INTL 20140424) – Secondary System Description Table for Power Management
SSDT 0x000000008AFCE000 0005AA (v02 PmRef ApIst 00003000 INTL 20140424)
SSDT 0x000000008AFCD000 00028F (v02 PmRef Cpu0Cst 00003001 INTL 20140424)
SSDT 0x000000008AFCC000 000119 (v02 PmRef ApCst 00003000 INTL 20140424)
SSDT 0x000000008AFCB000 000EE4 (v02 CpuRef CpuSsdt 00003000 INTL 20140424) – Secondary System Description Table for CPU
DMAR 0x000000008AFCA000 000088 (v01 APPLE SKL 00000001 INTL 00000001)
VFCT 0x000000008AFBA000 00FE84 (v01 APPLE Apple00 00000001 AMD 31504F47)
All ACPI Tables successfully acquired

ACPI is enabled for the available processor cores, in a sequence such as the following, for a four-core model:
AppleACPICPU: ProcessorId=1 LocalApicId=0 Enabled
AppleACPICPU: ProcessorId=2 LocalApicId=2 Enabled
AppleACPICPU: ProcessorId=3 LocalApicId=4 Enabled
AppleACPICPU: ProcessorId=4 LocalApicId=6 Enabled
AppleACPICPU: ProcessorId=5 LocalApicId=255 Disabled
AppleACPICPU: ProcessorId=6 LocalApicId=255 Disabled
AppleACPICPU: ProcessorId=7 LocalApicId=255 Disabled
AppleACPICPU: ProcessorId=8 LocalApicId=255 Disabled

ACPI setup normally completes with a declaration of the supported sleep states, on this iMac17,1 listed as S3, S4, and S5. These are defined in the ACPI standard, which is usefully explained in its Wikipedia entry:

  • S3 – sleep with power maintained to memory
  • S4 – hibernation, in which the contents of main memory are saved to non-volatile storage and the system is powered down
  • S5 – ‘soft off’ in which minimal power is maintained to allow wake from network or peripherals, but that a reboot will then be required.

Normally you should see little of ACPI in the log, at least on Mac hardware. The appearance of errors is good reason to check your hardware out carefully, using hardware test or diagnostics. If they come back with the result that your Mac is healthy, you would do well to download and install the latest macOS Combo updater, to ensure that your system software is in order.

Settings in the Energy Saver pane are of great importance too: if you have enabled Wake for network access and another device on your network keeps trying to wake it up, then repeated waking is the likely result.

If at the end of all this your problems continue, then the more extensive diagnostics available in a Genius Bar or an authorised service provider will be essential.

(Thanks to Phil Stokes of Sqwarq, who asked the question about wake reasons in the first place.)