diff mbox series

[2/2] PM: runtime: Allow unassigned ->runtime_suspend|resume callbacks

Message ID 20210528091202.11603-1-ulf.hansson@linaro.org (mailing list archive)
State Superseded, archived
Headers show
Series [1/2] PM: runtime: Improve path in rpm_idle() when no callback | expand

Commit Message

Ulf Hansson May 28, 2021, 9:12 a.m. UTC
We are currently allowing ->rpm_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 unassigned ->runtime_suspend|resume() callbacks as well.

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.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/base/power/runtime.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Alan Stern May 28, 2021, 3:27 p.m. UTC | #1
On Fri, May 28, 2021 at 11:12:02AM +0200, Ulf Hansson wrote:
> We are currently allowing ->rpm_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 unassigned ->runtime_suspend|resume() callbacks as well.
> 
> 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.
> 
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>  drivers/base/power/runtime.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 68bebbf81347..8a66eaf731e4 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -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;

This is a change in behavior, right?  What about drivers or subsystems 
that don't support runtime PM and consequently don't have any RPM 
callbacks assigned?

Also, assuming Rafael accepts this change, don't you also need to update 
the runtime-PM documentation?

Alan Stern

> -
>  	if (dev->power.memalloc_noio) {
>  		unsigned int noio_flag;
>  
> -- 
> 2.25.1
Ulf Hansson May 31, 2021, 7:08 a.m. UTC | #2
On Fri, 28 May 2021 at 17:27, Alan Stern <stern@rowland.harvard.edu> wrote:
>
> On Fri, May 28, 2021 at 11:12:02AM +0200, Ulf Hansson wrote:
> > We are currently allowing ->rpm_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 unassigned ->runtime_suspend|resume() callbacks as well.
> >
> > 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.
> >
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > ---
> >  drivers/base/power/runtime.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> > index 68bebbf81347..8a66eaf731e4 100644
> > --- a/drivers/base/power/runtime.c
> > +++ b/drivers/base/power/runtime.c
> > @@ -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;
>
> This is a change in behavior, right?  What about drivers or subsystems
> that don't support runtime PM and consequently don't have any RPM
> callbacks assigned?

Yes, you are right.

However, drivers/subsystems that support runtime PM should also call
pm_runtime_enable() and if they don't, the rpm_callback() should not
get called for them.

Then, at least to me, I think it would be quite odd that a
subsystem/driver that calls pm_runtime_enable(), would be checking
return values from pm_runtime_get|put_*() for -ENOSYS? I mean, why
bother calling pm_runtime_enable() in the first place?

>
> Also, assuming Rafael accepts this change, don't you also need to update
> the runtime-PM documentation?

Good point, thanks! Let me add a patch updating the docs.

>
> Alan Stern
>

Kind regards
Uffe
diff mbox series

Patch

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 68bebbf81347..8a66eaf731e4 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -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;