Skip to contentSkip to conversation

runtime PM: common hooks for static and runtime PM

DISCUSSION Kevin Hilman 4 participants 22 messages Feb 3, 2010 – Mar 18, 2010

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

Hello,

I'm implementing runtime PM for the TI OMAP SoCs by overriding the platform_bus hooks. All is working well for runtime PM, but it's brought up a couple snags for static PM.

Most of our drivers don't really need to distinguish between runtime PM and static PM as we can hit the same power states when idle as we can in suspend. Before switching to runtime PM we've been using the clock framework to do both runtime PM and static PM. The driver would disable its clocks & HW when idle and when going into suspend, typically using a common 'disable' function.

In converting a test driver to runtime PM, I just converted this common disable function from a clock disable to a pm_runtime_put_sync() and the common enable function to do a pm_runtime_get_sync(). This all worked well for runtime PM, resulting in my platform_pm_runtime_* hooks being called where I can then disable/re-enable the clocks/HW etc. So far so good.

However, I'm not able to use the common function in the static suspend path because dpm_prepare() does a pm_runtime_get_no_resume() which prevents any runtime PM transitions during suspend.

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

My current hack is to add an "extra" pm_runtime_put_sync() to the driver's static suspend hook (and 'get' in the resume hook) to essentially cancel out the 'get' held by dpm_prepare(), but I'm pretty sure this is not an acceptable long-term solution.

Any other ideas? Or maybe I've misunderstood something more basic. Any pointers would be appreciated.

Thanks,

Kevin

#1 lore raw
Quoted 24 lines · Kevin Hilman

Hello,

I'm implementing runtime PM for the TI OMAP SoCs by overriding the platform_bus hooks. All is working well for runtime PM, but it's brought up a couple snags for static PM.

Most of our drivers don't really need to distinguish between runtime PM and static PM as we can hit the same power states when idle as we can in suspend. Before switching to runtime PM we've been using the clock framework to do both runtime PM and static PM. The driver would disable its clocks & HW when idle and when going into suspend, typically using a common 'disable' function.

In converting a test driver to runtime PM, I just converted this common disable function from a clock disable to a pm_runtime_put_sync() and the common enable function to do a pm_runtime_get_sync(). This all worked well for runtime PM, resulting in my platform_pm_runtime_* hooks being called where I can then disable/re-enable the clocks/HW etc. So far so good.

However, I'm not able to use the common function in the static suspend path because dpm_prepare() does a pm_runtime_get_no_resume() which prevents any runtime PM transitions during suspend.

Quoted 5 lines

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

Or alternatively, both sets of PM methods could call a single pair of routines to handle the clocks etc.

Alan Stern

#2 lore raw
Quoted 8 lines · Alan Stern
Quoted 5 lines · Kevin Hilman

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

Quoted 7 lines

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

Or alternatively, both sets of PM methods could call a single pair of routines to handle the clocks etc.

One issue with avoiding the indirection is that they'll need to remember if the device is already suspended in order to avoid doing things like double disabling of clocks or regulators. Using the runtime PM calls would mean that the core would keep track of that for the driver.

#3 lore raw
Quoted 14 lines · Mark Brown
Quoted 12 lines · Alan Stern
Quoted 5 lines · Kevin Hilman

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

Quoted 7 lines
Quoted 2 lines

Or alternatively, both sets of PM methods could call a single pair of routines to handle the clocks etc.

One issue with avoiding the indirection is that they'll need to remember if the device is already suspended in order to avoid doing things like double disabling of clocks or regulators. Using the runtime PM calls would mean that the core would keep track of that for the driver.

As you have found out, that approach doesn't work. You need to figure out some way of your own to avoid double disabling. The PM core can't do it for you, because there may be devices that enter _different_ power states for runtime suspend and system suspend. For the sake of such devices the core _has_ to do double suspends.

Alan Stern

#4 lore raw
Quoted 23 lines · Alan Stern
Quoted 14 lines · Mark Brown
Quoted 12 lines · Alan Stern
Quoted 5 lines · Kevin Hilman

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

Quoted 7 lines
Quoted 2 lines

Or alternatively, both sets of PM methods could call a single pair of routines to handle the clocks etc.

One issue with avoiding the indirection is that they'll need to remember if the device is already suspended in order to avoid doing things like double disabling of clocks or regulators. Using the runtime PM calls would mean that the core would keep track of that for the driver.

Quoted 5 lines

As you have found out, that approach doesn't work. You need to figure out some way of your own to avoid double disabling. The PM core can't do it for you, because there may be devices that enter _different_ power states for runtime suspend and system suspend. For the sake of such devices the core _has_ to do double suspends.

Right, but my point is that one reason for wanting to call into the runtime PM API during vanilla suspend is that the indirection buys you the reference counting.

I wonder if it's worth the PM core providing an off the shelf suspend and resume via runtime PM implementation so drivers only need to assign function pointers? As Kevin says this is going to be *very* common for embedded drivers.

