Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm: Make device pm optional per state #60939

Closed
wants to merge 9 commits into from

Conversation

ceolin
Copy link
Member

@ceolin ceolin commented Jul 28, 2023

This is a proposal to make device power management (triggered when SoC is idle) completely optional.

  • Targets can select which power states should trigger device power management
  • If there is no power state with this property enabled, the pm subsystem won't trigger device power management
  • Removed the need for CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE

Notes:

This draft contains a proposal but it is not complete, some tests are failing because of the latest commit that completely disable device pm when it is not enabled in DT and we have some tests that don't use DT to check pm API. This is commit is basically an additional optimization to have the same we had with CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE.

In case of consensus, I will restore the current behavior adding zephyr,pm-device-enabled in all power states (across the tree) that are currently triggering device power management, then we can in a case by case disable it if need. But the idea is not breaking the current behavior.

Additional context:

@knthm
Copy link
Collaborator

knthm commented Aug 3, 2023

I think this is a very nice non-destructive compromise of #60463.

The ability to individually disable device PM for peripherals where it might conflict with system PM is a great idea! :)

@ceolin
Copy link
Member Author

ceolin commented Aug 3, 2023

I think this is a very nice non-destructive compromise of #60463.

The ability to individually disable device PM for peripherals where it might conflict with system PM is a great idea! :)

Thanks for looking it.

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

I think this PR doesn't solve the problems in device PM itself. At least with CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=y you had the guarantee that CONFIG_PM_DEVICE did nothing, now, as soon as you have a single state with zephyr,pm-device-enabled and a device with a blocking PM callback you're screwed again.

The main problem with CONFIG_PM_DEVICE is not that it doesn't allow blocking, but that it treats all devices equally. If we really want to keep this mode, I think it needs its own set of PM callbacks (where you can ask clients to not block), separate from PM device runtime (as on Linux, actually). But on MCUs this PM model doesn't make sense, you typically don't want to deal with devices on every LP state transition. Some MCUs need to perform actions when exiting certain LP states on a per-device basis (e.g. the STOP modes in STM32), but this is something that can be solved in a better way, for example, subscribing to such events as needed. And to me, such a mechanism could likely be re-used to finally get rid of CONFIG_PM_DEVICE. The problem here is that we've never got technical details on how it is being used to discuss a proper way forward, and we've been stuck forever with this.

@ceolin
Copy link
Member Author

ceolin commented Aug 4, 2023

I think this PR doesn't solve the problems in device PM itself. At least with CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=y you had the guarantee that CONFIG_PM_DEVICE did nothing, now, as soon as you have a single state with zephyr,pm-device-enabled and a device with a blocking PM callback you're screwed again.

That is not what this pr aims. The goal here is bring more flexibility for those who wants to use it and not breaking the current behavior. I can restore PM_DEVICE_RUNTIME_EXCLUSIVE though, since this pr does not easily replace it indeed.

The main problem with CONFIG_PM_DEVICE is not that it doesn't allow blocking, but that it treats all devices equally. If we really want to keep this mode, I think it needs its own set of PM callbacks (where you can ask clients to not block), separate from PM device runtime (as on Linux, actually). But on MCUs this PM model doesn't make sense, you typically don't want to deal with devices on every LP state transition.

That is one reason to allow them to choose only low power states that it should be triggered.

Some MCUs need to perform actions when exiting certain LP states on a per-device basis (e.g. the STOP modes in STM32), but this is something that can be solved in a better way, for example, subscribing to such events as needed. And to me, such a mechanism could likely be re-used to finally get rid of CONFIG_PM_DEVICE.

notifiers don't solve it now since they can't block as well (they are called from idle thread)

The problem here is that we've never got technical details on how it is being used to discuss a proper way forward, and we've been stuck forever with this.

We can work through this, but there are real use cases. Note that this is bring more flexibility making even easier to not use it if that is wanted. We may work through a better way but this change is just giving the capability to tell whether or not a state triggers device pm.

Is removing CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE the reason for blocking it ? If that is the case it can easily be restored. Other than that this is not doing anything other than make easier to avoid system device pm since one can now select only states (or none) that this should happen.

@ceolin ceolin changed the title [RFC] pm: Make device pm optional per state pm: Make device pm optional per state Aug 4, 2023
@ceolin
Copy link
Member Author

ceolin commented Aug 8, 2023

@gmarull ping

doc/services/pm/device.rst Outdated Show resolved Hide resolved
@ceolin ceolin added the dev-review To be discussed in dev-review meeting label Jan 31, 2024
@ceolin ceolin added this to the v3.6.0 milestone Jan 31, 2024
include/zephyr/pm/state.h Outdated Show resolved Hide resolved
subsys/pm/device_system_managed.c Outdated Show resolved Hide resolved
subsys/pm/Kconfig Outdated Show resolved Hide resolved
On system suspend / resume do not trigger the Device PM hooks but
only rely on Runtime PM to manage the devices power states.
This option enables the device system managed power management. The
power management subsystem will suspend devices when it gets idle
Copy link
Collaborator

Choose a reason for hiding this comment

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

gets idle -> goes to idle or transitions to idle

