linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>,
	Imre Deak <imre.deak@intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Intel graphics driver community testing & development
	<intel-gfx@lists.freedesktop.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>
Subject: Re: [PATCH v2] PM / runtime: Add new helper for conditional usage count incrementation
Date: Thu, 17 Dec 2015 10:03:35 +0100	[thread overview]
Message-ID: <CAPDyKFriRJQtq5v6A=yoEzTyb49hpm__n3QPnx5E-dgQ68r28A@mail.gmail.com> (raw)
In-Reply-To: <8499566.e3riUpjlOo@vostro.rjw.lan>

On 17 December 2015 at 02:54, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Introduce a new runtime PM function, pm_runtime_get_if_in_use(),
> 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@intel.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>

Kind regards
Uffe

> ---
>
> Changes from v1:
> - kerneldoc and runtime PM doc changes as suggested by Alan.
> - The new function returns an int now and -EINVAL is returned for devices
>   with runtime PM disabled.
>
> ---
>  Documentation/power/runtime_pm.txt |    6 ++++++
>  drivers/base/power/runtime.c       |   24 ++++++++++++++++++++++++
>  include/linux/pm_runtime.h         |    5 +++++
>  3 files changed, 35 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,30 @@ 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.
> + *
> + * Return -EINVAL if runtime PM is disabled for the device.
> + *
> + * If that's not the case and if the device's runtime PM status is RPM_ACTIVE
> + * and the runtime PM usage counter is nonzero, increment the counter and
> + * return 1.  Otherwise return 0 without changing the counter.
> + */
> +int pm_runtime_get_if_in_use(struct device *dev)
> +{
> +       unsigned long flags;
> +       int retval;
> +
> +       spin_lock_irqsave(&dev->power.lock, flags);
> +       retval = dev->power.disable_depth > 0 ? -EINVAL :
> +               dev->power.runtime_status == RPM_ACTIVE
> +                       && atomic_inc_not_zero(&dev->power.usage_count);
> +       spin_unlock_irqrestore(&dev->power.lock, flags);
> +       return retval;
> +}
> +EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use);
> +
> +/**
>   * __pm_runtime_set_status - Set runtime PM status of a device.
>   * @dev: Device to handle.
>   * @status: New runtime PM status of the device.
> Index: linux-pm/include/linux/pm_runtime.h
> ===================================================================
> --- linux-pm.orig/include/linux/pm_runtime.h
> +++ linux-pm/include/linux/pm_runtime.h
> @@ -39,6 +39,7 @@ extern int pm_runtime_force_resume(struc
>  extern int __pm_runtime_idle(struct device *dev, int rpmflags);
>  extern int __pm_runtime_suspend(struct device *dev, int rpmflags);
>  extern int __pm_runtime_resume(struct device *dev, int rpmflags);
> +extern int pm_runtime_get_if_in_use(struct device *dev);
>  extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
>  extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
>  extern int pm_runtime_barrier(struct device *dev);
> @@ -143,6 +144,10 @@ static inline int pm_schedule_suspend(st
>  {
>         return -ENOSYS;
>  }
> +static inline int pm_runtime_get_if_in_use(struct device *dev)
> +{
> +       return -EINVAL;
> +}
>  static inline int __pm_runtime_set_status(struct device *dev,
>                                             unsigned int status) { return 0; }
>  static inline int pm_runtime_barrier(struct device *dev) { return 0; }
> Index: linux-pm/Documentation/power/runtime_pm.txt
> ===================================================================
> --- linux-pm.orig/Documentation/power/runtime_pm.txt
> +++ linux-pm/Documentation/power/runtime_pm.txt
> @@ -371,6 +371,12 @@ drivers/base/power/runtime.c and include
>      - increment the device's usage counter, run pm_runtime_resume(dev) and
>        return its result
>
> +  int pm_runtime_get_if_in_use(struct device *dev);
> +    - return -EINVAL if 'power.disable_depth' is nonzero; otherwise, if the
> +      runtime PM status is RPM_ACTIVE and the runtime PM usage counter is
> +      nonzero, increment the counter and return 1; otherwise return 0 without
> +      changing the counter
> +
>    void pm_runtime_put_noidle(struct device *dev);
>      - decrement the device's usage counter
>
>

      reply	other threads:[~2015-12-17  9:03 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-09 15:45 [PATCH 1/3] PM / Runtime: Introduce pm_runtime_get_noidle Joonas Lahtinen
2015-12-09 16:22 ` [PATCH v2] " Joonas Lahtinen
2015-12-10  0:58   ` Rafael J. Wysocki
2015-12-10  9:43     ` [Intel-gfx] " Imre Deak
2015-12-10 21:36       ` Rafael J. Wysocki
2015-12-10 21:42         ` Rafael J. Wysocki
2015-12-10 21:20           ` Imre Deak
2015-12-10 22:14             ` Rafael J. Wysocki
2015-12-11 11:08               ` Dave Gordon
2015-12-11 12:03               ` Ulf Hansson
2015-12-11 15:13                 ` Rafael J. Wysocki
2015-12-11 15:59                   ` Ulf Hansson
2015-12-11 23:37                     ` Rafael J. Wysocki
2015-12-11 12:54               ` Imre Deak
2015-12-11 15:40                 ` [Intel-gfx] " Rafael J. Wysocki
2015-12-11 15:47                   ` Imre Deak
2015-12-11 23:21                     ` Rafael J. Wysocki
2015-12-11 23:41                       ` Rafael J. Wysocki
2015-12-12  1:51                         ` Rafael J. Wysocki
2015-12-12 19:40                           ` Imre Deak
2015-12-12 19:49                             ` Chris Wilson
2015-12-14  2:04                               ` Rafael J. Wysocki
2015-12-14 22:22                               ` [PATCH] PM / runtime: Add new helper for conditional usage count incrementation Rafael J. Wysocki
2015-12-15 10:21                                 ` Joonas Lahtinen
2015-12-15 14:28                                 ` Ulf Hansson
2015-12-16  3:10                                   ` Rafael J. Wysocki
2015-12-15 15:06                                 ` Alan Stern
2015-12-16  3:11                                   ` Rafael J. Wysocki
2015-12-17  1:54                                 ` [PATCH v2] " Rafael J. Wysocki
2015-12-17  9:03                                   ` Ulf Hansson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPDyKFriRJQtq5v6A=yoEzTyb49hpm__n3QPnx5E-dgQ68r28A@mail.gmail.com' \
    --to=ulf.hansson@linaro.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).