#5 lore raw
Quoted 9 lines · Mark Brown
Quoted 5 lines

As you have found out, that approach doesn't work. You need to figure out some way of your own to avoid double disabling. The PM core can't do it for you, because there may be devices that enter _different_ power states for runtime suspend and system suspend. For the sake of such devices the core _has_ to do double suspends.

Right, but my point is that one reason for wanting to call into the runtime PM API during vanilla suspend is that the indirection buys you the reference counting.

It's not reference counting; it's just a state variable. (There _is_ a reference counter involved, but you don't want to use it.)

Quoted 4 lines

I wonder if it's worth the PM core providing an off the shelf suspend and resume via runtime PM implementation so drivers only need to assign function pointers? As Kevin says this is going to be *very* common for embedded drivers.

What's so hard about doing this?

	int my_suspend(struct device *dev)
	{
		if (dev->power.runtime_status == RPM_SUSPENDED)
			return 0;
		return my_runtime_suspend(dev);
	}

Or if you prefer, stick the "if" statement at the beginning of your suspend method and then set both function pointers to the same method.

Alan Stern

#6 lore raw
Quoted 16 lines · Alan Stern
Quoted 4 lines · Mark Brown

I wonder if it's worth the PM core providing an off the shelf suspend and resume via runtime PM implementation so drivers only need to assign function pointers? As Kevin says this is going to be *very* common for embedded drivers.

What's so hard about doing this?

	int my_suspend(struct device *dev)
	{
		if (dev->power.runtime_status == RPM_SUSPENDED)
			return 0;
		return my_runtime_suspend(dev);
	}
Quoted 2 lines

Or if you prefer, stick the "if" statement at the beginning of your suspend method and then set both function pointers to the same method.

It's not that it's hard per se, it's that it feels like it's peering inside the implementation of the API. Having the PM core provide something would make it clear that this is the expected approach and ensure that there aren't any silly mistakes, in much the same way that having SIMPLE_DEV_PM_OPS makes the handling of drivers that use the same suspend path for both suspend to disk and suspend to RAM clear.

#7 lore raw
Quoted 20 lines · Mark Brown
Quoted 16 lines · Alan Stern
Quoted 4 lines · Mark Brown

I wonder if it's worth the PM core providing an off the shelf suspend and resume via runtime PM implementation so drivers only need to assign function pointers? As Kevin says this is going to be *very* common for embedded drivers.

What's so hard about doing this?

	int my_suspend(struct device *dev)
	{
		if (dev->power.runtime_status == RPM_SUSPENDED)
			return 0;
		return my_runtime_suspend(dev);
	}
Quoted 2 lines

Or if you prefer, stick the "if" statement at the beginning of your suspend method and then set both function pointers to the same method.

Quoted 6 lines

It's not that it's hard per se, it's that it feels like it's peering inside the implementation of the API. Having the PM core provide something would make it clear that this is the expected approach and ensure that there aren't any silly mistakes, in much the same way that having SIMPLE_DEV_PM_OPS makes the handling of drivers that use the same suspend path for both suspend to disk and suspend to RAM clear.

You mean like providing an is_runtime_suspended() test? Then you could write:

	int my_suspend(struct device *dev)
	{
		if (is_runtime_suspended(dev))
			return 0;
		return my_runtime_suspend(dev);
	}

Or maybe you'd prefer to see a convenient pm_use_runtime_suspend() function that you could use for your dev_pm_ops.suspend pointer, which would do essentially the same as the above? (Along with a corresponding pm_use_runtime_resume() function, of course.)

Alan Stern

#8 lore raw
Quoted 15 lines · Alan Stern
Quoted 2 lines · Mark Brown

It's not that it's hard per se, it's that it feels like it's peering inside the implementation of the API. Having the PM core provide

You mean like providing an is_runtime_suspended() test? Then you could write:

	int my_suspend(struct device *dev)
	{
		if (is_runtime_suspended(dev))
			return 0;
		return my_runtime_suspend(dev);
	}
Quoted 4 lines

Or maybe you'd prefer to see a convenient pm_use_runtime_suspend() function that you could use for your dev_pm_ops.suspend pointer, which would do essentially the same as the above? (Along with a corresponding pm_use_runtime_resume() function, of course.)

Either (or both, of course - implementing the second would probably imply the former). The ops that can be assigned would be the clearest option but the accessor function should be enough to make it clear that this is something drivers are supposed to be doing.

#9 lore raw
Quoted 21 lines · Mark Brown
Quoted 15 lines · Alan Stern
Quoted 2 lines · Mark Brown

It's not that it's hard per se, it's that it feels like it's peering inside the implementation of the API. Having the PM core provide

You mean like providing an is_runtime_suspended() test? Then you could write:

	int my_suspend(struct device *dev)
	{
		if (is_runtime_suspended(dev))
			return 0;
		return my_runtime_suspend(dev);
	}
Quoted 4 lines

Or maybe you'd prefer to see a convenient pm_use_runtime_suspend() function that you could use for your dev_pm_ops.suspend pointer, which would do essentially the same as the above? (Along with a corresponding pm_use_runtime_resume() function, of course.)

Quoted 4 lines

Either (or both, of course - implementing the second would probably imply the former). The ops that can be assigned would be the clearest option but the accessor function should be enough to make it clear that this is something drivers are supposed to be doing.

Providing the new ops would be a little awkward because CONFIG_PM_SLEEP and CONFIG_PM_RUNTIME are independent: Either can be enabled without the other. This means the code to call the runtime_suspend and runtime_resume methods would have to be split out into a separate source file that would get built whenever either config option is enabled. It's doable, just somewhat awkward.

I'll give it a try and we'll see how it turns out...

Alan Stern

#10 lore raw
Quoted 28 lines · Alan Stern
Quoted 21 lines · Mark Brown
Quoted 15 lines · Alan Stern
Quoted 2 lines · Mark Brown

It's not that it's hard per se, it's that it feels like it's peering inside the implementation of the API. Having the PM core provide

You mean like providing an is_runtime_suspended() test? Then you could write:

	int my_suspend(struct device *dev)
	{
		if (is_runtime_suspended(dev))
			return 0;
		return my_runtime_suspend(dev);
	}
Quoted 4 lines

Or maybe you'd prefer to see a convenient pm_use_runtime_suspend() function that you could use for your dev_pm_ops.suspend pointer, which would do essentially the same as the above? (Along with a corresponding pm_use_runtime_resume() function, of course.)

Quoted 4 lines

Either (or both, of course - implementing the second would probably imply the former). The ops that can be assigned would be the clearest option but the accessor function should be enough to make it clear that this is something drivers are supposed to be doing.

Quoted 8 lines

Providing the new ops would be a little awkward because CONFIG_PM_SLEEP and CONFIG_PM_RUNTIME are independent: Either can be enabled without the other. This means the code to call the runtime_suspend and runtime_resume methods would have to be split out into a separate source file that would get built whenever either config option is enabled. It's doable, just somewhat awkward.

I'll give it a try and we'll see how it turns out...

And here it is. You can see that the patch isn't ideal.

Anyway, it should do what you want -- I haven't tested it.

Alan Stern

include/linux/pm.h +10 -0
Index: usb-2.6/include/linux/pm.h
===================================================================
@@ -508,6 +508,9 @@ extern void __suspend_report_result(cons
 		__suspend_report_result(__func__, fn, ret);		\
 	} while (0)
 
+extern int dpm_use_runtime_suspend(struct device *dev);
+extern int dpm_use_runtime_resume(struct device *dev);
+
 #else /* !CONFIG_PM_SLEEP */
 
 #define device_pm_lock() do {} while (0)
@@ -520,8 +523,15 @@ static inline int dpm_suspend_start(pm_m
 
 #define suspend_report_result(fn, ret)		do {} while (0)
 
+#define dpm_use_runtime_suspend		NULL
+#define dpm_use_runtime_resume		NULL
+
 #endif /* !CONFIG_PM_SLEEP */
 
+void rpm_invoke_runtime_idle(struct device *dev);
+int rpm_invoke_runtime_suspend(struct device *dev);
+int rpm_invoke_runtime_resume(struct device *dev);
+
 /* How to reorder dpm_list after device_move() */
 enum dpm_order {
 	DPM_ORDER_NONE,
include/linux/pm_runtime.h +8 -0
Index: usb-2.6/include/linux/pm_runtime.h
===================================================================
@@ -60,6 +60,11 @@ static inline void device_set_run_wake(s
 	dev->power.run_wake = enable;
 }
 
+static inline bool pm_is_runtime_suspended(struct device *dev)
+{
+	return dev->power.runtime_status == RPM_SUSPENDED;
+}
+
 #else /* !CONFIG_PM_RUNTIME */
 
 static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
@@ -86,6 +91,9 @@ static inline void pm_runtime_put_noidle
 static inline bool device_run_wake(struct device *dev) { return false; }
 static inline void device_set_run_wake(struct device *dev, bool enable) {}
 
+static inline bool pm_is_runtime_suspended(struct device *dev)
+		{ return false; }
+
 #endif /* !CONFIG_PM_RUNTIME */
 
 static inline int pm_runtime_get(struct device *dev)
drivers/base/power/Makefile +2 -2
Index: usb-2.6/drivers/base/power/Makefile
===================================================================
@@ -1,6 +1,6 @@
 obj-$(CONFIG_PM)	+= sysfs.o
-obj-$(CONFIG_PM_SLEEP)	+= main.o
-obj-$(CONFIG_PM_RUNTIME)	+= runtime.o
+obj-$(CONFIG_PM_SLEEP)	+= main.o invoke_runtime.o
+obj-$(CONFIG_PM_RUNTIME)	+= runtime.o invoke_runtime.o
 obj-$(CONFIG_PM_TRACE_RTC)	+= trace.o
 
 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/power/main.c +49 -0

52 lines not on this page · raw message

drivers/base/power/runtime.c +11 -70

101 lines not on this page · raw message

drivers/base/power/invoke_runtime.c new file +80 -0

80 lines not on this page · raw message

Documentation/power/runtime_pm.txt +6 -0
Index: usb-2.6/Documentation/power/runtime_pm.txt
===================================================================
@@ -329,6 +329,11 @@ drivers/base/power/runtime.c and include
       'power.runtime_error' is set or 'power.disable_depth' is greater than
       zero)
 
+  bool pm_is_runtime_suspended(struct device *dev);
+    - returns 'true' if the device's run-time PM status is 'suspended'; the
+      status is constantly subject to change, hence this function should be
+      used only in contexts such as during a system sleep transition
+
 It is safe to execute the following helper functions from interrupt context:
 
 pm_request_idle()
@@ -342,6 +347,7 @@ pm_suspend_ignore_children()
 pm_runtime_set_active()
 pm_runtime_set_suspended()
 pm_runtime_enable()
+pm_is_runtime_suspended()
 
 5. Run-time PM Initialization, Device Probing and Removal
 
#11 lore raw
Quoted 7 lines · Alan Stern
Quoted 1 line · Alan Stern

I'll give it a try and we'll see how it turns out...

And here it is. You can see that the patch isn't ideal.

Anyway, it should do what you want -- I haven't tested it.

It's taken a little while to test (and to be frank my testing is paper thin) but it looks like this does what I'm looking for - thanks!

#12 lore raw
Quoted 11 lines · Mark Brown
Quoted 7 lines · Alan Stern
Quoted 1 line · Alan Stern

I'll give it a try and we'll see how it turns out...

And here it is. You can see that the patch isn't ideal.

Anyway, it should do what you want -- I haven't tested it.

It's taken a little while to test (and to be frank my testing is paper thin) but it looks like this does what I'm looking for - thanks!

But should that patch be submitted for inclusion in the kernel, warts and all?

Alan Stern

#13 lore raw
Quoted 9 lines · Alan Stern
Quoted 7 lines · Mark Brown
Quoted 5 lines · Alan Stern
Quoted 1 line · Alan Stern

I'll give it a try and we'll see how it turns out...

And here it is. You can see that the patch isn't ideal.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Anyway, it should do what you want -- I haven't tested it.

It's taken a little while to test (and to be frank my testing is paper
thin) but it looks like this does what I'm looking for - thanks!

But should that patch be submitted for inclusion in the kernel, warts and all?

My feeling is that it solves a real problem so yes and if it turns out there are issues we can always bug fix it later - if it's not merged then cross tree issues would mean that there'd be a substantial lag before it could be used in drivers.

#14 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 7 lines · Mark Brown
Quoted 5 lines · Alan Stern
Quoted 1 line · Alan Stern

I'll give it a try and we'll see how it turns out...

And here it is. You can see that the patch isn't ideal.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Anyway, it should do what you want -- I haven't tested it.

It's taken a little while to test (and to be frank my testing is paper thin) but it looks like this does what I'm looking for - thanks!

But should that patch be submitted for inclusion in the kernel, warts and all?

I vote yes.

Kevin

#15 lore raw
In reply to Alan Stern
Quoted 32 lines · Alan Stern
Quoted 24 lines · Kevin Hilman

Hello,

I'm implementing runtime PM for the TI OMAP SoCs by overriding the platform_bus hooks. All is working well for runtime PM, but it's brought up a couple snags for static PM.

Most of our drivers don't really need to distinguish between runtime PM and static PM as we can hit the same power states when idle as we can in suspend. Before switching to runtime PM we've been using the clock framework to do both runtime PM and static PM. The driver would disable its clocks & HW when idle and when going into suspend, typically using a common 'disable' function.

In converting a test driver to runtime PM, I just converted this common disable function from a clock disable to a pm_runtime_put_sync() and the common enable function to do a pm_runtime_get_sync(). This all worked well for runtime PM, resulting in my platform_pm_runtime_* hooks being called where I can then disable/re-enable the clocks/HW etc. So far so good.

However, I'm not able to use the common function in the static suspend path because dpm_prepare() does a pm_runtime_get_no_resume() which prevents any runtime PM transitions during suspend.

Quoted 5 lines

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

Quoted 5 lines

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

[Revisiting this thread again... with a slightly different problem]

In my case, the driver's runtime_suspend and runtime_resume hooks are not where the clocks are managed. The actual hardware enable/disable is done in the bus-level runtime PM hooks, in this case platform_bus. So having the system PM methods directly call the drivers runtime PM methods doesn't help. In fact, because we handle the hardware at the bus level, most drivers can live without any runtime PM methods, and simply use get/put.

I've worked around this temporarily by calling the bus->pm->runtime_suspend() and ->runtime_resume() methods from the system PM methods, but am curious if that is an acceptable solution.

Kevin

#16 lore raw
Quoted 50 lines · Kevin Hilman
Quoted 32 lines · Alan Stern
Quoted 24 lines · Kevin Hilman

Hello,

I'm implementing runtime PM for the TI OMAP SoCs by overriding the platform_bus hooks. All is working well for runtime PM, but it's brought up a couple snags for static PM.

Most of our drivers don't really need to distinguish between runtime PM and static PM as we can hit the same power states when idle as we can in suspend. Before switching to runtime PM we've been using the clock framework to do both runtime PM and static PM. The driver would disable its clocks & HW when idle and when going into suspend, typically using a common 'disable' function.

In converting a test driver to runtime PM, I just converted this common disable function from a clock disable to a pm_runtime_put_sync() and the common enable function to do a pm_runtime_get_sync(). This all worked well for runtime PM, resulting in my platform_pm_runtime_* hooks being called where I can then disable/re-enable the clocks/HW etc. So far so good.

However, I'm not able to use the common function in the static suspend path because dpm_prepare() does a pm_runtime_get_no_resume() which prevents any runtime PM transitions during suspend.

Quoted 5 lines

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

Quoted 5 lines

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

[Revisiting this thread again... with a slightly different problem]

In my case, the driver's runtime_suspend and runtime_resume hooks are not where the clocks are managed. The actual hardware enable/disable is done in the bus-level runtime PM hooks, in this case platform_bus. So having the system PM methods directly call the drivers runtime PM methods doesn't help. In fact, because we handle the hardware at the bus level, most drivers can live without any runtime PM methods, and simply use get/put.

Quoted 3 lines

I've worked around this temporarily by calling the bus->pm->runtime_suspend() and ->runtime_resume() methods from the system PM methods, but am curious if that is an acceptable solution.

If the platform bus manages the clocks from within its runtime-PM routines, then it ought to provide a similar service from within its system-PM routines. You could do it by calling the bus's runtime-PM routines indirectly through the method pointers (as you do now), or by calling the runtime-PM routines directly, or by making the runtime-PM routines and the system-PM routines both call a separate common function responsible for managing the clocks.

Each of these approaches is acceptable, assuming it doesn't mess up any of the other platform drivers in your system.

Alan Stern

#17 lore raw
Quoted 52 lines · Alan Stern
Quoted 50 lines · Kevin Hilman
Quoted 32 lines · Alan Stern
Quoted 24 lines · Kevin Hilman

Hello,

I'm implementing runtime PM for the TI OMAP SoCs by overriding the platform_bus hooks. All is working well for runtime PM, but it's brought up a couple snags for static PM.

Most of our drivers don't really need to distinguish between runtime PM and static PM as we can hit the same power states when idle as we can in suspend. Before switching to runtime PM we've been using the clock framework to do both runtime PM and static PM. The driver would disable its clocks & HW when idle and when going into suspend, typically using a common 'disable' function.

In converting a test driver to runtime PM, I just converted this common disable function from a clock disable to a pm_runtime_put_sync() and the common enable function to do a pm_runtime_get_sync(). This all worked well for runtime PM, resulting in my platform_pm_runtime_* hooks being called where I can then disable/re-enable the clocks/HW etc. So far so good.

However, I'm not able to use the common function in the static suspend path because dpm_prepare() does a pm_runtime_get_no_resume() which prevents any runtime PM transitions during suspend.

Quoted 5 lines

I understand the motivation for this is probably to prevent runtime PM transitions during static suspend, and that makes sense. However, I'm wondering if there's some other way to handle my problem without having to have the driver have different paths for static and runtime PM.

Quoted 5 lines

The system PM methods could directly call the runtime_suspend and runtime_resume methods (which presumably is where you actually disable or enable the clocks etc.), instead of going indirectly through pm_runtime_put_sync() and pm_runtime_get_sync().

[Revisiting this thread again... with a slightly different problem]

In my case, the driver's runtime_suspend and runtime_resume hooks are not where the clocks are managed. The actual hardware enable/disable is done in the bus-level runtime PM hooks, in this case platform_bus. So having the system PM methods directly call the drivers runtime PM methods doesn't help. In fact, because we handle the hardware at the bus level, most drivers can live without any runtime PM methods, and simply use get/put.

Quoted 7 lines
Quoted 3 lines

I've worked around this temporarily by calling the bus->pm->runtime_suspend() and ->runtime_resume() methods from the system PM methods, but am curious if that is an acceptable solution.

If the platform bus manages the clocks from within its runtime-PM routines, then it ought to provide a similar service from within its system-PM routines.

Hmm, good point. Currently the platform bus code allows overriding the runtime PM methods via weak functions (drivers/base/platform.c) but not the system PM methods. Below is a patch that allows platforms to extend the system PM methods of the platform bus as well.

Quoted 5 lines

You could do it by calling the bus's runtime-PM
routines indirectly through the method pointers (as you do now), or by calling the runtime-PM routines directly, or by making the runtime-PM routines and the system-PM routines both call a separate common function responsible for managing the clocks.

Using the patch below, I am able to add custom system PM hooks and then use common code to manage the clocks for runtime PM and system PM.

Comments?

Kevin

commit ca2173923bae3ba631e12698401ef0b59ec0433c

Author: Kevin Hilman <[email protected]>
Date:   Wed Mar 17 09:36:10 2010 -0700

platform_bus: allow custom extensions to system PM methods

When runtime PM for platform_bus was added, it allowed for platforms to customize the runtime PM methods since they are defined as weak symbols.

This patch allows platforms to extend the system PM methods with custom hooks as well so runtime PM and system PM extensions can be managed together.

drivers/base/platform.c +28 -0
index 1ba9d61..a30f850 100644
@@ -729,6 +729,26 @@ static void platform_pm_complete(struct device *dev)
 
 #ifdef CONFIG_SUSPEND
 
+int __weak platform_pm_suspend_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_suspend_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
 static int platform_pm_suspend(struct device *dev)
 {
 	struct device_driver *drv = dev->driver;
@@ -744,6 +764,8 @@ static int platform_pm_suspend(struct device *dev)
 		ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
 	}
 
+	platform_pm_suspend_hook(dev);
+
 	return ret;
 }
 
