Remix.run Logo
▲ cowlevel 4 hours ago

It's not actually the CPU itself, which sleeps reliably. it's the whole very complicated ACPI thing and the drivers and hardware devices.

Because the PC platform can run on almost any hardware the OS needs a standard way to enter a sleep state, no matter the hardware. The hardware does this using something called ACPI tables, which essentially hold a bytecode program that's distributed as part of the BIOS flash image and is a black box to the OS. The program in ACPI tries to suspend all the hardware but it doesn't know what the OS is doing, and the OS doesn't know what the ACPI is doing, so they frequently conflict and get into weird states.

On embedded devices, suspend actually works quite well. Your phone doesn't have ACPI or BIOS, it has a kernel with direct access to hardware and that has no problem just toggling a few register bits to shut down certain clock domains and voltage regulators. In fact it works so well it all comes back online within half a second when you press the wake-up button, not the 20-second wake-up you get on PCs. It works so well the operating system continually suspends itself whenever apps aren't using a certain hardware feature. As I'm typing this the CPU is probably suspending itself between keystrokes, the radio is powering down its AFE outside of its timeslot, the speaker amplifier is probably off because I'm not listening to music. This stuff is why phones have good battery life but Linux phones don't, because desktop Linux is built around the whole computer being turned on while it's turned on.