SlideShare a Scribd company logo
Combining
Runtime PM
and
suspend/resume
Kevin Hilman
khilman@linaro.org
For an Introduction to runtime PM
http://people.linaro.org/~khilman/runtime_PM.html
What ? !!!
Now I have to add
Runtime PM to
my driver?
I thought
suspend/resume
was enough !!
System PM Runtime PM
Today: Separate worlds
Tomorrow
Happy
together
Runtime PM
· suspend on inactivity
· resume when needed
System PM
· suspend when requested
· resume with system
Hey! what if I could
implement runtime PM,
and get suspend
for free?
So... how to combine them?
First, make runtime PM work.
Use PM domains to manage common resources
(clocks, mux, power domains, IP common...)
Then, add suspend/resume... if needed.
Suspend triggers runtime PM
· Force inactivity in suspend
· device is now idle/inactive
· runtime PM takes over
Don't implement suspend
Necessary if device
is used by other
devices during
suspend
Example: OMAP I2C driver
Needed during suspend by other drivers
· I2C-connected RTC
· regulators on I2C-connected PMIC
Solution:
· runtime PM only (no suspend/resume hooks)
· full (re)init per xfer; stateless
Quiz 1: What if I2C driver implemented suspend and
was suspended before RTC?
Quiz 2: Who decides suspend ordering?
Great, so...
runtime PM, plus a little "enforcement"
in ->suspend() gets me both… right?
Yes...
Well...
Almost...
Except... there are several
ways for devices to be kept awake.
Tricky: async callbacks
PM workqueue frozen during suspend
· Asynchronous callbacks happen via
PM core workqueue (pm_wq)
· workqueue frozen during suspend
· Result: no async callbacks
Solution: use _sync() methods
Tricky: Autosuspend timeouts
Driver does some work during ->suspend()
· _get_sync()
· _put_sync_autosuspend()
· autosuspend callbacks are asynchronous
· Result: device left runtime enabled
Solution: PM domain magic
Tricky: PM core "protections"
PM core: device_prepare()
· increments usecount, decrements in _complete()
· effectively disables runtime suspend (but not resume)
Example: device runtime suspended: usecount = 0
· PM core prepare: _get_noresume(): usecount = 1
· driver ->suspend(): _get_sync(): usecount = 2
· driver uses HW
· driver ->suspend(): _put_sync(): usecount = 1
Result: stuck with usecount > 0, runtime enabled
Solution: PM domain magic
Tricky: userspace disable
runtime PM can be disabled from userspace
# echo on > /sys/devices/.../power/control
Oops, drivers using only runtime PM will
be left runtime enabled during suspend.
Solution: PM domain magic
PM domain magic
Use "late" callbacks
Ensure all devices are suspended
struct dev_pm_ops {
[...]
int (*suspend_late)(struct device *dev);
int (*resume_early)(struct device *dev);
};
struct dev_pm_domain {
struct dev_pm_ops ops;
};
The magic trick
Runtime suspend "enforced" for stuck devices
static int my_domain_suspend_late(struct device *dev)>
{
if (!pm_runtime_status_suspended(dev)) {
if (pm_generic_runtime_suspend(dev) == 0) {
/* platform-specific PM */
}
}
return 0;
}
Summary
· Runtime PM first
· use PM domains
· Keep drivers generic
What next?
· better understand PM core
protections in device_prepare()
· Help PM domains proliferate
· What else?
¿ Questions ?
結束

More Related Content

PDF
Android presentation
PDF
Embedded Android : System Development - Part IV
PDF
Kernel Recipes 2019 - XDP closer integration with network stack
PDF
introduction to linux kernel tcp/ip ptocotol stack
PDF
Embedded Android : System Development - Part III (Audio / Video HAL)
ODP
4. linux file systems
PDF
malloc & vmalloc in Linux
PDF
Introduction to eBPF and XDP
Android presentation
Embedded Android : System Development - Part IV
Kernel Recipes 2019 - XDP closer integration with network stack
introduction to linux kernel tcp/ip ptocotol stack
Embedded Android : System Development - Part III (Audio / Video HAL)
4. linux file systems
malloc & vmalloc in Linux
Introduction to eBPF and XDP

What's hot (20)