@@ -760,6 +782,8 @@ static int platform_pm_suspend_noirq(struct device *dev)
 			ret = drv->pm->suspend_noirq(dev);
 	}
 
+	platform_pm_suspend_noirq_hook(dev);
+
 	return ret;
 }
 
@@ -768,6 +792,8 @@ static int platform_pm_resume(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
+	platform_pm_resume_hook(dev);
+
 	if (!drv)
 		return 0;
 
@@ -786,6 +812,8 @@ static int platform_pm_resume_noirq(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
+	platform_pm_resume_noirq_hook(dev);
+
 	if (!drv)
 		return 0;
 
#18 lore raw
Quoted 56 lines · Kevin Hilman
Quoted 8 lines
Quoted 8 lines

In my case, the driver's runtime_suspend and runtime_resume hooks are not where the clocks are managed. The actual hardware enable/disable is done in the bus-level runtime PM hooks, in this case platform_bus. So having the system PM methods directly call the drivers runtime PM methods doesn't help. In fact, because we handle the hardware at the bus level, most drivers can live without any runtime PM methods, and simply use get/put.

Quoted 7 lines
Quoted 3 lines

I've worked around this temporarily by calling the bus->pm->runtime_suspend() and ->runtime_resume() methods from the system PM methods, but am curious if that is an acceptable solution.

If the platform bus manages the clocks from within its runtime-PM routines, then it ought to provide a similar service from within its system-PM routines.

Hmm, good point. Currently the platform bus code allows overriding the runtime PM methods via weak functions (drivers/base/platform.c) but not the system PM methods. Below is a patch that allows platforms to extend the system PM methods of the platform bus as well.

Quoted 5 lines

You could do it by calling the bus's runtime-PM
routines indirectly through the method pointers (as you do now), or by calling the runtime-PM routines directly, or by making the runtime-PM routines and the system-PM routines both call a separate common function responsible for managing the clocks.

Using the patch below, I am able to add custom system PM hooks and then use common code to manage the clocks for runtime PM and system PM.

Comments?

Kevin

commit ca2173923bae3ba631e12698401ef0b59ec0433c

Author: Kevin Hilman <[email protected]>
Date:   Wed Mar 17 09:36:10 2010 -0700

platform_bus: allow custom extensions to system PM methods

When runtime PM for platform_bus was added, it allowed for platforms to customize the runtime PM methods since they are defined as weak symbols.

This patch allows platforms to extend the system PM methods with custom hooks as well so runtime PM and system PM extensions can be managed together.

drivers/base/platform.c +0 -0
index 1ba9d61..a30f850 100644

drivers/base/platform.c static void platform_pm_complete(struct device *dev) · line 730

Quoted 2 lines
drivers/base/platform.c +0 -0
@@ -729,6 +729,26 @@ static void platform_pm_complete(struct device *dev)
 
 #ifdef CONFIG_SUSPEND

This probably should be CONFIG_SLEEP.

Quoted 52 lines
drivers/base/platform.c +26 -0
+int __weak platform_pm_suspend_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_suspend_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
 static int platform_pm_suspend(struct device *dev)
 {
 	struct device_driver *drv = dev->driver;
@@ -744,6 +764,8 @@ static int platform_pm_suspend(struct device *dev)
 		ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
 	}
 
+	platform_pm_suspend_hook(dev);
+
 	return ret;
 }
 
@@ -760,6 +782,8 @@ static int platform_pm_suspend_noirq(struct device *dev)
 			ret = drv->pm->suspend_noirq(dev);
 	}
 
