Skip to content

Conversation

@bjarki-andreasen
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen commented Jul 25, 2025

Introduce the option config PM_DEVICE_RUNTIME_DEFAULT_ENABLE which effectively implicitly adds the devicetree flag zephyr,pm-device-runtime-auto to every node in the devicetree. In reality, it ignores the flag and enables PM_DEVICE_RUNTIME unconditionally, but the behavior is identical from the outside.

Typically, SoCs which utilize PM_DEVICE_RUNTIME need it enabled for every device. Having to add a flag manually to every node all of the devicetrees for these SoCs is tedious and error prone. It is also a software property being set in the devicetree, so in multiple ways a problematic pattern.

Most of nordics SoCs require all devices to enable PM_DEVICE_RUNTIME if PM_DEVICE_RUNTIME is enabled, and the rest are not harmed by it since they have additional logic in the drivers to deal with runtime not being enabled (which can be optimized away by this change). It looks like this also is the case for Ambiq Apollo (@AlessandroLuo @RichardSWheatley @aaronyegx) and Xtensa Ace (@dcpleung @andyross @nashif), please check if this option would be helpful for your platforms as well :)

With the addition in this PR, we will stop running into issues like:

@bjarki-andreasen bjarki-andreasen force-pushed the nrf-pm-device-runtime-align branch 4 times, most recently from 0352a64 to 2f14d77 Compare July 25, 2025 13:00
@bjarki-andreasen bjarki-andreasen changed the title nRF pm device runtime align Introduce CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE Jul 25, 2025
@bjarki-andreasen bjarki-andreasen changed the title Introduce CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE Introduce CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE Jul 25, 2025
@bjarki-andreasen bjarki-andreasen marked this pull request as ready for review July 25, 2025 14:06
@zephyrbot zephyrbot added area: Samples Samples area: UART Universal Asynchronous Receiver-Transmitter area: Power Management platform: nRF Nordic nRFx area: SPI SPI bus labels Jul 25, 2025
@JordanYates
Copy link
Contributor

I'm not against this, but what is the reasoning behind this

Typically, SoCs which utilize PM_DEVICE_RUNTIME need it enabled for every device.

All of nordics SoCs require all devices to enable PM_DEVICE_RUNTIME if PM_DEVICE_RUNTIME is enabled

I've never had a situation where only enabling PM on some devices was problematic.

@bjarki-andreasen
Copy link
Contributor Author

bjarki-andreasen commented Jul 26, 2025

I'm not against this, but what is the reasoning behind this

Typically, SoCs which utilize PM_DEVICE_RUNTIME need it enabled for every device.
All of nordics SoCs require all devices to enable PM_DEVICE_RUNTIME if PM_DEVICE_RUNTIME is enabled

I've never had a situation where only enabling PM on some devices was problematic.

The reasoning is the 100+ redundant occurrences of zephyr,pm-device-runtime-auto; removed in the third commit of this PR. And that's just for nordic SoCs, there are 100+ more occurances in tree which could potentially be removed as well for other platforms mentioned in the description :)

@tbursztyka tbursztyka removed their assignment Aug 18, 2025
@bjarki-andreasen bjarki-andreasen force-pushed the nrf-pm-device-runtime-align branch from aa44db5 to d79e741 Compare August 19, 2025 10:59
nordic-krch
nordic-krch previously approved these changes Aug 19, 2025
decsny
decsny previously approved these changes Aug 27, 2025
@bjarki-andreasen
Copy link
Contributor Author

ping @ceolin

@bjarki-andreasen bjarki-andreasen requested a review from lyakh August 29, 2025 11:56
@bjarki-andreasen bjarki-andreasen dismissed stale reviews from decsny and nordic-krch via c331965 September 11, 2025 08:49
@bjarki-andreasen bjarki-andreasen force-pushed the nrf-pm-device-runtime-align branch from d79e741 to c331965 Compare September 11, 2025 08:49
@bjarki-andreasen
Copy link
Contributor Author

bjarki-andreasen commented Sep 11, 2025

I dropped the last commit with the 100+ removals of zephyr,pm-device-runtime-auto to avoid merge conflicts, it will be addressed with its own PR after this one has been merged

decsny
decsny previously approved these changes Sep 12, 2025
anangl
anangl previously approved these changes Sep 15, 2025
Copy link
Contributor

@tmleman tmleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can always be done later, but it would be worth updating the function documentation in zephyr/pm/device_runtime.h.
Now it won't automatically enable device runtime based solely on what's defined in the devicetree.

Comment on lines 390 to 392
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) {
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE) ||
(IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be something more like:

if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) && (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE) || atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO))) { return 0;	}

This way, it is more logically consistent because in the current version, this if suggests that CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE can be enabled without CONFIG_PM_DEVICE_RUNTIME.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While both work, I think your approach is a bit clearer, I will refactor it and add documentation regarding the runtime flag

@bjarki-andreasen bjarki-andreasen dismissed stale reviews from anangl and decsny via 967abef September 17, 2025 10:07
@bjarki-andreasen bjarki-andreasen force-pushed the nrf-pm-device-runtime-align branch from c331965 to 967abef Compare September 17, 2025 10:07
Many SoCs which use PM_DEVICE_RUNTIME need every device in the system to have PM_DEVICE_RUNTIME enabled to function. Currently, this is only possible by adding zephyr,pm-device-runtime-auto; to every node in every devicetree which could potentially implement device power management. This is very error prone since its easy to miss a node, especially if users apply overlays, where users need to know and remember to apply or reapply this property. This commit adds a Kconfig, disabled by default, which automatically treats every device as if it had the zephyr,pm-device-runtime-auto property added to every node. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Document the new CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE option. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Mention CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE in 4.3 release notes. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Enable CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE by default for all nordic SoCs if CONFIG_PM_DEVICE_RUNTIME is used. This will ensure consistent behavior across all nordic SoCs and remove the need for pasting the devicetree propert zephyr,pm-device-runtime-auto everywhere. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
@bjarki-andreasen bjarki-andreasen force-pushed the nrf-pm-device-runtime-align branch from 967abef to 6552d4e Compare September 17, 2025 10:07
@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label Sep 17, 2025
@bjarki-andreasen
Copy link
Contributor Author

Added documentation of the new option, and mentioned it in release notes. Additionally refactored an if statement based on input from @tmleman

@kartben kartben merged commit 61a9d6a into zephyrproject-rtos:main Sep 19, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Power Management area: Samples Samples area: SPI SPI bus area: UART Universal Asynchronous Receiver-Transmitter platform: nRF Nordic nRFx Release Notes To be mentioned in the release notes