Sleeping Beauty
NetBSD on modern laptops

Jörg Sonnenberger

Jared D. McNeill





Device interface of PMF

The PCI/Cardbus bus handling

The network class handling

The audio class handling

System interface

Event interface

ACPI infrastructure

ACPICA update (I)

ACPICA update (II)

ACPI EC rewrite (I)

ACPI EC rewrite (II)

ACPI EC rewrite (III)

ACPI EC rewrite (IV)

ACPI EC rewrite (V)

ACPI EC rewrite (VI)

  • Problems:
    • Hardware doesn't polling in tight loop: 100ms delay from experiments
    • Missing interrupts: schedule callout and just poll after a tick
  • Robust driver and easily to add work arounds to

Existing Suspend-to-RAM support

  • i386 only
  • UP only
  • APM or ACPI S3

Cleanup for ACPI S3 (I)

  • setjmp/longjmp semantic and inline assembly harmful:
    • Move register saving and restoring into acpi_md_sleep_prepare (asm)
    • Suspend: acpi_md_sleep -> acpi_md_sleep_prepare -> acpi_md_sleep_enter
    • Resume: acpi_md_sleep_exit -> acpi_md_sleep_prepare -> acpi_md_sleep
    • Don't bother with callee-saved registers

Cleanup for ACPI S3 (II)

  • KISS: hard wire addresses, ld can handle the offset
  • KISS: copy page table and add identity mapping in the copy
  • KISS: only initialize what is required
    • ES, GS, SS or FS are not used early
    • IDT can be loaded after using the real GDT
    • GDT can be reloaded with the temporary GDT
    • PSE must be enabled when page table contains such pages — kernel code does

ACPI S3 on AMD64

  • Bootstrap simplified as real mode is guaranteed to be under 4GB
  • Two bootstrap:
    • Move to Protect Mode without Paging
    • Enable Long Mode
  • Must restore No Executable Bit early (like PSE)
  • Still very similar code


  • Mark Application Processors (APs) as offline during device suspend
  • Force FPU context switch on all CPUs.
  • Registers are saved to cpu_info
  • Inter-processor interrupt (IPI) for saving AP first
  • Restart APs on resume individually
  • Note: L1 cache flushes are core-local!

Video devices (I)

Video devices (II)

  • Too many incompatible VGA chips
  • Many don't have public specifications
  • DRM modesetting and initialisation not usable (yet?)

Video devices (II)

  • Some BIOSes turn on VGA (Thinkpads)
  • Some can be tricked into by setting a BIOS password
  • For some the Power On Self Test (POST) can be kicked on early
  • Some just crash with that (Dell)
  • Quo Vadis?

Video devices (II)

  • Most systems works by forcing a VGA POST
  • PCI bridges have to be reinitialised first
  • Solution: Emulate the Real Mode and call the VGA BIOS


  • Works entirely in userland
  • Either uses VM86 or software emulation
  • Problems:
    • Too late for debugging resume issues
    • Needs access to physical memory and IO ports

libx86emu (I)

  • Based on x86emu in vbetool and XFree86
  • Allows early POST
  • Problems:
    • Increases kernel size
    • VGA BIOS can crash kernel

libx86emu (II)

  • Size: 80 KB on AMD64
  • Allows emulation of specific devices, e.g. 8254 timers
  • Allows panic from within X11 to reset the console
  • Can be used for vesafb

Future work

  • Processor sleep states (4% for C2, 8% for C3)
  • Suspend of file systems
  • Low power states for devices (esp. USB, Firewire)
  • Suspend-to-disk