From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-pm@lists.linux-foundation.org, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: Re: [linux-pm] [PATCH] PM: add synchronous ...)
Date: Sat, 2 Oct 2010 00:37:55 +0200 [thread overview]
Message-ID: <201010020037.55277.rjw@sisk.pl> (raw)
In-Reply-To: <201010012314.38089.rjw@sisk.pl>
On Friday, October 01, 2010, Rafael J. Wysocki wrote:
> On Friday, October 01, 2010, Alan Stern wrote:
> > On Fri, 1 Oct 2010, Rafael J. Wysocki wrote:
> >
> > > On Thursday, September 30, 2010, Alan Stern wrote:
> > > > This patch (as1431) adds a synchronous runtime-PM interface suitable
> > > > for use in interrupt handlers. Four new helper functions are defined:
> > > >
> > > > pm_runtime_suspend_irq(), pm_runtime_resume_irq(),
> > > > pm_runtime_get_sync_irq(), pm_runtime_put_sync_irq(),
> > > >
> > > > together with pm_runtime_callbacks_in_irq(), which subsystems use to
> > > > tell the PM core that the runtime callbacks should be invoked with
> > > > interrupts disabled.
> > >
> > > BTW, I like some changes made by your patch that aren't really related to
> > > the issue at hand, so I think the patch below can be applied regardless of
> > > the other changes, unless I made a mistake I can see now.
> >
> > It looks like a good change, but you forgot to preserve the assignments
> > to dev->power.runtime_error.
>
> That's correct and there's a difference betwee _idle and the other cases
> because of that. I'll send updated patch with a changelog shortly.
Appended as promised.
Thanks,
Rafael
---
From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: PM / Runtime: Reduce code duplication in core helper functions
Reduce code duplication in rpm_idle(), rpm_suspend() and rpm_resume()
by using local pointers to store callback addresses and moving some
duplicated code into a separate function.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
drivers/base/power/runtime.c | 122 +++++++++++++++++++------------------------
1 file changed, 54 insertions(+), 68 deletions(-)
Index: linux-2.6/drivers/base/power/runtime.c
===================================================================
--- linux-2.6.orig/drivers/base/power/runtime.c
+++ linux-2.6/drivers/base/power/runtime.c
@@ -153,7 +153,6 @@ static int rpm_check_suspend_allowed(str
return retval;
}
-
/**
* rpm_idle - Notify device bus type if the device can be suspended.
* @dev: Device to notify the bus type about.
@@ -167,8 +166,8 @@ static int rpm_check_suspend_allowed(str
* This function must be called under dev->power.lock with interrupts disabled.
*/
static int rpm_idle(struct device *dev, int rpmflags)
- __releases(&dev->power.lock) __acquires(&dev->power.lock)
{
+ int (*callback)(struct device *);
int retval;
retval = rpm_check_suspend_allowed(dev);
@@ -214,23 +213,19 @@ static int rpm_idle(struct device *dev,
dev->power.idle_notification = true;
- if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_idle) {
- spin_unlock_irq(&dev->power.lock);
-
- dev->bus->pm->runtime_idle(dev);
-
- spin_lock_irq(&dev->power.lock);
- } else if (dev->type && dev->type->pm && dev->type->pm->runtime_idle) {
- spin_unlock_irq(&dev->power.lock);
-
- dev->type->pm->runtime_idle(dev);
+ if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_idle)
+ callback = dev->bus->pm->runtime_idle;
+ else if (dev->type && dev->type->pm && dev->type->pm->runtime_idle)
+ callback = dev->type->pm->runtime_idle;
+ else if (dev->class && dev->class->pm)
+ callback = dev->class->pm->runtime_idle;
+ else
+ callback = NULL;
- spin_lock_irq(&dev->power.lock);
- } else if (dev->class && dev->class->pm
- && dev->class->pm->runtime_idle) {
+ if (callback) {
spin_unlock_irq(&dev->power.lock);
- dev->class->pm->runtime_idle(dev);
+ callback(dev);
spin_lock_irq(&dev->power.lock);
}
@@ -243,6 +238,29 @@ static int rpm_idle(struct device *dev,
}
/**
+ * rpm_callback - Run a given runtime PM callback for a given device.
+ * @cb: Runtime PM callback to run.
+ * @dev: Device to run the callback for.
+ */
+static int rpm_callback(int (*cb)(struct device *), struct device *dev)
+ __releases(&dev->power.lock) __acquires(&dev->power.lock)
+{
+ int retval;
+
+ if (!cb)
+ return -ENOSYS;
+
+ spin_unlock_irq(&dev->power.lock);
+
+ retval = cb(dev);
+
+ spin_lock_irq(&dev->power.lock);
+ dev->power.runtime_error = retval;
+
+ return retval;
+}
+
+/**
* rpm_suspend - Carry out run-time suspend of given device.
* @dev: Device to suspend.
* @rpmflags: Flag bits.
@@ -261,6 +279,7 @@ static int rpm_idle(struct device *dev,
static int rpm_suspend(struct device *dev, int rpmflags)
__releases(&dev->power.lock) __acquires(&dev->power.lock)
{
+ int (*callback)(struct device *);
struct device *parent = NULL;
bool notify = false;
int retval;
@@ -351,33 +370,16 @@ static int rpm_suspend(struct device *de
__update_runtime_status(dev, RPM_SUSPENDING);
- if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend) {
- spin_unlock_irq(&dev->power.lock);
-
- retval = dev->bus->pm->runtime_suspend(dev);
-
- spin_lock_irq(&dev->power.lock);
- dev->power.runtime_error = retval;
- } else if (dev->type && dev->type->pm
- && dev->type->pm->runtime_suspend) {
- spin_unlock_irq(&dev->power.lock);
-
- retval = dev->type->pm->runtime_suspend(dev);
-
- spin_lock_irq(&dev->power.lock);
- dev->power.runtime_error = retval;
- } else if (dev->class && dev->class->pm
- && dev->class->pm->runtime_suspend) {
- spin_unlock_irq(&dev->power.lock);
-
- retval = dev->class->pm->runtime_suspend(dev);
-
- spin_lock_irq(&dev->power.lock);
- dev->power.runtime_error = retval;
- } else {
- retval = -ENOSYS;
- }
+ if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend)
+ callback = dev->bus->pm->runtime_suspend;
+ else if (dev->type && dev->type->pm && dev->type->pm->runtime_suspend)
+ callback = dev->type->pm->runtime_suspend;
+ else if (dev->class && dev->class->pm)
+ callback = dev->class->pm->runtime_suspend;
+ else
+ callback = NULL;
+ retval = rpm_callback(callback, dev);
if (retval) {
__update_runtime_status(dev, RPM_ACTIVE);
dev->power.deferred_resume = 0;
@@ -443,6 +445,7 @@ static int rpm_suspend(struct device *de
static int rpm_resume(struct device *dev, int rpmflags)
__releases(&dev->power.lock) __acquires(&dev->power.lock)
{
+ int (*callback)(struct device *);
struct device *parent = NULL;
int retval = 0;
@@ -563,33 +566,16 @@ static int rpm_resume(struct device *dev
__update_runtime_status(dev, RPM_RESUMING);
- if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume) {
- spin_unlock_irq(&dev->power.lock);
-
- retval = dev->bus->pm->runtime_resume(dev);
-
- spin_lock_irq(&dev->power.lock);
- dev->power.runtime_error = retval;
- } else if (dev->type && dev->type->pm
- && dev->type->pm->runtime_resume) {
- spin_unlock_irq(&dev->power.lock);
-
- retval = dev->type->pm->runtime_resume(dev);
-
- spin_lock_irq(&dev->power.lock);
- dev->power.runtime_error = retval;
- } else if (dev->class && dev->class->pm
- && dev->class->pm->runtime_resume) {
- spin_unlock_irq(&dev->power.lock);
-
- retval = dev->class->pm->runtime_resume(dev);
-
- spin_lock_irq(&dev->power.lock);
- dev->power.runtime_error = retval;
- } else {
- retval = -ENOSYS;
- }
+ if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume)
+ callback = dev->bus->pm->runtime_resume;
+ else if (dev->type && dev->type->pm && dev->type->pm->runtime_resume)
+ callback = dev->type->pm->runtime_resume;
+ else if (dev->class && dev->class->pm)
+ callback = dev->class->pm->runtime_resume;
+ else
+ callback = NULL;
+ retval = rpm_callback(callback, dev);
if (retval) {
__update_runtime_status(dev, RPM_SUSPENDED);
pm_runtime_cancel_pending(dev);
next prev parent reply other threads:[~2010-10-01 22:38 UTC|newest]
Thread overview: 144+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-24 0:05 runtime_pm_get_sync() from ISR with IRQs disabled? Kevin Hilman
2010-09-24 15:13 ` [linux-pm] " Alan Stern
2010-09-24 18:54 ` Kevin Hilman
2010-09-24 20:04 ` Rafael J. Wysocki
2010-09-24 20:04 ` [linux-pm] " Rafael J. Wysocki
2010-09-27 13:57 ` Alan Stern
2010-09-27 13:57 ` [linux-pm] " Alan Stern
2010-09-27 20:00 ` Rafael J. Wysocki
2010-09-27 20:00 ` [linux-pm] " Rafael J. Wysocki
2010-09-27 20:39 ` Alan Stern
2010-09-27 20:39 ` [linux-pm] " Alan Stern
2010-09-27 21:09 ` Rafael J. Wysocki
2010-09-28 14:55 ` Alan Stern
2010-09-28 14:55 ` [linux-pm] " Alan Stern
2010-09-28 18:19 ` Rafael J. Wysocki
2010-09-28 18:19 ` [linux-pm] " Rafael J. Wysocki
2010-09-30 18:25 ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Alan Stern
2010-09-30 20:15 ` Rafael J. Wysocki
2010-09-30 20:15 ` Rafael J. Wysocki
2010-09-30 21:42 ` Alan Stern
2010-09-30 21:42 ` Alan Stern
2010-09-30 21:42 ` Alan Stern
2010-09-30 22:41 ` Rafael J. Wysocki
2010-10-01 14:28 ` Alan Stern
2010-10-01 21:23 ` Rafael J. Wysocki
2010-10-02 14:12 ` Alan Stern
2010-10-02 22:06 ` Rafael J. Wysocki
2010-10-02 22:06 ` Rafael J. Wysocki
2010-10-03 15:52 ` Alan Stern
2010-10-03 15:52 ` Alan Stern
2010-10-03 20:33 ` Rafael J. Wysocki
2010-10-03 20:33 ` Rafael J. Wysocki
2010-10-08 23:24 ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: Re: [PATCH] PM: add synchronous ...) Rafael J. Wysocki
2010-10-08 23:24 ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: Re: [linux-pm] " Rafael J. Wysocki
2010-10-10 20:18 ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: " Alan Stern
2010-10-10 20:18 ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: Re: [linux-pm] " Alan Stern
2010-10-05 21:44 ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Kevin Hilman
2010-10-05 21:44 ` Kevin Hilman
2010-10-06 15:58 ` Alan Stern
2010-10-06 19:33 ` Rafael J. Wysocki
2010-10-06 19:33 ` Rafael J. Wysocki
2010-10-06 19:35 ` Kevin Hilman
2010-10-06 19:35 ` Kevin Hilman
2010-10-06 20:28 ` Alan Stern
2010-10-06 21:47 ` Rafael J. Wysocki
2010-10-07 15:26 ` Alan Stern
2010-10-07 15:26 ` Alan Stern
2010-10-07 16:52 ` Kevin Hilman
2010-10-07 16:52 ` Kevin Hilman
2010-10-07 17:35 ` Alan Stern
2010-10-07 21:11 ` Rafael J. Wysocki
2010-10-07 21:11 ` Rafael J. Wysocki
2010-10-07 23:15 ` Kevin Hilman
2010-10-07 23:37 ` Rafael J. Wysocki
2010-10-07 23:37 ` Rafael J. Wysocki
2010-10-07 23:55 ` Kevin Hilman
2010-10-07 23:55 ` Kevin Hilman
2010-10-08 16:22 ` Alan Stern
2010-10-08 21:04 ` Kevin Hilman
2010-10-08 21:04 ` Kevin Hilman
2010-10-08 16:22 ` Alan Stern
2010-10-08 19:57 ` Rafael J. Wysocki
2010-10-08 19:57 ` Rafael J. Wysocki
2010-10-07 23:15 ` Kevin Hilman
2010-10-08 16:18 ` Alan Stern
2010-10-08 19:53 ` Rafael J. Wysocki
2010-10-08 19:53 ` Rafael J. Wysocki
2010-10-09 11:09 ` Rafael J. Wysocki
2010-10-09 11:09 ` [linux-pm] " Rafael J. Wysocki
2010-10-11 17:00 ` Alan Stern
2010-10-11 22:30 ` Rafael J. Wysocki
2010-10-11 22:30 ` [linux-pm] " Rafael J. Wysocki
2010-10-11 17:00 ` Alan Stern
2010-10-08 16:18 ` Alan Stern
2010-10-07 17:35 ` Alan Stern
2010-11-19 15:45 ` [PATCH ver. 2] " Alan Stern
2010-11-20 12:56 ` Rafael J. Wysocki
2010-11-20 16:59 ` Alan Stern
2010-11-20 16:59 ` Alan Stern
2010-11-20 19:41 ` [linux-pm] " Alan Stern
2010-11-21 23:45 ` Rafael J. Wysocki
2010-11-21 23:45 ` [linux-pm] " Rafael J. Wysocki
2010-11-20 19:41 ` Alan Stern
2010-11-21 23:41 ` Rafael J. Wysocki
2010-11-21 23:41 ` Rafael J. Wysocki
2010-11-22 15:38 ` Alan Stern
2010-11-22 15:38 ` Alan Stern
2010-11-22 23:01 ` Rafael J. Wysocki
2010-11-23 3:19 ` Alan Stern
2010-11-23 3:19 ` Alan Stern
2010-11-23 22:51 ` Rafael J. Wysocki
2010-11-24 0:11 ` Kevin Hilman
2010-11-24 16:43 ` Alan Stern
2010-11-24 18:03 ` Kevin Hilman
2010-11-24 18:03 ` Kevin Hilman
2010-11-24 16:43 ` Alan Stern
2010-11-24 0:11 ` Kevin Hilman
2010-11-24 14:56 ` Alan Stern
2010-11-24 14:56 ` Alan Stern
2010-11-24 20:33 ` Rafael J. Wysocki
2010-11-25 15:52 ` [PATCH ver. 3] " Alan Stern
2010-11-25 15:52 ` Alan Stern
2010-11-25 18:58 ` Oliver Neukum
2010-11-25 18:58 ` [linux-pm] " Oliver Neukum
2010-11-25 20:03 ` Rafael J. Wysocki
2010-11-25 20:03 ` Rafael J. Wysocki
2010-11-26 22:23 ` Rafael J. Wysocki
2010-11-26 22:23 ` Rafael J. Wysocki
2010-11-24 20:33 ` [PATCH ver. 2] " Rafael J. Wysocki
2010-11-23 22:51 ` Rafael J. Wysocki
2010-11-22 23:01 ` Rafael J. Wysocki
2010-11-20 12:56 ` Rafael J. Wysocki
2010-11-19 15:45 ` Alan Stern
2011-04-11 15:47 ` Sylwester Nawrocki
2011-04-11 16:08 ` Alan Stern
2011-04-11 17:20 ` Sylwester Nawrocki
2011-04-11 18:37 ` Alan Stern
2010-10-06 21:47 ` [PATCH] " Rafael J. Wysocki
2010-10-06 23:51 ` Kevin Hilman
2010-10-06 23:51 ` Kevin Hilman
2010-10-06 20:28 ` Alan Stern
2010-10-06 15:58 ` Alan Stern
2010-10-02 14:12 ` Alan Stern
2010-10-01 14:28 ` Alan Stern
2010-09-30 22:41 ` Rafael J. Wysocki
2010-09-30 22:02 ` Rafael J. Wysocki
2010-10-01 14:12 ` Alan Stern
2010-10-01 21:14 ` Rafael J. Wysocki
2010-10-01 22:37 ` [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: Re: [PATCH] PM: add synchronous ...) Rafael J. Wysocki
2010-10-01 22:37 ` Rafael J. Wysocki [this message]
2010-10-02 14:15 ` [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: Re: [linux-pm] " Alan Stern
2010-10-02 14:15 ` [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: " Alan Stern
2010-10-01 21:14 ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Rafael J. Wysocki
2010-10-01 14:12 ` Alan Stern
2010-09-30 18:25 ` Alan Stern
2010-09-27 21:09 ` runtime_pm_get_sync() from ISR with IRQs disabled? Rafael J. Wysocki
2010-09-27 21:11 ` [linux-pm] " Kevin Hilman
2010-09-27 21:11 ` Kevin Hilman
2010-09-24 20:27 ` [linux-pm] " Alan Stern
2010-09-24 21:52 ` Kevin Hilman
2010-09-24 21:52 ` Kevin Hilman
2010-09-24 20:27 ` Alan Stern
2010-09-24 18:54 ` Kevin Hilman
2010-09-24 15:13 ` Alan Stern
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=201010020037.55277.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.