+	platform_pm_suspend_noirq_hook(dev);
+
 	return ret;
 }
 
@@ -768,6 +792,8 @@ static int platform_pm_resume(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
+	platform_pm_resume_hook(dev);
+
 	if (!drv)
 		return 0;
 

drivers/base/platform.c static int platform_pm_resume_noirq(struct device *dev) · line 819

Quoted 8 lines
drivers/base/platform.c +2 -0
@@ -786,6 +812,8 @@ static int platform_pm_resume_noirq(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
+	platform_pm_resume_noirq_hook(dev);
+
 	if (!drv)
 		return 0;
 

It looks reasonable to me, but I'm not actively involved in PM for the platform bus. Magnus Damm might have some suggestions.

Alan Stern

#19 lore raw
Quoted 59 lines · Alan Stern
Quoted 57 lines · Kevin Hilman
Quoted 8 lines
Quoted 8 lines

In my case, the driver's runtime_suspend and runtime_resume hooks are not where the clocks are managed. The actual hardware enable/disable is done in the bus-level runtime PM hooks, in this case platform_bus. So having the system PM methods directly call the drivers runtime PM methods doesn't help. In fact, because we handle the hardware at the bus level, most drivers can live without any runtime PM methods, and simply use get/put.

Quoted 7 lines
Quoted 3 lines

I've worked around this temporarily by calling the bus->pm->runtime_suspend() and ->runtime_resume() methods from the system PM methods, but am curious if that is an acceptable solution.

If the platform bus manages the clocks from within its runtime-PM routines, then it ought to provide a similar service from within its system-PM routines.

Hmm, good point. Currently the platform bus code allows overriding the runtime PM methods via weak functions (drivers/base/platform.c) but not the system PM methods. Below is a patch that allows platforms to extend the system PM methods of the platform bus as well.

Quoted 5 lines

You could do it by calling the bus's runtime-PM
routines indirectly through the method pointers (as you do now), or by calling the runtime-PM routines directly, or by making the runtime-PM routines and the system-PM routines both call a separate common function responsible for managing the clocks.

Using the patch below, I am able to add custom system PM hooks and then use common code to manage the clocks for runtime PM and system PM.

Comments?

Kevin

commit ca2173923bae3ba631e12698401ef0b59ec0433c

Author: Kevin Hilman <[email protected]>
Date:   Wed Mar 17 09:36:10 2010 -0700

platform_bus: allow custom extensions to system PM methods

When runtime PM for platform_bus was added, it allowed for platforms to customize the runtime PM methods since they are defined as weak symbols.

This patch allows platforms to extend the system PM methods with custom hooks as well so runtime PM and system PM extensions can be managed together.

drivers/base/platform.c +0 -0
index 1ba9d61..a30f850 100644
@@ -729,6 +729,26 @@ static void platform_pm_complete(struct device *dev)
 
Quoted 3 lines

drivers/base/platform.c static void platform_pm_complete(struct device *dev) · line 730

Quoted 1 line
drivers/base/platform.c +0 -0
 #ifdef CONFIG_SUSPEND

This probably should be CONFIG_SLEEP.

CONFIG_PM_SLEEP to be precise.

Quoted 54 lines
Quoted 54 lines
drivers/base/platform.c +26 -0
+int __weak platform_pm_suspend_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_suspend_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
 static int platform_pm_suspend(struct device *dev)
 {
 	struct device_driver *drv = dev->driver;
@@ -744,6 +764,8 @@ static int platform_pm_suspend(struct device *dev)
 		ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
 	}
 
+	platform_pm_suspend_hook(dev);
+
 	return ret;
 }
 
@@ -760,6 +782,8 @@ static int platform_pm_suspend_noirq(struct device *dev)
 			ret = drv->pm->suspend_noirq(dev);
 	}
 
