public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Partha Basak <p-basak2@ti.com>,
	Linux-pm mailing list <linux-pm@lists.linux-foundation.org>,
	linux-omap@vger.kernel.org
Subject: Re: [PATCH] PM: add synchronous runtime interface for interrupt handlers
Date: Fri, 1 Oct 2010 00:02:19 +0200	[thread overview]
Message-ID: <201010010002.19204.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1009301420520.1314-100000@iolanthe.rowland.org>

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.

Thanks,
Rafael


---
 drivers/base/power/runtime.c |  123 +++++++++++++++++--------------------------
 1 file changed, 51 insertions(+), 72 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,6 +153,27 @@ static int rpm_check_suspend_allowed(str
 	return retval;
 }
 
+/**
+ * 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);
+
+	return retval;
+}
 
 /**
  * rpm_idle - Notify device bus type if the device can be suspended.
@@ -167,8 +188,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,26 +235,16 @@ 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);
-
-		spin_lock_irq(&dev->power.lock);
-	} else if (dev->class && dev->class->pm
-	    && dev->class->pm->runtime_idle) {
-		spin_unlock_irq(&dev->power.lock);
+	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;
 
-		dev->class->pm->runtime_idle(dev);
-
-		spin_lock_irq(&dev->power.lock);
-	}
+	rpm_callback(callback, dev);
 
 	dev->power.idle_notification = false;
 	wake_up_all(&dev->power.wait_queue);
@@ -261,6 +272,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 +363,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 +438,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 +559,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);

  parent reply	other threads:[~2010-09-30 22:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.44L0.1009301420520.1314-100000@iolanthe.rowland.org>
2010-09-30 20:15 ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Rafael J. Wysocki
2010-09-30 22:02 ` Rafael J. Wysocki [this message]
2010-10-01 14:12   ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010111254430.2339-100000@netrider.rowland.org>
2010-10-11 22:30 ` Rafael J. Wysocki
     [not found] <201010091309.18552.rjw@sisk.pl>
2010-10-11 17:00 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010081220150.27105-100000@netrider.rowland.org>
2010-10-08 21:04 ` Kevin Hilman
     [not found] <Pine.LNX.4.44L0.1010081200200.27105-100000@netrider.rowland.org>
2010-10-08 19:53 ` Rafael J. Wysocki
     [not found] ` <201010082153.35192.rjw@sisk.pl>
2010-10-09 11:09   ` Rafael J. Wysocki
     [not found] <Pine.LNX.4.44L0.1010071318570.1753-100000@iolanthe.rowland.org>
2010-10-07 21:11 ` Rafael J. Wysocki
     [not found] ` <201010072311.31071.rjw@sisk.pl>
2010-10-07 23:15   ` Kevin Hilman
     [not found]   ` <8762xd4msy.fsf@deeprootsystems.com>
2010-10-07 23:37     ` Rafael J. Wysocki
     [not found]     ` <201010080137.38422.rjw@sisk.pl>
2010-10-07 23:55       ` Kevin Hilman
     [not found]       ` <87y6a9zhf7.fsf@deeprootsystems.com>
2010-10-08 16:22         ` Alan Stern
2010-10-08 19:57         ` Rafael J. Wysocki
2010-10-08 16:18   ` Alan Stern
     [not found] <87aamqaqt9.fsf@deeprootsystems.com>
2010-10-07 17:35 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010071048100.1753-100000@iolanthe.rowland.org>
2010-10-07 16:52 ` Kevin Hilman
     [not found] <201010062347.18232.rjw@sisk.pl>
2010-10-07 15:26 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010061609060.2047-100000@iolanthe.rowland.org>
2010-10-06 21:47 ` Rafael J. Wysocki
2010-10-06 23:51 ` Kevin Hilman
     [not found] <8739sjktbd.fsf@deeprootsystems.com>
2010-10-06 20:28 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010061156460.2047-100000@iolanthe.rowland.org>
2010-10-06 19:33 ` Rafael J. Wysocki
2010-10-06 19:35 ` Kevin Hilman
     [not found] <878w2cnwky.fsf@deeprootsystems.com>
2010-10-06 15:58 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010031144420.26676-100000@netrider.rowland.org>
2010-10-03 20:33 ` Rafael J. Wysocki
     [not found] <201010030006.33454.rjw@sisk.pl>
2010-10-03 15:52 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010021004150.15874-100000@netrider.rowland.org>
2010-10-02 22:06 ` Rafael J. Wysocki
2010-10-05 21:44 ` Kevin Hilman
     [not found] <Pine.LNX.4.44L0.1010011012560.1813-100000@iolanthe.rowland.org>
2010-10-01 21:23 ` Rafael J. Wysocki
2010-10-02 14:12   ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1010011011380.1813-100000@iolanthe.rowland.org>
2010-10-01 21:14 ` Rafael J. Wysocki
     [not found] <201010010041.26326.rjw@sisk.pl>
2010-10-01 14:28 ` Alan Stern
     [not found] <Pine.LNX.4.44L0.1009301703270.1314-100000@iolanthe.rowland.org>
2010-09-30 22:41 ` Rafael J. Wysocki
     [not found] <201009302215.59937.rjw@sisk.pl>
2010-09-30 21:42 ` Alan Stern
2010-09-30 21:42 ` Alan Stern
     [not found] <201009282019.07598.rjw@sisk.pl>
2010-09-30 18:25 ` 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=201010010002.19204.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=p-basak2@ti.com \
    --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