PDF
Extending kubernetes with CustomResourceDefinitions
PDF
A crash course in CRUSH
PDF
PDF
Spi drivers
PDF
The linux networking architecture
PPTX
Linux Network Stack
PPTX
U-Boot presentation 2013
PDF
Embedded Android : System Development - Part IV (Android System Services)
PDF
Linux-Internals-and-Networking
PPT
Linux kernel memory allocators
PDF
Kubernetes extensibility: CRDs & Operators
PDF
Fun with Network Interfaces
PDF
Booting Android: bootloaders, fastboot and boot images
PDF
Splash screen for Embedded Linux 101: How to customize your boot sequence
PDF
Linux Performance Profiling and Monitoring
PDF
Android Internals
PPT
linux device driver
PDF
Implementing generic JNI hardware control for Kotlin based app on AOSP
PPTX
Linux Serial Driver
ODP
Q4.11: Porting Android to new Platforms
Extending kubernetes with CustomResourceDefinitions
A crash course in CRUSH
Spi drivers
The linux networking architecture
Linux Network Stack
U-Boot presentation 2013
Embedded Android : System Development - Part IV (Android System Services)
Linux-Internals-and-Networking
Linux kernel memory allocators
Kubernetes extensibility: CRDs & Operators
Fun with Network Interfaces
Booting Android: bootloaders, fastboot and boot images
Splash screen for Embedded Linux 101: How to customize your boot sequence
Linux Performance Profiling and Monitoring
Android Internals
linux device driver
Implementing generic JNI hardware control for Kotlin based app on AOSP
Linux Serial Driver
Q4.11: Porting Android to new Platforms
Ad

Similar to LCA13: Combining Runtime PM and suspend/resume (18)

PDF
Hilman-Runtime-Power management linux .pdf
PDF
Kernel Recipes 2015: Introduction to Kernel Power Management
PDF
Kernel Recipes 2019 - What To Do When Your Device Depends on Another One
PDF
HKG15-107: ACPI Power Management on ARM64 Servers (v2)
PDF
SoC Idling for unconf COSCUP 2016
PDF
Linux Device Driver parallelism using SMP and Kernel Pre-emption
PDF
Linux Power Management Discussions & Lessons Learned
PDF
LCA13: CPUIDLE: One driver to rule them all?
PDF
Isometric Making Essay
PPTX
Window IO
PDF
Linux_swspnd_v0.3_pub1
PDF
BUD17-510: Power management in Linux together with secure firmware
PDF
Lecture Presentation 11.pdfLecture Presentation 9.pdf fpga soc
PPT
OS_Unit_II_Ch3 Process and CPU Scheduling
PPT
Operatingsystems lecture2
PDF
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
PDF
Kernel Features for Reducing Power Consumption on Embedded Devices
PDF
Lect17
Hilman-Runtime-Power management linux .pdf
Kernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2019 - What To Do When Your Device Depends on Another One
HKG15-107: ACPI Power Management on ARM64 Servers (v2)
SoC Idling for unconf COSCUP 2016
Linux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Power Management Discussions & Lessons Learned
LCA13: CPUIDLE: One driver to rule them all?
Isometric Making Essay
Window IO
Linux_swspnd_v0.3_pub1
BUD17-510: Power management in Linux together with secure firmware
Lecture Presentation 11.pdfLecture Presentation 9.pdf fpga soc
OS_Unit_II_Ch3 Process and CPU Scheduling
Operatingsystems lecture2
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
Kernel Features for Reducing Power Consumption on Embedded Devices
Lect17
Ad

More from Linaro (20)

PDF
Deep Learning Neural Network Acceleration at the Edge - Andrea Gallo
PDF
Arm Architecture HPC Workshop Santa Clara 2018 - Kanta Vekaria
PDF
Huawei’s requirements for the ARM based HPC solution readiness - Joshua Mora
PDF
Bud17 113: distribution ci using qemu and open qa
PDF
OpenHPC Automation with Ansible - Renato Golin - Linaro Arm HPC Workshop 2018
PDF
HPC network stack on ARM - Linaro HPC Workshop 2018
PDF
It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
PDF
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
PDF
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
PDF
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
PDF
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
PDF
HKG18-100K1 - George Grey: Opening Keynote
PDF
HKG18-318 - OpenAMP Workshop
PDF
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
PDF
HKG18-315 - Why the ecosystem is a wonderful thing, warts and all
PDF
HKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
PDF
HKG18-TR08 - Upstreaming SVE in QEMU
PDF
HKG18-113- Secure Data Path work with i.MX8M
PPTX
HKG18-120 - Devicetree Schema Documentation and Validation
PPTX
HKG18-223 - Trusted FirmwareM: Trusted boot
Deep Learning Neural Network Acceleration at the Edge - Andrea Gallo
Arm Architecture HPC Workshop Santa Clara 2018 - Kanta Vekaria
Huawei’s requirements for the ARM based HPC solution readiness - Joshua Mora
Bud17 113: distribution ci using qemu and open qa
OpenHPC Automation with Ansible - Renato Golin - Linaro Arm HPC Workshop 2018
HPC network stack on ARM - Linaro HPC Workshop 2018
It just keeps getting better - SUSE enablement for Arm - Linaro HPC Workshop ...
Intelligent Interconnect Architecture to Enable Next Generation HPC - Linaro ...
Yutaka Ishikawa - Post-K and Arm HPC Ecosystem - Linaro Arm HPC Workshop Sant...
Andrew J Younge - Vanguard Astra - Petascale Arm Platform for U.S. DOE/ASC Su...
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-100K1 - George Grey: Opening Keynote
HKG18-318 - OpenAMP Workshop
HKG18-501 - EAS on Common Kernel 4.14 and getting (much) closer to mainline
HKG18-315 - Why the ecosystem is a wonderful thing, warts and all
HKG18- 115 - Partitioning ARM Systems with the Jailhouse Hypervisor
HKG18-TR08 - Upstreaming SVE in QEMU
HKG18-113- Secure Data Path work with i.MX8M
HKG18-120 - Devicetree Schema Documentation and Validation
HKG18-223 - Trusted FirmwareM: Trusted boot

