PM: Introduce core framework for run-time PM of I/O devices (rev. 8)
Subsystems (5)
RFC PATCH 1/1 PM: Introduce core framework for run-time PM of I/O devices (rev. 8)
Hi,
There's a rev. 8 of the run-time PM framework patch.
Highlights:
* I did my best to follow the design we've recently discussed.
* pm_runtime_[get|put]() and the sync versions call pm_[request|runtime]_[resume|idle](), because I don't see much point manipulating the usage counter alone.
* pm_runtime_disable() carries out a (synchronous) wake-up if there's a resume request pending.
Comments welcome.
Best,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Introduce a core framework for run-time power management of I/O devices. Add device run-time PM fields to 'struct dev_pm_info' and device run-time PM callbacks to 'struct dev_pm_ops'. Introduce a run-time PM workqueue and define some device run-time PM helper functions at the core level.
--- drivers/base/dd.c | 10 drivers/base/power/Makefile | 1 drivers/base/power/main.c | 21 - drivers/base/power/power.h | 11 drivers/base/power/runtime.c | 901 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 102 ++++ include/linux/pm_runtime.h | 105 +++++ kernel/power/Kconfig | 14 kernel/power/main.c | 17 9 files changed, 1170 insertions(+), 12 deletions(-)
kernel/power/Kconfig +14 -0
@@ -208,3 +208,17 @@ config APM_EMULATION random kernel OOPSes or reboots that don't seem to be related to anything, try disabling/enabling this option (or disabling/enabling APM in your BIOS). + +config PM_RUNTIME + bool "Run-time PM core functionality" + depends on PM + ---help--- + Enable functionality allowing I/O devices to be put into energy-saving + (low power) states at run time (or autosuspended) after a specified + period of inactivity and woken up in response to a hardware-generated + wake-up event or a driver's request. + + Hardware support is generally required for this functionality to work + and the bus type drivers of the buses the devices are on are + responsible for the actual handling of the autosuspend requests and + wake-up events.
kernel/power/main.c +17 -0
@@ -11,6 +11,7 @@#include <linux/kobject.h> #include <linux/string.h> #include <linux/resume-trace.h> +#include <linux/workqueue.h> #include "power.h"
@@ -217,8 +218,24 @@ static struct attribute_group attr_group .attrs = g, }; +#ifdef CONFIG_PM_RUNTIME +struct workqueue_struct *pm_wq; + +static int __init pm_start_workqueue (void ) +{ + pm_wq =create_freezeable_workqueue ("pm" ); + +return pm_wq ?0 : -ENOMEM ; +} +#else +static inline int pm_start_workqueue (void ) {return 0 ; } +#endif +static int __init pm_init (void ) { +int error =pm_start_workqueue (); +if (error) +return error; power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;
include/linux/pm.h +99 -3
131 lines not on this page · raw message
drivers/base/power/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_PM) += sysfs.o obj-$(CONFIG_PM_SLEEP) += main.o +obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/power/runtime.c new file +901 -0
901 lines not on this page · raw message
include/linux/pm_runtime.h new file +105 -0
105 lines not on this page · raw message
drivers/base/power/main.c +20 -1
@@ -21,6 +21,7 @@#include <linux/kallsyms.h> #include <linux/mutex.h> #include <linux/pm.h> +#include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/rwsem.h> #include <linux/interrupt.h>
@@ -49,6 +50,16 @@ static DEFINE_MUTEX(dpm_list_mtx);static bool transition_started;/** +* device_pm_init - Initialize the PM-related part of a device object +* @dev: Device object to initialize. +*/ +void device_pm_init (struct device *dev) +{ + dev->power.status =DPM_ON ; +pm_runtime_init (dev); +} + +/** * device_pm_lock - lock the list of active devices used by the PM core */ void device_pm_lock (void )
@@ -89,6 +100,8 @@ void device_pm_add(struct device *dev)list_add_tail (&dev->power.entry, &dpm_list);mutex_unlock (&dpm_list_mtx); + +pm_runtime_add (dev); }/**
@@ -105,6 +118,8 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); + +pm_runtime_remove (dev); }/**
@@ -510,6 +525,7 @@ static void dpm_complete(pm_message_t stmutex_unlock (&dpm_list_mtx);device_complete (dev, state); +pm_runtime_enable (dev);mutex_lock (&dpm_list_mtx); }
@@ -755,11 +771,14 @@ static int dpm_prepare(pm_message_t stat dev->power.status =DPM_PREPARING ;mutex_unlock (&dpm_list_mtx); - error =device_prepare (dev, state); + error =pm_runtime_disable (dev); +if (!error || !device_may_wakeup (dev)) + error =device_prepare (dev, state);mutex_lock (&dpm_list_mtx);if (error) { dev->power.status =DPM_ON ; +pm_runtime_enable (dev);if (error == -EAGAIN ) {put_device (dev); error =0 ;
drivers/base/dd.c +9 -1
@@ -23,6 +23,7 @@#include <linux/kthread.h> #include <linux/wait.h> #include <linux/async.h> +#include <linux/pm_runtime.h> #include "base.h" #include "power/power.h"
@@ -202,7 +203,10 @@ int driver_probe_device(struct device_drpr_debug ("bus: '%s': %s: matched device %s with driver %s\n" , drv->bus->name, __func__,dev_name (dev), drv->name); - ret =really_probe (dev, drv); + ret =pm_runtime_get_sync (dev); +if (ret >=0 ) + ret =really_probe (dev, drv); +pm_runtime_put (dev);return ret; }
@@ -306,6 +310,8 @@ static void __device_release_driver(stru drv = dev->driver;if (drv) { +pm_runtime_disable (dev); +driver_sysfs_remove (dev);if (dev->bus)
@@ -324,6 +330,8 @@ static void __device_release_driver(strublocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_UNBOUND_DRIVER , dev); + +pm_runtime_enable (dev); } }
drivers/base/power/power.h +4 -7
@@ -1,8 +1,3 @@ -static inline void device_pm_init (struct device *dev) -{ - dev->power.status =DPM_ON ; -} -#ifdef CONFIG_PM_SLEEP /*
@@ -16,14 +11,16 @@ static inline struct device *to_device(s return container_of(entry, struct device, power.entry); } +extern void device_pm_init (struct device *dev);extern void device_pm_add (struct device *);extern void device_pm_remove (struct device *);extern void device_pm_move_before (struct device *,struct device *);extern void device_pm_move_after (struct device *,struct device *);extern void device_pm_move_last (struct device *); -#else /* CONFIG_PM_SLEEP */ +#else /* !CONFIG_PM_SLEEP */ +static inline void device_pm_init (struct device *dev) {}static inline void device_pm_add (struct device *dev) {}static inline void device_pm_remove (struct device *dev) {} static inline void device_pm_move_before(struct device *deva,
@@ -32,7 +29,7 @@ static inline void device_pm_move_after( struct device *devb) {}static inline void device_pm_move_last (struct device *dev) {} -#endif +#endif /* !CONFIG_PM_SLEEP */ #ifdef CONFIG_PM
Hi Rafael,
Quoted 12 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
Highlights:
* I did my best to follow the design we've recently discussed.
* pm_runtime_[get|put]() and the sync versions call pm_[request|runtime]_[resume|idle](), because I don't see much point manipulating the usage counter alone.
*pm_runtime_disable()carries out a (synchronous) wake-up if there's a resume request pending.
Quoted 1 line
Comments welcome.
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
My intention was to post a SuperH prototype last week, but I got side tracked with other stuff. And today I ran into some problems related to probe() that I'd like to ask about right away. At this point I've got a few device drivers converted and some simple bus runtime_suspend()/runtime_resume() code that stop and start clocks.
Issue 1:
------------
Device drivers which do not perform any hardware access in probe() work fine. During software setup in probe() the runtime pm code is initialized with the following:
+ pm_suspend_ignore_children(&dev->dev, true);
+ pm_runtime_set_suspended(&dev->dev);
+ pm_runtime_enable(&dev->dev);
Before accessing hardware I perform:
+ pm_runtime_resume(pd->dev);
When done with the hardware I do:
+ pm_runtime_suspend(pd->dev);
Not so complicated. Am I supposed to initialize something else as well?
All good with the code above, but there seem to be some issue with how usage_count is counted up and down and when runtime_disabled is set:
1. pm_runtime_init(): usage_count = 1, runtime_disabled = true
2. driver_probe_device(): pm_runtime_get_sync()
3. pm_runtime_get_sync(): usage_count = 2
4. device driver probe(): pm_runtime_enable()
5. pm_runtime_enable(): usage_count = 1
6. driver_probe_device(): pm_runtime_put()
7. pm_runtime_put(): usage_count = 0
I expect runtime_disabled = false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks from probe(). This also seems related to usage_count and pm_runtime_get_sync() in driver_probe_device(). Basically, from probe(), calling pm_runtime_resume() after pm_runtime_set_suspended() results in error and not in a ->runtime_resume() callback. Some device drives access hardware in probe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
Random thought:
-------------------------
The runtime_pm_get() and runtime_pm_put() look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...
Let me know what you think!
Cheers,
/ magnus
Hi Rafael,
Quoted 12 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
Highlights:
* I did my best to follow the design we've recently discussed.
* pm_runtime_[get|put]() and the sync versions call pm_[request|runtime]_[resume|idle](), because I don't see much point manipulating the usage counter alone.
*pm_runtime_disable()carries out a (synchronous) wake-up if there's a resume request pending.
Quoted 1 line
Comments welcome.
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
My intention was to post a SuperH prototype last week, but I got side tracked with other stuff. And today I ran into some problems related to probe() that I'd like to ask about right away. At this point I've got a few device drivers converted and some simple bus runtime_suspend()/runtime_resume() code that stop and start clocks.
Issue 1:
------------
Device drivers which do not perform any hardware access in probe() work fine. During software setup in probe() the runtime pm code is initialized with the following:
+ pm_suspend_ignore_children(&dev->dev, true);
+ pm_runtime_set_suspended(&dev->dev);
+ pm_runtime_enable(&dev->dev);
Before accessing hardware I perform:
+ pm_runtime_resume(pd->dev);
When done with the hardware I do:
+ pm_runtime_suspend(pd->dev);
Not so complicated. Am I supposed to initialize something else as well?
All good with the code above, but there seem to be some issue with how usage_count is counted up and down and when runtime_disabled is set:
1. pm_runtime_init(): usage_count = 1, runtime_disabled = true
2. driver_probe_device(): pm_runtime_get_sync()
3. pm_runtime_get_sync(): usage_count = 2
4. device driver probe(): pm_runtime_enable()
5. pm_runtime_enable(): usage_count = 1
6. driver_probe_device(): pm_runtime_put()
7. pm_runtime_put(): usage_count = 0
I expect runtime_disabled = false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks from probe(). This also seems related to usage_count and pm_runtime_get_sync() in driver_probe_device(). Basically, from probe(), calling pm_runtime_resume() after pm_runtime_set_suspended() results in error and not in a ->runtime_resume() callback. Some device drives access hardware in probe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
Random thought:
-------------------------
The runtime_pm_get() and runtime_pm_put() look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...
Let me know what you think!
Cheers,
/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Magnus Damm
Hi Rafael,
Quoted 12 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
Highlights:
* I did my best to follow the design we've recently discussed.
* pm_runtime_[get|put]() and the sync versions call pm_[request|runtime]_[resume|idle](), because I don't see much point manipulating the usage counter alone.
*pm_runtime_disable()carries out a (synchronous) wake-up if there's a resume request pending.
Quoted 4 lines
Quoted 1 line
Comments welcome.
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
That's mostly thanks to Alan.
Quoted 35 lines
My intention was to post a SuperH prototype last week, but I got side tracked with other stuff. And today I ran into some problems related to
probe()that I'd like to ask about right away. At this point I've got a few device drivers converted and some simple bus runtime_suspend()/runtime_resume() code that stop and start clocks.Issue 1:
------------
Device drivers which do not perform any hardware access inprobe()work fine. During software setup inprobe()the runtime pm code is initialized with the following:(quoted diff) +3
-0+ pm_suspend_ignore_children(&dev->dev, true); + pm_runtime_set_suspended(&dev->dev); + pm_runtime_enable(&dev->dev);Before accessing hardware I perform:
(quoted diff) +1
-0+ pm_runtime_resume(pd->dev);When done with the hardware I do:
(quoted diff) +1
-0+ pm_runtime_suspend(pd->dev);Not so complicated. Am I supposed to initialize something else as well?
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 3 lines
I expect
runtime_disabled= false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.
Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought usage_counter would be sufficient. Will fix.
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
I think the problem is that pm_runtime_get_sync() in driver_probe_device() calls ->runtime_resume(), so the device is active from the core's point of view when you call pm_runtime_resume() from probe().
Hmm. OK, perhaps we should just increment usage_count in driver_device_probe() to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.
Quoted 8 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
However, I'm now thinking it should work like this:
* pm_runtime_get() increments usage_count and if it was zero before the incrementation, it calls pm_request_resume() (pm_runtime_resume() is called by the 'sync' version).
* pm_runtime_put() decrements usage_count and if it's zero after the decrementation, it calls pm_request_idle() (pm_runtime_idle() is called by the 'sync' version).
* The 'suspend' callbacks won't succeed for usage_count > 0.
This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then usage_count would have to be modified under the spinlock only.
Best,
Rafael
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
That's mostly thanks to Alan.
I haven't had time yet to look through the new code. Things have been very busy.
Quoted 10 lines
Quoted 10 lines
Issue 1:
------------
Device drivers which do not perform any hardware access inprobe()work fine. During software setup inprobe()the runtime pm code is initialized with the following:(quoted diff) +3
-0+ pm_suspend_ignore_children(&dev->dev, true); + pm_runtime_set_suspended(&dev->dev); + pm_runtime_enable(&dev->dev);
Quoted 7 lines
Quoted 7 lines
Before accessing hardware I perform:
(quoted diff) +1
-0+ pm_runtime_resume(pd->dev);When done with the hardware I do:
(quoted diff) +1
-0+ pm_runtime_suspend(pd->dev);Not so complicated. Am I supposed to initialize something else as well?
No, that's all you need.
Quoted 11 lines
Quoted 11 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 1 line
Quoted 1 line
I expect
runtime_disabled= false in 7.
Wasn't it? It should have been set to false in step 4 and remained that way.
Quoted 6 lines
Quoted 3 lines
Modifying the get/put calls to
do enable/disable may work around the issue, but that's probably not what you guys want.Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought
usage_counterwould be sufficient. Will fix.
Presumably there won't be much nesting of disable/enable. The counter will need only a few bits.
Quoted 10 lines
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
Quoted 3 lines
I think the problem is that
pm_runtime_get_sync()indriver_probe_device()calls ->runtime_resume(), so the device is active from the core's point of view when you callpm_runtime_resume()fromprobe().
Yes. Maybe devices should be initialized with runtime PM enabled. Or perhaps it should be enabled when device_add runs (before the probe).
Quoted 4 lines
Hmm. OK, perhaps we should just increment
usage_countindriver_device_probe()to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.
Not necessary if you enable runtime PM first. Or maybe pm_runtime_enable should compare the state and the counters, calling pm_runtime_resume or pm_runtime_idle as needed.
Quoted 19 lines
Quoted 8 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
However, I'm now thinking it should work like this:
*
pm_runtime_get()incrementsusage_countand if it was zero before the incrementation, it callspm_request_resume()(pm_runtime_resume()is called by the 'sync' version).
Quoted 5 lines
*
pm_runtime_put()decrementsusage_countand if it's zero after the decrementation, it callspm_request_idle()(pm_runtime_idle()is called by the 'sync' version).* The 'suspend' callbacks won't succeed for
usage_count> 0.
I agree.
I wonder if there should be a way for drivers to increment usage_count without forcing a resume. For example, if a driver stores up pending I/O for its own work routine to handle then it would want to prevent suspends before the work routine runs, but it would also want the work routine to call pm_runtime_resume directly. Hence it would be pointless to have _get queue an extra resume request.
Quoted 3 lines
This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then
usage_countwould have to be modified under the spinlock only.
Why? That is, why would it have to be any different from the way it is now? All you really need is that the test for zero should be part of the atomic operation.
Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
That's mostly thanks to Alan.
I haven't had time yet to look through the new code. Things have been very busy.
Quoted 10 lines
Quoted 10 lines
Issue 1:
------------
Device drivers which do not perform any hardware access inprobe()work fine. During software setup inprobe()the runtime pm code is initialized with the following:(quoted diff) +3
-0+ pm_suspend_ignore_children(&dev->dev, true); + pm_runtime_set_suspended(&dev->dev); + pm_runtime_enable(&dev->dev);
Quoted 7 lines
Quoted 7 lines
Before accessing hardware I perform:
(quoted diff) +1
-0+ pm_runtime_resume(pd->dev);When done with the hardware I do:
(quoted diff) +1
-0+ pm_runtime_suspend(pd->dev);Not so complicated. Am I supposed to initialize something else as well?
No, that's all you need.
Quoted 11 lines
Quoted 11 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 1 line
Quoted 1 line
I expect
runtime_disabled= false in 7.
Wasn't it? It should have been set to false in step 4 and remained that way.
Quoted 6 lines
Quoted 3 lines
Modifying the get/put calls to
do enable/disable may work around the issue, but that's probably not what you guys want.Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought
usage_counterwould be sufficient. Will fix.
Presumably there won't be much nesting of disable/enable. The counter will need only a few bits.
Quoted 10 lines
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
Quoted 3 lines
I think the problem is that
pm_runtime_get_sync()indriver_probe_device()calls ->runtime_resume(), so the device is active from the core's point of view when you callpm_runtime_resume()fromprobe().
Yes. Maybe devices should be initialized with runtime PM enabled. Or perhaps it should be enabled when device_add runs (before the probe).
Quoted 4 lines
Hmm. OK, perhaps we should just increment
usage_countindriver_device_probe()to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.
Not necessary if you enable runtime PM first. Or maybe pm_runtime_enable should compare the state and the counters, calling pm_runtime_resume or pm_runtime_idle as needed.
Quoted 19 lines
Quoted 8 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
However, I'm now thinking it should work like this:
*
pm_runtime_get()incrementsusage_countand if it was zero before the incrementation, it callspm_request_resume()(pm_runtime_resume()is called by the 'sync' version).
Quoted 5 lines
*
pm_runtime_put()decrementsusage_countand if it's zero after the decrementation, it callspm_request_idle()(pm_runtime_idle()is called by the 'sync' version).* The 'suspend' callbacks won't succeed for
usage_count> 0.
I agree.
I wonder if there should be a way for drivers to increment usage_count without forcing a resume. For example, if a driver stores up pending I/O for its own work routine to handle then it would want to prevent suspends before the work routine runs, but it would also want the work routine to call pm_runtime_resume directly. Hence it would be pointless to have _get queue an extra resume request.
Quoted 3 lines
This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then
usage_countwould have to be modified under the spinlock only.
Why? That is, why would it have to be any different from the way it is now? All you really need is that the test for zero should be part of the atomic operation.
Alan Stern
Quoted 23 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
That's mostly thanks to Alan.
I haven't had time yet to look through the new code. Things have been very busy.
Quoted 13 lines
Quoted 13 lines
Issue 1:
------------
Device drivers which do not perform any hardware access inprobe()work fine. During software setup inprobe()the runtime pm code is initialized with the following:+
pm_suspend_ignore_children(&dev->dev, true);
+pm_runtime_set_suspended(&dev->dev);
+pm_runtime_enable(&dev->dev);Before accessing hardware I perform:
+pm_runtime_resume(pd->dev);
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
When done with the hardware I do:
+pm_runtime_suspend(pd->dev);Not so complicated. Am I supposed to initialize something else as well?
No, that's all you need.
Ok, thank you!
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 4 lines
Quoted 1 line
Quoted 1 line
I expect
runtime_disabled= false in 7.Wasn't it? It should have been set to false in step 4 and remained that way.
I may misunderstand, but in v8 won't the pm_runtime_enable() function do a atomic_dec_test() where the counter value will go from 2 to 1 in the case above? This would mean that atomic_dec_test() returns false so runtime_disabled is never modified.
Thanks for your feedback,
/ magnus
Quoted 23 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
That's mostly thanks to Alan.
I haven't had time yet to look through the new code. Things have been very busy.
Quoted 13 lines
Quoted 13 lines
Issue 1:
------------
Device drivers which do not perform any hardware access inprobe()work fine. During software setup inprobe()the runtime pm code is initialized with the following:+
pm_suspend_ignore_children(&dev->dev, true);
+pm_runtime_set_suspended(&dev->dev);
+pm_runtime_enable(&dev->dev);Before accessing hardware I perform:
+pm_runtime_resume(pd->dev);
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
When done with the hardware I do:
+pm_runtime_suspend(pd->dev);Not so complicated. Am I supposed to initialize something else as well?
No, that's all you need.
Ok, thank you!
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 4 lines
Quoted 1 line
Quoted 1 line
I expect
runtime_disabled= false in 7.Wasn't it? It should have been set to false in step 4 and remained that way.
I may misunderstand, but in v8 won't the pm_runtime_enable() function do a atomic_dec_test() where the counter value will go from 2 to 1 in the case above? This would mean that atomic_dec_test() returns false so runtime_disabled is never modified.
Thanks for your feedback,
/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 13 lines · Magnus Damm
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0I expect
runtime_disabled= false in 7.
Quoted 7 lines
Quoted 2 lines
Wasn't it? It should have been set to false in step 4 and remained that way.
I may misunderstand, but in v8 won't the
pm_runtime_enable()function do aatomic_dec_test()where the counter value will go from 2 to 1 in the case above? This would mean thatatomic_dec_test()returns false soruntime_disabledis never modified.
There still hasn't been any time for me to look through the code. It sounds like Rafael was trying to use one counter for two separate purposes.
Alan Stern
Quoted 13 lines · Magnus Damm
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0I expect
runtime_disabled= false in 7.
Quoted 7 lines
Quoted 2 lines
Wasn't it? It should have been set to false in step 4 and remained that way.
I may misunderstand, but in v8 won't the
pm_runtime_enable()function do aatomic_dec_test()where the counter value will go from 2 to 1 in the case above? This would mean thatatomic_dec_test()returns false soruntime_disabledis never modified.
There still hasn't been any time for me to look through the code. It sounds like Rafael was trying to use one counter for two separate purposes.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC PATCH 1/1 PM: Introduce core framework for run-time PM of I/O devices (rev. 9)
Quoted 18 lines · Alan Stern
Quoted 16 lines · Magnus Damm
Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0Quoted 1 line
Quoted 1 line
I expect
runtime_disabled= false in 7.Wasn't it? It should have been set to false in step 4 and remained that way.
Quoted 8 lines
Quoted 4 lines
I may misunderstand, but in v8 won't the
pm_runtime_enable()function do aatomic_dec_test()where the counter value will go from 2 to 1 in the case above? This would mean thatatomic_dec_test()returns false soruntime_disabledis never modified.There still hasn't been any time for me to look through the code. It sounds like Rafael was trying to use one counter for two separate purposes.
That's correct. It's (hopefully) fixed in the appended update of the patch.
In addition, I reworked the pm_runtime_[put|get|put_sync|get_sync]() to work as described in my previous message (ie. 'resume' is only called if usage_count was 0 when the function was called and 'idle' is only called if the function has decreasd the usage counter down to 0).
There also are pm_runtime_get_noresume() and pm_runtime_put_noidle() that only increment and decrement the usage counter (respectively). They are used in driver_probe_device() to prevent a suspend of the device from being started while ->probe() is running while allowing ->runtime_resume() to be called from ->probe() (as requested by Magnus).
Best,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM: Introduce core framework for run-time PM of I/O devices (rev. 9)
Introduce a core framework for run-time power management of I/O devices. Add device run-time PM fields to 'struct dev_pm_info' and device run-time PM callbacks to 'struct dev_pm_ops'. Introduce a run-time PM workqueue and define some device run-time PM helper functions at the core level.
--- drivers/base/dd.c | 7 drivers/base/power/Makefile | 1 drivers/base/power/main.c | 21 drivers/base/power/power.h | 11 drivers/base/power/runtime.c | 950 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 102 ++++ include/linux/pm_runtime.h | 113 +++++ kernel/power/Kconfig | 14 kernel/power/main.c | 17 9 files changed, 1225 insertions(+), 11 deletions(-)
kernel/power/Kconfig +14 -0
@@ -208,3 +208,17 @@ config APM_EMULATION random kernel OOPSes or reboots that don't seem to be related to anything, try disabling/enabling this option (or disabling/enabling APM in your BIOS). + +config PM_RUNTIME + bool "Run-time PM core functionality" + depends on PM + ---help--- + Enable functionality allowing I/O devices to be put into energy-saving + (low power) states at run time (or autosuspended) after a specified + period of inactivity and woken up in response to a hardware-generated + wake-up event or a driver's request. + + Hardware support is generally required for this functionality to work + and the bus type drivers of the buses the devices are on are + responsible for the actual handling of the autosuspend requests and + wake-up events.
kernel/power/main.c +17 -0
@@ -11,6 +11,7 @@#include <linux/kobject.h> #include <linux/string.h> #include <linux/resume-trace.h> +#include <linux/workqueue.h> #include "power.h"
@@ -217,8 +218,24 @@ static struct attribute_group attr_group .attrs = g, }; +#ifdef CONFIG_PM_RUNTIME +struct workqueue_struct *pm_wq; + +static int __init pm_start_workqueue (void ) +{ + pm_wq =create_freezeable_workqueue ("pm" ); + +return pm_wq ?0 : -ENOMEM ; +} +#else +static inline int pm_start_workqueue (void ) {return 0 ; } +#endif +static int __init pm_init (void ) { +int error =pm_start_workqueue (); +if (error) +return error; power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;
include/linux/pm.h +99 -3
131 lines not on this page · raw message
drivers/base/power/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_PM) += sysfs.o obj-$(CONFIG_PM_SLEEP) += main.o +obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/power/runtime.c new file +950 -0
950 lines not on this page · raw message
include/linux/pm_runtime.h new file +113 -0
113 lines not on this page · raw message
drivers/base/power/main.c +20 -1
@@ -21,6 +21,7 @@#include <linux/kallsyms.h> #include <linux/mutex.h> #include <linux/pm.h> +#include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/rwsem.h> #include <linux/interrupt.h>
@@ -49,6 +50,16 @@ static DEFINE_MUTEX(dpm_list_mtx);static bool transition_started;/** +* device_pm_init - Initialize the PM-related part of a device object +* @dev: Device object to initialize. +*/ +void device_pm_init (struct device *dev) +{ + dev->power.status =DPM_ON ; +pm_runtime_init (dev); +} + +/** * device_pm_lock - lock the list of active devices used by the PM core */ void device_pm_lock (void )
@@ -89,6 +100,8 @@ void device_pm_add(struct device *dev)list_add_tail (&dev->power.entry, &dpm_list);mutex_unlock (&dpm_list_mtx); + +pm_runtime_add (dev); }/**
@@ -105,6 +118,8 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); + +pm_runtime_remove (dev); }/**
@@ -510,6 +525,7 @@ static void dpm_complete(pm_message_t stmutex_unlock (&dpm_list_mtx);device_complete (dev, state); +pm_runtime_enable (dev);mutex_lock (&dpm_list_mtx); }
@@ -755,11 +771,14 @@ static int dpm_prepare(pm_message_t stat dev->power.status =DPM_PREPARING ;mutex_unlock (&dpm_list_mtx); - error =device_prepare (dev, state); + error =pm_runtime_disable (dev); +if (!error || !device_may_wakeup (dev)) + error =device_prepare (dev, state);mutex_lock (&dpm_list_mtx);if (error) { dev->power.status =DPM_ON ; +pm_runtime_enable (dev);if (error == -EAGAIN ) {put_device (dev); error =0 ;
drivers/base/dd.c +7 -0
@@ -23,6 +23,7 @@#include <linux/kthread.h> #include <linux/wait.h> #include <linux/async.h> +#include <linux/pm_runtime.h> #include "base.h" #include "power/power.h"
@@ -202,7 +203,9 @@ int driver_probe_device(struct device_drpr_debug ("bus: '%s': %s: matched device %s with driver %s\n" , drv->bus->name, __func__,dev_name (dev), drv->name); +pm_runtime_get_noresume (dev); ret =really_probe (dev, drv); +pm_runtime_put_noidle (dev);return ret; }
@@ -306,6 +309,8 @@ static void __device_release_driver(stru drv = dev->driver;if (drv) { +pm_runtime_disable (dev); +driver_sysfs_remove (dev);if (dev->bus)
@@ -324,6 +329,8 @@ static void __device_release_driver(strublocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_UNBOUND_DRIVER , dev); + +pm_runtime_enable (dev); } }
drivers/base/power/power.h +4 -7
@@ -1,8 +1,3 @@ -static inline void device_pm_init (struct device *dev) -{ - dev->power.status =DPM_ON ; -} -#ifdef CONFIG_PM_SLEEP /*
@@ -16,14 +11,16 @@ static inline struct device *to_device(s return container_of(entry, struct device, power.entry); } +extern void device_pm_init (struct device *dev);extern void device_pm_add (struct device *);extern void device_pm_remove (struct device *);extern void device_pm_move_before (struct device *,struct device *);extern void device_pm_move_after (struct device *,struct device *);extern void device_pm_move_last (struct device *); -#else /* CONFIG_PM_SLEEP */ +#else /* !CONFIG_PM_SLEEP */ +static inline void device_pm_init (struct device *dev) {}static inline void device_pm_add (struct device *dev) {}static inline void device_pm_remove (struct device *dev) {} static inline void device_pm_move_before(struct device *deva,
@@ -32,7 +29,7 @@ static inline void device_pm_move_after( struct device *devb) {}static inline void device_pm_move_last (struct device *dev) {} -#endif +#endif /* !CONFIG_PM_SLEEP */ #ifdef CONFIG_PM
RFC PATCH 1/1 PM: Introduce core framework for run-time PM of I/O devices (rev. 9)
In reply to Alan SternQuoted 18 lines · Alan Stern
Quoted 16 lines · Magnus Damm
Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0Quoted 1 line
Quoted 1 line
I expect
runtime_disabled= false in 7.Wasn't it? It should have been set to false in step 4 and remained that way.
Quoted 8 lines
Quoted 4 lines
I may misunderstand, but in v8 won't the
pm_runtime_enable()function do aatomic_dec_test()where the counter value will go from 2 to 1 in the case above? This would mean thatatomic_dec_test()returns false soruntime_disabledis never modified.There still hasn't been any time for me to look through the code. It sounds like Rafael was trying to use one counter for two separate purposes.
That's correct. It's (hopefully) fixed in the appended update of the patch.
In addition, I reworked the pm_runtime_[put|get|put_sync|get_sync]() to work as described in my previous message (ie. 'resume' is only called if usage_count was 0 when the function was called and 'idle' is only called if the function has decreasd the usage counter down to 0).
There also are pm_runtime_get_noresume() and pm_runtime_put_noidle() that only increment and decrement the usage counter (respectively). They are used in driver_probe_device() to prevent a suspend of the device from being started while ->probe() is running while allowing ->runtime_resume() to be called from ->probe() (as requested by Magnus).
Best,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: PM: Introduce core framework for run-time PM of I/O devices (rev. 9)
Introduce a core framework for run-time power management of I/O devices. Add device run-time PM fields to 'struct dev_pm_info' and device run-time PM callbacks to 'struct dev_pm_ops'. Introduce a run-time PM workqueue and define some device run-time PM helper functions at the core level.
--- drivers/base/dd.c | 7 drivers/base/power/Makefile | 1 drivers/base/power/main.c | 21 drivers/base/power/power.h | 11 drivers/base/power/runtime.c | 950 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 102 ++++ include/linux/pm_runtime.h | 113 +++++ kernel/power/Kconfig | 14 kernel/power/main.c | 17 9 files changed, 1225 insertions(+), 11 deletions(-)
kernel/power/Kconfig +14 -0
@@ -208,3 +208,17 @@ config APM_EMULATION random kernel OOPSes or reboots that don't seem to be related to anything, try disabling/enabling this option (or disabling/enabling APM in your BIOS). + +config PM_RUNTIME + bool "Run-time PM core functionality" + depends on PM + ---help--- + Enable functionality allowing I/O devices to be put into energy-saving + (low power) states at run time (or autosuspended) after a specified + period of inactivity and woken up in response to a hardware-generated + wake-up event or a driver's request. + + Hardware support is generally required for this functionality to work + and the bus type drivers of the buses the devices are on are + responsible for the actual handling of the autosuspend requests and + wake-up events.
kernel/power/main.c +17 -0
@@ -11,6 +11,7 @@#include <linux/kobject.h> #include <linux/string.h> #include <linux/resume-trace.h> +#include <linux/workqueue.h> #include "power.h"
@@ -217,8 +218,24 @@ static struct attribute_group attr_group .attrs = g, }; +#ifdef CONFIG_PM_RUNTIME +struct workqueue_struct *pm_wq; + +static int __init pm_start_workqueue (void ) +{ + pm_wq =create_freezeable_workqueue ("pm" ); + +return pm_wq ?0 : -ENOMEM ; +} +#else +static inline int pm_start_workqueue (void ) {return 0 ; } +#endif +static int __init pm_init (void ) { +int error =pm_start_workqueue (); +if (error) +return error; power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;
include/linux/pm.h +99 -3
131 lines not on this page · raw message
drivers/base/power/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_PM) += sysfs.o obj-$(CONFIG_PM_SLEEP) += main.o +obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/power/runtime.c new file +950 -0
950 lines not on this page · raw message
include/linux/pm_runtime.h new file +113 -0
113 lines not on this page · raw message
drivers/base/power/main.c +20 -1
@@ -21,6 +21,7 @@#include <linux/kallsyms.h> #include <linux/mutex.h> #include <linux/pm.h> +#include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/rwsem.h> #include <linux/interrupt.h>
@@ -49,6 +50,16 @@ static DEFINE_MUTEX(dpm_list_mtx);static bool transition_started;/** +* device_pm_init - Initialize the PM-related part of a device object +* @dev: Device object to initialize. +*/ +void device_pm_init (struct device *dev) +{ + dev->power.status =DPM_ON ; +pm_runtime_init (dev); +} + +/** * device_pm_lock - lock the list of active devices used by the PM core */ void device_pm_lock (void )
@@ -89,6 +100,8 @@ void device_pm_add(struct device *dev)list_add_tail (&dev->power.entry, &dpm_list);mutex_unlock (&dpm_list_mtx); + +pm_runtime_add (dev); }/**
@@ -105,6 +118,8 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); + +pm_runtime_remove (dev); }/**
@@ -510,6 +525,7 @@ static void dpm_complete(pm_message_t stmutex_unlock (&dpm_list_mtx);device_complete (dev, state); +pm_runtime_enable (dev);mutex_lock (&dpm_list_mtx); }
@@ -755,11 +771,14 @@ static int dpm_prepare(pm_message_t stat dev->power.status =DPM_PREPARING ;mutex_unlock (&dpm_list_mtx); - error =device_prepare (dev, state); + error =pm_runtime_disable (dev); +if (!error || !device_may_wakeup (dev)) + error =device_prepare (dev, state);mutex_lock (&dpm_list_mtx);if (error) { dev->power.status =DPM_ON ; +pm_runtime_enable (dev);if (error == -EAGAIN ) {put_device (dev); error =0 ;
drivers/base/dd.c +7 -0
@@ -23,6 +23,7 @@#include <linux/kthread.h> #include <linux/wait.h> #include <linux/async.h> +#include <linux/pm_runtime.h> #include "base.h" #include "power/power.h"
@@ -202,7 +203,9 @@ int driver_probe_device(struct device_drpr_debug ("bus: '%s': %s: matched device %s with driver %s\n" , drv->bus->name, __func__,dev_name (dev), drv->name); +pm_runtime_get_noresume (dev); ret =really_probe (dev, drv); +pm_runtime_put_noidle (dev);return ret; }
@@ -306,6 +309,8 @@ static void __device_release_driver(stru drv = dev->driver;if (drv) { +pm_runtime_disable (dev); +driver_sysfs_remove (dev);if (dev->bus)
@@ -324,6 +329,8 @@ static void __device_release_driver(strublocking_notifier_call_chain (&dev->bus->p->bus_notifier,BUS_NOTIFY_UNBOUND_DRIVER , dev); + +pm_runtime_enable (dev); } }
drivers/base/power/power.h +4 -7
@@ -1,8 +1,3 @@ -static inline void device_pm_init (struct device *dev) -{ - dev->power.status =DPM_ON ; -} -#ifdef CONFIG_PM_SLEEP /*
@@ -16,14 +11,16 @@ static inline struct device *to_device(s return container_of(entry, struct device, power.entry); } +extern void device_pm_init (struct device *dev);extern void device_pm_add (struct device *);extern void device_pm_remove (struct device *);extern void device_pm_move_before (struct device *,struct device *);extern void device_pm_move_after (struct device *,struct device *);extern void device_pm_move_last (struct device *); -#else /* CONFIG_PM_SLEEP */ +#else /* !CONFIG_PM_SLEEP */ +static inline void device_pm_init (struct device *dev) {}static inline void device_pm_add (struct device *dev) {}static inline void device_pm_remove (struct device *dev) {} static inline void device_pm_move_before(struct device *deva,
@@ -32,7 +29,7 @@ static inline void device_pm_move_after( struct device *devb) {}static inline void device_pm_move_last (struct device *dev) {} -#endif +#endif /* !CONFIG_PM_SLEEP */ #ifdef CONFIG_PM
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Magnus Damm
Quoted 3 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 6 lines
Quoted 3 lines
I expect
runtime_disabled= false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought
usage_counterwould be sufficient. Will fix.
Thank you. No problem.
Quoted 10 lines
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
Quoted 8 lines
I think the problem is that
pm_runtime_get_sync()indriver_probe_device()calls ->runtime_resume(), so the device is active from the core's point of view when you callpm_runtime_resume()fromprobe().Hmm. OK, perhaps we should just increment
usage_countindriver_device_probe()to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.
Sounds good.
Quoted 7 lines
Quoted 7 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...
Quoted 5 lines
Quoted 1 line
Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
I think that's a nicer interface, but I must figure out how to use ->runtime_idle before I can switch to that...
Quoted 10 lines
However, I'm now thinking it should work like this:
*
pm_runtime_get()incrementsusage_countand if it was zero before the incrementation, it callspm_request_resume()(pm_runtime_resume()is called by the 'sync' version).*
pm_runtime_put()decrementsusage_countand if it's zero after the decrementation, it callspm_request_idle()(pm_runtime_idle()is called by the 'sync' version).
Quoted 5 lines
* The 'suspend' callbacks won't succeed for
usage_count> 0.This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then
usage_countwould have to be modified under the spinlock only.
If all usage_count users are moved under the spinlock then there would be no need for atomic operations, right?
This get()/put() interface is interesting.
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain. So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of pm_runtime_resume() and pm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.
Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Drivers call pm_runtime_get_sync() and pm_runtime_put() before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending on put() or put_sync(), but no timer). The bus->runtime_idle() callback stops the clock and decreases the power domain usage count. If the power domain is unused, then the pm_schedule_suspend() is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.
I can't get the above to work with v8 though. This is because after the clock is stopped with ->runtime_idle() the runtime_status of the device is still RPM_ACTIVE, so when pm_runtime_get_sync() gets called the ->runtime_resume() never gets invoked and the clock is never started...
So I don't know if you think the ->runtime_idle usage above is a good plan. I guess no, it's probably quite different from the USB case. I can of course always skip using ->runtime_idle() and just use suspend()/resume().
Any thoughts?
Thanks,
/ magnus
Quoted 123 lines · Magnus Damm
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Magnus Damm
Quoted 3 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0Quoted 6 lines
Quoted 3 lines
I expect
runtime_disabled= false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought
usage_counterwould be sufficient. Will fix.Thank you. No problem.
Quoted 10 lines
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.Quoted 8 lines
I think the problem is that
pm_runtime_get_sync()indriver_probe_device()calls ->runtime_resume(), so the device is active from the core's point of view when you callpm_runtime_resume()fromprobe().Hmm. OK, perhaps we should just increment
usage_countindriver_device_probe()to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.Sounds good.
Quoted 7 lines
Quoted 7 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...Quoted 5 lines
Quoted 1 line
Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
I think that's a nicer interface, but I must figure out how to use ->runtime_idle before I can switch to that...
Quoted 10 lines
However, I'm now thinking it should work like this:
*
pm_runtime_get()incrementsusage_countand if it was zero before the incrementation, it callspm_request_resume()(pm_runtime_resume()is called by the 'sync' version).*
pm_runtime_put()decrementsusage_countand if it's zero after the decrementation, it callspm_request_idle()(pm_runtime_idle()is called by the 'sync' version).Quoted 5 lines
* The 'suspend' callbacks won't succeed for
usage_count> 0.This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then
usage_countwould have to be modified under the spinlock only.If all
usage_countusers are moved under the spinlock then there would be no need for atomic operations, right?This get()/put() interface is interesting.
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain. So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.I can't get the above to work with v8 though. This is because after the clock is stopped with ->runtime_idle() the
runtime_statusof the device is stillRPM_ACTIVE, so whenpm_runtime_get_sync()gets called the ->runtime_resume() never gets invoked and the clock is never started...
Quoted 6 lines
So I don't know if you think the ->runtime_idle usage above is a good plan. I guess no, it's probably quite different from the USB case. I can of course always skip using ->runtime_idle() and just use suspend()/resume().
Any thoughts?
I think you'd need a separate bus type callback for that, call it ->runtime_deepen() for now, which could be executed for a _suspended_ (from the core's point of view) device and the role of which would be to put the (already suspended) device into a deeper low power state.
Something like this might also be used for PCI and it's worth discussing IMO.
So, if we had such a callback, your scenario would be the following.
Drivers call pm_runtime_get_sync() and pm_runtime_put() before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback that in turn calls pm_runtime_suspend() or pm_schedule_suspend() and the ->runtime_suspend() executed as a result stops the clock and decreases the power domain usage count. If the domain usage count happens to be zero, pm_runtime_deepen() or pm_schedule_deepen() is called for each device in the power domain. Consequently, the bus type's ->runtime_deepen() is invoked and that can call the device's ->runtime_suspend(), for example. If there's pm_runtime_get_sync() any time when this is happening, it will cancel the pending requests and run ->runtime_resume().
Does it make sense?
Rafael
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain.
I take it the devices in a single power domain don't all share a common parent.
Quoted 3 lines
Quoted 3 lines
So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
Why? That is, why not tell the driver as soon as the device's own clock is stopped? What point is there in waiting for all the other clocks to be stopped as well?
Quoted 10 lines
Quoted 10 lines
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Quoted 10 lines
Quoted 10 lines
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.
Instead, you should call pm_runtime_suspend from within the runtime_idle method. When the runtime_suspend method runs, have it decrement the power domain's usage count. Is the power domain represented by a single struct device? If it is then that device's power.usage_count field would naturally be the thing to use; otherwise you'd have to set up your own counter.
Then depending on how things are organized, when the power-domain device's usage_count goes to 0 you'll get a runtime_idle callback. Call pm_runtime_resume for the power-domain device, and have that routine shut off the power. Or if you set up your own private counter for the power domain, shut off the power when the counter goes to 0.
Quoted 6 lines
I think you'd need a separate bus type callback for that, call it ->runtime_deepen() for now, which could be executed for a _suspended_ (from the core's point of view) device and the role of which would be to put the (already suspended) device into a deeper low power state.
Something like this might also be used for PCI and it's worth discussing IMO.
I thought you wanted to avoid this sort of complication.
Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain.
I take it the devices in a single power domain don't all share a common parent.
Quoted 3 lines
Quoted 3 lines
So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
Why? That is, why not tell the driver as soon as the device's own clock is stopped? What point is there in waiting for all the other clocks to be stopped as well?
Quoted 10 lines
Quoted 10 lines
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Quoted 10 lines
Quoted 10 lines
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.
Instead, you should call pm_runtime_suspend from within the runtime_idle method. When the runtime_suspend method runs, have it decrement the power domain's usage count. Is the power domain represented by a single struct device? If it is then that device's power.usage_count field would naturally be the thing to use; otherwise you'd have to set up your own counter.
Then depending on how things are organized, when the power-domain device's usage_count goes to 0 you'll get a runtime_idle callback. Call pm_runtime_resume for the power-domain device, and have that routine shut off the power. Or if you set up your own private counter for the power domain, shut off the power when the counter goes to 0.
Quoted 6 lines
I think you'd need a separate bus type callback for that, call it ->runtime_deepen() for now, which could be executed for a _suspended_ (from the core's point of view) device and the role of which would be to put the (already suspended) device into a deeper low power state.
Something like this might also be used for PCI and it's worth discussing IMO.
I thought you wanted to avoid this sort of complication.
Alan Stern
Quoted 49 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain.
I take it the devices in a single power domain don't all share a common parent.
Quoted 3 lines
Quoted 3 lines
So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
Why? That is, why not tell the driver as soon as the device's own clock is stopped? What point is there in waiting for all the other clocks to be stopped as well?
Quoted 10 lines
Quoted 10 lines
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Quoted 10 lines
Quoted 10 lines
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.Instead, you should call
pm_runtime_suspendfrom within theruntime_idlemethod. When theruntime_suspendmethod runs, have it decrement the power domain's usage count. Is the power domain represented by a single struct device? If it is then that device's power.usage_count field would naturally be the thing to use; otherwise you'd have to set up your own counter.
Quoted 5 lines
Then depending on how things are organized, when the power-domain device's
usage_countgoes to 0 you'll get aruntime_idlecallback. Callpm_runtime_resumefor the power-domain device, and have that routine shut off the power. Or if you set up your own private counter for the power domain, shut off the power when the counter goes to 0.
Yes, I think the approach with a private counter should work in the Magnus' case.
Quoted 8 lines
Quoted 6 lines
I think you'd need a separate bus type callback for that, call it ->runtime_deepen() for now, which could be executed for a _suspended_ (from the core's point of view) device and the role of which would be to put the (already suspended) device into a deeper low power state.
Something like this might also be used for PCI and it's worth discussing IMO.
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
pm_runtime_suspend() can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).
Best,
Rafael
Quoted 11 lines · Rafael J. Wysocki
Quoted 1 line
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
Quoted 4 lines
pm_runtime_suspend()can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).
Maybe we can provide a way for drivers to set up their own timer callback or work routine for use while the status is RPM_SUSPENDED.
Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 1 line
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
Quoted 4 lines
pm_runtime_suspend()can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).
Maybe we can provide a way for drivers to set up their own timer callback or work routine for use while the status is RPM_SUSPENDED.
Alan Stern
Quoted 13 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 1 line
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
Quoted 7 lines
Quoted 4 lines
pm_runtime_suspend()can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).Maybe we can provide a way for drivers to set up their own timer callback or work routine for use while the status is
RPM_SUSPENDED.
Agreed.
Anyway, I don't think it's really necessary in the Magnus' usage case, as you pointed out earlier in this thread, so I think we can consider it as something to add in future.
The current patch is already more that 1200 lines and there's some documentation to add, so I wouldn't like to make it any bigger. :-)
Best,
Rafael
Quoted 13 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 1 line
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
Quoted 7 lines
Quoted 4 lines
pm_runtime_suspend()can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).Maybe we can provide a way for drivers to set up their own timer callback or work routine for use while the status is
RPM_SUSPENDED.
Agreed.
Anyway, I don't think it's really necessary in the Magnus' usage case, as you pointed out earlier in this thread, so I think we can consider it as something to add in future.
The current patch is already more that 1200 lines and there's some documentation to add, so I wouldn't like to make it any bigger. :-)
Best,
Rafael
Quoted 13 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 1 line
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
Quoted 7 lines
Quoted 4 lines
pm_runtime_suspend()can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).Maybe we can provide a way for drivers to set up their own timer callback or work routine for use while the status is
RPM_SUSPENDED.
Agreed.
Anyway, I don't think it's really necessary in the Magnus' usage case, as you pointed out earlier in this thread, so I think we can consider it as something to add in future.
The current patch is already more that 1200 lines and there's some documentation to add, so I wouldn't like to make it any bigger. :-)
Best,
Rafael
Quoted 13 lines · Alan Stern
Quoted 11 lines · Rafael J. Wysocki
Quoted 1 line
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
Quoted 7 lines
Quoted 4 lines
pm_runtime_suspend()can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).Maybe we can provide a way for drivers to set up their own timer callback or work routine for use while the status is
RPM_SUSPENDED.
Agreed.
Anyway, I don't think it's really necessary in the Magnus' usage case, as you pointed out earlier in this thread, so I think we can consider it as something to add in future.
The current patch is already more that 1200 lines and there's some documentation to add, so I wouldn't like to make it any bigger. :-)
Best,
Rafael
Quoted 49 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 7 lines
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain.
I take it the devices in a single power domain don't all share a common parent.
Quoted 3 lines
Quoted 3 lines
So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
Why? That is, why not tell the driver as soon as the device's own clock is stopped? What point is there in waiting for all the other clocks to be stopped as well?
Quoted 10 lines
Quoted 10 lines
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Quoted 10 lines
Quoted 10 lines
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.Instead, you should call
pm_runtime_suspendfrom within theruntime_idlemethod. When theruntime_suspendmethod runs, have it decrement the power domain's usage count. Is the power domain represented by a single struct device? If it is then that device's power.usage_count field would naturally be the thing to use; otherwise you'd have to set up your own counter.
Quoted 5 lines
Then depending on how things are organized, when the power-domain device's
usage_countgoes to 0 you'll get aruntime_idlecallback. Callpm_runtime_resumefor the power-domain device, and have that routine shut off the power. Or if you set up your own private counter for the power domain, shut off the power when the counter goes to 0.
Yes, I think the approach with a private counter should work in the Magnus' case.
Quoted 8 lines
Quoted 6 lines
I think you'd need a separate bus type callback for that, call it ->runtime_deepen() for now, which could be executed for a _suspended_ (from the core's point of view) device and the role of which would be to put the (already suspended) device into a deeper low power state.
Something like this might also be used for PCI and it's worth discussing IMO.
I thought you wanted to avoid this sort of complication.
I did, but there might be some benefits. For example, the timer and the work structure provided by dev.power can be used for scheduling such operations if they are defined at the core level.
Suppose your device has 3 low power states D1 - D3 (like PCI) and you want it to go into D1 first, then, after a delay, to D2 and finally, again after a delay, to D3. Of course, if there's a resume in the meantime, it should cancel whichever transition is in progress.
pm_runtime_suspend() can be used for the first transition, but the bus type or driver will have to provide its own mechanics for going down to D2 and D3, which must be synchronized with its ->runtime_resume(). That might be tricky and the core already has what's necessary (well, almost).
Best,
Rafael
Hi Alan,
Quoted 8 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 6 lines
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
On top of the clock stopping I'd like to turn off power to the domain.
I take it the devices in a single power domain don't all share a common parent.
It all depends on how we implement the software bus topology in the future. Right now from the software perspective the platform bus topology on SuperH is flat and more or less unused. It sounds sane to map in the power domains into the bus topology. I'm not sure if it is the best choice though, each device also has clock dependencies and it's of course communicating through some internal hardware bus with it's own hardware topology.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
Why? That is, why not tell the driver as soon as the device's own clock is stopped? What point is there in waiting for all the other clocks to be stopped as well?
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks. Delaying the clock stopping does not make any sense to me.
For my use case the driver callbacks manage context save and restore. This to allow turning off power domains.
The reason why I don't want to execute the driver ->runtime_suspend() callbacks directly is performance. Basically, we only want to execute the driver callbacks when we know that we will be able to power off the domain. The driver callbacks need to save and restore registers, and each uncached memory access is expensive. Executing the driver callback does not give us any power savings at all, it's just consumes power.
I want to avoid the situation where the driver ->runtime_suspend() and ->runtime_resume() callbacks get invoked over and over for all devices except one in a certain power domain even though we will never be able to power off because a single device in the power domain is active.
The situation above can be described with a practical example with an open a serial port. The receive side of the serial port hardware needs the clock to be enabled, so we can't turn off the clock. This leads to that we can't runtime suspend the device driver. In my opinion it's pure overhead to call ->runtime_suspend() and ->runtime_resume() for all other devices in the same power domain as the serial port, this because we already know that the open serial port is blocking the entire power domain.
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Quoted 10 lines
Quoted 10 lines
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.
Quoted 6 lines
Instead, you should call
pm_runtime_suspendfrom within theruntime_idlemethod. When theruntime_suspendmethod runs, have it decrement the power domain's usage count. Is the power domain represented by a single struct device? If it is then that device's power.usage_count field would naturally be the thing to use; otherwise you'd have to set up your own counter.
Ok, calling pm_runtime_suspend() from the bus ->runtime_idle callback sounds like a good plan. The power domain is only represented by a simple structure at this point. I agree it would be nice to make use of the usage_count for this purpose.
Quoted 5 lines
Then depending on how things are organized, when the power-domain device's
usage_countgoes to 0 you'll get aruntime_idlecallback. Callpm_runtime_resumefor the power-domain device, and have that routine shut off the power. Or if you set up your own private counter for the power domain, shut off the power when the counter goes to 0.
Right, I'm with you how it works. I have to think a bit more about how to tie in both clock stopping and power domain control with runtime_idle though.
Thanks for your suggestions,
/ magnus
Hi Alan,
Quoted 8 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 6 lines
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
On top of the clock stopping I'd like to turn off power to the domain.
I take it the devices in a single power domain don't all share a common parent.
It all depends on how we implement the software bus topology in the future. Right now from the software perspective the platform bus topology on SuperH is flat and more or less unused. It sounds sane to map in the power domains into the bus topology. I'm not sure if it is the best choice though, each device also has clock dependencies and it's of course communicating through some internal hardware bus with it's own hardware topology.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
Why? That is, why not tell the driver as soon as the device's own clock is stopped? What point is there in waiting for all the other clocks to be stopped as well?
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks. Delaying the clock stopping does not make any sense to me.
For my use case the driver callbacks manage context save and restore. This to allow turning off power domains.
The reason why I don't want to execute the driver ->runtime_suspend() callbacks directly is performance. Basically, we only want to execute the driver callbacks when we know that we will be able to power off the domain. The driver callbacks need to save and restore registers, and each uncached memory access is expensive. Executing the driver callback does not give us any power savings at all, it's just consumes power.
I want to avoid the situation where the driver ->runtime_suspend() and ->runtime_resume() callbacks get invoked over and over for all devices except one in a certain power domain even though we will never be able to power off because a single device in the power domain is active.
The situation above can be described with a practical example with an open a serial port. The receive side of the serial port hardware needs the clock to be enabled, so we can't turn off the clock. This leads to that we can't runtime suspend the device driver. In my opinion it's pure overhead to call ->runtime_suspend() and ->runtime_resume() for all other devices in the same power domain as the serial port, this because we already know that the open serial port is blocking the entire power domain.
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Quoted 10 lines
Quoted 10 lines
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.
Quoted 6 lines
Instead, you should call
pm_runtime_suspendfrom within theruntime_idlemethod. When theruntime_suspendmethod runs, have it decrement the power domain's usage count. Is the power domain represented by a single struct device? If it is then that device's power.usage_count field would naturally be the thing to use; otherwise you'd have to set up your own counter.
Ok, calling pm_runtime_suspend() from the bus ->runtime_idle callback sounds like a good plan. The power domain is only represented by a simple structure at this point. I agree it would be nice to make use of the usage_count for this purpose.
Quoted 5 lines
Then depending on how things are organized, when the power-domain device's
usage_countgoes to 0 you'll get aruntime_idlecallback. Callpm_runtime_resumefor the power-domain device, and have that routine shut off the power. Or if you set up your own private counter for the power domain, shut off the power when the counter goes to 0.
Right, I'm with you how it works. I have to think a bit more about how to tie in both clock stopping and power domain control with runtime_idle though.
Thanks for your suggestions,
/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Magnus Damm
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks. Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 11 lines
For my use case the driver callbacks manage context save and restore. This to allow turning off power domains.
The reason why I don't want to execute the driver ->runtime_suspend() callbacks directly is performance. Basically, we only want to execute the driver callbacks when we know that we will be able to power off the domain. The driver callbacks need to save and restore registers, and each uncached memory access is expensive. Executing the driver callback does not give us any power savings at all, it's just consumes power.
Quoted 4 lines
I want to avoid the situation where the driver ->runtime_suspend() and ->runtime_resume() callbacks get invoked over and over for all devices except one in a certain power domain even though we will never be able to power off because a single device in the power domain is active.
Okay, I get the picture. So what you want is something like this: Each time a driver starts a clock, it does a pm_runtime_get on the power-domain device. Each time it stops the clock, it does a pm_runtime_put on the power-domain device.
When the power-domain device's runtime_idle callback runs, it should call pm_schedule_suspend. The runtime_suspend callback should call pm_runtime_suspend for each of the devices in the power domain before turning off the power supply. Conversely, the runtime_resume callback for the power-domain device should turn on the power supply and then call pm_runtime_resume for each of the devices in the domain.
This will have to get more complicated if the individual device drivers want to maintain their own usage counters -- especially if they want to turn off the clock while leaving the counter positive.
Alan Stern
Quoted 4 lines · Magnus Damm
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks. Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 11 lines
For my use case the driver callbacks manage context save and restore. This to allow turning off power domains.
The reason why I don't want to execute the driver ->runtime_suspend() callbacks directly is performance. Basically, we only want to execute the driver callbacks when we know that we will be able to power off the domain. The driver callbacks need to save and restore registers, and each uncached memory access is expensive. Executing the driver callback does not give us any power savings at all, it's just consumes power.
Quoted 4 lines
I want to avoid the situation where the driver ->runtime_suspend() and ->runtime_resume() callbacks get invoked over and over for all devices except one in a certain power domain even though we will never be able to power off because a single device in the power domain is active.
Okay, I get the picture. So what you want is something like this: Each time a driver starts a clock, it does a pm_runtime_get on the power-domain device. Each time it stops the clock, it does a pm_runtime_put on the power-domain device.
When the power-domain device's runtime_idle callback runs, it should call pm_schedule_suspend. The runtime_suspend callback should call pm_runtime_suspend for each of the devices in the power domain before turning off the power supply. Conversely, the runtime_resume callback for the power-domain device should turn on the power supply and then call pm_runtime_resume for each of the devices in the domain.
This will have to get more complicated if the individual device drivers want to maintain their own usage counters -- especially if they want to turn off the clock while leaving the counter positive.
Alan Stern
Quoted 11 lines · Alan Stern
Quoted 4 lines · Magnus Damm
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks. Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Quoted 16 lines
Quoted 11 lines
For my use case the driver callbacks manage context save and restore. This to allow turning off power domains.
The reason why I don't want to execute the driver ->runtime_suspend() callbacks directly is performance. Basically, we only want to execute the driver callbacks when we know that we will be able to power off the domain. The driver callbacks need to save and restore registers, and each uncached memory access is expensive. Executing the driver callback does not give us any power savings at all, it's just consumes power.
Quoted 4 lines
I want to avoid the situation where the driver ->runtime_suspend() and ->runtime_resume() callbacks get invoked over and over for all devices except one in a certain power domain even though we will never be able to power off because a single device in the power domain is active.
Quoted 4 lines
Okay, I get the picture. So what you want is something like this: Each time a driver starts a clock, it does a
pm_runtime_geton the power-domain device. Each time it stops the clock, it does apm_runtime_puton the power-domain device.
Yes, this is exactly what I'd like to do in the driver.
Quoted 10 lines
When the power-domain device's
runtime_idlecallback runs, it should callpm_schedule_suspend. Theruntime_suspendcallback should callpm_runtime_suspendfor each of the devices in the power domain before turning off the power supply. Conversely, theruntime_resumecallback for the power-domain device should turn on the power supply and then callpm_runtime_resumefor each of the devices in the domain.This will have to get more complicated if the individual device drivers want to maintain their own usage counters -- especially if they want to turn off the clock while leaving the counter positive.
I'd like to mange both clocks and power domains using Runtime PM. The prototype I just posted does that, but the code is not very well integrated with the shared Runtime PM code.
/ magnus
Quoted 11 lines · Alan Stern
Quoted 4 lines · Magnus Damm
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks. Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Quoted 16 lines
Quoted 11 lines
For my use case the driver callbacks manage context save and restore. This to allow turning off power domains.
The reason why I don't want to execute the driver ->runtime_suspend() callbacks directly is performance. Basically, we only want to execute the driver callbacks when we know that we will be able to power off the domain. The driver callbacks need to save and restore registers, and each uncached memory access is expensive. Executing the driver callback does not give us any power savings at all, it's just consumes power.
Quoted 4 lines
I want to avoid the situation where the driver ->runtime_suspend() and ->runtime_resume() callbacks get invoked over and over for all devices except one in a certain power domain even though we will never be able to power off because a single device in the power domain is active.
Quoted 4 lines
Okay, I get the picture. So what you want is something like this: Each time a driver starts a clock, it does a
pm_runtime_geton the power-domain device. Each time it stops the clock, it does apm_runtime_puton the power-domain device.
Yes, this is exactly what I'd like to do in the driver.
Quoted 10 lines
When the power-domain device's
runtime_idlecallback runs, it should callpm_schedule_suspend. Theruntime_suspendcallback should callpm_runtime_suspendfor each of the devices in the power domain before turning off the power supply. Conversely, theruntime_resumecallback for the power-domain device should turn on the power supply and then callpm_runtime_resumefor each of the devices in the domain.This will have to get more complicated if the individual device drivers want to maintain their own usage counters -- especially if they want to turn off the clock while leaving the counter positive.
I'd like to mange both clocks and power domains using Runtime PM. The prototype I just posted does that, but the code is not very well integrated with the shared Runtime PM code.
/ magnus
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
I am newbee to this mailing list. Please excuse me if I am talking nonsense here.
Quoted 12 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Quoted 3 lines
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock
stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 5 lines
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms?
Hi,
I am newbee to this mailing list. Please excuse me if I am talking nonsense here.
Quoted 12 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Quoted 3 lines
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock
stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 5 lines
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms? --
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line · Nithish
Hi,
Hi,
Quoted 17 lines
I am newbee to this mailing list. Please excuse me if I am talking nonsense here.
Quoted 11 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Quoted 3 lines
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock
stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 8 lines
Quoted 5 lines
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms?
I don't have any plan to do that and I heaven't heard of anyone planning to do it.
Best,
Rafael
Quoted 25 lines
Hi,
Quoted 23 lines
I am newbee to this mailing list. Please excuse me if I am talking nonsense here.
Quoted 17 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Quoted 5 lines
Quoted 2 lines
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms?
I don't have any plan to do that and I heaven't heard of anyone planning to do it.
Thanks for the reply Rafael. I felt if we are talking about controlling a device clock from a runtime PM framework we should look at extending the Clock framework rather than re-inventing things.
Regards,
Nithish Mahalingam
Quoted 25 lines
Hi,
Quoted 23 lines
I am newbee to this mailing list. Please excuse me if I am talking nonsense here.
Quoted 17 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Quoted 5 lines
Quoted 2 lines
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms?
I don't have any plan to do that and I heaven't heard of anyone planning to do it.
Thanks for the reply Rafael. I felt if we are talking about controlling a device clock from a runtime PM framework we should look at extending the Clock framework rather than re-inventing things.
Regards,
Nithish Mahalingam
Quoted 1 line · Nithish
Hi,
Hi,
Quoted 17 lines
I am newbee to this mailing list. Please excuse me if I am talking nonsense here.
Quoted 11 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Quoted 3 lines
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock
stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 8 lines
Quoted 5 lines
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms?
I don't have any plan to do that and I heaven't heard of anyone planning to do it.
Best,
Rafael
Quoted 13 lines · Nithish
Quoted 11 lines · Alan Stern
Quoted 11 lines · Magnus Damm
Quoted 3 lines
Clocks should be stopped as soon as possible without any delay. The clock stopping is very cheap performance wise. Also, the clock
stopping is done on bus level without invoking any driver callbacks.
Quoted 1 line
Delaying the clock stopping does not make any sense to me.
In that case the device driver or bus subsystem should manage the device's clock directly. There's no need to tie it in with the runtime PM framework. Simply start the clock before each I/O operation and stop it afterward.
Quoted 7 lines
Quoted 5 lines
It's not that easy. The clock needs to be enabled to let the hardware device perform device specific stuff. For instance, the clock for the LCD controller needs to be on to redraw the screen. When the driver knows that it's done with the clock it can notify the bus using Runtime PM.
Is there any plan to look into the "Clock Framework" that was developed as part of OMAP and extending this to make it generic for all platforms?
Do you mean vendor specific extensions to the clock framework? I'm quite sure a bunch of architectures already support the clock framework. Some architectures probably have extensions that would be nice if they could be made more generic. Do you have any special extensions in mind? =)
As for Runtime PM, clock stopping is only one part of the problem. On SuperH we manage clock stopping through the clock framework and I'm pretty sure other embedded architectures do that as well. That problem is more or less already solved in my opinion.
For efficient power management on embedded systems we need more than just clock stopping. We also want to save and restore device context so we can turn off power to power domains during runtime. This is somewhat tied together with clock stopping because we want to disable clocks as soon as possible when the device gets idle but in the case of domain power off we also need to start the clock before we can call the ->runtime_suspend() callback provided by the driver. All this can of course be handled by the device driver, but that would just be duplicating too much code - I'd rather let the Runtime PM bus code manage that.
Many runtime power management aware device drivers use clk_enable() and clk_disable() stop and start clocks. But the clk_disable() function is actually often used to signal that the device is idle. Allowing device drivers to replace clk_enable()/clk_disable() with Runtime PM callbacks to add support for context save and restore is a logical next step from my point of view.
For SuperH we will most likely allow clock stopping through the clock framework _or_ using Runtime PM in parallel, at least until all drivers are converted to make use of Runtime PM.
Cheers,
/ magnus
Quoted 123 lines · Magnus Damm
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Magnus Damm
Quoted 3 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0Quoted 6 lines
Quoted 3 lines
I expect
runtime_disabled= false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought
usage_counterwould be sufficient. Will fix.Thank you. No problem.
Quoted 10 lines
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.Quoted 8 lines
I think the problem is that
pm_runtime_get_sync()indriver_probe_device()calls ->runtime_resume(), so the device is active from the core's point of view when you callpm_runtime_resume()fromprobe().Hmm. OK, perhaps we should just increment
usage_countindriver_device_probe()to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.Sounds good.
Quoted 7 lines
Quoted 7 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...Quoted 5 lines
Quoted 1 line
Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
I think that's a nicer interface, but I must figure out how to use ->runtime_idle before I can switch to that...
Quoted 10 lines
However, I'm now thinking it should work like this:
*
pm_runtime_get()incrementsusage_countand if it was zero before the incrementation, it callspm_request_resume()(pm_runtime_resume()is called by the 'sync' version).*
pm_runtime_put()decrementsusage_countand if it's zero after the decrementation, it callspm_request_idle()(pm_runtime_idle()is called by the 'sync' version).Quoted 5 lines
* The 'suspend' callbacks won't succeed for
usage_count> 0.This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then
usage_countwould have to be modified under the spinlock only.If all
usage_countusers are moved under the spinlock then there would be no need for atomic operations, right?This get()/put() interface is interesting.
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain. So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of
pm_runtime_resume()andpm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Drivers call
pm_runtime_get_sync()andpm_runtime_put()before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending onput()orput_sync(), but no timer). Thebus->runtime_idle()callback stops the clock and decreases the power domain usage count. If the power domain is unused, then thepm_schedule_suspend()is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.I can't get the above to work with v8 though. This is because after the clock is stopped with ->runtime_idle() the
runtime_statusof the device is stillRPM_ACTIVE, so whenpm_runtime_get_sync()gets called the ->runtime_resume() never gets invoked and the clock is never started...
Quoted 6 lines
So I don't know if you think the ->runtime_idle usage above is a good plan. I guess no, it's probably quite different from the USB case. I can of course always skip using ->runtime_idle() and just use suspend()/resume().
Any thoughts?
I think you'd need a separate bus type callback for that, call it ->runtime_deepen() for now, which could be executed for a _suspended_ (from the core's point of view) device and the role of which would be to put the (already suspended) device into a deeper low power state.
Something like this might also be used for PCI and it's worth discussing IMO.
So, if we had such a callback, your scenario would be the following.
Drivers call pm_runtime_get_sync() and pm_runtime_put() before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback that in turn calls pm_runtime_suspend() or pm_schedule_suspend() and the ->runtime_suspend() executed as a result stops the clock and decreases the power domain usage count. If the domain usage count happens to be zero, pm_runtime_deepen() or pm_schedule_deepen() is called for each device in the power domain. Consequently, the bus type's ->runtime_deepen() is invoked and that can call the device's ->runtime_suspend(), for example. If there's pm_runtime_get_sync() any time when this is happening, it will cancel the pending requests and run ->runtime_resume().
Does it make sense?
Rafael
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Magnus Damm
Quoted 3 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 6 lines
Quoted 3 lines
I expect
runtime_disabled= false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought
usage_counterwould be sufficient. Will fix.
Thank you. No problem.
Quoted 10 lines
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
Quoted 8 lines
I think the problem is that
pm_runtime_get_sync()indriver_probe_device()calls ->runtime_resume(), so the device is active from the core's point of view when you callpm_runtime_resume()fromprobe().Hmm. OK, perhaps we should just increment
usage_countindriver_device_probe()to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.
Sounds good.
Quoted 7 lines
Quoted 7 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...
Quoted 5 lines
Quoted 1 line
Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
I think that's a nicer interface, but I must figure out how to use ->runtime_idle before I can switch to that...
Quoted 10 lines
However, I'm now thinking it should work like this:
*
pm_runtime_get()incrementsusage_countand if it was zero before the incrementation, it callspm_request_resume()(pm_runtime_resume()is called by the 'sync' version).*
pm_runtime_put()decrementsusage_countand if it's zero after the decrementation, it callspm_request_idle()(pm_runtime_idle()is called by the 'sync' version).
Quoted 5 lines
* The 'suspend' callbacks won't succeed for
usage_count> 0.This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then
usage_countwould have to be modified under the spinlock only.
If all usage_count users are moved under the spinlock then there would be no need for atomic operations, right?
This get()/put() interface is interesting.
So I'd like to tie in two levels of power management in our runtime PM implementation. The most simple level is clock stopping, and I can do that using the bus callbacks ->runtime_suspend() and ->runtime_resume() with v8. The driver runtime callbacks are never invoked for clock stopping.
On top of the clock stopping I'd like to turn off power to the domain. So if all clocks are stopped to the devices within a domain, then I'd like to call the per-device ->runtime_suspend() callbacks provided by the drivers.
I wonder how to fit these two levels of power management into the runtime PM in a nice way. My first attempts simply made use of pm_runtime_resume() and pm_runtime_suspend(), but I'd like to move to get()/put() if possible. But for that to work I need to implement ->runtime_idle() in my bus code, and I wonder if the current runtime PM idle behaviour is a good fit.
Below is how I'd like to make use of the runtime PM code. I'm not sure if it's compatible with your view. =)
Drivers call pm_runtime_get_sync() and pm_runtime_put() before and after using the hardware. The runtime PM code invokes the bus ->runtime_idle() callback ASAP (of course depending on put() or put_sync(), but no timer). The bus->runtime_idle() callback stops the clock and decreases the power domain usage count. If the power domain is unused, then the pm_schedule_suspend() is called for each of the devices in the power domain. This in turn will invoke the ->runtime_suspend() callback which starts the clock, calls the driver ->runtime_suspend() and stops the clock again. When all devices are runtime suspended the power domain is turned off.
I can't get the above to work with v8 though. This is because after the clock is stopped with ->runtime_idle() the runtime_status of the device is still RPM_ACTIVE, so when pm_runtime_get_sync() gets called the ->runtime_resume() never gets invoked and the clock is never started...
So I don't know if you think the ->runtime_idle usage above is a good plan. I guess no, it's probably quite different from the USB case. I can of course always skip using ->runtime_idle() and just use suspend()/resume().
Any thoughts?
Thanks,
/ magnus
Quoted 15 lines · Magnus Damm
Hi Rafael,
Quoted 12 lines · Rafael J. Wysocki
Hi,
There's a rev. 8 of the run-time PM framework patch.
Highlights:
* I did my best to follow the design we've recently discussed.
* pm_runtime_[get|put]() and the sync versions call pm_[request|runtime]_[resume|idle](), because I don't see much point manipulating the usage counter alone.
*pm_runtime_disable()carries out a (synchronous) wake-up if there's a resume request pending.
Quoted 4 lines
Quoted 1 line
Comments welcome.
I've now jumped from v5 to v8 and I feel that the code is getting cleaner and cleaner. Very nice.
That's mostly thanks to Alan.
Quoted 35 lines
My intention was to post a SuperH prototype last week, but I got side tracked with other stuff. And today I ran into some problems related to
probe()that I'd like to ask about right away. At this point I've got a few device drivers converted and some simple bus runtime_suspend()/runtime_resume() code that stop and start clocks.Issue 1:
------------
Device drivers which do not perform any hardware access inprobe()work fine. During software setup inprobe()the runtime pm code is initialized with the following:(quoted diff) +3
-0+ pm_suspend_ignore_children(&dev->dev, true); + pm_runtime_set_suspended(&dev->dev); + pm_runtime_enable(&dev->dev);Before accessing hardware I perform:
(quoted diff) +1
-0+ pm_runtime_resume(pd->dev);When done with the hardware I do:
(quoted diff) +1
-0+ pm_runtime_suspend(pd->dev);Not so complicated. Am I supposed to initialize something else as well?
All good with the code above, but there seem to be some issue with how
usage_countis counted up and down and whenruntime_disabledis set:1.
pm_runtime_init():usage_count= 1,runtime_disabled= true
2.driver_probe_device():pm_runtime_get_sync()
3.pm_runtime_get_sync():usage_count= 2
4. device driverprobe():pm_runtime_enable()
5.pm_runtime_enable():usage_count= 1
6.driver_probe_device():pm_runtime_put()
7.pm_runtime_put():usage_count= 0
Quoted 3 lines
I expect
runtime_disabled= false in 7. Modifying the get/put calls to do enable/disable may work around the issue, but that's probably not what you guys want.
Sure, that's my mistake. I should have used a separate counter for disable/enable, but I thought usage_counter would be sufficient. Will fix.
Quoted 9 lines
Issue 2:
------------
I cannot get any bus ->runtime_resume() callbacks fromprobe(). This also seems related tousage_countandpm_runtime_get_sync()indriver_probe_device(). Basically, fromprobe(), callingpm_runtime_resume()afterpm_runtime_set_suspended()results in error and not in a ->runtime_resume() callback. Some device drives access hardware inprobe(), so the ->runtime_resume() callback is needed at that point to turn on clocks before the hardware can be accessed.
I think the problem is that pm_runtime_get_sync() in driver_probe_device() calls ->runtime_resume(), so the device is active from the core's point of view when you call pm_runtime_resume() from probe().
Hmm. OK, perhaps we should just increment usage_count in driver_device_probe() to prevent suspends from happening at that time, without calling ->runtime_resume() so that the driver can do it by itself. I'll do that in the next version.
Quoted 8 lines
Random thought:
-------------------------
Theruntime_pm_get()andruntime_pm_put()look very nice. I assume that inteface is supposed to be used by bus code. I wonder if it would be cleaner to use a similar counter based interface from the driver instead of the pm_runtime_idle()/suspend()/resume()...Let me know what you think!
In fact I thought drivers could also use pm_runtime_[get|put]() and the 'sync' versions. At least, I don't see why not at the moment (well, I'm a bit tired right now ...).
However, I'm now thinking it should work like this:
* pm_runtime_get() increments usage_count and if it was zero before the incrementation, it calls pm_request_resume() (pm_runtime_resume() is called by the 'sync' version).
* pm_runtime_put() decrements usage_count and if it's zero after the decrementation, it calls pm_request_idle() (pm_runtime_idle() is called by the 'sync' version).
* The 'suspend' callbacks won't succeed for usage_count > 0.
This way we would avoid calling the 'suspend' and 'idle' functions each time unnecessarily, but then usage_count would have to be modified under the spinlock only.
Best,
Rafael
hi!
Quoted 36 lines
include/linux/pm.h +28
-3+/** +* Device run-time power management request types. +* +* RPM_REQ_NONE Do nothing. +* +* RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback +* +* RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback +* +* RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback +*/ + +enum rpm_request { +RPM_REQ_NONE =0 , +RPM_REQ_IDLE , +RPM_REQ_SUSPEND , +RPM_REQ_RESUME , +}; +struct dev_pm_info {pm_message_t power_state; -unsigned can_wakeup:1 ; -unsigned should_wakeup:1 ; +unsigned int can_wakeup:1 ; +unsigned int should_wakeup:1 ;enum dpm_state status;/* Owned by the PM core */ -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM_SLEEP struct list_head entry;#endif +#ifdef CONFIG_PM_RUNTIME +struct timer_list suspend_timer; +unsigned long timer_expires; +struct work_struct work; +wait_queue_head_t wait_queue; +spinlock_t lock;
include/linux/pm.h enum dpm_state { · line 419
Quoted 10 lines
include/linux/pm.h +10
-0+atomic_t usage_count; +atomic_t child_count; + unsigned int ignore_children:1; + unsigned int runtime_disabled:1; + unsigned int runtime_failure:1; + unsigned int idle_notification:1; + unsigned int request_pending:1; + unsigned int deferred_resume:1; +enum rpm_request request; +enum rpm_status runtime_status;
runtime_status seems to be accessed outside spinlocks. Should it be of type atomic_t?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html