+	platform_pm_suspend_noirq_hook(dev);
+
 	return ret;
 }
 
@@ -768,6 +792,8 @@ static int platform_pm_resume(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
+	platform_pm_resume_hook(dev);
+
 	if (!drv)
 		return 0;
 
@@ -786,6 +812,8 @@ static int platform_pm_resume_noirq(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
Quoted 8 lines

drivers/base/platform.c static int platform_pm_resume_noirq(struct device *dev) · line 819

Quoted 5 lines
drivers/base/platform.c +2 -0
+	platform_pm_resume_noirq_hook(dev);
+
 	if (!drv)
 		return 0;
 

It looks reasonable to me, but I'm not actively involved in PM for the platform bus. Magnus Damm might have some suggestions.

Yes, I think Magnus is the right person to ask for comments.

Rafael

#20 lore raw
Quoted 60 lines · Rafael J. Wysocki
Quoted 59 lines · Alan Stern
Quoted 57 lines · Kevin Hilman
Quoted 8 lines
Quoted 8 lines

In my case, the driver's runtime_suspend and runtime_resume hooks are not where the clocks are managed. The actual hardware enable/disable is done in the bus-level runtime PM hooks, in this case platform_bus. So having the system PM methods directly call the drivers runtime PM methods doesn't help. In fact, because we handle the hardware at the bus level, most drivers can live without any runtime PM methods, and simply use get/put.

Quoted 7 lines
Quoted 3 lines

I've worked around this temporarily by calling the bus->pm->runtime_suspend() and ->runtime_resume() methods from the system PM methods, but am curious if that is an acceptable solution.

If the platform bus manages the clocks from within its runtime-PM routines, then it ought to provide a similar service from within its system-PM routines.

Hmm, good point. Currently the platform bus code allows overriding the runtime PM methods via weak functions (drivers/base/platform.c) but not the system PM methods. Below is a patch that allows platforms to extend the system PM methods of the platform bus as well.

Quoted 5 lines

You could do it by calling the bus's runtime-PM
routines indirectly through the method pointers (as you do now), or by calling the runtime-PM routines directly, or by making the runtime-PM routines and the system-PM routines both call a separate common function responsible for managing the clocks.

Using the patch below, I am able to add custom system PM hooks and then use common code to manage the clocks for runtime PM and system PM.

Comments?

Kevin

commit ca2173923bae3ba631e12698401ef0b59ec0433c

Author: Kevin Hilman <[email protected]>
Date:   Wed Mar 17 09:36:10 2010 -0700

platform_bus: allow custom extensions to system PM methods

When runtime PM for platform_bus was added, it allowed for platforms to customize the runtime PM methods since they are defined as weak symbols.

This patch allows platforms to extend the system PM methods with custom hooks as well so runtime PM and system PM extensions can be managed together.

drivers/base/platform.c +0 -0
index 1ba9d61..a30f850 100644
@@ -729,6 +729,26 @@ static void platform_pm_complete(struct device *dev)
 
Quoted 5 lines
Quoted 3 lines

drivers/base/platform.c static void platform_pm_complete(struct device *dev) · line 730

Quoted 1 line
drivers/base/platform.c +0 -0
 #ifdef CONFIG_SUSPEND

This probably should be CONFIG_SLEEP.

CONFIG_PM_SLEEP to be precise.

That #ifdef was not part of my patch, it was just part of the diff context. I'm just adding these new hooks inside the same ifdef that the platform_bus system PM hooks are defined.

Are you suggesting I also fixup the #ifdef in that code?

Quoted 63 lines
Quoted 54 lines
Quoted 54 lines
drivers/base/platform.c +26 -0
+int __weak platform_pm_suspend_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_suspend_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_hook(struct device *dev)
+{
+	return 0;
+}
+
+int __weak platform_pm_resume_noirq_hook(struct device *dev)
+{
+	return 0;
+}
+
 static int platform_pm_suspend(struct device *dev)
 {
 	struct device_driver *drv = dev->driver;
@@ -744,6 +764,8 @@ static int platform_pm_suspend(struct device *dev)
 		ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
 	}
 
+	platform_pm_suspend_hook(dev);
+
 	return ret;
 }
 
@@ -760,6 +782,8 @@ static int platform_pm_suspend_noirq(struct device *dev)
 			ret = drv->pm->suspend_noirq(dev);
 	}
 
