[Intel-gfx] [PATCH] PM / runtime: Add new helper for conditional usage count incrementation

Rafael J. Wysocki rjw at rjwysocki.net
Tue Dec 15 19:10:17 PST 2015


On Tuesday, December 15, 2015 03:28:54 PM Ulf Hansson wrote:
> On 14 December 2015 at 23:22, Rafael J. Wysocki <rjw at rjwysocki.net> wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
> >
> > Introduce a new runtime PM function, pm_runtime_get_if_in_use(),
> 
> As we already have pm_runtime_set_active() and pm_runtime_active(),
> changing the new function name to "pm_runtime_get_if_active" may be
> better!?

"In use" is supposed to mean "active and reference counted".

> > that will increment the device's runtime PM usage counter and
> > return 'true' if its status is RPM_ACTIVE and its usage counter
> > is greater than 0 at the same time ('false' will be returned
> > otherwise).
> >
> > This is useful for things that should only be done if the device
> > is active (from the runtime PM perspective) and used by somebody
> > (as indicated by the usage counter) already and they are not worth
> > bothering otherwise.
> >
> > Requested-by: Imre Deak <imre.deak at intel.com>
> > Acked-by: Imre Deak <imre.deak at intel.com>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
> > ---
> >  Documentation/power/runtime_pm.txt |    5 +++++
> >  drivers/base/power/runtime.c       |   21 +++++++++++++++++++++
> >  include/linux/pm_runtime.h         |    5 +++++
> >  3 files changed, 31 insertions(+)
> >
> > Index: linux-pm/drivers/base/power/runtime.c
> > ===================================================================
> > --- linux-pm.orig/drivers/base/power/runtime.c
> > +++ linux-pm/drivers/base/power/runtime.c
> > @@ -966,6 +966,27 @@ int __pm_runtime_resume(struct device *d
> >  EXPORT_SYMBOL_GPL(__pm_runtime_resume);
> >
> >  /**
> > + * pm_runtime_get_if_in_use - Conditionally bump up the device's usage counter.
> > + * @dev: Device to handle.
> > + *
> > + * Increment the device's runtime PM usage counter and return 'true' if its
> > + * runtime PM status is RPM_ACTIVE and its usage counter is already different
> > + * from zero at the same time.  Otherwise, return 'false'.
> > + */
> > +bool pm_runtime_get_if_in_use(struct device *dev)
> > +{
> > +       unsigned long flags;
> > +       bool retval;
> > +
> > +       spin_lock_irqsave(&dev->power.lock, flags);
> > +       retval = dev->power.runtime_status == RPM_ACTIVE
> > +               && atomic_inc_not_zero(&dev->power.usage_count);
> 
> Don't we also need to check that runtime PM is enabled (&&
> !dev->power.disable_depth), or the user of this function don't care
> about that?

The user probably cares, but calling this for devices with runtime PM
disabled doesn't really make sense to me (the status is not meaningful
then).

> > +       spin_unlock_irqrestore(&dev->power.lock, flags);
> > +       return retval;
> > +}
> > +EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use);
> > +
> 
> [...]

Thanks,
Rafael



More information about the Intel-gfx mailing list