Recently uploaded (20)

PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
STKI Israel Market Study 2025 version august
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
1. Introduction to Computer Programming.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Modernising the Digital Integration Hub
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
The various Industrial Revolutions .pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
STKI Israel Market Study 2025 version august
A comparative study of natural language inference in Swahili using monolingua...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
WOOl fibre morphology and structure.pdf for textiles
OMC Textile Division Presentation 2021.pptx
Hindi spoken digit analysis for native and non-native speakers
1. Introduction to Computer Programming.pptx
NewMind AI Weekly Chronicles - August'25-Week II
1 - Historical Antecedents, Social Consideration.pdf
Hybrid model detection and classification of lung cancer
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Tartificialntelligence_presentation.pptx
Modernising the Digital Integration Hub
Assigned Numbers - 2025 - Bluetooth® Document
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Zenith AI: Advanced Artificial Intelligence
The various Industrial Revolutions .pptx

LCA13: Combining Runtime PM and suspend/resume

  • 1. Combining Runtime PM and suspend/resume Kevin Hilman khilman@linaro.org For an Introduction to runtime PM http://people.linaro.org/~khilman/runtime_PM.html
  • 2. What ? !!! Now I have to add Runtime PM to my driver? I thought suspend/resume was enough !!
  • 3. System PM Runtime PM Today: Separate worlds
  • 5. Runtime PM · suspend on inactivity · resume when needed
  • 6. System PM · suspend when requested · resume with system
  • 7. Hey! what if I could implement runtime PM, and get suspend for free?
  • 8. So... how to combine them?
  • 9. First, make runtime PM work. Use PM domains to manage common resources (clocks, mux, power domains, IP common...) Then, add suspend/resume... if needed.
  • 10. Suspend triggers runtime PM · Force inactivity in suspend · device is now idle/inactive · runtime PM takes over
  • 11. Don't implement suspend Necessary if device is used by other devices during suspend
  • 12. Example: OMAP I2C driver Needed during suspend by other drivers · I2C-connected RTC · regulators on I2C-connected PMIC Solution: · runtime PM only (no suspend/resume hooks) · full (re)init per xfer; stateless Quiz 1: What if I2C driver implemented suspend and was suspended before RTC? Quiz 2: Who decides suspend ordering?
  • 13. Great, so... runtime PM, plus a little "enforcement" in ->suspend() gets me both… right? Yes... Well... Almost...
  • 14. Except... there are several ways for devices to be kept awake.
  • 15. Tricky: async callbacks PM workqueue frozen during suspend · Asynchronous callbacks happen via PM core workqueue (pm_wq) · workqueue frozen during suspend · Result: no async callbacks Solution: use _sync() methods
  • 16. Tricky: Autosuspend timeouts Driver does some work during ->suspend() · _get_sync() · _put_sync_autosuspend() · autosuspend callbacks are asynchronous · Result: device left runtime enabled Solution: PM domain magic
  • 17. Tricky: PM core "protections" PM core: device_prepare() · increments usecount, decrements in _complete() · effectively disables runtime suspend (but not resume) Example: device runtime suspended: usecount = 0 · PM core prepare: _get_noresume(): usecount = 1 · driver ->suspend(): _get_sync(): usecount = 2 · driver uses HW · driver ->suspend(): _put_sync(): usecount = 1 Result: stuck with usecount > 0, runtime enabled Solution: PM domain magic
  • 18. Tricky: userspace disable runtime PM can be disabled from userspace # echo on > /sys/devices/.../power/control Oops, drivers using only runtime PM will be left runtime enabled during suspend. Solution: PM domain magic
  • 20. Use "late" callbacks Ensure all devices are suspended struct dev_pm_ops { [...] int (*suspend_late)(struct device *dev); int (*resume_early)(struct device *dev); }; struct dev_pm_domain { struct dev_pm_ops ops; };
  • 21. The magic trick Runtime suspend "enforced" for stuck devices static int my_domain_suspend_late(struct device *dev)> { if (!pm_runtime_status_suspended(dev)) { if (pm_generic_runtime_suspend(dev) == 0) { /* platform-specific PM */ } } return 0; }
  • 22. Summary · Runtime PM first · use PM domains · Keep drivers generic
  • 23. What next? · better understand PM core protections in device_prepare() · Help PM domains proliferate · What else?