PM: runtime: Update behaviour for no callbacks
Subsystems (4)
v2 cover PM: runtime: Update behaviour for no callbacks
While reviewing a patch on the mmc-list, I ended up inspecting the behaviour of how we deal with the no callback case for runtime PM.
A couple of observations:
*) When pm_runtime_no_callbacks() have been called, it allows the PM core to takes a quicker path, but at the same time, consumer/supplier device links are being skipped in rpm_resume|suspend().
**) Calling pm_runtime_no_callbacks() to avoid boiler plate code (assigning empty functions to ->runtime_suspend|resume()), doesn't work if there could be consumer/supplier device link being used or a platform dependent PM domain that could get attached to the device.
Therefore, this series suggests to change the behaviour in the PM core, to allow the ->runtime_suspend|resume() callbacks to be unassigned. This is already supported for ->runtime_idle() callbacks, so it would also move things into a more consistent behaviour.
I have looked at various error paths, in the kernel of callers of pm_runtime_get_sync(). I couldn't find anyone that made sense, that looked for the special error code, -ENOSYS, which is the error code getting returned when a callback is missing. Whether that is sufficient proof that these changes are 100% safe, I can't guarantee, but I think it would be worth a try as the benefits of avoiding boilerplate code and the corresponding additional code paths are quite nice, if you ask me.
Kind regards
Ulf Hansson
Ulf Hansson (3):
PM: runtime: Improve path in rpm_idle() when no callback
PM: runtime: Allow unassigned ->runtime_suspend|resume callbacks
PM: runtime: Clarify documentation when callbacks are unassigned
Documentation/power/runtime_pm.rst | 8 ++++++++ drivers/base/power/runtime.c | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 PM: runtime: Improve path in rpm_idle() when no callback
When pm_runtime_no_callbacks() has been called for a struct device to set the dev->power.no_callbacks flag for it, it enables rpm_idle() to take a slightly quicker path by assuming that a ->runtime_idle() callback would have returned 0 to indicate success.
A device that does not have the dev->power.no_callbacks flag set for it, may still be missing a corresponding ->runtime_idle() callback, in which case the slower path in rpm_idle() is taken. Let's improve the behaviour for this case, by aligning code to the quicker path.
---
Changes in v2:
- None.
--- drivers/base/power/runtime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/base/power/runtime.c +5 -5
@@ -446,7 +446,10 @@ static int rpm_idle(struct device *dev, int rpmflags)/* Pending requests need to be canceled. */ dev->power.request =RPM_REQ_NONE ; -if (dev->power.no_callbacks) + callback =RPM_GET_CALLBACK (dev, runtime_idle); + +/* If no callback assume success. */ +if (!callback || dev->power.no_callbacks) goto out;/* Carry out an asynchronous or a synchronous idle notification. */
@@ -462,10 +465,7 @@ static int rpm_idle(struct device *dev, int rpmflags) dev->power.idle_notification = true; - callback =RPM_GET_CALLBACK (dev, runtime_idle); - -if (callback) - retval =__rpm_callback (callback, dev); + retval =__rpm_callback (callback, dev); dev->power.idle_notification = false;wake_up_all (&dev->power.wait_queue);
Signature · 1 line
2.25.1
PATCH v2 2/3 PM: runtime: Allow unassigned ->runtime_suspend|resume callbacks
In reply to Ulf HanssonWe are currently allowing ->runtime_idle() callbacks to be unassigned without returning an error code from rpm_idle(). This has been useful to avoid boilerplate code in drivers. Let's take this approach a step further, by allowing also unassigned ->runtime_suspend|resume() callbacks.
In this way, a consumer/supplier device link can be used to let a consumer device be power managed through its supplier device, without requiring assigned ->runtime_suspend|resume() callbacks for the consumer device, for example.
---
Changes in v2:
- Small updates to commit message.
--- drivers/base/power/runtime.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/base/power/runtime.c +3 -5
@@ -345,7 +345,7 @@ static void rpm_suspend_suppliers(struct device *dev)static int __rpm_callback (int (*cb)(struct device *),struct device *dev) __releases(&dev->power.lock) __acquires(&dev->power.lock) { -int retval, idx; +int retval =0 , idx;bool use_links = dev->power.links_count >0 ;if (dev->power.irq_safe) {
@@ -373,7 +373,8 @@ static int __rpm_callback(int (*cb)(struct device *), struct device *dev) } } - retval =cb (dev); +if (cb) + retval =cb (dev);if (dev->power.irq_safe) {spin_lock (&dev->power.lock);
@@ -484,9 +485,6 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev) {int retval; -if (!cb) -return -ENOSYS ; -if (dev->power.memalloc_noio) {unsigned int noio_flag;
Signature · 1 line
2.25.1
PATCH v2 3/3 PM: runtime: Clarify documentation when callbacks are unassigned
In reply to Ulf HanssonRecent changes to the PM core allows ->runtime_suspend|resume callbacks to be unassigned.
In the earlier behaviour the PM core would return -ENOSYS, when trying to runtime resume a device, for example. Let's update the documentation to clarify this.
---
Changes in v2:
- Added a new patch for the updating the docs, as pointed out by Alan.
--- Documentation/power/runtime_pm.rst | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/power/runtime_pm.rst +8 -0
@@ -827,6 +827,14 @@ or driver about runtime power changes. Instead, the driver for the device's parent must take responsibility for telling the device's driver when the parent's power state changes. +Note that, in some cases it may not be desirable for subsystems/drivers to call +pm_runtime_no_callbacks() for their devices. This could be because a subset of +the runtime PM callbacks needs to be implemented, a platform dependent PM +domain could get attached to the device or that the device is power manged +through a supplier device link. For these reasons and to avoid boilerplate code +in subsystems/drivers, the PM core allows runtime PM callbacks to be +unassigned. + 9. Autosuspend, or automatically-delayed suspends =================================================
Signature · 1 line
2.25.1
Re: [PATCH v2 3/3] PM: runtime: Clarify documentation when callbacks are unassigned
Quoted 23 lines · Ulf Hansson
Recent changes to the PM core allows ->runtime_suspend|resume callbacks to be unassigned.
In the earlier behaviour the PM core would return
-ENOSYS, when trying to runtime resume a device, for example. Let's update the documentation to clarify this.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v2:
- Added a new patch for the updating the docs, as pointed out by Alan.--- Documentation/power/runtime_pm.rst | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/power/runtime_pm.rst +0
-0@@ -827,6 +827,14 @@ or driver about runtime power changes. Instead, the driver for the device's parent must take responsibility for telling the device's driver when the
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 837
Quoted 10 lines
Documentation/power/runtime_pm.rst +8
-0parent's power state changes. +Note that, in some cases it may not be desirable for subsystems/drivers to call +pm_runtime_no_callbacks() for their devices. This could be because a subset of +the runtime PM callbacks needs to be implemented, a platform dependent PM +domain could get attached to the device or that the device is power manged +through a supplier device link. For these reasons and to avoid boilerplate code +in subsystems/drivers, the PM core allows runtime PM callbacks to be +unassigned. +
You should also mention that if a callback pointer is NULL, the runtime PM core will act as though there was a callback and it returned 0. That's an important consideration.
Also, notice that this file was carefully edited to make sure that none of the lines exceed 80 characters. Your new addition should be the same.
Alan Stern
Re: [PATCH v2 3/3] PM: runtime: Clarify documentation when callbacks are unassigned
Quoted 27 lines · Alan Stern
Quoted 25 lines · Ulf Hansson
Recent changes to the PM core allows ->runtime_suspend|resume callbacks to be unassigned.
In the earlier behaviour the PM core would return
-ENOSYS, when trying to runtime resume a device, for example. Let's update the documentation to clarify this.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v2:
- Added a new patch for the updating the docs, as pointed out by Alan.--- Documentation/power/runtime_pm.rst | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/power/runtime_pm.rst +0
-0@@ -827,6 +827,14 @@ or driver about runtime power changes. Instead, the driver for the device's parent must take responsibility for telling the device's driver when the parent's power state changes.
Quoted 12 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 837
Quoted 8 lines
Documentation/power/runtime_pm.rst +8
-0+Note that, in some cases it may not be desirable for subsystems/drivers to call +pm_runtime_no_callbacks() for their devices. This could be because a subset of +the runtime PM callbacks needs to be implemented, a platform dependent PM +domain could get attached to the device or that the device is power manged +through a supplier device link. For these reasons and to avoid boilerplate code +in subsystems/drivers, the PM core allows runtime PM callbacks to be +unassigned. +You should also mention that if a callback pointer is NULL, the runtime PM core will act as though there was a callback and it returned 0. That's an important consideration.
Good point, let me add it.
I send a new version of $subject patch, unless Rafael is happy to do the amending when/if applying?
Quoted 4 lines
Also, notice that this file was carefully edited to make sure that none of the lines exceed 80 characters. Your new addition should be the same.
Absolutely, but it should be okay already, no?
Quoted 2 lines
Alan Stern
Kind regards
Uffe
Re: [PATCH v2 3/3] PM: runtime: Clarify documentation when callbacks are unassigned
Quoted 28 lines · Ulf Hansson
Quoted 27 lines · Alan Stern
Quoted 25 lines · Ulf Hansson
Recent changes to the PM core allows ->runtime_suspend|resume callbacks to be unassigned.
In the earlier behaviour the PM core would return
-ENOSYS, when trying to runtime resume a device, for example. Let's update the documentation to clarify this.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v2:
- Added a new patch for the updating the docs, as pointed out by Alan.--- Documentation/power/runtime_pm.rst | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/power/runtime_pm.rst +0
-0@@ -827,6 +827,14 @@ or driver about runtime power changes. Instead, the driver for the device's parent must take responsibility for telling the device's driver when the parent's power state changes.
Quoted 1 line
Quoted 1 line
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 830
Quoted 1 line
Documentation/power/runtime_pm.rst +1
-0+Note that, in some cases it may not be desirable for subsystems/drivers to call
More than 80 chars.
Quoted 1 line
Quoted 1 line
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 831
Quoted 1 line
Documentation/power/runtime_pm.rst +1
-0+pm_runtime_no_callbacks() for their devices. This could be because a subset of
More than 80 chars.
Quoted 2 lines
Quoted 2 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 833
Quoted 2 lines
Documentation/power/runtime_pm.rst +2
-0+the runtime PM callbacks needs to be implemented, a platform dependent PM +domain could get attached to the device or that the device is power manged
s/manged/managed/
Quoted 1 line
Quoted 1 line
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 834
Quoted 1 line
Documentation/power/runtime_pm.rst +1
-0+through a supplier device link. For these reasons and to avoid boilerplate code
More than 80 chars.
Quoted 14 lines
Quoted 7 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 837
Quoted 3 lines
Documentation/power/runtime_pm.rst +3
-0+in subsystems/drivers, the PM core allows runtime PM callbacks to be +unassigned. +You should also mention that if a callback pointer is NULL, the runtime PM core will act as though there was a callback and it returned 0. That's an important consideration.
Good point, let me add it.
I send a new version of $subject patch, unless Rafael is happy to do the amending when/if applying?
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
Also, notice that this file was carefully edited to make sure that none of the lines exceed 80 characters. Your new addition should be the same.
Absolutely, but it should be okay already, no?
See above.
Alan
Re: [PATCH v2 3/3] PM: runtime: Clarify documentation when callbacks are unassigned
Quoted 30 lines · Alan Stern
Quoted 28 lines · Ulf Hansson
Quoted 27 lines · Alan Stern
Quoted 25 lines · Ulf Hansson
Recent changes to the PM core allows ->runtime_suspend|resume callbacks to be unassigned.
In the earlier behaviour the PM core would return
-ENOSYS, when trying to runtime resume a device, for example. Let's update the documentation to clarify this.Signed-off-by Ulf Hansson <[email protected]>---
Changes in v2:
- Added a new patch for the updating the docs, as pointed out by Alan.--- Documentation/power/runtime_pm.rst | 8 ++++++++ 1 file changed, 8 insertions(+)Documentation/power/runtime_pm.rst +0
-0@@ -827,6 +827,14 @@ or driver about runtime power changes. Instead, the driver for the device's parent must take responsibility for telling the device's driver when the parent's power state changes.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 830
Quoted 1 line
Documentation/power/runtime_pm.rst +1
-0+Note that, in some cases it may not be desirable for subsystems/drivers to callMore than 80 chars.
Perhaps it's the email client that messes up the patch in some way. This above line in the patch is 79 chars.
If you have a look at the patch in patchwork [1], you should see (I hope) that it respects the 80 chars per line!?
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 831
Quoted 2 lines
Documentation/power/runtime_pm.rst +1
-0+pm_runtime_no_callbacks() for their devices. This could be because a subset ofMore than 80 chars.
Quoted 2 lines
Quoted 2 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 833
Quoted 2 lines
Documentation/power/runtime_pm.rst +2
-0+the runtime PM callbacks needs to be implemented, a platform dependent PM +domain could get attached to the device or that the device is power mangeds/manged/managed/
Thanks for spotting this, my spell checker accepted "manged". :-)
Quoted 23 lines
Quoted 2 lines
Quoted 2 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 834
Quoted 2 lines
Documentation/power/runtime_pm.rst +1
-0+through a supplier device link. For these reasons and to avoid boilerplate codeMore than 80 chars.
Quoted 18 lines
Quoted 7 lines
Documentation/power/runtime_pm.rst or driver about runtime power changes. Instead, the driver for the device's · line 837
Quoted 3 lines
Documentation/power/runtime_pm.rst +3
-0+in subsystems/drivers, the PM core allows runtime PM callbacks to be +unassigned. +You should also mention that if a callback pointer is NULL, the runtime PM core will act as though there was a callback and it returned 0. That's an important consideration.
Good point, let me add it.
I send a new version of $subject patch, unless Rafael is happy to do the amending when/if applying?
Quoted 4 lines
Also, notice that this file was carefully edited to make sure that none of the lines exceed 80 characters. Your new addition should be the same.
Quoted 5 lines
Quoted 1 line
Absolutely, but it should be okay already, no?
See above.
Alan
Kind regards
Uffe
[1]
https://patchwork.kernel.org/project/linux-pm/patch/[email protected]/
Quoted 19 lines · Ulf Hansson
While reviewing a patch on the mmc-list, I ended up inspecting the behaviour of how we deal with the no callback case for runtime PM.
A couple of observations:
*) When
pm_runtime_no_callbacks()have been called, it allows the PM core to takes a quicker path, but at the same time, consumer/supplier device links are being skipped in rpm_resume|suspend().**) Calling
pm_runtime_no_callbacks()to avoid boiler plate code (assigning empty functions to ->runtime_suspend|resume()), doesn't work if there could be consumer/supplier device link being used or a platform dependent PM domain that could get attached to the device.Therefore, this series suggests to change the behaviour in the PM core, to allow the ->runtime_suspend|resume() callbacks to be unassigned. This is already supported for ->runtime_idle() callbacks, so it would also move things into a more consistent behaviour.
Quoted 7 lines
I have looked at various error paths, in the kernel of callers of
pm_runtime_get_sync(). I couldn't find anyone that made sense, that looked for the special error code,-ENOSYS, which is the error code getting returned when a callback is missing. Whether that is sufficient proof that these changes are 100% safe, I can't guarantee, but I think it would be worth a try as the benefits of avoiding boilerplate code and the corresponding additional code paths are quite nice, if you ask me.
In principle I have no objection to these changes. It's likely that if any problems do crop up, we'll be able to fix them pretty easily. For patches 1 and 2:
Alan Stern