Power Management Concepts
Understand the difference between runtime PM and system sleep.
Runtime PM: Idle Power Saving
Runtime PM suspends devices when they’re not in use while the system is running.
Example scenario: Network driver
- No packets for 5 seconds
- Driver calls
pm_runtime_put() - If reference count → 0,
runtime_suspend()is called - Device enters low-power mode
- Packet arrives →
pm_runtime_get()→runtime_resume()
flowchart LR
A["Device Active<br/>refcount > 0"] -->|"pm_runtime_put()<br/>refcount--"| B{"refcount == 0?"}
B -->|Yes| C["runtime_suspend()"]
C --> D["Device Suspended"]
D -->|"pm_runtime_get()<br/>refcount++"| E["runtime_resume()"]
E --> A
B -->|No| A
style C fill:#738f99,stroke:#0277bd
style E fill:#7a8f73,stroke:#2e7d32
System Sleep: Suspend/Resume
System sleep happens when the entire system enters a low-power state (S3 = suspend to RAM, S4 = hibernate).
Example scenario: Laptop lid close
- User closes lid
- System calls
suspend()on all devices - Devices save state, disable hardware
- System enters S3
- User opens lid
- System calls
resume()on all devices - Devices restore state
Reference Counting
Runtime PM uses reference counting to track active users:
/* Increment count - ensures device is active */
pm_runtime_get(dev); /* Async, returns immediately */
pm_runtime_get_sync(dev); /* Blocks until device is active */
/* Decrement count - may trigger suspend */
pm_runtime_put(dev); /* Async, may schedule suspend */
pm_runtime_put_sync(dev); /* Blocks if suspend happens */
/* Check status */
bool active = pm_runtime_active(dev);
Rule: Every get needs a matching put.
Always use
pm_runtime_get_sync()before accessing hardware to ensure the device is powered.
Autosuspend
To avoid rapid suspend/resume cycles, use autosuspend:
/* In probe: enable autosuspend with delay */
pm_runtime_set_autosuspend_delay(dev, 1000); /* 1 second */
pm_runtime_use_autosuspend(dev);
/* In code: mark idle, will suspend after delay */
pm_runtime_mark_last_busy(dev);
pm_runtime_put_autosuspend(dev);
This is useful for devices with bursty activity.
PM States
| State | Meaning | Power |
|---|---|---|
| Active | Device fully powered, processing | High |
| Runtime Suspended | Device idle, may be powered down | Low |
| System Suspended | System in S3/S4, device state saved | Very Low |
Callbacks Summary
| Callback | When Called |
|---|---|
runtime_suspend |
Device idle, refcount → 0 |
runtime_resume |
Device needed, pm_runtime_get() |
suspend |
System entering sleep |
resume |
System waking up |
Summary
| Concept | Description |
|---|---|
| Runtime PM | Saves power when device idle, system running |
| System Sleep | Saves power when system suspended |
| Reference count | Tracks active users of device |
| Autosuspend | Delays suspend to avoid rapid cycles |
Further Reading
- Runtime PM - Complete reference
- Device PM - Guidelines