How do wake timers work

sleepwake-up

Windows most commonly places a computer in S3 (standby/save-to-RAM) mode, where power is cut from the CPU but not to RAM.

If power is cut to the CPU, then how are wake timers triggered? Which component knows when to automatically wake the computer up?

If it is in the BIOS, how does Windows inform the BIOS of the next wakeup time?

Best Answer

This is done via the "alarm" registers in the RTC (real-time clock). On the original PC-AT, this chip was a Motorola MC146818.

Before going to sleep (ACPI S3), the kernel will program the next-scheduled wake-up time into the "alarm" registers on the RTC, which is always powered-on. When this wake-up time arrives, the RTC will trigger the chipset to power-on the system, and resume from S3. (Note that in most modern systems, the RTC is actually part of the southbridge itself, so the power-on signalling happens internally).

After the system resumes from sleep, the kernel will evaluate its list of pending wake events, dispatching the ones that have arrived.

This paper from Intel describes the interface (for x86 systems):

The programming of these registers is done in the Linux kernel in cmos_set_alarm.