+	platform_pm_suspend_noirq_hook(dev);
+
 	return ret;
 }
 
@@ -768,6 +792,8 @@ static int platform_pm_resume(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
+	platform_pm_resume_hook(dev);
+
 	if (!drv)
 		return 0;
 
@@ -786,6 +812,8 @@ static int platform_pm_resume_noirq(struct device *dev)
 	struct device_driver *drv = dev->driver;
 	int ret = 0;
 
Quoted 8 lines

drivers/base/platform.c static int platform_pm_resume_noirq(struct device *dev) · line 819

Quoted 5 lines
drivers/base/platform.c +2 -0
+	platform_pm_resume_noirq_hook(dev);
+
 	if (!drv)
 		return 0;
 

It looks reasonable to me, but I'm not actively involved in PM for the platform bus. Magnus Damm might have some suggestions.

Quoted 1 line

Yes, I think Magnus is the right person to ask for comments.

OK, will post a slighly updated version to a broader audience.

Kevin

#21 lore raw
Quoted 6 lines · Kevin Hilman
Quoted 6 lines
Quoted 5 lines

drivers/base/platform.c static void platform_pm_complete(struct device *dev) · line 730

Quoted 3 lines
drivers/base/platform.c +0 -0
@@ -729,6 +729,26 @@ static void platform_pm_complete(struct device *dev)
 
 #ifdef CONFIG_SUSPEND

This probably should be CONFIG_SLEEP.

Quoted 7 lines
Quoted 1 line

CONFIG_PM_SLEEP to be precise.

That #ifdef was not part of my patch, it was just part of the diff context. I'm just adding these new hooks inside the same ifdef that the platform_bus system PM hooks are defined.

Are you suggesting I also fixup the #ifdef in that code?

That would be a good idea. It can be done in a separate patch.

The point is that CONFIG_SUSPEND is defined only when you enable standby or suspend-to-RAM, and CONFIG_HIBERNATION is defined only when you enable suspend-to-disk, whereas CONFIG_SLEEP is defined when either of the others is.

Alan Stern