subsys/pm/device_system_managed.c Show resolved Hide resolved
@ceolin
Copy link
Member Author

ceolin commented Feb 2, 2024

@JordanYates thanks for looking it ! Have update with suggestions.

@ceolin ceolin requested a review from erwango February 2, 2024 14:56
config PM_DEVICE_RUNTIME_EXCLUSIVE
depends on PM_DEVICE_RUNTIME
bool "Use only on Runtime Power Management on system suspend / resume"
config PM_DEVICE_SYSTEM_MANAGED
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this changing the default behaviour when PM_DEVICE=y and PM_DEVICE_RUNTIME=y?
Previously hooks wouldn't be enabled, now they are.

Copy link
Member Author

Choose a reason for hiding this comment

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

PM_DEVICE_RUNTIME_EXCLUSIVE=y can be replace with PM_DEVICE_SYSTEM_MANAGED=n.

I believe this is more clear.

PM_DEVICE is the base and need by RUNTIME and SYSTEM_MANAGED. PM_DEVICE is the base to enable pm in a device (aka pm callback)

PM_DEVICE_RUNTIME enables device runtime
PM_DEVICE_SYSTEM_MANAGED tell the pm subsystem to suspend / resume devices when the soc goes idle.

If one does not want device system managed pm, just disable it. We can make default n if PM_DEVICE_RIUNTIME

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand it can be replaced, but PM_DEVICE_RUNTIME_EXCLUSIVE=y was the previous default, and PM_DEVICE_SYSTEM_MANAGED=y is the new default, which is the opposite behaviour.

Copy link
Member Author

@ceolin ceolin Feb 4, 2024

Choose a reason for hiding this comment

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

Right ... but now we have to explicitly set, in DT, which states triggers system managed device pm.

If we want to keep exactly the same behavior, I can change this pr to;

  1. By default, states trigger device pm when PM_DEVICE_SYSTEM_MANAGED is set (and users can disable specific sates setting it in DT)
  2. PM_DEVICE_SYSTEM_MANAGED is disabled (by default) when PM_DEVICE_RUNTIME is enabled.

With these changes we keep the current behavior. I was already thinking about it (especially due dt changes).
@JordanYates what you think ?

@henrikbrixandersen
Copy link
Member

@ceolin I see you have added this to the v3.6.0 milestone. Do you still intend for this to go in before v3.6.0? It looks like an enhancement to me.

@ceolin
Copy link
Member Author

ceolin commented Feb 14, 2024

@ceolin I see you have added this to the v3.6.0 milestone. Do you still intend for this to go in before v3.6.0? It looks like an enhancement to me.

@henrikbrixandersen it won't. It is to late for it now. I'll wait the merge window open to move it.

@ceolin ceolin removed this from the v3.6.0 milestone Feb 14, 2024
@MaureenHelm MaureenHelm removed the dev-review To be discussed in dev-review meeting label Feb 14, 2024
@ceolin ceolin removed the DNM This PR should not be merged (Do Not Merge) label Mar 18, 2024
Flavio Ceolin added 9 commits March 18, 2024 21:34
That is option has shown confusing on it is attempt to prevent
system pm doing device power management. Lets address this
problem properly.

Signed-off-by: Flavio Ceolin <[email protected]>
Enable device power management individually per power state.
This allows targets tuning which state should trigger
device power management or completely disable it simply not
enabling it in any power state.

Signed-off-by: Flavio Ceolin <[email protected]>
Remove device pm path when there is no is no power state in DT with
device pm enabled. This basically does the same thing that was done
by PM_DEVICE_RUNTIME_EXCLUSIVE.

Signed-off-by: Flavio Ceolin <[email protected]>
PM_DEVICE is not attached to system managed device power management.
It is a very common use case targets with device runtime power
management that don't want system device power management enabled.

We introduce a new symbol (PM_DEVICE_SYSTEM_MANAGED) to explicit
control whether or not system device power management should be
globally enabled.

Signed-off-by: Flavio Ceolin <[email protected]>
Define the power state needed in the test in DT.

Signed-off-by: Flavio Ceolin <[email protected]>
Define the power state needed in the test in DT.

Signed-off-by: Flavio Ceolin <[email protected]>
Add new information about new property to
enable/disable device power management per
power state.

Signed-off-by: Flavio Ceolin <[email protected]>
Add a new test that disables PM_DEVICE_SYSTEM_MANAGED, since this
option is enabled by default.

Signed-off-by: Flavio Ceolin <[email protected]>
Bump SoF to a version that does not have reference to
PM_DEVICE_RUNTIME_EXCLUSIVE

Signed-off-by: Flavio Ceolin <[email protected]>
@zephyrbot zephyrbot added the DNM This PR should not be merged (Do Not Merge) label Mar 18, 2024
@ceolin
Copy link
Member Author

ceolin commented Mar 22, 2024

@JordanYates I have kept the current behavior in #70623. Please take a look.

@erwango ^

@ceolin
Copy link
Member Author

ceolin commented Apr 23, 2024

Closing it in favor of #70623

@ceolin ceolin closed this Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Power Management DNM This PR should not be merged (Do Not Merge) manifest manifest-sof
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants