Repository navigation
Power management
Part III of the system development guide.
Suspending to RAM, hibernating and powering parts of a device down while idle all need every driver's cooperation: save state, stop the hardware, and bring it back. Parts marked (stub) are abridged.
A driver registers suspend and resume handlers at attach and deregisters them at detach:
if (!pmf_device_register(self, mydrv_suspend, mydrv_resume))
aprint_error_dev(self, "couldn't establish power handler\n");
...
pmf_device_deregister(self);Handlers return bool and receive a pmf_qual_t describing the kind
of suspend. The framework also calls bus and class layers:
PCI saves and restores configuration space and power state around the
driver's handlers; network and input classes have their own helpers
(pmf_class_network_register(), pmf_class_input_register()).
pmf_device_register1() adds a shutdown handler.
System suspend (pmf_system_suspend(), kern_pmf.c):
- refuses outright if any attached device has no pmf handlers
(
pmf_check_system_drivers()prints "Devices without power management support: ..."), so every driver must register, even with handlers that do nothing; - syncs file systems;
- suspends devices leaves first (children before parents,
DEVITER_F_LEAVES_FIRST). A handler that returns false is only logged ("(failed)"): the suspend is not aborted (anXXXin the code).
-
struct dev_pm_opson the driver:suspend/resumefor sleep;freeze/thaw/poweroff/restorefor hibernation;_lateand_noirqphases for ordering;prepare/complete. -
Runtime PM: devices power down while idle on their own;
pm_runtime_get_sync()/pm_runtime_put_autosuspend()around use,runtime_suspend/runtime_resumecallbacks. GPUs use it heavily (discrete GPUs in laptops sleep when not rendering).
- Each attachment registers pmf handlers that call the Linux driver's
own suspend and resume code — not its
dev_pm_ops, but the driver-internal functions behind them (amdgpu_do_suspend()callsdrm_suspend_ioctl()andamdgpu_device_suspend()). - Runtime PM calls are no-ops (
<linux/pm_runtime.h>): devices stay powered.struct dev_pm_infois minimal. - Hibernation is not supported by NetBSD.
pmf(9), sys/kern/kern_pmf.c, sys/sys/pmf.h;
sys/external/bsd/drm2/<driver>/<driver>_pci.c;
sys/external/bsd/drm2/include/linux/pm_runtime.h.
aiBSD system development guide
Tutorial
II — Building
III — The kernel
- Kernel basics
- Booting and kernel modules
- The boot loader
- Threads, processes, tasks
- Devices and drivers
- Files, descriptors, device nodes
- PCI
- Virtual memory
- Memory and DMA
- Page tables, TLBs, memory types
- Firmware
- State and events
- The console
- Power management
IV — Linux compat layer
V — DRM
VI — Testing
VII — Upstreams
Appendices