Skip to contentSkip to conversation

PM: Runtime PM v11 patches 20090731

PATCH New Magnus Damm 1 participant 5 messages Jul 31, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover PM: Runtime PM v11 patches 20090731

PM: Runtime PM v11 patches 20090731

[PATCH 01/04] PM: Runtime PM v11 - add dev_pm_ops helpers [PATCH 02/04] PM: Runtime PM v11 - let bus-less devices succeed [PATCH 03/04] PM: Runtime PM v11 - add debug printouts [PATCH 04/04] PM: Runtime PM v11 - CONFIG_PM_SLEEP=n support

These patches contain architecture independent changes for Runtime PM and are meant to be applied on top of:
"PM: Introduce core framework for run-time PM of I/O devices (rev. 11)" by Rafael J. Wysocki.

Patch 01 + 03 are very straightforward and would be useful to have upstream from the perspective of a Runtime PM bus developer.

Patch 02 + 04 try to address some problems I ran into while hacking on the Runtime PM platform bus code for SuperH. There may be better ways to solve those issues.

Please see each individual patch for more information. Thanks!

---

 drivers/base/core.c          |    3 ++
 drivers/base/power/main.c    |    3 --
 drivers/base/power/runtime.c |   55 ++++++++++++++++++++++++++----------------
 include/linux/pm_runtime.h   |   19 ++++++++++++++
 4 files changed, 57 insertions(+), 23 deletions(-)
#1 lore raw

PATCH 1/4 PM: Runtime PM v11 - add dev_pm_ops helpers

From: Magnus Damm <[email protected]>

This patch breaks out the dev_pm_ops handling code for Runtime PM into separate functions. This change makes is possible for the main code and separate bus implementations to deal with callbacks and error codes in a consistent fashion.

The broken out functions are used by the Runtime PM platform device bus implementation for SuperH.

---

 drivers/base/power/runtime.c |   10 ++++------
 include/linux/pm_runtime.h   |   19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)
drivers/base/power/runtime.c +4 -6
@@ -79,8 +79,8 @@ static int __pm_runtime_idle(struct devi
 
 	spin_unlock_irq(&dev->power.lock);
 
-	if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_idle)
-		dev->bus->pm->runtime_idle(dev);
+	if (dev->bus)
+		pm_runtime_ops_idle(dev, dev->bus->pm);
 
 	spin_lock_irq(&dev->power.lock);
 
@@ -177,8 +177,7 @@ int __pm_runtime_suspend(struct device *
 
 	spin_unlock_irq(&dev->power.lock);
 
-	retval = dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend ?
-		dev->bus->pm->runtime_suspend(dev) : -ENOSYS;
+	retval = dev->bus ? pm_runtime_ops_suspend(dev, dev->bus->pm) : -ENOSYS;
 
 	spin_lock_irq(&dev->power.lock);
 
@@ -319,8 +318,7 @@ int __pm_runtime_resume(struct device *d
 
 	spin_unlock_irq(&dev->power.lock);
 
-	retval = dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume ?
-		dev->bus->pm->runtime_resume(dev) : -ENOSYS;
+	retval = dev->bus ? pm_runtime_ops_resume(dev, dev->bus->pm) : -ENOSYS;
 
 	spin_lock_irq(&dev->power.lock);
 
include/linux/pm_runtime.h +19 -0
@@ -108,4 +108,23 @@ static inline void pm_runtime_set_suspen
 	__pm_runtime_set_status(dev, RPM_SUSPENDED);
 }
 
+static inline int pm_runtime_ops_suspend(struct device *dev,
+					 struct dev_pm_ops *p)
+{
+	return p && p->runtime_suspend ? p->runtime_suspend(dev) : -ENOSYS;
+}
+
+static inline int pm_runtime_ops_resume(struct device *dev,
+					struct dev_pm_ops *p)
+{
+	return p && p->runtime_resume ? p->runtime_resume(dev) : -ENOSYS;
+}
+
+static inline void pm_runtime_ops_idle(struct device *dev,
+				       struct dev_pm_ops *p)
+{
+	if (p && p->runtime_idle)
+		p->runtime_idle(dev);
+}
+
 #endif
#2 lore raw

PATCH 2/4 PM: Runtime PM v11 - let bus-less devices succeed

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

This patch allows bus-less devices to pass as being suspended even though there is no dev_pm_ops structure to use to get the Runtime PM callbacks.

Workarounds the fact that "struct device platform_bus" becomes the parent of otherwise parent-less platform devices. Runtime suspend and resume of devices on the platform bus is impossible without this change. It may however be better to modify the actual struct device than working around things in the Runtime PM core code.

---

 drivers/base/power/runtime.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/power/runtime.c +2 -2
@@ -177,7 +177,7 @@ int __pm_runtime_suspend(struct device *
 
 	spin_unlock_irq(&dev->power.lock);
 
-	retval = dev->bus ? pm_runtime_ops_suspend(dev, dev->bus->pm) : -ENOSYS;
+	retval = dev->bus ? pm_runtime_ops_suspend(dev, dev->bus->pm) : 0;
 
 	spin_lock_irq(&dev->power.lock);
 
@@ -318,7 +318,7 @@ int __pm_runtime_resume(struct device *d
 
 	spin_unlock_irq(&dev->power.lock);
 
-	retval = dev->bus ? pm_runtime_ops_resume(dev, dev->bus->pm) : -ENOSYS;
+	retval = dev->bus ? pm_runtime_ops_resume(dev, dev->bus->pm) : 0;
 
 	spin_lock_irq(&dev->power.lock);
 
#3 lore raw

PATCH 3/4 PM: Runtime PM v11 - add debug printouts

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

This patch adds dev_dbg() printouts to the Runtime PM code. Just add a #define DEBUG at the top of the file to get suspend and resume printouts. Also add a missing newline to the pm_runtime_enable() printout while at it.

---

 drivers/base/power/runtime.c |   41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)
drivers/base/power/runtime.c +29 -12
@@ -125,16 +125,22 @@ int __pm_runtime_suspend(struct device *
 	bool notify = false;
 	int retval = 0;
 
+	dev_dbg(dev, "__pm_runtime_suspend() %d!\n", from_wq);
  repeat:
-	if (dev->power.runtime_failure)
-		return -EINVAL;
+	if (dev->power.runtime_failure) {
+		retval = -EINVAL;
+		goto out;
+	}
 
 	pm_runtime_deactivate_timer(dev);
 
 	if (dev->power.request_pending) {
 		/* Pending resume requests take precedence over us. */
-		if (dev->power.request == RPM_REQ_RESUME)
-			return -EAGAIN;
+		if (dev->power.request == RPM_REQ_RESUME) {
+			retval = -EAGAIN;
+			goto out;
+		}
+
 		/* Other pending requests need to be canceled. */
 		dev->power.request = RPM_REQ_NONE;
 	}
@@ -148,13 +154,15 @@ int __pm_runtime_suspend(struct device *
 	else if (!pm_children_suspended(dev))
 		retval = -EBUSY;
 	if (retval)
-		return retval;
+		goto out;
 
 	if (dev->power.runtime_status == RPM_SUSPENDING) {
 		DEFINE_WAIT(wait);
 
-		if (from_wq)
-			return -EINPROGRESS;
+		if (from_wq) {
+			retval = -EINPROGRESS;
+			goto out;
+		}
 
 		/* Wait for the other suspend running in parallel with us. */
 		for (;;) {
@@ -217,6 +225,8 @@ int __pm_runtime_suspend(struct device *
 		pm_runtime_idle(dev);
 
 	spin_lock_irq(&dev->power.lock);
+ out:
+	dev_dbg(dev, "__pm_runtime_suspend() returns %d!\n", retval);
 
 	return retval;
 }
@@ -256,9 +266,12 @@ int __pm_runtime_resume(struct device *d
 	struct device *parent = NULL;
 	int retval = 0;
 
+	dev_dbg(dev, "__pm_runtime_resume() %d!\n", from_wq);
  repeat:
-	if (dev->power.runtime_failure)
-		return -EINVAL;
+	if (dev->power.runtime_failure) {
+		retval = -EINVAL;
+		goto out;
+	}
 
 	pm_runtime_cancel_pending(dev);
 
@@ -267,7 +280,7 @@ int __pm_runtime_resume(struct device *d
 	else if (dev->power.disable_depth > 0)
 		retval = -EAGAIN;
 	if (retval)
-		return retval;
+		goto out;
 
 	if (dev->power.runtime_status == RPM_RESUMING
 	    || dev->power.runtime_status == RPM_SUSPENDING) {
@@ -276,7 +289,9 @@ int __pm_runtime_resume(struct device *d
 		if (from_wq) {
 			if (dev->power.runtime_status == RPM_SUSPENDING)
 				dev->power.deferred_resume = true;
-			return -EINPROGRESS;
+
+			retval = -EINPROGRESS;
+			goto out;
 		}
 
 		/* Wait for the operation carried out in parallel with us. */
@@ -347,6 +362,8 @@ int __pm_runtime_resume(struct device *d
 		pm_request_idle(dev);
 
 	spin_lock_irq(&dev->power.lock);
+ out:
+	dev_dbg(dev, "__pm_runtime_resume() returns %d!\n", retval);
 
 	return retval;
 }
@@ -771,7 +788,7 @@ void pm_runtime_enable(struct device *de
 	if (dev->power.disable_depth > 0)
 		dev->power.disable_depth--;
 	else
-		dev_warn(dev, "Unbalanced %s!", __func__);
+		dev_warn(dev, "Unbalanced %s!\n", __func__);
 
 	spin_unlock_irqrestore(&dev->power.lock, flags);
 }
#4 lore raw

PATCH 4/4 PM: Runtime PM v11 - CONFIG_PM_SLEEP=n support

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

This patch contains a few fixes to allow Runtime PM to be used even though suspend and hibernation are disabled in the kconfig. Without this patch the Runtime PM code compiles just fine with CONFIG_PM_SLEEP=n but the functions pm_runtime_init() and pm_runtime_remove() never gets called during runtime.

Not sure if CONFIG_PM_RUNTIME=y and CONFIG_PM_SLEEP=n really is a valid combination, but I can easily imagine use cases for Runtime PM without system suspend/hibernation support.

---

 drivers/base/core.c       |    3 +++
 drivers/base/power/main.c |    3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/base/core.c +3 -0
@@ -23,6 +23,7 @@
 #include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
+#include <linux/pm_runtime.h>
 
 #include "base.h"
 #include "power/power.h"
@@ -555,6 +556,7 @@ void device_initialize(struct device *de
 	INIT_LIST_HEAD(&dev->devres_head);
 	device_init_wakeup(dev, 0);
 	device_pm_init(dev);
+	pm_runtime_init(dev);
 	set_dev_node(dev, -1);
 }
 
@@ -1063,6 +1065,7 @@ void device_del(struct device *dev)
 		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 					     BUS_NOTIFY_DEL_DEVICE, dev);
 	device_pm_remove(dev);
+	pm_runtime_remove(dev);
 	dpm_sysfs_remove(dev);
 	if (parent)
 		klist_del(&dev->p->knode_parent);
drivers/base/power/main.c +0 -3
@@ -56,7 +56,6 @@ static bool transition_started;
 void device_pm_init(struct device *dev)
 {
 	dev->power.status = DPM_ON;
-	pm_runtime_init(dev);
 }
 
 /**
@@ -116,8 +115,6 @@ void device_pm_remove(struct device *dev
 	mutex_lock(&dpm_list_mtx);
 	list_del_init(&dev->power.entry);
 	mutex_unlock(&dpm_list_mtx);
-
-	pm_runtime_remove(dev);
 }
 
 /**