PM: Rearrange core suspend code
Subsystems (6)
cover PM: Rearrange core suspend code
Hi,
Here's something I wanted to do quite some time ago.
kernel/power/main.c becomes more and more difficult to maintain over time, since it contains both the suspend to RAM core code and some common PM code that is also used for hibernation. For this reason [1/2] separates the suspend to RAM code from main.c and puts it into two new files (the test facility is, again, separated from the core code for clarity).
[2/2] renames kernel/power/disk.c to kernel/power/hibernate.c, because the role of this file is analogous to kernel/power/suspend.c (introduced by [1/2]).
Comments welcome.
Best,
Rafael
RFC PATCH 1/2 PM: Separate suspend to RAM functionality from core
From: Rafael J. Wysocki <[email protected]>
Move the suspend to RAM and standby code from kernel/power/main.c to two separate files, kernel/power/suspend.c containing the basic functions and kernel/power/suspend-test.c containing the automatic suspend test facility based on the RTC clock alarm.
There are no changes in functionality related to these modifications.
--- kernel/power/Makefile | 2 kernel/power/main.c | 503 -------------------------------------------- kernel/power/power.h | 17 + kernel/power/suspend-test.c | 187 ++++++++++++++++ kernel/power/suspend.c | 300 ++++++++++++++++++++++++++ 5 files changed, 505 insertions(+), 504 deletions(-)
kernel/power/main.c +0 -503
@@ -8,20 +8,9 @@* */ -#include <linux/module.h> -#include <linux/suspend.h> #include <linux/kobject.h> #include <linux/string.h> -#include <linux/delay.h> -#include <linux/errno.h> -#include <linux/kmod.h> -#include <linux/init.h> -#include <linux/console.h> -#include <linux/cpu.h> #include <linux/resume-trace.h> -#include <linux/freezer.h> -#include <linux/vmstat.h> -#include <linux/syscalls.h> #include "power.h"
@@ -119,355 +108,6 @@ power_attr(pm_test);#endif /* CONFIG_PM_SLEEP */ -#ifdef CONFIG_SUSPEND - -static int suspend_test (int level) -{ -#ifdef CONFIG_PM_DEBUG -if (pm_test_level == level) { -printk (KERN_INFO "suspend debug: Waiting for 5 seconds.\n" ); -mdelay (5000 ); -return 1 ; - } -#endif /* !CONFIG_PM_DEBUG */ -return 0 ; -} - -#ifdef CONFIG_PM_TEST_SUSPEND - -/* -* We test the system suspend code by setting an RTC wakealarm a short -* time in the future, then suspending. Suspending the devices won't -* normally take long ... some systems only need a few milliseconds. -* -* The time it takes is system-specific though, so when we test this -* during system bootup we allow a LOT of time. -*/ -#define TEST_SUSPEND_SECONDS 5 - -static unsigned long suspend_test_start_time; - -static void suspend_test_start (void ) -{ -/* FIXME Use better timebase than "jiffies", ideally a clocksource. -* What we want is a hardware counter that will work correctly even -* during the irqs-are-off stages of the suspend/resume cycle... -*/ - suspend_test_start_time = jiffies; -} - -static void suspend_test_finish (const char *label) -{ -long nj = jiffies - suspend_test_start_time; -unsigned msec; - - msec =jiffies_to_msecs (abs (nj)); -pr_info ("PM: %s took %d.%03d seconds\n" , label, - msec /1000 , msec %1000 ); - -/* Warning on suspend means the RTC alarm period needs to be -* larger -- the system was sooo slooowwww to suspend that the -* alarm (should have) fired before the system went to sleep! -* -* Warning on either suspend or resume also means the system -* has some performance issues. The stack dump of a WARN_ON -* is more likely to get the right attention than a printk... -*/ -WARN (msec > (TEST_SUSPEND_SECONDS *1000 ),"Component: %s\n" , label); -} - -#else - -static void suspend_test_start (void ) -{ -} - -static void suspend_test_finish (const char *label) -{ -} - -#endif - -static struct platform_suspend_ops *suspend_ops; - -/** -* suspend_set_ops - Set the global suspend method table. -* @ops: Pointer to ops structure. -*/ - -void suspend_set_ops (struct platform_suspend_ops *ops) -{ -mutex_lock (&pm_mutex); - suspend_ops = ops; -mutex_unlock (&pm_mutex); -} - -/** -* suspend_valid_only_mem - generic memory-only valid callback -* -* Platform drivers that implement mem suspend only and only need -* to check for that in their .valid callback can use this instead -* of rolling their own .valid callback. -*/ -int suspend_valid_only_mem (suspend_state_t state) -{ -return state ==PM_SUSPEND_MEM ; -} - -/** -* suspend_prepare - Do prep work before entering low-power state. -* -* This is common code that is called for each state that we're entering. -* Run suspend notifiers, allocate a console and stop all processes. -*/ -static int suspend_prepare (void ) -{ -int error; - -if (!suspend_ops || !suspend_ops->enter) -return -EPERM ; - -pm_prepare_console (); - - error =pm_notifier_call_chain (PM_SUSPEND_PREPARE ); -if (error) - goto Finish; - - error =usermodehelper_disable (); -if (error) - goto Finish; - - error =suspend_freeze_processes (); -if (!error) -return 0 ; - -suspend_thaw_processes (); -usermodehelper_enable (); - Finish: -pm_notifier_call_chain (PM_POST_SUSPEND ); -pm_restore_console (); -return error; -} - -/* default implementation */ -void __attribute__ ((weak))arch_suspend_disable_irqs (void ) -{ -local_irq_disable (); -} - -/* default implementation */ -void __attribute__ ((weak))arch_suspend_enable_irqs (void ) -{ -local_irq_enable (); -} - -/** -* suspend_enter - enter the desired system sleep state. -* @state: state to enter -* -* This function should be called after devices have been suspended. -*/ -static int suspend_enter (suspend_state_t state) -{ -int error; - -if (suspend_ops->prepare) { - error = suspend_ops->prepare (); -if (error) -return error; - } - - error =dpm_suspend_noirq (PMSG_SUSPEND ); -if (error) { -printk (KERN_ERR "PM: Some devices failed to power down\n" ); - goto Platfrom_finish; - } - -if (suspend_ops->prepare_late) { - error = suspend_ops->prepare_late (); -if (error) - goto Power_up_devices; - } - -if (suspend_test (TEST_PLATFORM )) - goto Platform_wake; - - error =disable_nonboot_cpus (); -if (error ||suspend_test (TEST_CPUS )) - goto Enable_cpus; - -arch_suspend_disable_irqs (); -BUG_ON (!irqs_disabled ()); - - error =sysdev_suspend (PMSG_SUSPEND ); -if (!error) { -if (!suspend_test (TEST_CORE )) - error = suspend_ops->enter (state); -sysdev_resume (); - } - -arch_suspend_enable_irqs (); -BUG_ON (irqs_disabled ()); - - Enable_cpus: -enable_nonboot_cpus (); - - Platform_wake: -if (suspend_ops->wake) - suspend_ops->wake (); - - Power_up_devices: -dpm_resume_noirq (PMSG_RESUME ); - - Platfrom_finish: -if (suspend_ops->finish) - suspend_ops->finish (); - -return error; -} - -/** -* suspend_devices_and_enter - suspend devices and enter the desired system -* sleep state. -* @state: state to enter -*/ -int suspend_devices_and_enter (suspend_state_t state) -{ -int error; - -if (!suspend_ops) -return -ENOSYS ; - -if (suspend_ops->begin) { - error = suspend_ops->begin (state); -if (error) - goto Close; - } -suspend_console (); -suspend_test_start (); - error =dpm_suspend_start (PMSG_SUSPEND ); -if (error) { -printk (KERN_ERR "PM: Some devices failed to suspend\n" ); - goto Recover_platform; - } -suspend_test_finish ("suspend devices" ); -if (suspend_test (TEST_DEVICES )) - goto Recover_platform; - -suspend_enter (state); - - Resume_devices: -suspend_test_start (); -dpm_resume_end (PMSG_RESUME ); -suspend_test_finish ("resume devices" ); -resume_console (); - Close: -if (suspend_ops->end) - suspend_ops->end (); -return error; - - Recover_platform: -if (suspend_ops->recover) - suspend_ops->recover (); - goto Resume_devices; -} - -/** -* suspend_finish - Do final work before exiting suspend sequence. -* -* Call platform code to clean up, restart processes, and free the -* console that we've allocated. This is not called for suspend-to-disk. -*/ -static void suspend_finish (void ) -{ -suspend_thaw_processes (); -usermodehelper_enable (); -pm_notifier_call_chain (PM_POST_SUSPEND ); -pm_restore_console (); -} - - - - -static const char *const pm_states[PM_SUSPEND_MAX ] = { - [PM_SUSPEND_STANDBY ] ="standby" , - [PM_SUSPEND_MEM ] ="mem" , -}; - -static inline int valid_state (suspend_state_t state) -{ -/* All states need lowlevel support and need to be valid -* to the lowlevel implementation, no valid callback -* implies that none are valid. */ -if (!suspend_ops || !suspend_ops->valid || !suspend_ops->valid (state)) -return 0 ; -return 1 ; -} - - -/** -* enter_state - Do common work of entering low-power state. -* @state: pm_state structure for state we're entering. -* -* Make sure we're the only ones trying to enter a sleep state. Fail -* if someone has beat us to it, since we don't want anything weird to -* happen when we wake up. -* Then, do the setup for suspend, enter the state, and cleaup (after -* we've woken up). -*/ -static int enter_state (suspend_state_t state) -{ -int error; - -if (!valid_state (state)) -return -ENODEV ; - -if (!mutex_trylock (&pm_mutex)) -return -EBUSY ; - -printk (KERN_INFO "PM: Syncing filesystems ... " ); -sys_sync (); -printk ("done.\n" ); - -pr_debug ("PM: Preparing system for %s sleep\n" , pm_states[state]); - error =suspend_prepare (); -if (error) - goto Unlock; - -if (suspend_test (TEST_FREEZER )) - goto Finish; - -pr_debug ("PM: Entering %s sleep\n" , pm_states[state]); - error =suspend_devices_and_enter (state); - - Finish: -pr_debug ("PM: Finishing wakeup.\n" ); -suspend_finish (); - Unlock: -mutex_unlock (&pm_mutex); -return error; -} - - -/** -* pm_suspend - Externally visible function for suspending system. -* @state: Enumerated value of state to enter. -* -* Determine whether or not value is within range, get state -* structure, and enter (above). -*/ - -int pm_suspend (suspend_state_t state) -{ -if (state >PM_SUSPEND_ON && state <=PM_SUSPEND_MAX ) -return enter_state (state); -return -EINVAL ; -} - -EXPORT_SYMBOL (pm_suspend); - -#endif /* CONFIG_SUSPEND */ -struct kobject *power_kobj;/**
@@ -480,7 +120,6 @@ struct kobject *power_kobj;* store() accepts one of those strings, translates it into the * proper enumerated value, and initiates a suspend transition. */ -static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {
@@ -578,7 +217,6 @@ static struct attribute_group attr_group .attrs = g, }; -static int __init pm_init (void ) { power_kobj =kobject_create_and_add ("power" ,NULL );
@@ -588,144 +226,3 @@ static int __init pm_init(void) }core_initcall (pm_init); - - -#ifdef CONFIG_PM_TEST_SUSPEND - -#include <linux/rtc.h> - -/* -* To test system suspend, we need a hands-off mechanism to resume the -* system. RTCs wake alarms are a common self-contained mechanism. -*/ - -static void __init test_wakealarm (struct rtc_device *rtc,suspend_state_t state) -{ -static char err_readtime[]__initdata = -KERN_ERR "PM: can't read %s time, err %d\n" ; -static char err_wakealarm []__initdata = -KERN_ERR "PM: can't set %s wakealarm, err %d\n" ; -static char err_suspend[]__initdata = -KERN_ERR "PM: suspend test failed, error %d\n" ; -static char info_test[]__initdata = -KERN_INFO "PM: test RTC wakeup from '%s' suspend\n" ; - -unsigned long now; -struct rtc_wkalrm alm; -int status; - -/* this may fail if the RTC hasn't been initialized */ - status =rtc_read_time (rtc, &alm.time); -if (status <0 ) { -printk (err_readtime,dev_name (&rtc->dev), status); -return ; - } -rtc_tm_to_time (&alm.time, &now); - -memset (&alm,0 ,sizeof alm); -rtc_time_to_tm (now +TEST_SUSPEND_SECONDS , &alm.time); - alm.enabled = true; - - status =rtc_set_alarm (rtc, &alm); -if (status <0 ) { -printk (err_wakealarm,dev_name (&rtc->dev), status); -return ; - } - -if (state ==PM_SUSPEND_MEM ) { -printk (info_test, pm_states[state]); - status =pm_suspend (state); -if (status == -ENODEV ) - state =PM_SUSPEND_STANDBY ; - } -if (state ==PM_SUSPEND_STANDBY ) { -printk (info_test, pm_states[state]); - status =pm_suspend (state); - } -if (status <0 ) -printk (err_suspend, status); - -/* Some platforms can't detect that the alarm triggered the -* wakeup, or (accordingly) disable it after it afterwards. -* It's supposed to give oneshot behavior; cope. -*/ - alm.enabled = false; -rtc_set_alarm (rtc, &alm); -} - -static int __init has_wakealarm (struct device *dev,void *name_ptr) -{ -struct rtc_device *candidate =to_rtc_device (dev); - -if (!candidate->ops->set_alarm) -return 0 ; -if (!device_may_wakeup (candidate->dev.parent)) -return 0 ; - - *(const char **)name_ptr =dev_name (dev); -return 1 ; -} - -/* -* Kernel options like "test_suspend=mem" force suspend/resume sanity tests -* at startup time. They're normally disabled, for faster boot and because -* we can't know which states really work on this particular system. -*/ -static suspend_state_t test_state__initdata =PM_SUSPEND_ON ; - -static char warn_bad_state[]__initdata = -KERN_WARNING "PM: can't test '%s' suspend state\n" ; - -static int __init setup_test_suspend (char *value) -{ -unsigned i; - -/* "=mem" ==> "mem" */ - value++; -for (i =0 ; i <PM_SUSPEND_MAX ; i++) { -if (!pm_states[i]) -continue ; -if (strcmp (pm_states[i], value) !=0 ) -continue ; - test_state = (__force suspend_state_t ) i; -return 0 ; - } -printk (warn_bad_state, value); -return 0 ; -} -__setup ("test_suspend" , setup_test_suspend); - -static int __init test_suspend (void ) -{ -static char warn_no_rtc[]__initdata = -KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n" ; - -char *pony =NULL ; -struct rtc_device *rtc =NULL ; - -/* PM is initialized by now; is that state testable? */ -if (test_state ==PM_SUSPEND_ON ) - goto done; -if (!valid_state (test_state)) { -printk (warn_bad_state, pm_states[test_state]); - goto done; - } - -/* RTCs have initialized by now too ... can we use one? */ -class_find_device (rtc_class,NULL , &pony, has_wakealarm); -if (pony) - rtc =rtc_class_open (pony); -if (!rtc) { -printk (warn_no_rtc); - goto done; - } - -/* go for it */ -test_wakealarm (rtc, test_state); -rtc_class_close (rtc); -done: -return 0 ; -} -late_initcall (test_suspend); - -#endif /* CONFIG_PM_TEST_SUSPEND */
kernel/power/suspend.c new file +300 -0
300 lines not on this page · raw message
kernel/power/power.h +16 -1
@@ -160,15 +160,30 @@ extern void swsusp_show_speed(struct tim unsigned int, char *);#ifdef CONFIG_SUSPEND -/* kernel/power/main.c */ +/* kernel/power/suspend.c */ +extern const char *const pm_states[]; + +extern bool valid_state (suspend_state_t state);extern int suspend_devices_and_enter (suspend_state_t state); +extern int enter_state (suspend_state_t state);#else /* !CONFIG_SUSPEND */ static inline int suspend_devices_and_enter (suspend_state_t state) {return -ENOSYS ; } +static inline int enter_state (suspend_state_t state) {return -ENOSYS ; } +static inline bool valid_state (suspend_state_t state) {return false; }#endif /* !CONFIG_SUSPEND */ +#ifdef CONFIG_PM_TEST_SUSPEND +/* kernel/power/suspend-test.c */ +extern void suspend_test_start (void ); +extern void suspend_test_finish (const char *label); +#else /* !CONFIG_PM_TEST_SUSPEND */ +static inline void suspend_test_start (void ) {} +static inline void suspend_test_finish (const char *label) {} +#endif /* !CONFIG_PM_TEST_SUSPEND */ +#ifdef CONFIG_PM_SLEEP /* kernel/power/main.c */ extern int pm_notifier_call_chain (unsigned long val);
kernel/power/Makefile +2 -0
@@ -6,6 +6,8 @@ endif obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o +obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_PM_TEST_SUSPEND) += suspend-test.o obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
kernel/power/suspend-test.c new file +187 -0
187 lines not on this page · raw message
RFC PATCH 1/2 PM: Separate suspend to RAM functionality from core
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Move the suspend to RAM and standby code from kernel/power/main.c to two separate files, kernel/power/suspend.c containing the basic functions and kernel/power/suspend-test.c containing the automatic suspend test facility based on the RTC clock alarm.
There are no changes in functionality related to these modifications.
--- kernel/power/Makefile | 2 kernel/power/main.c | 503 -------------------------------------------- kernel/power/power.h | 17 + kernel/power/suspend-test.c | 187 ++++++++++++++++ kernel/power/suspend.c | 300 ++++++++++++++++++++++++++ 5 files changed, 505 insertions(+), 504 deletions(-)
kernel/power/main.c +0 -503
@@ -8,20 +8,9 @@* */ -#include <linux/module.h> -#include <linux/suspend.h> #include <linux/kobject.h> #include <linux/string.h> -#include <linux/delay.h> -#include <linux/errno.h> -#include <linux/kmod.h> -#include <linux/init.h> -#include <linux/console.h> -#include <linux/cpu.h> #include <linux/resume-trace.h> -#include <linux/freezer.h> -#include <linux/vmstat.h> -#include <linux/syscalls.h> #include "power.h"
@@ -119,355 +108,6 @@ power_attr(pm_test);#endif /* CONFIG_PM_SLEEP */ -#ifdef CONFIG_SUSPEND - -static int suspend_test (int level) -{ -#ifdef CONFIG_PM_DEBUG -if (pm_test_level == level) { -printk (KERN_INFO "suspend debug: Waiting for 5 seconds.\n" ); -mdelay (5000 ); -return 1 ; - } -#endif /* !CONFIG_PM_DEBUG */ -return 0 ; -} - -#ifdef CONFIG_PM_TEST_SUSPEND - -/* -* We test the system suspend code by setting an RTC wakealarm a short -* time in the future, then suspending. Suspending the devices won't -* normally take long ... some systems only need a few milliseconds. -* -* The time it takes is system-specific though, so when we test this -* during system bootup we allow a LOT of time. -*/ -#define TEST_SUSPEND_SECONDS 5 - -static unsigned long suspend_test_start_time; - -static void suspend_test_start (void ) -{ -/* FIXME Use better timebase than "jiffies", ideally a clocksource. -* What we want is a hardware counter that will work correctly even -* during the irqs-are-off stages of the suspend/resume cycle... -*/ - suspend_test_start_time = jiffies; -} - -static void suspend_test_finish (const char *label) -{ -long nj = jiffies - suspend_test_start_time; -unsigned msec; - - msec =jiffies_to_msecs (abs (nj)); -pr_info ("PM: %s took %d.%03d seconds\n" , label, - msec /1000 , msec %1000 ); - -/* Warning on suspend means the RTC alarm period needs to be -* larger -- the system was sooo slooowwww to suspend that the -* alarm (should have) fired before the system went to sleep! -* -* Warning on either suspend or resume also means the system -* has some performance issues. The stack dump of a WARN_ON -* is more likely to get the right attention than a printk... -*/ -WARN (msec > (TEST_SUSPEND_SECONDS *1000 ),"Component: %s\n" , label); -} - -#else - -static void suspend_test_start (void ) -{ -} - -static void suspend_test_finish (const char *label) -{ -} - -#endif - -static struct platform_suspend_ops *suspend_ops; - -/** -* suspend_set_ops - Set the global suspend method table. -* @ops: Pointer to ops structure. -*/ - -void suspend_set_ops (struct platform_suspend_ops *ops) -{ -mutex_lock (&pm_mutex); - suspend_ops = ops; -mutex_unlock (&pm_mutex); -} - -/** -* suspend_valid_only_mem - generic memory-only valid callback -* -* Platform drivers that implement mem suspend only and only need -* to check for that in their .valid callback can use this instead -* of rolling their own .valid callback. -*/ -int suspend_valid_only_mem (suspend_state_t state) -{ -return state ==PM_SUSPEND_MEM ; -} - -/** -* suspend_prepare - Do prep work before entering low-power state. -* -* This is common code that is called for each state that we're entering. -* Run suspend notifiers, allocate a console and stop all processes. -*/ -static int suspend_prepare (void ) -{ -int error; - -if (!suspend_ops || !suspend_ops->enter) -return -EPERM ; - -pm_prepare_console (); - - error =pm_notifier_call_chain (PM_SUSPEND_PREPARE ); -if (error) - goto Finish; - - error =usermodehelper_disable (); -if (error) - goto Finish; - - error =suspend_freeze_processes (); -if (!error) -return 0 ; - -suspend_thaw_processes (); -usermodehelper_enable (); - Finish: -pm_notifier_call_chain (PM_POST_SUSPEND ); -pm_restore_console (); -return error; -} - -/* default implementation */ -void __attribute__ ((weak))arch_suspend_disable_irqs (void ) -{ -local_irq_disable (); -} - -/* default implementation */ -void __attribute__ ((weak))arch_suspend_enable_irqs (void ) -{ -local_irq_enable (); -} - -/** -* suspend_enter - enter the desired system sleep state. -* @state: state to enter -* -* This function should be called after devices have been suspended. -*/ -static int suspend_enter (suspend_state_t state) -{ -int error; - -if (suspend_ops->prepare) { - error = suspend_ops->prepare (); -if (error) -return error; - } - - error =dpm_suspend_noirq (PMSG_SUSPEND ); -if (error) { -printk (KERN_ERR "PM: Some devices failed to power down\n" ); - goto Platfrom_finish; - } - -if (suspend_ops->prepare_late) { - error = suspend_ops->prepare_late (); -if (error) - goto Power_up_devices; - } - -if (suspend_test (TEST_PLATFORM )) - goto Platform_wake; - - error =disable_nonboot_cpus (); -if (error ||suspend_test (TEST_CPUS )) - goto Enable_cpus; - -arch_suspend_disable_irqs (); -BUG_ON (!irqs_disabled ()); - - error =sysdev_suspend (PMSG_SUSPEND ); -if (!error) { -if (!suspend_test (TEST_CORE )) - error = suspend_ops->enter (state); -sysdev_resume (); - } - -arch_suspend_enable_irqs (); -BUG_ON (irqs_disabled ()); - - Enable_cpus: -enable_nonboot_cpus (); - - Platform_wake: -if (suspend_ops->wake) - suspend_ops->wake (); - - Power_up_devices: -dpm_resume_noirq (PMSG_RESUME ); - - Platfrom_finish: -if (suspend_ops->finish) - suspend_ops->finish (); - -return error; -} - -/** -* suspend_devices_and_enter - suspend devices and enter the desired system -* sleep state. -* @state: state to enter -*/ -int suspend_devices_and_enter (suspend_state_t state) -{ -int error; - -if (!suspend_ops) -return -ENOSYS ; - -if (suspend_ops->begin) { - error = suspend_ops->begin (state); -if (error) - goto Close; - } -suspend_console (); -suspend_test_start (); - error =dpm_suspend_start (PMSG_SUSPEND ); -if (error) { -printk (KERN_ERR "PM: Some devices failed to suspend\n" ); - goto Recover_platform; - } -suspend_test_finish ("suspend devices" ); -if (suspend_test (TEST_DEVICES )) - goto Recover_platform; - -suspend_enter (state); - - Resume_devices: -suspend_test_start (); -dpm_resume_end (PMSG_RESUME ); -suspend_test_finish ("resume devices" ); -resume_console (); - Close: -if (suspend_ops->end) - suspend_ops->end (); -return error; - - Recover_platform: -if (suspend_ops->recover) - suspend_ops->recover (); - goto Resume_devices; -} - -/** -* suspend_finish - Do final work before exiting suspend sequence. -* -* Call platform code to clean up, restart processes, and free the -* console that we've allocated. This is not called for suspend-to-disk. -*/ -static void suspend_finish (void ) -{ -suspend_thaw_processes (); -usermodehelper_enable (); -pm_notifier_call_chain (PM_POST_SUSPEND ); -pm_restore_console (); -} - - - - -static const char *const pm_states[PM_SUSPEND_MAX ] = { - [PM_SUSPEND_STANDBY ] ="standby" , - [PM_SUSPEND_MEM ] ="mem" , -}; - -static inline int valid_state (suspend_state_t state) -{ -/* All states need lowlevel support and need to be valid -* to the lowlevel implementation, no valid callback -* implies that none are valid. */ -if (!suspend_ops || !suspend_ops->valid || !suspend_ops->valid (state)) -return 0 ; -return 1 ; -} - - -/** -* enter_state - Do common work of entering low-power state. -* @state: pm_state structure for state we're entering. -* -* Make sure we're the only ones trying to enter a sleep state. Fail -* if someone has beat us to it, since we don't want anything weird to -* happen when we wake up. -* Then, do the setup for suspend, enter the state, and cleaup (after -* we've woken up). -*/ -static int enter_state (suspend_state_t state) -{ -int error; - -if (!valid_state (state)) -return -ENODEV ; - -if (!mutex_trylock (&pm_mutex)) -return -EBUSY ; - -printk (KERN_INFO "PM: Syncing filesystems ... " ); -sys_sync (); -printk ("done.\n" ); - -pr_debug ("PM: Preparing system for %s sleep\n" , pm_states[state]); - error =suspend_prepare (); -if (error) - goto Unlock; - -if (suspend_test (TEST_FREEZER )) - goto Finish; - -pr_debug ("PM: Entering %s sleep\n" , pm_states[state]); - error =suspend_devices_and_enter (state); - - Finish: -pr_debug ("PM: Finishing wakeup.\n" ); -suspend_finish (); - Unlock: -mutex_unlock (&pm_mutex); -return error; -} - - -/** -* pm_suspend - Externally visible function for suspending system. -* @state: Enumerated value of state to enter. -* -* Determine whether or not value is within range, get state -* structure, and enter (above). -*/ - -int pm_suspend (suspend_state_t state) -{ -if (state >PM_SUSPEND_ON && state <=PM_SUSPEND_MAX ) -return enter_state (state); -return -EINVAL ; -} - -EXPORT_SYMBOL (pm_suspend); - -#endif /* CONFIG_SUSPEND */ -struct kobject *power_kobj;/**
@@ -480,7 +120,6 @@ struct kobject *power_kobj;* store() accepts one of those strings, translates it into the * proper enumerated value, and initiates a suspend transition. */ -static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {
@@ -578,7 +217,6 @@ static struct attribute_group attr_group .attrs = g, }; -static int __init pm_init (void ) { power_kobj =kobject_create_and_add ("power" ,NULL );
@@ -588,144 +226,3 @@ static int __init pm_init(void) }core_initcall (pm_init); - - -#ifdef CONFIG_PM_TEST_SUSPEND - -#include <linux/rtc.h> - -/* -* To test system suspend, we need a hands-off mechanism to resume the -* system. RTCs wake alarms are a common self-contained mechanism. -*/ - -static void __init test_wakealarm (struct rtc_device *rtc,suspend_state_t state) -{ -static char err_readtime[]__initdata = -KERN_ERR "PM: can't read %s time, err %d\n" ; -static char err_wakealarm []__initdata = -KERN_ERR "PM: can't set %s wakealarm, err %d\n" ; -static char err_suspend[]__initdata = -KERN_ERR "PM: suspend test failed, error %d\n" ; -static char info_test[]__initdata = -KERN_INFO "PM: test RTC wakeup from '%s' suspend\n" ; - -unsigned long now; -struct rtc_wkalrm alm; -int status; - -/* this may fail if the RTC hasn't been initialized */ - status =rtc_read_time (rtc, &alm.time); -if (status <0 ) { -printk (err_readtime,dev_name (&rtc->dev), status); -return ; - } -rtc_tm_to_time (&alm.time, &now); - -memset (&alm,0 ,sizeof alm); -rtc_time_to_tm (now +TEST_SUSPEND_SECONDS , &alm.time); - alm.enabled = true; - - status =rtc_set_alarm (rtc, &alm); -if (status <0 ) { -printk (err_wakealarm,dev_name (&rtc->dev), status); -return ; - } - -if (state ==PM_SUSPEND_MEM ) { -printk (info_test, pm_states[state]); - status =pm_suspend (state); -if (status == -ENODEV ) - state =PM_SUSPEND_STANDBY ; - } -if (state ==PM_SUSPEND_STANDBY ) { -printk (info_test, pm_states[state]); - status =pm_suspend (state); - } -if (status <0 ) -printk (err_suspend, status); - -/* Some platforms can't detect that the alarm triggered the -* wakeup, or (accordingly) disable it after it afterwards. -* It's supposed to give oneshot behavior; cope. -*/ - alm.enabled = false; -rtc_set_alarm (rtc, &alm); -} - -static int __init has_wakealarm (struct device *dev,void *name_ptr) -{ -struct rtc_device *candidate =to_rtc_device (dev); - -if (!candidate->ops->set_alarm) -return 0 ; -if (!device_may_wakeup (candidate->dev.parent)) -return 0 ; - - *(const char **)name_ptr =dev_name (dev); -return 1 ; -} - -/* -* Kernel options like "test_suspend=mem" force suspend/resume sanity tests -* at startup time. They're normally disabled, for faster boot and because -* we can't know which states really work on this particular system. -*/ -static suspend_state_t test_state__initdata =PM_SUSPEND_ON ; - -static char warn_bad_state[]__initdata = -KERN_WARNING "PM: can't test '%s' suspend state\n" ; - -static int __init setup_test_suspend (char *value) -{ -unsigned i; - -/* "=mem" ==> "mem" */ - value++; -for (i =0 ; i <PM_SUSPEND_MAX ; i++) { -if (!pm_states[i]) -continue ; -if (strcmp (pm_states[i], value) !=0 ) -continue ; - test_state = (__force suspend_state_t ) i; -return 0 ; - } -printk (warn_bad_state, value); -return 0 ; -} -__setup ("test_suspend" , setup_test_suspend); - -static int __init test_suspend (void ) -{ -static char warn_no_rtc[]__initdata = -KERN_WARNING "PM: no wakealarm-capable RTC driver is ready\n" ; - -char *pony =NULL ; -struct rtc_device *rtc =NULL ; - -/* PM is initialized by now; is that state testable? */ -if (test_state ==PM_SUSPEND_ON ) - goto done; -if (!valid_state (test_state)) { -printk (warn_bad_state, pm_states[test_state]); - goto done; - } - -/* RTCs have initialized by now too ... can we use one? */ -class_find_device (rtc_class,NULL , &pony, has_wakealarm); -if (pony) - rtc =rtc_class_open (pony); -if (!rtc) { -printk (warn_no_rtc); - goto done; - } - -/* go for it */ -test_wakealarm (rtc, test_state); -rtc_class_close (rtc); -done: -return 0 ; -} -late_initcall (test_suspend); - -#endif /* CONFIG_PM_TEST_SUSPEND */
kernel/power/suspend.c new file +300 -0
300 lines not on this page · raw message
kernel/power/power.h +16 -1
@@ -160,15 +160,30 @@ extern void swsusp_show_speed(struct tim unsigned int, char *);#ifdef CONFIG_SUSPEND -/* kernel/power/main.c */ +/* kernel/power/suspend.c */ +extern const char *const pm_states[]; + +extern bool valid_state (suspend_state_t state);extern int suspend_devices_and_enter (suspend_state_t state); +extern int enter_state (suspend_state_t state);#else /* !CONFIG_SUSPEND */ static inline int suspend_devices_and_enter (suspend_state_t state) {return -ENOSYS ; } +static inline int enter_state (suspend_state_t state) {return -ENOSYS ; } +static inline bool valid_state (suspend_state_t state) {return false; }#endif /* !CONFIG_SUSPEND */ +#ifdef CONFIG_PM_TEST_SUSPEND +/* kernel/power/suspend-test.c */ +extern void suspend_test_start (void ); +extern void suspend_test_finish (const char *label); +#else /* !CONFIG_PM_TEST_SUSPEND */ +static inline void suspend_test_start (void ) {} +static inline void suspend_test_finish (const char *label) {} +#endif /* !CONFIG_PM_TEST_SUSPEND */ +#ifdef CONFIG_PM_SLEEP /* kernel/power/main.c */ extern int pm_notifier_call_chain (unsigned long val);
kernel/power/Makefile +2 -0
@@ -6,6 +6,8 @@ endif obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o +obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_PM_TEST_SUSPEND) += suspend-test.o obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
kernel/power/suspend-test.c new file +187 -0
187 lines not on this page · raw message
Re: [RFC][PATCH 1/2] PM: Separate suspend to RAM functionality from core
Quoted 10 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Move the suspend to RAM and standby code from
kernel/power/main.cto two separate files,kernel/power/suspend.ccontaining the basic functions andkernel/power/suspend-test.ccontaining the automatic suspend test facility based on the RTC clock alarm.There are no changes in functionality related to these modifications.
Signed-off-by Rafael J. Wysocki <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [RFC][PATCH 1/2] PM: Separate suspend to RAM functionality from core
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Move the suspend to RAM and standby code from
kernel/power/main.cto two separate files,kernel/power/suspend.ccontaining the basic functions andkernel/power/suspend-test.ccontaining the automatic suspend test facility based on the RTC clock alarm.There are no changes in functionality related to these modifications.
Signed-off-by Rafael J. Wysocki <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
RFC PATCH 2/2 PM/Hibernate: Rename disk.c to hibernate.c
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Change the name of kernel/power/disk.c to kernel/power/hibernate.c in analogy with the file names introduced by the changes that separated the suspend to RAM and standby funtionality from the common PM functions.
--- kernel/power/Makefile | 2 kernel/power/disk.c | 955 ----------------------------------------------- kernel/power/hibernate.c | 955 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/power/power.h | 4 4 files changed, 958 insertions(+), 958 deletions(-)
kernel/power/power.h +2 -2
@@ -45,7 +45,7 @@ static inline char *check_image_kernel(s*/ #define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT) -/* kernel/power/disk.c */ +/* kernel/power/hibernate.c */ extern int hibernation_snapshot (int platform_mode);extern int hibernation_restore (int platform_mode);extern int hibernation_platform_enter (void );
@@ -147,7 +147,7 @@ extern int swsusp_swap_in_use(void);*/ #define SF_PLATFORM_MODE 1 -/* kernel/power/disk.c */ +/* kernel/power/hibernate.c */ extern int swsusp_check (void );extern void swsusp_free (void );extern int swsusp_read (unsigned int *flags_p);
kernel/power/Makefile +1 -1
@@ -8,6 +8,6 @@ obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend-test.o -obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o +obj-$(CONFIG_HIBERNATION) += swsusp.o hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
kernel/power/disk.c deleted +0 -955
955 lines not on this page · raw message
kernel/power/hibernate.c new file +955 -0
955 lines not on this page · raw message
RFC PATCH 2/2 PM/Hibernate: Rename disk.c to hibernate.c
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Change the name of kernel/power/disk.c to kernel/power/hibernate.c in analogy with the file names introduced by the changes that separated the suspend to RAM and standby funtionality from the common PM functions.
--- kernel/power/Makefile | 2 kernel/power/disk.c | 955 ----------------------------------------------- kernel/power/hibernate.c | 955 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/power/power.h | 4 4 files changed, 958 insertions(+), 958 deletions(-)
kernel/power/power.h +2 -2
@@ -45,7 +45,7 @@ static inline char *check_image_kernel(s*/ #define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT) -/* kernel/power/disk.c */ +/* kernel/power/hibernate.c */ extern int hibernation_snapshot (int platform_mode);extern int hibernation_restore (int platform_mode);extern int hibernation_platform_enter (void );
@@ -147,7 +147,7 @@ extern int swsusp_swap_in_use(void);*/ #define SF_PLATFORM_MODE 1 -/* kernel/power/disk.c */ +/* kernel/power/hibernate.c */ extern int swsusp_check (void );extern void swsusp_free (void );extern int swsusp_read (unsigned int *flags_p);
kernel/power/Makefile +1 -1
@@ -8,6 +8,6 @@ obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend-test.o -obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o +obj-$(CONFIG_HIBERNATION) += swsusp.o hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
kernel/power/disk.c deleted +0 -955
955 lines not on this page · raw message
kernel/power/hibernate.c new file +955 -0
955 lines not on this page · raw message
Re: [RFC][PATCH 2/2] PM/Hibernate: Rename disk.c to hibernate.c
Quoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Change the name of
kernel/power/disk.ctokernel/power/hibernate.cin analogy with the file names introduced by the changes that separated the suspend to RAM and standby funtionality from the common PM functions.Signed-off-by Rafael J. Wysocki <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [RFC][PATCH 2/2] PM/Hibernate: Rename disk.c to hibernate.c
In reply to Rafael J. WysockiQuoted 8 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Change the name of
kernel/power/disk.ctokernel/power/hibernate.cin analogy with the file names introduced by the changes that separated the suspend to RAM and standby funtionality from the common PM functions.Signed-off-by Rafael J. Wysocki <[email protected]>
ACK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 10 lines · Rafael J. Wysocki
Hi,
Here's something I wanted to do quite some time ago.
kernel/power/main.cbecomes more and more difficult to maintain over time, since it contains both the suspend to RAM core code and some common PM code that is also used for hibernation. For this reason [1/2] separates the suspend to RAM code frommain.cand puts it into two new files (the test facility is, again, separated from the core code for clarity).
Quoted 4 lines
[2/2] renames
kernel/power/disk.ctokernel/power/hibernate.c, because the role of this file is analogous tokernel/power/suspend.c(introduced by [1/2]).Comments welcome.
Looks like a good idea to me.
Alan Stern
Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 12 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
Hi,
Here's something I wanted to do quite some time ago.
kernel/power/main.cbecomes more and more difficult to maintain over time, since it contains both the suspend to RAM core code and some common PM code that is also used for hibernation. For this reason [1/2] separates the suspend to RAM code frommain.cand puts it into two new files (the test facility is, again, separated from the core code for clarity).
Quoted 6 lines
Quoted 4 lines
[2/2] renames
kernel/power/disk.ctokernel/power/hibernate.c, because the role of this file is analogous tokernel/power/suspend.c(introduced by [1/2]).Comments welcome.
Looks like a good idea to me.
Great, thanks for your feedback! :-)
BTW, I've been considering the run-time PM a bit recently and the result is below (on top of this series).
I noticed that since resume can be scheduled while suspend is in progress, we need two work structures in struct device, one for suspend and one for resume. Also, in theory, we may want to resume the device before the suspend has a chance to run, so there should be some synchronization between them, which is done with the help of the spinlock in dev_pm_info.
The general idea is that drivers or bus types may use pm_schedule_suspend() to put a suspend request into the work queue and pm_schedule_resume() to queue a resume request or cancel a pending suspend request. There's no requirement to use these functions, but I think they may be helpful in some simple cases.
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
Please have a look.
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 6 + drivers/base/power/runtime.c | 163 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 36 ++++++++- include/linux/pm_runtime.h | 82 +++++++++++++++++++++ kernel/power/Kconfig | 14 +++ kernel/power/main.c | 17 ++++ 7 files changed, 316 insertions(+), 3 deletions(-)
kernel/power/Kconfig +14 -0
@@ -204,3 +204,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 + responsibile 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 +34 -2
@@ -22,6 +22,8 @@#define _LINUX_PM_H#include <linux/list.h> +#include <linux/workqueue.h> +#include <linux/spinlock.h> /* * Callbacks for platform drivers to implement.
@@ -165,6 +167,15 @@ typedef struct pm_message {* It is allowed to unregister devices while the above callbacks are being * executed. However, it is not allowed to unregister a device from within any * of its own callbacks. +* +* There also are two callbacks related to run-time power management of devices: +* +* @autosuspend: Save the device registers and put it into an energy-saving (low +* power) state at run-time, enable wake-up events as appropriate. +* +* @autoresume: Put the device into the full power state and restore its +* registers (if applicable) at run time, in response to a wake-up event +* generated by hardware or at a request of software. */ struct dev_pm_ops {
@@ -182,6 +193,10 @@ struct dev_pm_ops {int (*thaw_noirq)(struct device *dev);int (*poweroff_noirq)(struct device *dev);int (*restore_noirq)(struct device *dev); +#ifdef CONFIG_PM_RUNTIME +int (*autosuspend)(struct device *dev); +int (*autoresume)(struct device *dev); +#endif };/**
@@ -315,14 +330,31 @@ enum dpm_state { DPM_OFF_IRQ, }; +enum rpm_state { +RPM_UNKNOWN =-1 , +RPM_ACTIVE , +RPM_IDLE , +RPM_SUSPENDING , +RPM_SUSPENDED , +}; +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 struct list_head entry;#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; +struct work_struct resume_work; +unsigned int suspend_autocancel:1 ; +unsigned int resume_autocancel:1 ; +unsigned int suspend_aborted:1 ; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };/*
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 +163 -0
163 lines not on this page · raw message
include/linux/pm_runtime.h new file +82 -0
82 lines not on this page · raw message
drivers/base/power/main.c +5 -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
@@ -355,7 +357,7 @@ void dpm_resume_noirq(pm_message_t statestruct device *dev;mutex_lock (&dpm_list_mtx); -list_for_each_entry (dev, &dpm_list, power.entry) +list_for_each_entry (dev, &dpm_list, power.entry) {if (dev->power.status >DPM_OFF ) {int error;
@@ -364,6 +366,8 @@ void dpm_resume_noirq(pm_message_t stateif (error)pm_dev_err (dev, state," early" , error); } +pm_runtime_autocancel (dev); + }mutex_unlock (&dpm_list_mtx);resume_device_irqs (); }
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Review
Quoted 7 lines
+ * Use @work to get the device object the resume has been scheduled for,
+ * check if the device is really suspended and run the ->autoresume() callback + * from the device's bus type driver. Update the run-time PM flags in the + * device object to reflect the current status of the device.
+ */(quoted diff) +2
-0+static void pm_autoresume(struct work_struct *work) +{
Why do you pass it a struct work pointer?
Regards
Oliver
--
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
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Review
Quoted 7 lines
+ * Use @work to get the device object the resume has been scheduled for,
+ * check if the device is really suspended and run the ->autoresume() callback + * from the device's bus type driver. Update the run-time PM flags in the + * device object to reflect the current status of the device.
+ */(quoted diff) +2
-0+static void pm_autoresume(struct work_struct *work) +{
Why do you pass it a struct work pointer?
Regards
Oliver
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
Regards
Oliver
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 7 lines · Oliver Neukum
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
But I need to be able to call __pm_schedule_resume() (at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)
Anyway, below is a version with synchronous resume.
Thanks,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 6 - drivers/base/power/runtime.c | 223 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 36 ++++++ include/linux/pm_runtime.h | 82 +++++++++++++++ kernel/power/Kconfig | 14 ++ kernel/power/main.c | 17 +++ 7 files changed, 376 insertions(+), 3 deletions(-)
kernel/power/Kconfig +14 -0
@@ -204,3 +204,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 + responsibile 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 +34 -2
@@ -22,6 +22,8 @@#define _LINUX_PM_H#include <linux/list.h> +#include <linux/workqueue.h> +#include <linux/spinlock.h> /* * Callbacks for platform drivers to implement.
@@ -165,6 +167,15 @@ typedef struct pm_message {* It is allowed to unregister devices while the above callbacks are being * executed. However, it is not allowed to unregister a device from within any * of its own callbacks. +* +* There also are two callbacks related to run-time power management of devices: +* +* @autosuspend: Save the device registers and put it into an energy-saving (low +* power) state at run-time, enable wake-up events as appropriate. +* +* @autoresume: Put the device into the full power state and restore its +* registers (if applicable) at run time, in response to a wake-up event +* generated by hardware or at a request of software. */ struct dev_pm_ops {
@@ -182,6 +193,10 @@ struct dev_pm_ops {int (*thaw_noirq)(struct device *dev);int (*poweroff_noirq)(struct device *dev);int (*restore_noirq)(struct device *dev); +#ifdef CONFIG_PM_RUNTIME +int (*autosuspend)(struct device *dev); +int (*autoresume)(struct device *dev); +#endif };/**
@@ -315,14 +330,31 @@ enum dpm_state { DPM_OFF_IRQ, }; +enum rpm_state { +RPM_UNKNOWN =-1 , +RPM_ACTIVE , +RPM_IDLE , +RPM_SUSPENDING , +RPM_SUSPENDED , +}; +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 struct list_head entry;#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; +struct work_struct resume_work; +unsigned int suspend_autocancel:1 ; +unsigned int resume_autocancel:1 ; +unsigned int suspend_aborted:1 ; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };/*
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 +223 -0
223 lines not on this page · raw message
include/linux/pm_runtime.h new file +82 -0
82 lines not on this page · raw message
drivers/base/power/main.c +5 -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
@@ -355,7 +357,7 @@ void dpm_resume_noirq(pm_message_t statestruct device *dev;mutex_lock (&dpm_list_mtx); -list_for_each_entry (dev, &dpm_list, power.entry) +list_for_each_entry (dev, &dpm_list, power.entry) {if (dev->power.status >DPM_OFF ) {int error;
@@ -364,6 +366,8 @@ void dpm_resume_noirq(pm_message_t stateif (error)pm_dev_err (dev, state," early" , error); } +pm_runtime_autocancel (dev); + }mutex_unlock (&dpm_list_mtx);resume_device_irqs (); }
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Quoted 3 lines
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)
I see.
Quoted 1 line
Anyway, below is a version with synchronous resume.
You are assuming autosuspend should always be with a delay. Why?
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
Quoted 3 lines
+ *
__pm_schedule_suspend- Schedule run-time suspend of given device.
+ * @dev: Device to suspend.
+ * @delay: Time to wait before attempting to suspend the device.
In which unit of time? If this is to go into kerneldoc that must be specified.
Quoted 2 lines
+ * @autocancel: If set, the request will be cancelled during a resume from
a + * system-wide sleep state if it happens before @delay elapses.
Why is this needed?
Quoted 3 lines
+ */
drivers/base/power/runtime.c new file +2
-0+void __pm_schedule_suspend (struct device *dev,unsigned long delay, +bool autocancel)
[..]
Quoted 7 lines
drivers/base/power/runtime.c new file +5
-0+ +/** +* __pm_schedule_resume - Schedule run-time resume of given device. +* @dev: Device to resume. +* @autocancel: If set, the request will be cancelled during a resume from a + * system-wide sleep state if it happens before
pm_autoresume()can be
run. + */
Eeek! This is a bad idea. You never want to a resume to be cancelled.
Quoted 1 line
+void
__pm_schedule_resume(struct device *dev, bool autocancel)
[..]
Quoted 8 lines
drivers/base/power/runtime.c new file +8
-0+int pm_resume_sync (struct device *dev) +{ +int error =0 ; + +pm_lock_device (dev); +if (dev->power.runtime_status ==RPM_IDLE ) { +/* ->autosuspend() hasn't started yet, no need to resume. */ +pm_cancel_suspend (dev);
drivers/base/power/runtime.c line 167
Quoted 10 lines
drivers/base/power/runtime.c new file +10
-0+ goto out; + } + +if (dev->power.runtime_status ==RPM_SUSPENDING ) { +/* +* The ->autosuspend() callback is being executed right now, +* wait for it to complete. +*/ +pm_unlock_device (dev); +cancel_delayed_work_sync (&dev->power.suspend_work);
That is the most glorious abuse of an API I've seen this year :-)
Regards
Oliver
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 11 lines · Oliver Neukum
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Quoted 3 lines
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)I see.
Quoted 1 line
Anyway, below is a version with synchronous resume.
You are assuming autosuspend should always be with a delay. Why?
I couldn't invent a valid case for doing it without a delay. Perhaps my imagination is constrained too much. ;-)
Quoted 2 lines
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
I didn't think about it to be honest. Obviously this patch doesn't cover all of the possible cases and I'm not even sure it's worth trying to cover them upfront.
Quoted 5 lines
Quoted 3 lines
+ *
__pm_schedule_suspend- Schedule run-time suspend of given device.
+ * @dev: Device to suspend.
+ * @delay: Time to wait before attempting to suspend the device.In which unit of time? If this is to go into kerneldoc that must be specified.
That's in jiifies. Yes, I should have documented it.
Quoted 4 lines
Quoted 2 lines
+ * @autocancel: If set, the request will be cancelled during a resume from
a + * system-wide sleep state if it happens before @delay elapses.Why is this needed?
In some subsystems, like PCI, devices will be resumed by the BIOS unconditionally in the majority of cases and then it's not worth trying to complete run-time PM requests from before the suspend.
Quoted 7 lines
Quoted 3 lines
+ */
drivers/base/power/runtime.c new file +2
-0+void __pm_schedule_suspend (struct device *dev,unsigned long delay, +bool autocancel)[..]
Quoted 9 lines
Quoted 7 lines
drivers/base/power/runtime.c new file +5
-0+ +/** +* __pm_schedule_resume - Schedule run-time resume of given device. +* @dev: Device to resume. +* @autocancel: If set, the request will be cancelled during a resume from a + * system-wide sleep state if it happens before
pm_autoresume()can be
run. + */Eeek! This is a bad idea. You never want to a resume to be cancelled.
Sometimes I do (see above).
Quoted 15 lines
Quoted 1 line
+void
__pm_schedule_resume(struct device *dev, bool autocancel)[..]
Quoted 12 lines
drivers/base/power/runtime.c new file +12
-0+int pm_resume_sync (struct device *dev) +{ +int error =0 ; + +pm_lock_device (dev); +if (dev->power.runtime_status ==RPM_IDLE ) { +/* ->autosuspend() hasn't started yet, no need to resume. */ +pm_cancel_suspend (dev); + goto out; + } + +if (dev->power.runtime_status ==RPM_SUSPENDING ) {
Quoted 8 lines
drivers/base/power/runtime.c line 167
Quoted 6 lines
drivers/base/power/runtime.c new file +6
-0+/* +* The ->autosuspend() callback is being executed right now, +* wait for it to complete. +*/ +pm_unlock_device (dev); +cancel_delayed_work_sync (&dev->power.suspend_work);That is the most glorious abuse of an API I've seen this year :-)
Heh.
OK, what would you do instead?
Rafael
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Montag, 8. Juni 2009 20:34:30 schrieb Rafael J. Wysocki:
Quoted 9 lines · Oliver Neukum
Quoted 4 lines
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
I didn't think about it to be honest. Obviously this patch doesn't cover all of the possible cases and I'm not even sure it's worth trying to cover them upfront.
I am thinking of multimedia cards, which have separate drivers for i2c, tuner and so on.
Quoted 5 lines
Quoted 1 line
Why is this needed?
In some subsystems, like PCI, devices will be resumed by the BIOS unconditionally in the majority of cases and then it's not worth trying to complete run-time PM requests from before the suspend.
But why is it worth canceling them? That feature seems to be an unnecessary complication. As long as you can safely suspend them, why not do it?
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
+/**
+ *__pm_schedule_resume- Schedule run-time resume of given device.
+ * @dev: Device to resume.
+ * @autocancel: If set, the request will be cancelled during a resume from a
+ * system-wide sleep state if it happens beforepm_autoresume()can be run.
+ */Eeek! This is a bad idea. You never want to a resume to be cancelled.
Sometimes I do (see above).
Well no. A driver requests a resume because it has to. This needs a defined call sequence.
Do you guarantee that autoresume follows autosuspend or not?
If not what sequences can happen? Obviously an autosuspended device can be unplugged.
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead of autoresume() being called? A driver has to know that its device has become active without its knowledge.
Quoted 7 lines
Quoted 3 lines
drivers/base/power/runtime.c line 167
Quoted 1 line
drivers/base/power/runtime.c new file +1
-0+cancel_delayed_work_sync (&dev->power.suspend_work);That is the most glorious abuse of an API I've seen this year :-)
Heh.
OK, what would you do instead?
A waitqueue.
Regards
Oliver
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 3 lines · Oliver Neukum
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead of
autoresume()being called? A driver has to know that its device has become active without its knowledge.
That would be a wonderful contradiction in terms. :-)
Alan Stern
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Dienstag, 9. Juni 2009 16:33:12 schrieb Alan Stern:
Quoted 7 lines · Oliver Neukum
Quoted 4 lines
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead of
autoresume()being called? A driver has to know that its device has become active without its knowledge.That would be a wonderful contradiction in terms. :-)
A practical application of the uncertainty principle in quantum computing.
But you have to notify a driver if you notice that a device's power state has been changed without the knowledge of its driver.
Regards
Oliver
--
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
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternAm Dienstag, 9. Juni 2009 16:33:12 schrieb Alan Stern:
Quoted 7 lines · Oliver Neukum
Quoted 4 lines
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead of
autoresume()being called? A driver has to know that its device has become active without its knowledge.That would be a wonderful contradiction in terms. :-)
A practical application of the uncertainty principle in quantum computing.
But you have to notify a driver if you notice that a device's power state has been changed without the knowledge of its driver.
Regards
Oliver
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 3 lines · Oliver Neukum
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead of
autoresume()being called? A driver has to know that its device has become active without its knowledge.
That would be a wonderful contradiction in terms. :-)
Alan Stern
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 7 lines · Oliver Neukum
Am Montag, 8. Juni 2009 20:34:30 schrieb Rafael J. Wysocki:
Quoted 6 lines · Oliver Neukum
Quoted 4 lines
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
Quoted 6 lines
Quoted 3 lines
I didn't think about it to be honest. Obviously this patch doesn't cover all of the possible cases and I'm not even sure it's worth trying to cover them upfront.
I am thinking of multimedia cards, which have separate drivers for i2c, tuner and so on.
Hmm, OK there. But there's only one bus type per device anyway, isn't it? So I'm not sure how a counter can help in this case.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Why is this needed?
In some subsystems, like PCI, devices will be resumed by the BIOS unconditionally in the majority of cases and then it's not worth trying to complete run-time PM requests from before the suspend.
But why is it worth canceling them? That feature seems to be an unnecessary complication. As long as you can safely suspend them, why not do it?
Because that's an operation that need not be necessary. I'd like to avoid unnecessary operations, but you're right, it can be done differently.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+/**
+ *__pm_schedule_resume- Schedule run-time resume of given device.
+ * @dev: Device to resume.
+ * @autocancel: If set, the request will be cancelled during a resume from a
+ * system-wide sleep state if it happens beforepm_autoresume()can be run.
+ */
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Eeek! This is a bad idea. You never want to a resume to be cancelled.
Sometimes I do (see above).
Well no. A driver requests a resume because it has to. This needs a defined call sequence.
Do you guarantee that autoresume follows autosuspend or not?
Not necessarily. If there's an autoresume request pending during STR or STD, the "sleep resume" will do very much the same thing as the autoresume, it will put the device into the full power state. IOW, the "sleep resume" can satisfy an autoresume request, so there should be a mechanism to cancel pending autoresume requests during 'sleep resume'. Still, it may be better if the driver's or bus type's ->resume() does that.
Quoted 5 lines
If not what sequences can happen? Obviously an autosuspended device can be unplugged.
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead ofautoresume()being called? A driver has to know that its device has become active without its knowledge.
Actually, the driver will know what happens to the device anyway, because its ->resume() callback is going to be executed and it has to be synchronized with the ->auto[suspend|resume]() callbacks.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
drivers/base/power/runtime.c line 167
Quoted 1 line
drivers/base/power/runtime.c new file +1
-0+cancel_delayed_work_sync (&dev->power.suspend_work);That is the most glorious abuse of an API I've seen this year :-)
Heh.
OK, what would you do instead?
A waitqueue.
Or perhaps a completion?
OK
I tried to address the majority of your comments in the new version of the patch which I'm going to send in a while in a reply to an Alan's message.
Best,
Rafael
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 7 lines · Oliver Neukum
Am Montag, 8. Juni 2009 20:34:30 schrieb Rafael J. Wysocki:
Quoted 6 lines · Oliver Neukum
Quoted 4 lines
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
Quoted 6 lines
Quoted 3 lines
I didn't think about it to be honest. Obviously this patch doesn't cover all of the possible cases and I'm not even sure it's worth trying to cover them upfront.
I am thinking of multimedia cards, which have separate drivers for i2c, tuner and so on.
Hmm, OK there. But there's only one bus type per device anyway, isn't it? So I'm not sure how a counter can help in this case.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Why is this needed?
In some subsystems, like PCI, devices will be resumed by the BIOS unconditionally in the majority of cases and then it's not worth trying to complete run-time PM requests from before the suspend.
But why is it worth canceling them? That feature seems to be an unnecessary complication. As long as you can safely suspend them, why not do it?
Because that's an operation that need not be necessary. I'd like to avoid unnecessary operations, but you're right, it can be done differently.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+/**
+ *__pm_schedule_resume- Schedule run-time resume of given device.
+ * @dev: Device to resume.
+ * @autocancel: If set, the request will be cancelled during a resume from a
+ * system-wide sleep state if it happens beforepm_autoresume()can be run.
+ */
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Eeek! This is a bad idea. You never want to a resume to be cancelled.
Sometimes I do (see above).
Well no. A driver requests a resume because it has to. This needs a defined call sequence.
Do you guarantee that autoresume follows autosuspend or not?
Not necessarily. If there's an autoresume request pending during STR or STD, the "sleep resume" will do very much the same thing as the autoresume, it will put the device into the full power state. IOW, the "sleep resume" can satisfy an autoresume request, so there should be a mechanism to cancel pending autoresume requests during 'sleep resume'. Still, it may be better if the driver's or bus type's ->resume() does that.
Quoted 5 lines
If not what sequences can happen? Obviously an autosuspended device can be unplugged.
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead ofautoresume()being called? A driver has to know that its device has become active without its knowledge.
Actually, the driver will know what happens to the device anyway, because its ->resume() callback is going to be executed and it has to be synchronized with the ->auto[suspend|resume]() callbacks.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
drivers/base/power/runtime.c line 167
Quoted 1 line
drivers/base/power/runtime.c new file +1
-0+cancel_delayed_work_sync (&dev->power.suspend_work);That is the most glorious abuse of an API I've seen this year :-)
Heh.
OK, what would you do instead?
A waitqueue.
Or perhaps a completion?
OK
I tried to address the majority of your comments in the new version of the patch which I'm going to send in a while in a reply to an Alan's message.
Best,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Montag, 8. Juni 2009 20:34:30 schrieb Rafael J. Wysocki:
Quoted 9 lines · Oliver Neukum
Quoted 4 lines
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
I didn't think about it to be honest. Obviously this patch doesn't cover all of the possible cases and I'm not even sure it's worth trying to cover them upfront.
I am thinking of multimedia cards, which have separate drivers for i2c, tuner and so on.
Quoted 5 lines
Quoted 1 line
Why is this needed?
In some subsystems, like PCI, devices will be resumed by the BIOS unconditionally in the majority of cases and then it's not worth trying to complete run-time PM requests from before the suspend.
But why is it worth canceling them? That feature seems to be an unnecessary complication. As long as you can safely suspend them, why not do it?
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
+/**
+ *__pm_schedule_resume- Schedule run-time resume of given device.
+ * @dev: Device to resume.
+ * @autocancel: If set, the request will be cancelled during a resume from a
+ * system-wide sleep state if it happens beforepm_autoresume()can be run.
+ */Eeek! This is a bad idea. You never want to a resume to be cancelled.
Sometimes I do (see above).
Well no. A driver requests a resume because it has to. This needs a defined call sequence.
Do you guarantee that autoresume follows autosuspend or not?
If not what sequences can happen? Obviously an autosuspended device can be unplugged.
But the problem here is STR or STD. How do you notify drivers that the BIOS has resumed their device instead of autoresume() being called? A driver has to know that its device has become active without its knowledge.
Quoted 7 lines
Quoted 3 lines
drivers/base/power/runtime.c line 167
Quoted 1 line
drivers/base/power/runtime.c new file +1
-0+cancel_delayed_work_sync (&dev->power.suspend_work);That is the most glorious abuse of an API I've seen this year :-)
Heh.
OK, what would you do instead?
A waitqueue.
Regards
Oliver
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 11 lines · Oliver Neukum
Am Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Quoted 3 lines
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)I see.
Quoted 1 line
Anyway, below is a version with synchronous resume.
You are assuming autosuspend should always be with a delay. Why?
I couldn't invent a valid case for doing it without a delay. Perhaps my imagination is constrained too much. ;-)
Quoted 2 lines
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
I didn't think about it to be honest. Obviously this patch doesn't cover all of the possible cases and I'm not even sure it's worth trying to cover them upfront.
Quoted 5 lines
Quoted 3 lines
+ *
__pm_schedule_suspend- Schedule run-time suspend of given device.
+ * @dev: Device to suspend.
+ * @delay: Time to wait before attempting to suspend the device.In which unit of time? If this is to go into kerneldoc that must be specified.
That's in jiifies. Yes, I should have documented it.
Quoted 4 lines
Quoted 2 lines
+ * @autocancel: If set, the request will be cancelled during a resume from
a + * system-wide sleep state if it happens before @delay elapses.Why is this needed?
In some subsystems, like PCI, devices will be resumed by the BIOS unconditionally in the majority of cases and then it's not worth trying to complete run-time PM requests from before the suspend.
Quoted 7 lines
Quoted 3 lines
+ */
drivers/base/power/runtime.c new file +2
-0+void __pm_schedule_suspend (struct device *dev,unsigned long delay, +bool autocancel)[..]
Quoted 9 lines
Quoted 7 lines
drivers/base/power/runtime.c new file +5
-0+ +/** +* __pm_schedule_resume - Schedule run-time resume of given device. +* @dev: Device to resume. +* @autocancel: If set, the request will be cancelled during a resume from a + * system-wide sleep state if it happens before
pm_autoresume()can be
run. + */Eeek! This is a bad idea. You never want to a resume to be cancelled.
Sometimes I do (see above).
Quoted 15 lines
Quoted 1 line
+void
__pm_schedule_resume(struct device *dev, bool autocancel)[..]
Quoted 12 lines
drivers/base/power/runtime.c new file +12
-0+int pm_resume_sync (struct device *dev) +{ +int error =0 ; + +pm_lock_device (dev); +if (dev->power.runtime_status ==RPM_IDLE ) { +/* ->autosuspend() hasn't started yet, no need to resume. */ +pm_cancel_suspend (dev); + goto out; + } + +if (dev->power.runtime_status ==RPM_SUSPENDING ) {
Quoted 8 lines
drivers/base/power/runtime.c line 167
Quoted 6 lines
drivers/base/power/runtime.c new file +6
-0+/* +* The ->autosuspend() callback is being executed right now, +* wait for it to complete. +*/ +pm_unlock_device (dev); +cancel_delayed_work_sync (&dev->power.suspend_work);That is the most glorious abuse of an API I've seen this year :-)
Heh.
OK, what would you do instead?
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Montag, 8. Juni 2009 13:29:26 schrieb Rafael J. Wysocki:
Quoted 3 lines
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)
I see.
Quoted 1 line
Anyway, below is a version with synchronous resume.
You are assuming autosuspend should always be with a delay. Why?
Secondly, you are not using a counter. Therefore only one driver can control the PM state of a device at a given time. Is that wise?
Quoted 3 lines
+ *
__pm_schedule_suspend- Schedule run-time suspend of given device.
+ * @dev: Device to suspend.
+ * @delay: Time to wait before attempting to suspend the device.
In which unit of time? If this is to go into kerneldoc that must be specified.
Quoted 2 lines
+ * @autocancel: If set, the request will be cancelled during a resume from
a + * system-wide sleep state if it happens before @delay elapses.
Why is this needed?
Quoted 3 lines
+ */
drivers/base/power/runtime.c new file +2
-0+void __pm_schedule_suspend (struct device *dev,unsigned long delay, +bool autocancel)
[..]
Quoted 7 lines
drivers/base/power/runtime.c new file +5
-0+ +/** +* __pm_schedule_resume - Schedule run-time resume of given device. +* @dev: Device to resume. +* @autocancel: If set, the request will be cancelled during a resume from a + * system-wide sleep state if it happens before
pm_autoresume()can be
run. + */
Eeek! This is a bad idea. You never want to a resume to be cancelled.
Quoted 1 line
+void
__pm_schedule_resume(struct device *dev, bool autocancel)
[..]
Quoted 8 lines
drivers/base/power/runtime.c new file +8
-0+int pm_resume_sync (struct device *dev) +{ +int error =0 ; + +pm_lock_device (dev); +if (dev->power.runtime_status ==RPM_IDLE ) { +/* ->autosuspend() hasn't started yet, no need to resume. */ +pm_cancel_suspend (dev);
drivers/base/power/runtime.c line 167
Quoted 10 lines
drivers/base/power/runtime.c new file +10
-0+ goto out; + } + +if (dev->power.runtime_status ==RPM_SUSPENDING ) { +/* +* The ->autosuspend() callback is being executed right now, +* wait for it to complete. +*/ +pm_unlock_device (dev); +cancel_delayed_work_sync (&dev->power.suspend_work);
That is the most glorious abuse of an API I've seen this year :-)
Regards
Oliver
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Oliver Neukum
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
Quoted 8 lines
Quoted 3 lines
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)Anyway, below is a version with synchronous resume.
There are a few things here which need further thought:
The implementation of pm_lock_device() assumes it will never be called with interrupts disabled. This is a bad assumption.
Use of the RPM_UNKNOWN state isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent. Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this? What about device's whose parent belongs to a different subsystem?
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That's what I come up with on a first reading. There may be more later on... :-)
Alan Stern
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 14 lines · Alan Stern
Quoted 12 lines · Rafael J. Wysocki
Quoted 7 lines · Oliver Neukum
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)
Quoted 6 lines
Quoted 1 line
Anyway, below is a version with synchronous resume.
There are a few things here which need further thought:
The implementation of
pm_lock_device()assumes it will never be called with interrupts disabled. This is a bad assumption.
Indeed.
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.
I'm not sure what you mean exactly.
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
The name of this constant may be confusing, but I didn't have any better ideas.
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Quoted 3 lines
Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this?
Yes, that was the idea.
Quoted 1 line
What about device's whose parent belongs to a different subsystem?
Good question. :-)
I think that requires some research. Probably a USB device attached to a PCI USB controller is a good example here, but we first need to have a prototype implementation for PCI to carry out some testing.
In fact I'd like to avoid the complexity for now and consider one bus type at a time. Especially that, for example, for PCI we won't autosuspend bridges initially, so this case is going to be really simple.
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.
Anyway, that will be the next step.
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
Quoted 2 lines
That's what I come up with on a first reading. There may be more later on... :-)
Sure.
Thanks for your comments! :-)
Best,
Rafael
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 10 lines · Rafael J. Wysocki
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.I'm not sure what you mean exactly.
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
But no matter what the driver or bus type sets the state to, your pm_autosuspend() will change it to one of RPM_UNKNOWN or RPM_SUSPENDED. Neither might be right.
Quoted 1 line
The name of this constant may be confusing, but I didn't have any better ideas.
It's not clear what RPM_ACTIVE, RPM_IDLE, and RPM_SUSPENDED are supposed to mean; this should be documented in the code. Also, why isn't there RPM_RESUMING?
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Shouldn't this happen after the device's state has changed to RPM_SUSPENDED? That's not until after the callback returns.
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.
I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
Quoted 10 lines
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
Quoted 6 lines
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
This too should be documented in the code. Or in a Documentation file.
Alan Stern
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 8 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.I'm not sure what you mean exactly.
Quoted 8 lines
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
But no matter what the driver or bus type sets the state to, your
pm_autosuspend()will change it to one ofRPM_UNKNOWNorRPM_SUSPENDED. Neither might be right.
The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
Quoted 5 lines
Quoted 1 line
The name of this constant may be confusing, but I didn't have any better ideas.
It's not clear what
RPM_ACTIVE,RPM_IDLE, andRPM_SUSPENDEDare supposed to mean; this should be documented in the code. Also, why isn't thereRPM_RESUMING?
Yes, there should be. In fact it's in the current version of the patch, which is appended. Also, there's a comment explaining the meaning of the RPM_* constants in pm.h .
Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Shouldn't this happen after the device's state has changed to
RPM_SUSPENDED? That's not until after the callback returns.
OK, I tried to address the issue of parent suspend/resume in the new version of the patch below (I'm not sure if I did the nesting of spinlocks in pm_request_resume() correctly).
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
Quoted 8 lines
Quoted 6 lines
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
This too should be documented in the code. Or in a Documentation file.
OK
I tried to address your comments and the Oliver's comments too in the new version of the patch below. Please have a look and tell me what you think.
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 2 drivers/base/power/runtime.c | 318 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 76 ++++++++++ include/linux/pm_runtime.h | 50 ++++++ kernel/power/Kconfig | 14 + kernel/power/main.c | 17 ++ 7 files changed, 476 insertions(+), 2 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 + responsibile 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 +74 -2
106 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 +318 -0
318 lines not on this page · raw message
include/linux/pm_runtime.h new file +50 -0
50 lines not on this page · raw message
drivers/base/power/main.c +2 -0
@@ -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 8 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.I'm not sure what you mean exactly.
Quoted 8 lines
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
But no matter what the driver or bus type sets the state to, your
pm_autosuspend()will change it to one ofRPM_UNKNOWNorRPM_SUSPENDED. Neither might be right.
The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
Quoted 5 lines
Quoted 1 line
The name of this constant may be confusing, but I didn't have any better ideas.
It's not clear what
RPM_ACTIVE,RPM_IDLE, andRPM_SUSPENDEDare supposed to mean; this should be documented in the code. Also, why isn't thereRPM_RESUMING?
Yes, there should be. In fact it's in the current version of the patch, which is appended. Also, there's a comment explaining the meaning of the RPM_* constants in pm.h .
Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Shouldn't this happen after the device's state has changed to
RPM_SUSPENDED? That's not until after the callback returns.
OK, I tried to address the issue of parent suspend/resume in the new version of the patch below (I'm not sure if I did the nesting of spinlocks in pm_request_resume() correctly).
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
Quoted 8 lines
Quoted 6 lines
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
This too should be documented in the code. Or in a Documentation file.
OK
I tried to address your comments and the Oliver's comments too in the new version of the patch below. Please have a look and tell me what you think.
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 2 drivers/base/power/runtime.c | 318 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 76 ++++++++++ include/linux/pm_runtime.h | 50 ++++++ kernel/power/Kconfig | 14 + kernel/power/main.c | 17 ++ 7 files changed, 476 insertions(+), 2 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 + responsibile 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 +74 -2
106 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 +318 -0
318 lines not on this page · raw message
include/linux/pm_runtime.h new file +50 -0
50 lines not on this page · raw message
drivers/base/power/main.c +2 -0
@@ -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
[patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 86 lines · Rafael J. Wysocki
Quoted 8 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.I'm not sure what you mean exactly.
Quoted 8 lines
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
But no matter what the driver or bus type sets the state to, your
pm_autosuspend()will change it to one ofRPM_UNKNOWNorRPM_SUSPENDED. Neither might be right.The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
Quoted 5 lines
Quoted 1 line
The name of this constant may be confusing, but I didn't have any better ideas.
It's not clear what
RPM_ACTIVE,RPM_IDLE, andRPM_SUSPENDEDare supposed to mean; this should be documented in the code. Also, why isn't thereRPM_RESUMING?Yes, there should be. In fact it's in the current version of the patch, which is appended. Also, there's a comment explaining the meaning of the RPM_* constants in
pm.h.Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Shouldn't this happen after the device's state has changed to
RPM_SUSPENDED? That's not until after the callback returns.OK, I tried to address the issue of parent suspend/resume in the new version of the patch below (I'm not sure if I did the nesting of spinlocks in
pm_request_resume()correctly).Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
Quoted 17 lines
Quoted 16 lines
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
Quoted 6 lines
Quoted 1 line
This too should be documented in the code. Or in a Documentation file.
OK
I tried to address your comments and the Oliver's comments too in the new version of the patch below. Please have a look and tell me what you think.
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use -EAGAIN and -EBUSY for this purpose.
Updated patch follows, sorry for the confusion.
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 2 drivers/base/power/runtime.c | 393 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 78 ++++++++ include/linux/pm_runtime.h | 50 +++++ kernel/power/Kconfig | 14 + kernel/power/main.c | 17 + 7 files changed, 553 insertions(+), 2 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 + responsibile 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 +76 -2
108 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 +393 -0
393 lines not on this page · raw message
include/linux/pm_runtime.h new file +50 -0
50 lines not on this page · raw message
drivers/base/power/main.c +2 -0
@@ -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Mittwoch, 10. Juni 2009 10:29:26 schrieb Rafael J. Wysocki:
Quoted 7 lines
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 11 lines · Oliver Neukum
Am Mittwoch, 10. Juni 2009 10:29:26 schrieb Rafael J. Wysocki:
Quoted 7 lines
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Hmm, I thought I did.
[Looks]
pm_request_resume(dev) will call pm_request_resume(dev->parent), if necessary, and that will call pm_request_resume(dev->parent->parent) and so on. Each of them will queue a work item and the one for the topmost parent will be queued first. So, the resume requests for all parents will be executed before the one for the device, due to the fact that the workqueue is singlethread.
Well, there is a bug related to it, namely pm_autosuspend() may change the status to RPM_SUSPENDED after pm_request_resume() has changed it to RPM_WAKE, that needs fixing.
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 11 lines · Oliver Neukum
Am Mittwoch, 10. Juni 2009 10:29:26 schrieb Rafael J. Wysocki:
Quoted 7 lines
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Hmm, I thought I did.
[Looks]
pm_request_resume(dev) will call pm_request_resume(dev->parent), if necessary, and that will call pm_request_resume(dev->parent->parent) and so on. Each of them will queue a work item and the one for the topmost parent will be queued first. So, the resume requests for all parents will be executed before the one for the device, due to the fact that the workqueue is singlethread.
Well, there is a bug related to it, namely pm_autosuspend() may change the status to RPM_SUSPENDED after pm_request_resume() has changed it to RPM_WAKE, that needs fixing.
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Mittwoch, 10. Juni 2009 21:27:56 schrieb Rafael J. Wysocki:
Quoted 5 lines
Quoted 2 lines
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Hmm, I thought I did.
Quoted 8 lines
[Looks]
pm_request_resume(dev)will callpm_request_resume(dev->parent), if necessary, and that will callpm_request_resume(dev->parent->parent)and so on. Each of them will queue a work item and the one for the topmost parent will be queued first. So, the resume requests for all parents will be executed before the one for the device, due to the fact that the workqueue is singlethread.
Sneaky, I overlooked that.
Quoted 3 lines
Well, there is a bug related to it, namely
pm_autosuspend()may change the status toRPM_SUSPENDEDafterpm_request_resume()has changed it toRPM_WAKE, that needs fixing.
Ok, maybe this is related. You recurse if the parent isn't in RPM_ACTIVE. But that is not enough. You must ensure that all the nodes higher up stay in RPM_ACTIVE. It seems to me that you must go up until you find an active node (or the root) and put it a blocked state.
Regards
Oliver
--
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 17 lines · Oliver Neukum
Am Mittwoch, 10. Juni 2009 21:27:56 schrieb Rafael J. Wysocki:
Quoted 5 lines
Quoted 2 lines
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Hmm, I thought I did.
Quoted 8 lines
[Looks]
pm_request_resume(dev)will callpm_request_resume(dev->parent), if necessary, and that will callpm_request_resume(dev->parent->parent)and so on. Each of them will queue a work item and the one for the topmost parent will be queued first. So, the resume requests for all parents will be executed before the one for the device, due to the fact that the workqueue is singlethread.Sneaky, I overlooked that.
Quoted 8 lines
Quoted 3 lines
Well, there is a bug related to it, namely
pm_autosuspend()may change the status toRPM_SUSPENDEDafterpm_request_resume()has changed it toRPM_WAKE, that needs fixing.Ok, maybe this is related. You recurse if the parent isn't in
RPM_ACTIVE. But that is not enough. You must ensure that all the nodes higher up stay inRPM_ACTIVE. It seems to me that you must go up until you find an active node (or the root) and put it a blocked state.
If you're referring to pm_autoresume(), then this again is tricky.
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so pm_autoresume() is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent is RPM_ACTIVE. *However*, there also is pm_resume_sync(), which can take the device directly from RPM_SUSPENDED to RPM_RESUMING and that may be done in parallel with our pm_autoresume(). That's why I put the wait_for_completion() in there.
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.
A (IDLE)
/ \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
+ && (dev->parent->power.runtime_status == RPM_IDLE
+ || dev->parent->power.runtime_status == RPM_SUSPENDING
+ || dev->parent->power.runtime_status == RPM_SUSPENDED)) {+ spin_unlock_irqrestore(&dev->power.lock, flags);
+ spin_unlock_irqrestore(&dev->parent->power.lock, parent_flags);
+
+ /* We have to resume the parent first. */
+ pm_request_resume(dev->parent);
But after pm_request_resume() returns there's no means to make sure nothing alters it back to RPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still in RPM_SUSPENDED.
Regards
Oliver
--
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 23 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.A (IDLE) / \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
drivers/base/power/runtime.c new file +8
-0+ && (dev->parent->power.runtime_status == RPM_IDLE + || dev->parent->power.runtime_status == RPM_SUSPENDING + || dev->parent->power.runtime_status == RPM_SUSPENDED)) { +spin_unlock_irqrestore (&dev->power.lock, flags); +spin_unlock_irqrestore (&dev->parent->power.lock, parent_flags); + +/* We have to resume the parent first. */ +pm_request_resume (dev->parent);
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.
This is an example where usage counters come in handy.
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 25 lines · Alan Stern
Quoted 23 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.A (IDLE) / \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
(quoted diff) +8
-0+ && (dev->parent->power.runtime_status == RPM_IDLE + || dev->parent->power.runtime_status == RPM_SUSPENDING + || dev->parent->power.runtime_status == RPM_SUSPENDED)) { + spin_unlock_irqrestore(&dev->power.lock, flags); + spin_unlock_irqrestore(&dev->parent->power.lock, parent_flags); + + /* We have to resume the parent first. */ + pm_request_resume(dev->parent);
Quoted 6 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.This is an example where usage counters come in handy.
Do you mean we can count suspend/resume requests for a device?
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Donnerstag, 11. Juni 2009 15:48:33 schrieb Rafael J. Wysocki:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.This is an example where usage counters come in handy.
Do you mean we can count suspend/resume requests for a device?
No, we count reasons a device cannot be suspended. Drivers are allowed to add their own reasons. The core uses that mechanism to indicate that an ongoing resumption lower down is also a reason.
The count going to zero is equivalent to a request to suspend.
Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 6 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 15:48:33 schrieb Rafael J. Wysocki:
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This is an example where usage counters come in handy.
Do you mean we can count suspend/resume requests for a device?
No, we count reasons a device cannot be suspended. Drivers are allowed to add their own reasons. The core uses that mechanism to indicate that an ongoing resumption lower down is also a reason.
The count going to zero is equivalent to a request to suspend.
Right.
Here's a related thought. Change the resume routines as follows:
void pm_runtime_resume(struct device *dev)
{
// Do the actual resume ...
}EXPORT_SYMBOL_GPL(pm_runtime_resume);
static void pm_runtime_resume_work(struct work_struct *work)
{
pm_runtime_resume(resume_work_to_device(work));
}Then there's no need for a separate pm_resume_sync(); drivers can simply call pm_runtime_resume() directly. The same trick works for suspending.
Of course, this means you have to give up the notion that all suspends and resumes are funnelled through the workqueue. IMO that notion isn't worth keeping in any case.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 10 lines · Alan Stern
Quoted 8 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 15:48:33 schrieb Rafael J. Wysocki:
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.This is an example where usage counters come in handy.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Do you mean we can count suspend/resume requests for a device?
No, we count reasons a device cannot be suspended. Drivers are allowed to add their own reasons. The core uses that mechanism to indicate that an ongoing resumption lower down is also a reason.
The count going to zero is equivalent to a request to suspend.Right.
Ah. *That* is what you had in mind. Yes, we can do that.
Quoted 13 lines
Here's a related thought. Change the resume routines as follows:
void
pm_runtime_resume(struct device *dev)
{
// Do the actual resume ...
}EXPORT_SYMBOL_GPL(pm_runtime_resume);static void
pm_runtime_resume_work(struct work_struct *work){ pm_runtime_resume(resume_work_to_device(work)); }
Quoted 7 lines
Then there's no need for a separate
pm_resume_sync(); drivers can simply callpm_runtime_resume()directly. The same trick works for suspending.Of course, this means you have to give up the notion that all suspends and resumes are funnelled through the workqueue. IMO that notion isn't worth keeping in any case.
That's already not the case for resuming.
Well, ISTR a reason why I thought pm_resume_sync() was needed anyway, but the idea is actually good.
Thanks,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 10 lines · Alan Stern
Quoted 8 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 15:48:33 schrieb Rafael J. Wysocki:
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.This is an example where usage counters come in handy.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Do you mean we can count suspend/resume requests for a device?
No, we count reasons a device cannot be suspended. Drivers are allowed to add their own reasons. The core uses that mechanism to indicate that an ongoing resumption lower down is also a reason.
The count going to zero is equivalent to a request to suspend.Right.
Ah. *That* is what you had in mind. Yes, we can do that.
Quoted 13 lines
Here's a related thought. Change the resume routines as follows:
void
pm_runtime_resume(struct device *dev)
{
// Do the actual resume ...
}EXPORT_SYMBOL_GPL(pm_runtime_resume);static void
pm_runtime_resume_work(struct work_struct *work){ pm_runtime_resume(resume_work_to_device(work)); }
Quoted 7 lines
Then there's no need for a separate
pm_resume_sync(); drivers can simply callpm_runtime_resume()directly. The same trick works for suspending.Of course, this means you have to give up the notion that all suspends and resumes are funnelled through the workqueue. IMO that notion isn't worth keeping in any case.
That's already not the case for resuming.
Well, ISTR a reason why I thought pm_resume_sync() was needed anyway, but the idea is actually good.
Thanks,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 6 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 15:48:33 schrieb Rafael J. Wysocki:
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This is an example where usage counters come in handy.
Do you mean we can count suspend/resume requests for a device?
No, we count reasons a device cannot be suspended. Drivers are allowed to add their own reasons. The core uses that mechanism to indicate that an ongoing resumption lower down is also a reason.
The count going to zero is equivalent to a request to suspend.
Right.
Here's a related thought. Change the resume routines as follows:
void pm_runtime_resume(struct device *dev)
{
// Do the actual resume ...
}EXPORT_SYMBOL_GPL(pm_runtime_resume);
static void pm_runtime_resume_work(struct work_struct *work)
{
pm_runtime_resume(resume_work_to_device(work));
}Then there's no need for a separate pm_resume_sync(); drivers can simply call pm_runtime_resume() directly. The same trick works for suspending.
Of course, this means you have to give up the notion that all suspends and resumes are funnelled through the workqueue. IMO that notion isn't worth keeping in any case.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Donnerstag, 11. Juni 2009 15:48:33 schrieb Rafael J. Wysocki:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.This is an example where usage counters come in handy.
Do you mean we can count suspend/resume requests for a device?
No, we count reasons a device cannot be suspended. Drivers are allowed to add their own reasons. The core uses that mechanism to indicate that an ongoing resumption lower down is also a reason.
The count going to zero is equivalent to a request to suspend.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 25 lines · Alan Stern
Quoted 23 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.A (IDLE) / \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
(quoted diff) +8
-0+ && (dev->parent->power.runtime_status == RPM_IDLE + || dev->parent->power.runtime_status == RPM_SUSPENDING + || dev->parent->power.runtime_status == RPM_SUSPENDED)) { + spin_unlock_irqrestore(&dev->power.lock, flags); + spin_unlock_irqrestore(&dev->parent->power.lock, parent_flags); + + /* We have to resume the parent first. */ + pm_request_resume(dev->parent);
Quoted 6 lines
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.This is an example where usage counters come in handy.
Do you mean we can count suspend/resume requests for a device?
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 23 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.A (IDLE) / \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
drivers/base/power/runtime.c new file +8
-0+ && (dev->parent->power.runtime_status == RPM_IDLE + || dev->parent->power.runtime_status == RPM_SUSPENDING + || dev->parent->power.runtime_status == RPM_SUSPENDED)) { +spin_unlock_irqrestore (&dev->power.lock, flags); +spin_unlock_irqrestore (&dev->parent->power.lock, parent_flags); + +/* We have to resume the parent first. */ +pm_request_resume (dev->parent);
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.
This is an example where usage counters come in handy.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 23 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.A (IDLE) / \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
(quoted diff) +8
-0+ && (dev->parent->power.runtime_status == RPM_IDLE + || dev->parent->power.runtime_status == RPM_SUSPENDING + || dev->parent->power.runtime_status == RPM_SUSPENDED)) { + spin_unlock_irqrestore(&dev->power.lock, flags); + spin_unlock_irqrestore(&dev->parent->power.lock, parent_flags); + + /* We have to resume the parent first. */ + pm_request_resume(dev->parent);
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.
That exactly is the bug I told you about in one of the previous messages. :-)
The solution I used in the current version of the patch (appended) is to have separate bits for RPM_WAKE and RPM_SUSPENDED (and for the other status constants), so that they both can be set at a time.
Well, there probably still are some bugs lurking in it ...
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 2 drivers/base/power/runtime.c | 415 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 82 ++++++++ include/linux/pm_runtime.h | 50 +++++ kernel/power/Kconfig | 14 + kernel/power/main.c | 17 + 7 files changed, 578 insertions(+), 3 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 + responsibile 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 +79 -3
111 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 +415 -0
415 lines not on this page · raw message
include/linux/pm_runtime.h new file +50 -0
50 lines not on this page · raw message
drivers/base/power/main.c +2 -0
@@ -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 23 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.A (IDLE) / \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
(quoted diff) +8
-0+ && (dev->parent->power.runtime_status == RPM_IDLE + || dev->parent->power.runtime_status == RPM_SUSPENDING + || dev->parent->power.runtime_status == RPM_SUSPENDED)) { + spin_unlock_irqrestore(&dev->power.lock, flags); + spin_unlock_irqrestore(&dev->parent->power.lock, parent_flags); + + /* We have to resume the parent first. */ + pm_request_resume(dev->parent);
Quoted 4 lines
But after
pm_request_resume()returns there's no means to make sure nothing alters it back toRPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still inRPM_SUSPENDED.
That exactly is the bug I told you about in one of the previous messages. :-)
The solution I used in the current version of the patch (appended) is to have separate bits for RPM_WAKE and RPM_SUSPENDED (and for the other status constants), so that they both can be set at a time.
Well, there probably still are some bugs lurking in it ...
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 2 drivers/base/power/runtime.c | 415 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 82 ++++++++ include/linux/pm_runtime.h | 50 +++++ kernel/power/Kconfig | 14 + kernel/power/main.c | 17 + 7 files changed, 578 insertions(+), 3 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 + responsibile 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 +79 -3
111 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 +415 -0
415 lines not on this page · raw message
include/linux/pm_runtime.h new file +50 -0
50 lines not on this page · raw message
drivers/base/power/main.c +2 -0
@@ -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Donnerstag, 11. Juni 2009 00:01:20 schrieb Rafael J. Wysocki:
Quoted 5 lines
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so
pm_autoresume()is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent isRPM_ACTIVE.
A (IDLE)
/ \B (SUSPENDED) C (SUSPENDED)
Suppose C is to be resumed. This means first in case of A the request to suspend would be cancelled. Here you drop the locks:
+ && (dev->parent->power.runtime_status == RPM_IDLE
+ || dev->parent->power.runtime_status == RPM_SUSPENDING
+ || dev->parent->power.runtime_status == RPM_SUSPENDED)) {+ spin_unlock_irqrestore(&dev->power.lock, flags);
+ spin_unlock_irqrestore(&dev->parent->power.lock, parent_flags);
+
+ /* We have to resume the parent first. */
+ pm_request_resume(dev->parent);
But after pm_request_resume() returns there's no means to make sure nothing alters it back to RPM_SUSPENDED. The workqueue doesn't help you because you've scheduled nothing by that time. The suspension will work because C is still in RPM_SUSPENDED.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 17 lines · Oliver Neukum
Am Mittwoch, 10. Juni 2009 21:27:56 schrieb Rafael J. Wysocki:
Quoted 5 lines
Quoted 2 lines
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Hmm, I thought I did.
Quoted 8 lines
[Looks]
pm_request_resume(dev)will callpm_request_resume(dev->parent), if necessary, and that will callpm_request_resume(dev->parent->parent)and so on. Each of them will queue a work item and the one for the topmost parent will be queued first. So, the resume requests for all parents will be executed before the one for the device, due to the fact that the workqueue is singlethread.Sneaky, I overlooked that.
Quoted 8 lines
Quoted 3 lines
Well, there is a bug related to it, namely
pm_autosuspend()may change the status toRPM_SUSPENDEDafterpm_request_resume()has changed it toRPM_WAKE, that needs fixing.Ok, maybe this is related. You recurse if the parent isn't in
RPM_ACTIVE. But that is not enough. You must ensure that all the nodes higher up stay inRPM_ACTIVE. It seems to me that you must go up until you find an active node (or the root) and put it a blocked state.
If you're referring to pm_autoresume(), then this again is tricky.
We have queued up resume requests for the device's parent, its parent etc., the topmost one goes first. The workqueue is singlethread, so pm_autoresume() is going to be run for all parents before the device itself, so if that were the only resume mechanism, it would be enough to check if the parent is RPM_ACTIVE. *However*, there also is pm_resume_sync(), which can take the device directly from RPM_SUSPENDED to RPM_RESUMING and that may be done in parallel with our pm_autoresume(). That's why I put the wait_for_completion() in there.
Best,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Mittwoch, 10. Juni 2009 21:27:56 schrieb Rafael J. Wysocki:
Quoted 5 lines
Quoted 2 lines
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Hmm, I thought I did.
Quoted 8 lines
[Looks]
pm_request_resume(dev)will callpm_request_resume(dev->parent), if necessary, and that will callpm_request_resume(dev->parent->parent)and so on. Each of them will queue a work item and the one for the topmost parent will be queued first. So, the resume requests for all parents will be executed before the one for the device, due to the fact that the workqueue is singlethread.
Sneaky, I overlooked that.
Quoted 3 lines
Well, there is a bug related to it, namely
pm_autosuspend()may change the status toRPM_SUSPENDEDafterpm_request_resume()has changed it toRPM_WAKE, that needs fixing.
Ok, maybe this is related. You recurse if the parent isn't in RPM_ACTIVE. But that is not enough. You must ensure that all the nodes higher up stay in RPM_ACTIVE. It seems to me that you must go up until you find an active node (or the root) and put it a blocked state.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Mittwoch, 10. Juni 2009 10:29:26 schrieb Rafael J. Wysocki:
Quoted 7 lines
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
What happens if the parent's parent is also suspended? It seems to me that you must code this recursively.
Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 5 lines
The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
I'm still not sure this is a good idea. When would the device driver clear the status? The autosuspend and autoresume methods run asynchronously, so after they're done the driver doesn't get a chance to do anything.
It might be best just to set the status to RPM_ACTIVE if a runtime suspend fails and RPM_SUSPENDED if a runtime resume fails.
Quoted 4 lines
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use
-EAGAINand-EBUSYfor this purpose.
Maybe...
Quoted 9 lines
struct
dev_pm_info{include/linux/pm.h +2
-2pm_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 struct list_head entry;
include/linux/pm.h enum dpm_state { · line 400
Quoted 10 lines
include/linux/pm.h +8
-0#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; + unsigned int suspend_aborted:1; +struct work_struct resume_work; +struct completion work_done; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };
You know, it doesn't make any sense to have a suspend and a resume both pending at the same time. So you could add only a delayed_work structure and use its embedded work_struct for resume requests.
Also, you might borrow a trick from Dave Brownell. Define the RPM_* values so that the individual bits have meanings. Then instead of testing for multiple possible values of runtime_status, you could do a simple bit test.
Quoted 6 lines
drivers/base/power/runtime.c new file +6
-0+/** +* pm_device_suspended - Check if given device has been suspended at run time. +* @dev: Device to check. +* @data: Ignored. +* +* Returns 0 if the device has been suspended or -EBUSY otherwise.
drivers/base/power/runtime.c line 36
Quoted 10 lines
drivers/base/power/runtime.c new file +10
-0+*/ +static int pm_device_suspended (struct device *dev,void *data) +{ +int ret; + +spin_lock (&dev->power.lock); + + ret = dev->power.runtime_status ==RPM_SUSPENDED ?0 : -EBUSY ; + +spin_unlock (&dev->power.lock);
How does acquiring the lock help here?
Quoted 7 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended.
+ * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended or-EBUSY
+ * otherwise.
+ */
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
drivers/base/power/runtime.c line 63
Quoted 11 lines
drivers/base/power/runtime.c new file +11
-0+/** +* pm_autosuspend - Run autosuspend callback of given device object's bus type. +* @work: Work structure used for scheduling the execution of this function. +* +* Use @work to get the device object the suspend has been scheduled for, +* check if the suspend request hasn't been cancelled and run the +* ->autosuspend() callback from the device's bus type driver. Update the +* run-time PM flags in the device object to reflect the current status of the +* device. +*/ +static void pm_autosuspend (struct work_struct *work)
Can we call this something else? "Autosuspend" implies that the suspend originated from within the kernel. How about "pm_suspend_work" or "pm_runtime_suspend"? Likewise for the resume routines.
I haven't checked the details of the code yet. More later...
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 47 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki
Quoted 5 lines
The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
I'm still not sure this is a good idea. When would the device driver clear the status? The autosuspend and autoresume methods run asynchronously, so after they're done the driver doesn't get a chance to do anything.
It might be best just to set the status to
RPM_ACTIVEif a runtime suspend fails andRPM_SUSPENDEDif a runtime resume fails.Quoted 4 lines
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use
-EAGAINand-EBUSYfor this purpose.Maybe...
Quoted 9 lines
struct
dev_pm_info{include/linux/pm.h +2
-2pm_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 struct list_head entry;include/linux/pm.h enum dpm_state { · line 400
Quoted 10 lines
include/linux/pm.h +8
-0#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; + unsigned int suspend_aborted:1; +struct work_struct resume_work; +struct completion work_done; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };You know, it doesn't make any sense to have a suspend and a resume both pending at the same time.
Quoted 2 lines
So you could add only a
delayed_workstructure and use its embeddedwork_structfor resume requests.
I thought so too, but I was wrong. ;-)
If resume is requested while the suspend hasn't completed yet, we should queue it (it's totally valid to request a suspending device to resume IMO), but the delayed work is still being used by the workqueue code, so we can't modify it.
Quoted 4 lines
Also, you might borrow a trick from Dave Brownell. Define the RPM_* values so that the individual bits have meanings. Then instead of testing for multiple possible values of
runtime_status, you could do a simple bit test.
Yes, I'm seriously considering using this approach.
Quoted 10 lines
Quoted 10 lines
drivers/base/power/runtime.c new file +10
-0+/** +* pm_device_suspended - Check if given device has been suspended at run time. +* @dev: Device to check. +* @data: Ignored. +* +* Returns 0 if the device has been suspended or -EBUSY otherwise. +*/ +static int pm_device_suspended (struct device *dev,void *data) +{ +int ret;
Quoted 8 lines
drivers/base/power/runtime.c line 36
Quoted 6 lines
drivers/base/power/runtime.c new file +6
-0+ +spin_lock (&dev->power.lock); + + ret = dev->power.runtime_status ==RPM_SUSPENDED ?0 : -EBUSY ; + +spin_unlock (&dev->power.lock);How does acquiring the lock help here?
OK, it doesn't.
Quoted 8 lines
Quoted 7 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended.
+ * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended or-EBUSY
+ * otherwise.
+ */
Quoted 5 lines
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
Quoted 7 lines
Quoted 7 lines
+/**
+ *pm_autosuspend- Run autosuspend callback of given device object's bus type.
+ * @work: Work structure used for scheduling the execution of this function.
+ *
+ * Use @work to get the device object the suspend has been scheduled for,
+ * check if the suspend request hasn't been cancelled and run the
+ * ->autosuspend() callback from the device's bus type driver. Update the
Quoted 8 lines
Quoted 4 lines
+ * run-time PM flags in the device object to reflect the current status of the
+ * device.
+ */
+static voidpm_autosuspend(struct work_struct *work)Can we call this something else? "Autosuspend" implies that the suspend originated from within the kernel. How about "
pm_suspend_work" or "pm_runtime_suspend"? Likewise for the resume routines.
OK
Quoted 1 line
I haven't checked the details of the code yet. More later...
OK, thanks.
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Mittwoch, 10. Juni 2009 23:31:13 schrieb Rafael J. Wysocki:
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended. + * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended orQuoted 8 lines
Quoted 2 lines
-EBUSY+ * otherwise.
+ */We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Quoted 3 lines
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
Some bussystems need this constraint others don't or only for some nodes. We need a way to communicate this to the core.
Regards
Oliver
--
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 15 lines · Oliver Neukum
Am Mittwoch, 10. Juni 2009 23:31:13 schrieb Rafael J. Wysocki:
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended. + * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended or-EBUSY+ * otherwise.
+ */We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Quoted 6 lines
Quoted 3 lines
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
Some bussystems need this constraint others don't or only for some nodes. We need a way to communicate this to the core.
I agree that this depends on the bus.
Our SuperH on-chip SoC platform devices are arranged in a flat fashion so no real problem there, but if there whould be dependencies then I think we need to manage it recursively somehow.
Compare that to PM of our I2C driver and the I2C bus hanging off from that. In that case I'd like to be able to autosuspend the I2C master driver regardless of the I2C slave devices and their PM state.
/ 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
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 15 lines · Oliver Neukum
Am Mittwoch, 10. Juni 2009 23:31:13 schrieb Rafael J. Wysocki:
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended. + * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended or-EBUSY+ * otherwise.
+ */We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Quoted 6 lines
Quoted 3 lines
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
Some bussystems need this constraint others don't or only for some nodes. We need a way to communicate this to the core.
I agree that this depends on the bus.
Our SuperH on-chip SoC platform devices are arranged in a flat fashion so no real problem there, but if there whould be dependencies then I think we need to manage it recursively somehow.
Compare that to PM of our I2C driver and the I2C bus hanging off from that. In that case I'd like to be able to autosuspend the I2C master driver regardless of the I2C slave devices and their PM state.
/ magnus
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Mittwoch, 10. Juni 2009 23:31:13 schrieb Rafael J. Wysocki:
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended. + * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended orQuoted 8 lines
Quoted 2 lines
-EBUSY+ * otherwise.
+ */We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Quoted 3 lines
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
Some bussystems need this constraint others don't or only for some nodes. We need a way to communicate this to the core.
Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 6 lines · Rafael J. Wysocki
Quoted 5 lines
You know, it doesn't make any sense to have a suspend and a resume both pending at the same time.
So you could add only a
delayed_workstructure and use its embeddedwork_structfor resume requests.
Quoted 6 lines
I thought so too, but I was wrong. ;-)
If resume is requested while the suspend hasn't completed yet, we should queue it (it's totally valid to request a suspending device to resume IMO), but the delayed work is still being used by the workqueue code, so we can't modify it.
Where is the delayed work still being used? There's even a comment in run_workqueue() that says a work_struct can be freed by the function it calls.
Quoted 9 lines
Quoted 5 lines
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
The dependencies aren't totally useless. It's still true that before you resume a device, you have to autoresume its parent. And it's still true that when you suspend a device, the parent should be given a chance to autosuspend.
I guess the real point is that the decision about whether all children must be suspended should be made by the driver, not the PM core.
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 10 lines · Alan Stern
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines
You know, it doesn't make any sense to have a suspend and a resume both pending at the same time.
So you could add only a
delayed_workstructure and use its embeddedwork_structfor resume requests.I thought so too, but I was wrong. ;-)
Quoted 8 lines
Quoted 4 lines
If resume is requested while the suspend hasn't completed yet, we should queue it (it's totally valid to request a suspending device to resume IMO), but the delayed work is still being used by the workqueue code, so we can't modify it.
Where is the delayed work still being used? There's even a comment in
run_workqueue()that says awork_structcan be freed by the function it calls.
You are right, I overlooked the comment and it wasn't clear to me from looking at the code.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Quoted 6 lines
Quoted 3 lines
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
The dependencies aren't totally useless. It's still true that before you resume a device, you have to autoresume its parent.
Well, in fact if we don't have the requirement that the children of a device have to be suspended for it to be able to suspend too, we have to check all parents up the device tree up to the one that doesn't have a parent and autoresume the ones that aren't active.
Quoted 5 lines
And it's still true that when you suspend a device, the parent should be given a chance to autosuspend.
I guess the real point is that the decision about whether all children must be suspended should be made by the driver, not the PM core.
The point here is what the core is supposed to do. Does it need to handle this at all or leave it to the bus type and driver?
After reconsidering it for a while I think that we should define what "suspended" is supposed to mean from the core point of view. And my opinion is that it should mean "device doesn't communicate with the CPUs and RAM due to power management". That need not be power management of the device itself, but such that leads to the device not doing I/O.
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
That's correct and I'm going to take care of this.
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Agreed.
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 9 lines · Rafael J. Wysocki
The point here is what the core is supposed to do. Does it need to handle this at all or leave it to the bus type and driver?
After reconsidering it for a while I think that we should define what "suspended" is supposed to mean from the core point of view. And my opinion is that it should mean "device doesn't communicate with the CPUs and RAM due to power management". That need not be power management of the device itself, but such that leads to the device not doing I/O.
Quoted 8 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
(But this example leaves open the question of how we would go about spinning down the disk. Submitting a 15-minute (or whatever) delayed autosuspend request wouldn't work; the request wouldn't be accepted because the disk is already suspended as far as the PM core is concerned. The disk's driver would have to implement its own spin-down delayed_work.)
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
Quoted 7 lines
That's correct and I'm going to take care of this.
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Agreed.
This is another case where a usage counter comes in handy. The driver core resumes the device and increments the counter -- thus preventing any unwanted autosuspends -- before making the probe and remove calls.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Donnerstag, 11. Juni 2009 16:52:03 schrieb Alan Stern:
Quoted 11 lines
Quoted 10 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0
Regards
Oliver
--
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 18 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 16:52:03 schrieb Alan Stern:
Quoted 11 lines
Quoted 10 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Quoted 4 lines
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0
I don't understand. Can you explain more fully?
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Donnerstag, 11. Juni 2009 17:22:06 schrieb Alan Stern:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Quoted 6 lines
Quoted 4 lines
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0I don't understand. Can you explain more fully?
I am talking about the U1 and U2 feature of USB 3.0.
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Regards
Oliver
--
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 20 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 17:22:06 schrieb Alan Stern:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Quoted 6 lines
Quoted 4 lines
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0I don't understand. Can you explain more fully?
I am talking about the U1 and U2 feature of USB 3.0.
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
Quoted 5 lines
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Okay, fine. What does this have to do with Rafael's work? Why does setting the status to RPM_SUSPENDED even when a device is not in a low-power state preclude handling buses that automatically change their power state?
I don't see any connection between Rafael's work and managing latencies, beyond the obvious fact that a device will have a higher latency when it is suspended than when it isn't.
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Donnerstag, 11. Juni 2009 20:36:30 schrieb Alan Stern:
Quoted 10 lines
Quoted 9 lines
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Quoted 4 lines
Okay, fine. What does this have to do with Rafael's work? Why does setting the status to
RPM_SUSPENDEDeven when a device is not in a low-power state preclude handling buses that automatically change their power state?
For these cases the tree constraint does not apply.
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Regards
Oliver
--
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 11 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 20:36:30 schrieb Alan Stern:
Quoted 10 lines
Quoted 9 lines
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Quoted 6 lines
Quoted 4 lines
Okay, fine. What does this have to do with Rafael's work? Why does setting the status to
RPM_SUSPENDEDeven when a device is not in a low-power state preclude handling buses that automatically change their power state?For these cases the tree constraint does not apply.
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the runtime_suspend method". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when calling runtime_suspend methods.
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Clearly it should be decided by the driver. Should there be a bit for it in the dev_pm_info structure?
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Freitag, 12. Juni 2009 04:16:10 schrieb Alan Stern:
Quoted 3 lines
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Because the hardware doesn't need it.
Quoted 6 lines
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the
runtime_suspendmethod". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when callingruntime_suspendmethods.
No. The core if it insists all children be suspended will not use the hardware's full capabilities.
If it leaves such power saving measures to the drivers, latency accounting will be wrong.
Quoted 6 lines
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Clearly it should be decided by the driver. Should there be a bit for it in the
dev_pm_infostructure?
Yes.
Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 6 lines · Oliver Neukum
Am Freitag, 12. Juni 2009 04:16:10 schrieb Alan Stern:
Quoted 3 lines
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Because the hardware doesn't need it.
But maybe drivers need it.
Quoted 9 lines
Quoted 6 lines
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the
runtime_suspendmethod". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when callingruntime_suspendmethods.No. The core if it insists all children be suspended will not use the hardware's full capabilities.
That isn't what I said. The core does not insist that all children be suspended, i.e., be in a low-power state. It insists only that the children's drivers' runtime_suspend methods have been called. Those methods are not obligated to put the children in a low-power state.
Quoted 11 lines
If it leaves such power saving measures to the drivers, latency accounting will be wrong.
Quoted 6 lines
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Clearly it should be decided by the driver. Should there be a bit for it in the
dev_pm_infostructure?Yes.
That would resolve the issue.
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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 33 lines · Alan Stern
Quoted 6 lines · Oliver Neukum
Am Freitag, 12. Juni 2009 04:16:10 schrieb Alan Stern:
Quoted 3 lines
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Because the hardware doesn't need it.
But maybe drivers need it.
Quoted 9 lines
Quoted 6 lines
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the
runtime_suspendmethod". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when callingruntime_suspendmethods.No. The core if it insists all children be suspended will not use the hardware's full capabilities.
That isn't what I said. The core does not insist that all children be suspended, i.e., be in a low-power state. It insists only that the children's drivers'
runtime_suspendmethods have been called. Those methods are not obligated to put the children in a low-power state.Quoted 7 lines
If it leaves such power saving measures to the drivers, latency accounting will be wrong.
Quoted 4 lines
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Clearly it should be decided by the driver. Should there be a bit for it in the
dev_pm_infostructure?Yes.
That would resolve the issue.
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in dev_pm_info?
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?
Or rather, check it only if the special flag _isn't_ set.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 6 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?Or rather, check it only if the special flag _isn't_ set.
Where the default is unset, I guess?
But then, what about the resuming of the parents before the device is resumed? Should the parents be resumed regardless of the flag state? And if so, what's the condition for breaking the recurrence? Surely it's not sufficient to check if the parent is active, because its parent need not be active if it has this special flag set.
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?Or rather, check it only if the special flag _isn't_ set.
Where the default is unset, I guess?
Yep.
Quoted 2 lines
But then, what about the resuming of the parents before the device is resumed? Should the parents be resumed regardless of the flag state?
Yes. In general you should assume a device's parent (and the device itself!) needs to be resumed whenever the kernel wants to do something with the device. The special flag arises because sometimes it's safe to suspend the parent without suspending the device _if_ the kernel isn't using the device.
Imagine an idle disk at the end of a link. We might want to autosuspend the link without spinning down the disk. When we have to communicate with the disk again, we autoresume the link. (Including the case where the communication is a "spin-down" command.)
Quoted 4 lines
And if so, what's
the condition for breaking the recurrence? Surely it's not sufficient to check if the parent is active, because its parent need not be active if it has this special flag set.
That's a good question. Let's assume that situations like this will be handled by the drivers.
For example, suppose A is the parent of B is the parent of C, and A is suspended but B isn't and C is. What happens when somebody wants to use C?
An autoresume request is generated for C. Since C's parent is already resumed, the runtime_resume method in C's driver is called. The driver has to do some I/O in order to resume C, so it passes an I/O request up to B's driver. The request then gets passed up to A's driver. This driver knows that A is suspended, so it starts an autoresume of A and waits for the autoresume to complete before carrying out the request.
Then the I/O can go through, so C gets resumed and everything works out.
I don't know how often this sort of pattern will arise. It certainly could be used in usb-storage; there would be no difficulty starting an autoresume when an I/O request arrives from the SCSI layer below. In fact, that is exactly how some early runtime-PM patches for usb-storage worked.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 47 lines · Alan Stern
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?Or rather, check it only if the special flag _isn't_ set.
Where the default is unset, I guess?
Yep.
Quoted 2 lines
But then, what about the resuming of the parents before the device is resumed? Should the parents be resumed regardless of the flag state?
Yes. In general you should assume a device's parent (and the device itself!) needs to be resumed whenever the kernel wants to do something with the device. The special flag arises because sometimes it's safe to suspend the parent without suspending the device _if_ the kernel isn't using the device.
Imagine an idle disk at the end of a link. We might want to autosuspend the link without spinning down the disk. When we have to communicate with the disk again, we autoresume the link. (Including the case where the communication is a "spin-down" command.)
Quoted 4 lines
And if so, what's
the condition for breaking the recurrence? Surely it's not sufficient to check if the parent is active, because its parent need not be active if it has this special flag set.That's a good question. Let's assume that situations like this will be handled by the drivers.
For example, suppose A is the parent of B is the parent of C, and A is suspended but B isn't and C is. What happens when somebody wants to use C?
An autoresume request is generated for C. Since C's parent is already resumed, the
runtime_resumemethod in C's driver is called. The driver has to do some I/O in order to resume C, so it passes an I/O request up to B's driver. The request then gets passed up to A's driver. This driver knows that A is suspended, so it starts an autoresume of A and waits for the autoresume to complete before carrying out the request.
Quoted 8 lines
Then the I/O can go through, so C gets resumed and everything works out.
I don't know how often this sort of pattern will arise. It certainly could be used in usb-storage; there would be no difficulty starting an autoresume when an I/O request arrives from the SCSI layer below. In fact, that is exactly how some early runtime-PM patches for usb-storage worked.
So, the conclusion seems to be that we should break the recurrence at the point we find an already active device or a device with no parent and let the driver(s) handle the more complicated cases. Is this correct?
BTW, is __device_release_driver() the right place for blocking the run-time PM temporarily during remove?
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 3 lines · Rafael J. Wysocki
So, the conclusion seems to be that we should break the recurrence at the point we find an already active device or a device with no parent and let the driver(s) handle the more complicated cases. Is this correct?
That's right.
Quoted 2 lines
BTW, is
__device_release_driver()the right place for blocking the run-time PM temporarily during remove?
It is. And for submitting a delayed autosuspend request afterward; we may as well try to suspend devices that don't have drivers.
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
So, the conclusion seems to be that we should break the recurrence at the point we find an already active device or a device with no parent and let the driver(s) handle the more complicated cases. Is this correct?
That's right.
OK
Quoted 4 lines
Quoted 2 lines
BTW, is
__device_release_driver()the right place for blocking the run-time PM temporarily during remove?It is.
OK
Quoted 2 lines
And for submitting a delayed autosuspend request afterward; we may as well try to suspend devices that don't have drivers.
OK, but I'd like to add this functionality if future, when at least one bus type starts using the framework.
I think I have all of the ducks in a row now, so I'm going to post a cleaned-up patch in a new thread in a while.
Thanks,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
So, the conclusion seems to be that we should break the recurrence at the point we find an already active device or a device with no parent and let the driver(s) handle the more complicated cases. Is this correct?
That's right.
OK
Quoted 4 lines
Quoted 2 lines
BTW, is
__device_release_driver()the right place for blocking the run-time PM temporarily during remove?It is.
OK
Quoted 2 lines
And for submitting a delayed autosuspend request afterward; we may as well try to suspend devices that don't have drivers.
OK, but I'd like to add this functionality if future, when at least one bus type starts using the framework.
I think I have all of the ducks in a row now, so I'm going to post a cleaned-up patch in a new thread in a while.
Thanks,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
So, the conclusion seems to be that we should break the recurrence at the point we find an already active device or a device with no parent and let the driver(s) handle the more complicated cases. Is this correct?
That's right.
Quoted 2 lines
BTW, is
__device_release_driver()the right place for blocking the run-time PM temporarily during remove?
It is. And for submitting a delayed autosuspend request afterward; we may as well try to suspend devices that don't have drivers.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 47 lines · Alan Stern
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?Or rather, check it only if the special flag _isn't_ set.
Where the default is unset, I guess?
Yep.
Quoted 2 lines
But then, what about the resuming of the parents before the device is resumed? Should the parents be resumed regardless of the flag state?
Yes. In general you should assume a device's parent (and the device itself!) needs to be resumed whenever the kernel wants to do something with the device. The special flag arises because sometimes it's safe to suspend the parent without suspending the device _if_ the kernel isn't using the device.
Imagine an idle disk at the end of a link. We might want to autosuspend the link without spinning down the disk. When we have to communicate with the disk again, we autoresume the link. (Including the case where the communication is a "spin-down" command.)
Quoted 4 lines
And if so, what's
the condition for breaking the recurrence? Surely it's not sufficient to check if the parent is active, because its parent need not be active if it has this special flag set.That's a good question. Let's assume that situations like this will be handled by the drivers.
For example, suppose A is the parent of B is the parent of C, and A is suspended but B isn't and C is. What happens when somebody wants to use C?
An autoresume request is generated for C. Since C's parent is already resumed, the
runtime_resumemethod in C's driver is called. The driver has to do some I/O in order to resume C, so it passes an I/O request up to B's driver. The request then gets passed up to A's driver. This driver knows that A is suspended, so it starts an autoresume of A and waits for the autoresume to complete before carrying out the request.
Quoted 8 lines
Then the I/O can go through, so C gets resumed and everything works out.
I don't know how often this sort of pattern will arise. It certainly could be used in usb-storage; there would be no difficulty starting an autoresume when an I/O request arrives from the SCSI layer below. In fact, that is exactly how some early runtime-PM patches for usb-storage worked.
So, the conclusion seems to be that we should break the recurrence at the point we find an already active device or a device with no parent and let the driver(s) handle the more complicated cases. Is this correct?
BTW, is __device_release_driver() the right place for blocking the run-time PM temporarily during remove?
Best,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?Or rather, check it only if the special flag _isn't_ set.
Where the default is unset, I guess?
Yep.
Quoted 2 lines
But then, what about the resuming of the parents before the device is resumed? Should the parents be resumed regardless of the flag state?
Yes. In general you should assume a device's parent (and the device itself!) needs to be resumed whenever the kernel wants to do something with the device. The special flag arises because sometimes it's safe to suspend the parent without suspending the device _if_ the kernel isn't using the device.
Imagine an idle disk at the end of a link. We might want to autosuspend the link without spinning down the disk. When we have to communicate with the disk again, we autoresume the link. (Including the case where the communication is a "spin-down" command.)
Quoted 4 lines
And if so, what's
the condition for breaking the recurrence? Surely it's not sufficient to check if the parent is active, because its parent need not be active if it has this special flag set.
That's a good question. Let's assume that situations like this will be handled by the drivers.
For example, suppose A is the parent of B is the parent of C, and A is suspended but B isn't and C is. What happens when somebody wants to use C?
An autoresume request is generated for C. Since C's parent is already resumed, the runtime_resume method in C's driver is called. The driver has to do some I/O in order to resume C, so it passes an I/O request up to B's driver. The request then gets passed up to A's driver. This driver knows that A is suspended, so it starts an autoresume of A and waits for the autoresume to complete before carrying out the request.
Then the I/O can go through, so C gets resumed and everything works out.
I don't know how often this sort of pattern will arise. It certainly could be used in usb-storage; there would be no difficulty starting an autoresume when an I/O request arrives from the SCSI layer below. In fact, that is exactly how some early runtime-PM patches for usb-storage worked.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 6 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?Or rather, check it only if the special flag _isn't_ set.
Where the default is unset, I guess?
But then, what about the resuming of the parents before the device is resumed? Should the parents be resumed regardless of the flag state? And if so, what's the condition for breaking the recurrence? Surely it's not sufficient to check if the parent is active, because its parent need not be active if it has this special flag set.
Best,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 2 lines · Rafael J. Wysocki
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in
dev_pm_info?
Or rather, check it only if the special flag _isn't_ set.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 33 lines · Alan Stern
Quoted 6 lines · Oliver Neukum
Am Freitag, 12. Juni 2009 04:16:10 schrieb Alan Stern:
Quoted 3 lines
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Because the hardware doesn't need it.
But maybe drivers need it.
Quoted 9 lines
Quoted 6 lines
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the
runtime_suspendmethod". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when callingruntime_suspendmethods.No. The core if it insists all children be suspended will not use the hardware's full capabilities.
That isn't what I said. The core does not insist that all children be suspended, i.e., be in a low-power state. It insists only that the children's drivers'
runtime_suspendmethods have been called. Those methods are not obligated to put the children in a low-power state.Quoted 7 lines
If it leaves such power saving measures to the drivers, latency accounting will be wrong.
Quoted 4 lines
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Clearly it should be decided by the driver. Should there be a bit for it in the
dev_pm_infostructure?Yes.
That would resolve the issue.
So, are you suggesting that the core should only check the "all children suspended" condition if special flag is set in dev_pm_info?
Best,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 6 lines · Oliver Neukum
Am Freitag, 12. Juni 2009 04:16:10 schrieb Alan Stern:
Quoted 3 lines
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Because the hardware doesn't need it.
But maybe drivers need it.
Quoted 9 lines
Quoted 6 lines
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the
runtime_suspendmethod". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when callingruntime_suspendmethods.No. The core if it insists all children be suspended will not use the hardware's full capabilities.
That isn't what I said. The core does not insist that all children be suspended, i.e., be in a low-power state. It insists only that the children's drivers' runtime_suspend methods have been called. Those methods are not obligated to put the children in a low-power state.
Quoted 11 lines
If it leaves such power saving measures to the drivers, latency accounting will be wrong.
Quoted 6 lines
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Clearly it should be decided by the driver. Should there be a bit for it in the
dev_pm_infostructure?Yes.
That would resolve the issue.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternAm Freitag, 12. Juni 2009 04:16:10 schrieb Alan Stern:
Quoted 3 lines
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Because the hardware doesn't need it.
Quoted 6 lines
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the
runtime_suspendmethod". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when callingruntime_suspendmethods.
No. The core if it insists all children be suspended will not use the hardware's full capabilities.
If it leaves such power saving measures to the drivers, latency accounting will be wrong.
Quoted 6 lines
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Clearly it should be decided by the driver. Should there be a bit for it in the
dev_pm_infostructure?
Yes.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 11 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 20:36:30 schrieb Alan Stern:
Quoted 10 lines
Quoted 9 lines
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Quoted 6 lines
Quoted 4 lines
Okay, fine. What does this have to do with Rafael's work? Why does setting the status to
RPM_SUSPENDEDeven when a device is not in a low-power state preclude handling buses that automatically change their power state?For these cases the tree constraint does not apply.
What tree constraint? You mean that the PM core shouldn't allow devices to suspend unless all their children are suspended? Why doesn't it still apply?
Remember, when Rafael and I say "suspend" here, we don't mean "go to a low-power state". We mean "the PM core calls the runtime_suspend method". No matter what actions the link hardware may decide to take on its own, the PM core will still want to observe the all-children-suspended restriction when calling runtime_suspend methods.
Quoted 3 lines
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Clearly it should be decided by the driver. Should there be a bit for it in the dev_pm_info structure?
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternAm Donnerstag, 11. Juni 2009 20:36:30 schrieb Alan Stern:
Quoted 10 lines
Quoted 9 lines
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Quoted 4 lines
Okay, fine. What does this have to do with Rafael's work? Why does setting the status to
RPM_SUSPENDEDeven when a device is not in a low-power state preclude handling buses that automatically change their power state?
For these cases the tree constraint does not apply.
I think there are devices who can be suspended while children are active and devices which can not be. This is an attribute of the device and should be evaluated by the core.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 20 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 17:22:06 schrieb Alan Stern:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Quoted 6 lines
Quoted 4 lines
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0I don't understand. Can you explain more fully?
I am talking about the U1 and U2 feature of USB 3.0.
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
Quoted 5 lines
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Okay, fine. What does this have to do with Rafael's work? Why does setting the status to RPM_SUSPENDED even when a device is not in a low-power state preclude handling buses that automatically change their power state?
I don't see any connection between Rafael's work and managing latencies, beyond the obvious fact that a device will have a higher latency when it is suspended than when it isn't.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternAm Donnerstag, 11. Juni 2009 17:22:06 schrieb Alan Stern:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Quoted 6 lines
Quoted 4 lines
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0I don't understand. Can you explain more fully?
I am talking about the U1 and U2 feature of USB 3.0.
Or abstractly any power saving state that does autoresume in hardware. In these cases you know that you can enter a powersaving state that will add X latency.
In terms of user space API we'll probably add a way for user space to specify how much latency may be added for power management's sake. If busses are stacked the "latency budget" has to be handled at core level. If furthermore states that allow IO but with additional latency are ignored, the budget will be calculated wrongly.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 18 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 16:52:03 schrieb Alan Stern:
Quoted 11 lines
Quoted 10 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Quoted 4 lines
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0
I don't understand. Can you explain more fully?
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternAm Donnerstag, 11. Juni 2009 16:52:03 schrieb Alan Stern:
Quoted 11 lines
Quoted 10 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
This precludes handling busses that have low power states that are left automatically. If such links are stacked the management of acceptable latencies cannot be left to the busses.
An actual example are the link states of USB 3.0
Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 20 lines · Alan Stern
Quoted 9 lines · Rafael J. Wysocki
The point here is what the core is supposed to do. Does it need to handle this at all or leave it to the bus type and driver?
After reconsidering it for a while I think that we should define what "suspended" is supposed to mean from the core point of view. And my opinion is that it should mean "device doesn't communicate with the CPUs and RAM due to power management". That need not be power management of the device itself, but such that leads to the device not doing I/O.
Quoted 8 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Exactly.
Quoted 6 lines
(But this example leaves open the question of how we would go about spinning down the disk. Submitting a 15-minute (or whatever) delayed autosuspend request wouldn't work; the request wouldn't be accepted because the disk is already suspended as far as the PM core is concerned. The disk's driver would have to implement its own spin-down
delayed_work.)
Yes, it would.
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
That's correct and I'm going to take care of this.
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Quoted 5 lines
Quoted 1 line
Agreed.
This is another case where a usage counter comes in handy. The driver core resumes the device and increments the counter -- thus preventing any unwanted autosuspends -- before making the probe and remove calls.
I like this idea.
BTW, where exactly the counter should be increased in that case?
I thought of driver_probe_device(), but is it sufficient? Or is there a better place?
Best,
Rafael
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Agreed.
This is another case where a usage counter comes in handy. The driver core resumes the device and increments the counter -- thus preventing any unwanted autosuspends -- before making the probe and remove calls.
Quoted 6 lines
I like this idea.
BTW, where exactly the counter should be increased in that case?
I thought of
driver_probe_device(), but is it sufficient? Or is there a better place?
That's okay. Or you could put it in really_probe(). Either one.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Agreed.
This is another case where a usage counter comes in handy. The driver core resumes the device and increments the counter -- thus preventing any unwanted autosuspends -- before making the probe and remove calls.
Quoted 6 lines
I like this idea.
BTW, where exactly the counter should be increased in that case?
I thought of
driver_probe_device(), but is it sufficient? Or is there a better place?
That's okay. Or you could put it in really_probe(). Either one.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 20 lines · Alan Stern
Quoted 9 lines · Rafael J. Wysocki
The point here is what the core is supposed to do. Does it need to handle this at all or leave it to the bus type and driver?
After reconsidering it for a while I think that we should define what "suspended" is supposed to mean from the core point of view. And my opinion is that it should mean "device doesn't communicate with the CPUs and RAM due to power management". That need not be power management of the device itself, but such that leads to the device not doing I/O.
Quoted 8 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Quoted 5 lines
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
Exactly.
Quoted 6 lines
(But this example leaves open the question of how we would go about spinning down the disk. Submitting a 15-minute (or whatever) delayed autosuspend request wouldn't work; the request wouldn't be accepted because the disk is already suspended as far as the PM core is concerned. The disk's driver would have to implement its own spin-down
delayed_work.)
Yes, it would.
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
That's correct and I'm going to take care of this.
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Quoted 5 lines
Quoted 1 line
Agreed.
This is another case where a usage counter comes in handy. The driver core resumes the device and increments the counter -- thus preventing any unwanted autosuspends -- before making the probe and remove calls.
I like this idea.
BTW, where exactly the counter should be increased in that case?
I thought of driver_probe_device(), but is it sufficient? Or is there a better place?
Best,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
The point here is what the core is supposed to do. Does it need to handle this at all or leave it to the bus type and driver?
After reconsidering it for a while I think that we should define what "suspended" is supposed to mean from the core point of view. And my opinion is that it should mean "device doesn't communicate with the CPUs and RAM due to power management". That need not be power management of the device itself, but such that leads to the device not doing I/O.
Quoted 8 lines
Under this definition all devices behind an inactive link are suspended, because they can't do any I/O. Which appears to makes sense, because their drivers have to be notified before the link is suspended and the link has to be turned on for the devices to be able to communicate with the CPU and RAM.
If this definition is adopted, then it's quite clear that the device can only be suspended if all of its children are suspended and it's always necessary to resume the parent of a device in order to resume the device itself.
Okay, I'll agree to that. It should be made clear that a device which is "suspended" according to this definition is not necessarily in a low-power state. For example, before powering down the link to a disk drive you might want the drive's suspend method to flush the drive's cache, but it wouldn't have to spin the drive down.
(But this example leaves open the question of how we would go about spinning down the disk. Submitting a 15-minute (or whatever) delayed autosuspend request wouldn't work; the request wouldn't be accepted because the disk is already suspended as far as the PM core is concerned. The disk's driver would have to implement its own spin-down delayed_work.)
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
Quoted 7 lines
That's correct and I'm going to take care of this.
Quoted 3 lines
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Agreed.
This is another case where a usage counter comes in handy. The driver core resumes the device and increments the counter -- thus preventing any unwanted autosuspends -- before making the probe and remove calls.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 6 lines · Rafael J. Wysocki
Quoted 5 lines
You know, it doesn't make any sense to have a suspend and a resume both pending at the same time.
So you could add only a
delayed_workstructure and use its embeddedwork_structfor resume requests.
Quoted 6 lines
I thought so too, but I was wrong. ;-)
If resume is requested while the suspend hasn't completed yet, we should queue it (it's totally valid to request a suspending device to resume IMO), but the delayed work is still being used by the workqueue code, so we can't modify it.
Where is the delayed work still being used? There's even a comment in run_workqueue() that says a work_struct can be freed by the function it calls.
Quoted 9 lines
Quoted 5 lines
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
The dependencies aren't totally useless. It's still true that before you resume a device, you have to autoresume its parent. And it's still true that when you suspend a device, the parent should be given a chance to autosuspend.
I guess the real point is that the decision about whether all children must be suspended should be made by the driver, not the PM core.
Quoted 1 line
Quoted 1 line
I haven't checked the details of the code yet. More later...
One more thought... The autosuspend and autoresume callbacks need to be mutually exclusive with probe and remove. So somehow the driver core will need to block runtime PM calls.
It might also be nice to make sure that the driver core autoresumes a device before probing it and autosuspends a device (after some reasonable delay) after unbinding its driver.
Alan Stern
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 47 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki
Quoted 5 lines
The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
I'm still not sure this is a good idea. When would the device driver clear the status? The autosuspend and autoresume methods run asynchronously, so after they're done the driver doesn't get a chance to do anything.
It might be best just to set the status to
RPM_ACTIVEif a runtime suspend fails andRPM_SUSPENDEDif a runtime resume fails.Quoted 4 lines
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use
-EAGAINand-EBUSYfor this purpose.Maybe...
Quoted 9 lines
struct
dev_pm_info{include/linux/pm.h +2
-2pm_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 struct list_head entry;include/linux/pm.h enum dpm_state { · line 400
Quoted 10 lines
include/linux/pm.h +8
-0#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; + unsigned int suspend_aborted:1; +struct work_struct resume_work; +struct completion work_done; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };You know, it doesn't make any sense to have a suspend and a resume both pending at the same time.
Quoted 2 lines
So you could add only a
delayed_workstructure and use its embeddedwork_structfor resume requests.
I thought so too, but I was wrong. ;-)
If resume is requested while the suspend hasn't completed yet, we should queue it (it's totally valid to request a suspending device to resume IMO), but the delayed work is still being used by the workqueue code, so we can't modify it.
Quoted 4 lines
Also, you might borrow a trick from Dave Brownell. Define the RPM_* values so that the individual bits have meanings. Then instead of testing for multiple possible values of
runtime_status, you could do a simple bit test.
Yes, I'm seriously considering using this approach.
Quoted 10 lines
Quoted 10 lines
drivers/base/power/runtime.c new file +10
-0+/** +* pm_device_suspended - Check if given device has been suspended at run time. +* @dev: Device to check. +* @data: Ignored. +* +* Returns 0 if the device has been suspended or -EBUSY otherwise. +*/ +static int pm_device_suspended (struct device *dev,void *data) +{ +int ret;
Quoted 8 lines
drivers/base/power/runtime.c line 36
Quoted 6 lines
drivers/base/power/runtime.c new file +6
-0+ +spin_lock (&dev->power.lock); + + ret = dev->power.runtime_status ==RPM_SUSPENDED ?0 : -EBUSY ; + +spin_unlock (&dev->power.lock);How does acquiring the lock help here?
OK, it doesn't.
Quoted 8 lines
Quoted 7 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended.
+ * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended or-EBUSY
+ * otherwise.
+ */
Quoted 5 lines
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
Well, this means that the dependencies between devices in the device tree are pretty much useless for the run-time PM as far as the core is concerned. In which case, why did you mention them at all?
Quoted 7 lines
Quoted 7 lines
+/**
+ *pm_autosuspend- Run autosuspend callback of given device object's bus type.
+ * @work: Work structure used for scheduling the execution of this function.
+ *
+ * Use @work to get the device object the suspend has been scheduled for,
+ * check if the suspend request hasn't been cancelled and run the
+ * ->autosuspend() callback from the device's bus type driver. Update the
Quoted 8 lines
Quoted 4 lines
+ * run-time PM flags in the device object to reflect the current status of the
+ * device.
+ */
+static voidpm_autosuspend(struct work_struct *work)Can we call this something else? "Autosuspend" implies that the suspend originated from within the kernel. How about "
pm_suspend_work" or "pm_runtime_suspend"? Likewise for the resume routines.
OK
Quoted 1 line
I haven't checked the details of the code yet. More later...
OK, thanks.
Best,
Rafael
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 5 lines
The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
I'm still not sure this is a good idea. When would the device driver clear the status? The autosuspend and autoresume methods run asynchronously, so after they're done the driver doesn't get a chance to do anything.
It might be best just to set the status to RPM_ACTIVE if a runtime suspend fails and RPM_SUSPENDED if a runtime resume fails.
Quoted 4 lines
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use
-EAGAINand-EBUSYfor this purpose.
Maybe...
Quoted 9 lines
struct
dev_pm_info{include/linux/pm.h +2
-2pm_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 struct list_head entry;
include/linux/pm.h enum dpm_state { · line 400
Quoted 10 lines
include/linux/pm.h +8
-0#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; + unsigned int suspend_aborted:1; +struct work_struct resume_work; +struct completion work_done; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };
You know, it doesn't make any sense to have a suspend and a resume both pending at the same time. So you could add only a delayed_work structure and use its embedded work_struct for resume requests.
Also, you might borrow a trick from Dave Brownell. Define the RPM_* values so that the individual bits have meanings. Then instead of testing for multiple possible values of runtime_status, you could do a simple bit test.
Quoted 6 lines
drivers/base/power/runtime.c new file +6
-0+/** +* pm_device_suspended - Check if given device has been suspended at run time. +* @dev: Device to check. +* @data: Ignored. +* +* Returns 0 if the device has been suspended or -EBUSY otherwise.
drivers/base/power/runtime.c line 36
Quoted 10 lines
drivers/base/power/runtime.c new file +10
-0+*/ +static int pm_device_suspended (struct device *dev,void *data) +{ +int ret; + +spin_lock (&dev->power.lock); + + ret = dev->power.runtime_status ==RPM_SUSPENDED ?0 : -EBUSY ; + +spin_unlock (&dev->power.lock);
How does acquiring the lock help here?
Quoted 7 lines
+/**
+ *pm_check_children- Check if all children of a device have been suspended.
+ * @dev: Device to check.
+ *
+ * Returns 0 if all children of the device have been suspended or-EBUSY
+ * otherwise.
+ */
We might want to do a runtime suspend even if the device's children aren't already suspended. For example, you could suspend a link while leaving the device on the other end of the link at full power -- especially if powering down the device is slow but changing the link's power level is fast.
drivers/base/power/runtime.c line 63
Quoted 11 lines
drivers/base/power/runtime.c new file +11
-0+/** +* pm_autosuspend - Run autosuspend callback of given device object's bus type. +* @work: Work structure used for scheduling the execution of this function. +* +* Use @work to get the device object the suspend has been scheduled for, +* check if the suspend request hasn't been cancelled and run the +* ->autosuspend() callback from the device's bus type driver. Update the +* run-time PM flags in the device object to reflect the current status of the +* device. +*/ +static void pm_autosuspend (struct work_struct *work)
Can we call this something else? "Autosuspend" implies that the suspend originated from within the kernel. How about "pm_suspend_work" or "pm_runtime_suspend"? Likewise for the resume routines.
I haven't checked the details of the code yet. More later...
Alan Stern
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiHi Rafael,
Quoted 11 lines · Rafael J. Wysocki
Quoted 2 lines
I tried to address your comments and the Oliver's comments too in the new version of the patch below. Please have a look and tell me what you think.
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
Quoted 6 lines
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use
-EAGAINand-EBUSYfor this purpose.Updated patch follows, sorry for the confusion.
Thanks for your work on this. I think the patch looks very good in general so I will not comment on the code itself. I do however have a few high level questions:
Q1) Regarding pm_request_suspend(), would it be possible to get a synchronous version or to make use of the completion somehow?
Q2) As pm_request_suspend() works today, the device is marked as RPM_IDLE and the delayed work is queued up. There is no real decision making going on except the time out. I'd like to let the bus code decide when to autosuspend a buch of devices. Maybe the idle handling should be broken out into a pm_request_idle() and pm_request_suspend() can be modified to synchronously suspend devices marked with pm_request_idle()?
Q3) Have you thought about how device drivers can inform the Runtime PM that the device are idle and that they need the hardware to be woken up? I'd like something similar to my "[PATCH 02/04] Driver Core:
Add idle and wakeup functions" patch but maybe not specific to platform devices. We talked about adding some hooks to the bus_type for this. Any ideas?
This is how I'm thinking of integrating your Runtime PM code with our SuperH platform devices:
Device Idle Handling:
1) Device drivers call pm_device_idle() (See Q3) which invokes arch specific platform bus code in the case of our SoC platform devices. This bus code marks the device as idle using pm_request_idle(). (See Q2). At this point light weight power management like clock stopping may be performed as well.
2) The arch specific bus code knows how the platform devices are grouped together (thanks to the data area in "[PATCH] Driver Core: Add platform device arch data V3"), and when all devices in one power domain are marked as idle the bus code calls the synchronous pm_request_suspend() (no delay).
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when all devices are idle is simply that we don't get any power savings from the per device autosuspend() callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.
4) Over time when the code in 2) should be extended to handle latencies.
Device Wakeup Handling:
1) Device drivers call pm_device_wakeup() (See Q3). This invokes arch specific bus code for our SoC platform devices. The bus code enables clocks if needed and also calls pm_resume_sync().
2) After the call to pm_resume_sync() the pm_device_wakeup() call returns and the device driver can access the hardware as usual.
That's it! Far from perfect but maybe a good start at least.
I have seen quite a few patches from you lately, nice work. To make tracking of the Runtime PM patches easier, can you pleae consider including the version of the patch in the subject when you post new versions?
Thanks!
/ 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
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
So you are saying that you have power dependencies independent of the device tree?
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.
Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
I suppose we could have a helper.
int pm_autosuspend_in_domain(struct device *dev)
{
int err;
mutex_lock(dev->power_domain);
if (! --dev->power_domain.active_devices)
err = dev->power_domain->power_down(dev->power_domain);
else
err = 0;
mutex_unlock(dev->power_domain);
return err;
} Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Hi Oliver,
Quoted 6 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
So you are saying that you have power dependencies independent of the device tree?
I can think of the following power dependencies:
- hardware bus topology
- clocks
- power domains
Quoted 8 lines
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
So you mean I should handle that in my arch/bus specific dev->bus->pm->autosuspend() code? So instead of calling dev->driver->pm->autosuspend() straight away I keep track of the use count of the power domain and when the domain is unused I call dev->driver->pm->autosuspend() for all devices in the power domain before powering off?
I guess hooking in things in dev->bus->pm->autosuspend() is doable, but then dev->power.runtime_status will be set to RPM_SUSPENDED even though the actual device isn't suspended at all. And RPM_IDLE state will be more or less unused since the drivers should pass a delay of zero to make sure the bus code gets notified about the idle state straight away.
Basically, for my use case it would make more sense to let the bus_type directly decide when a device should be suspended instead of using a timeout before calling the bus_type code. I rather let the bus_type decide if a timeout should be used or not instead of using it for all bus_types.
So I guess the plan is that drivers directly should invoke pm_request_suspend() to notify the bus that they are idle? (I guess similar to my platform_device_idle()?)
For my use case there is no point in having the delay in pm_request_suspend(), we want to notify the bus about the per-device idleness straight away. Using a delay in pm_request_suspend() before calling the bus type autosuspend will just keep the current per-device state away from the bus level and make sure we _cannot_ enter deep sleep states. Which I believe will result in worse battery life because we spend more time than necessary in not-so-deep sleep states.
So yes, I'd like to do things in dev->bus->pm->autosuspend(), and the code is quite close. I can't figure out why anyone would want the suspend delay at the current level though, but I guess other busses want to use that?
Thanks for your comments,
/ magnus
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Am Freitag, 12. Juni 2009 05:13:12 schrieb Magnus Damm:
Quoted 7 lines
Hi Oliver,
Quoted 4 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
Quoted 7 lines
Quoted 2 lines
So you are saying that you have power dependencies independent of the device tree?
I can think of the following power dependencies:
- hardware bus topology
- clocks
- power domains
That means that some devices otherwise unrelated have a common power switch, doesn't it?
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
Quoted 6 lines
So you mean I should handle that in my
arch/busspecificdev->bus->pm->autosuspend()code? So instead of callingdev->driver->pm->autosuspend()straight away I keep track of the use count of the power domain and when the domain is unused I calldev->driver->pm->autosuspend()for all devices in the power domain before powering off?
How much overhead do you have in autosuspend() if it actually powers down the devices? If it is small, I suggest you really run the autosuspend methods in the drivers but use a counter for the actual power switching on a bus level.
Quoted 3 lines
I guess hooking in things in
dev->bus->pm->autosuspend()is doable, but thendev->power.runtime_statuswill be set toRPM_SUSPENDEDeven though the actual device isn't suspended at all. AndRPM_IDLEstate
Why do you care about a device being in RPM_SUSPENDED while active. The inverse is a bug, but this seems harmless.
Quoted 3 lines
will be more or less unused since the drivers should pass a delay of zero to make sure the bus code gets notified about the idle state straight away.
So? You are not getting a common code without a little overhead for some cases.
Quoted 5 lines
Basically, for my use case it would make more sense to let the
bus_typedirectly decide when a device should be suspended instead of using a timeout before calling thebus_typecode. I rather let thebus_typedecide if a timeout should be used or not instead of using it for allbus_types.
So call with a delay of 0.
Quoted 3 lines
So I guess the plan is that drivers directly should invoke
pm_request_suspend()to notify the bus that they are idle? (I guess similar to myplatform_device_idle()?)
Yes.
Quoted 4 lines
So yes, I'd like to do things in
dev->bus->pm->autosuspend(), and the code is quite close. I can't figure out why anyone would want the suspend delay at the current level though, but I guess other busses want to use that?
In your case resumption seems to cost almost no energy. In other cases you must avoid short sleeps, as you conserve less energy sleeping than it takes to resume.
Regards
Oliver
Re: [patch update] Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 11 lines · Oliver Neukum
Am Freitag, 12. Juni 2009 05:13:12 schrieb Magnus Damm:
Quoted 10 lines
Hi Oliver,
Quoted 6 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
So you are saying that you have power dependencies independent of the device tree?
Quoted 7 lines
Quoted 4 lines
I can think of the following power dependencies:
- hardware bus topology
- clocks
- power domainsThat means that some devices otherwise unrelated have a common power switch, doesn't it?
Yes, various on chip devices share the same power switch.
On the SuperH Mobile SoCs that I've seen we basically have two power domains. One big which contains almost everything except what's in the second domain: a timer, watchdog and a rtc. I guess the devices are related to each other because they are in the same SoC, but exactly how they relate to each other depends on actual processor type. Same for clocks.
This presentation may give you an overview of the SuperH Mobile hardware and where we are today:
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
Quoted 6 lines
So you mean I should handle that in my
arch/busspecificdev->bus->pm->autosuspend()code? So instead of callingdev->driver->pm->autosuspend()straight away I keep track of the use count of the power domain and when the domain is unused I calldev->driver->pm->autosuspend()for all devices in the power domain before powering off?
Quoted 4 lines
How much overhead do you have in
autosuspend()if it actually powers down the devices? If it is small, I suggest you really run the autosuspend methods in the drivers but use a counter for the actual power switching on a bus level.
On a SoC scale, returning from the deepest sleep state takes a bit of time. It depends on clock configuration, but worst case i think it takes ~3ms to come back from the deepest sleep. Just to let the cpu core start executing instructions. And on the way back we also have to setup almost the entire system from scratch which probaly takes quite a bit of time.
Why I don't want to call dev->driver->pm_autosuspend() directly is basically our per-processor model hard coded clock dependencies. Some open devices may block deep sleep, for instance if a serial port is open we may not deep sleep unless we can live with stopping the clock and potentially loosing incoming data. So if these open devices block the entire power domain then there is no point in executing the dev->driver->pm autosuspend()/autoresume() all the time since we basically will never power off the domain.
The autosuspend()/autoresume() driver callbacks will save and restore registers which is quite expensive since each memory access is uncached. So I don't want to do that more than absolutely necessary.
But I can handle that in the bus type code, no problem. I'm sure ARM can as well.
Quoted 6 lines
Quoted 3 lines
I guess hooking in things in
dev->bus->pm->autosuspend()is doable, but thendev->power.runtime_statuswill be set toRPM_SUSPENDEDeven though the actual device isn't suspended at all. AndRPM_IDLEstateWhy do you care about a device being in
RPM_SUSPENDEDwhile active. The inverse is a bug, but this seems harmless.
Ok, just wanted to check if you guys agreed with that as a valid combination.
Quoted 6 lines
Quoted 3 lines
will be more or less unused since the drivers should pass a delay of zero to make sure the bus code gets notified about the idle state straight away.
So? You are not getting a common code without a little overhead for some cases.
Some overhead is of course acceptable. If it's too much then we can always optimize later.
Quoted 7 lines
Quoted 5 lines
Basically, for my use case it would make more sense to let the
bus_typedirectly decide when a device should be suspended instead of using a timeout before calling thebus_typecode. I rather let thebus_typedecide if a timeout should be used or not instead of using it for allbus_types.So call with a delay of 0.
Sure.
Quoted 5 lines
Quoted 3 lines
So I guess the plan is that drivers directly should invoke
pm_request_suspend()to notify the bus that they are idle? (I guess similar to myplatform_device_idle()?)Yes.
Ok, sounds good.
Quoted 8 lines
Quoted 4 lines
So yes, I'd like to do things in
dev->bus->pm->autosuspend(), and the code is quite close. I can't figure out why anyone would want the suspend delay at the current level though, but I guess other busses want to use that?In your case resumption seems to cost almost no energy. In other cases you must avoid short sleeps, as you conserve less energy sleeping than it takes to resume.
I want to avoid that as well, but I don't think a per-device timeout is enough. I need to tie in latencies into this somehow. But I prefer to do that after getting the basic stuff working. Step by step.
Thanks,
/ magnus
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 11 lines · Oliver Neukum
Am Freitag, 12. Juni 2009 05:13:12 schrieb Magnus Damm:
Quoted 10 lines
Hi Oliver,
Quoted 6 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
So you are saying that you have power dependencies independent of the device tree?
Quoted 7 lines
Quoted 4 lines
I can think of the following power dependencies:
- hardware bus topology
- clocks
- power domainsThat means that some devices otherwise unrelated have a common power switch, doesn't it?
Yes, various on chip devices share the same power switch.
On the SuperH Mobile SoCs that I've seen we basically have two power domains. One big which contains almost everything except what's in the second domain: a timer, watchdog and a rtc. I guess the devices are related to each other because they are in the same SoC, but exactly how they relate to each other depends on actual processor type. Same for clocks.
This presentation may give you an overview of the SuperH Mobile hardware and where we are today:
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
Quoted 6 lines
So you mean I should handle that in my
arch/busspecificdev->bus->pm->autosuspend()code? So instead of callingdev->driver->pm->autosuspend()straight away I keep track of the use count of the power domain and when the domain is unused I calldev->driver->pm->autosuspend()for all devices in the power domain before powering off?
Quoted 4 lines
How much overhead do you have in
autosuspend()if it actually powers down the devices? If it is small, I suggest you really run the autosuspend methods in the drivers but use a counter for the actual power switching on a bus level.
On a SoC scale, returning from the deepest sleep state takes a bit of time. It depends on clock configuration, but worst case i think it takes ~3ms to come back from the deepest sleep. Just to let the cpu core start executing instructions. And on the way back we also have to setup almost the entire system from scratch which probaly takes quite a bit of time.
Why I don't want to call dev->driver->pm_autosuspend() directly is basically our per-processor model hard coded clock dependencies. Some open devices may block deep sleep, for instance if a serial port is open we may not deep sleep unless we can live with stopping the clock and potentially loosing incoming data. So if these open devices block the entire power domain then there is no point in executing the dev->driver->pm autosuspend()/autoresume() all the time since we basically will never power off the domain.
The autosuspend()/autoresume() driver callbacks will save and restore registers which is quite expensive since each memory access is uncached. So I don't want to do that more than absolutely necessary.
But I can handle that in the bus type code, no problem. I'm sure ARM can as well.
Quoted 6 lines
Quoted 3 lines
I guess hooking in things in
dev->bus->pm->autosuspend()is doable, but thendev->power.runtime_statuswill be set toRPM_SUSPENDEDeven though the actual device isn't suspended at all. AndRPM_IDLEstateWhy do you care about a device being in
RPM_SUSPENDEDwhile active. The inverse is a bug, but this seems harmless.
Ok, just wanted to check if you guys agreed with that as a valid combination.
Quoted 6 lines
Quoted 3 lines
will be more or less unused since the drivers should pass a delay of zero to make sure the bus code gets notified about the idle state straight away.
So? You are not getting a common code without a little overhead for some cases.
Some overhead is of course acceptable. If it's too much then we can always optimize later.
Quoted 7 lines
Quoted 5 lines
Basically, for my use case it would make more sense to let the
bus_typedirectly decide when a device should be suspended instead of using a timeout before calling thebus_typecode. I rather let thebus_typedecide if a timeout should be used or not instead of using it for allbus_types.So call with a delay of 0.
Sure.
Quoted 5 lines
Quoted 3 lines
So I guess the plan is that drivers directly should invoke
pm_request_suspend()to notify the bus that they are idle? (I guess similar to myplatform_device_idle()?)Yes.
Ok, sounds good.
Quoted 8 lines
Quoted 4 lines
So yes, I'd like to do things in
dev->bus->pm->autosuspend(), and the code is quite close. I can't figure out why anyone would want the suspend delay at the current level though, but I guess other busses want to use that?In your case resumption seems to cost almost no energy. In other cases you must avoid short sleeps, as you conserve less energy sleeping than it takes to resume.
I want to avoid that as well, but I don't think a per-device timeout is enough. I need to tie in latencies into this somehow. But I prefer to do that after getting the basic stuff working. Step by step.
Thanks,
/ magnus
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Magnus DammAm Freitag, 12. Juni 2009 05:13:12 schrieb Magnus Damm:
Quoted 7 lines
Hi Oliver,
Quoted 4 lines · Oliver Neukum
Am Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
Quoted 7 lines
Quoted 2 lines
So you are saying that you have power dependencies independent of the device tree?
I can think of the following power dependencies:
- hardware bus topology
- clocks
- power domains
That means that some devices otherwise unrelated have a common power switch, doesn't it?
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
Quoted 6 lines
So you mean I should handle that in my
arch/busspecificdev->bus->pm->autosuspend()code? So instead of callingdev->driver->pm->autosuspend()straight away I keep track of the use count of the power domain and when the domain is unused I calldev->driver->pm->autosuspend()for all devices in the power domain before powering off?
How much overhead do you have in autosuspend() if it actually powers down the devices? If it is small, I suggest you really run the autosuspend methods in the drivers but use a counter for the actual power switching on a bus level.
Quoted 3 lines
I guess hooking in things in
dev->bus->pm->autosuspend()is doable, but thendev->power.runtime_statuswill be set toRPM_SUSPENDEDeven though the actual device isn't suspended at all. AndRPM_IDLEstate
Why do you care about a device being in RPM_SUSPENDED while active. The inverse is a bug, but this seems harmless.
Quoted 3 lines
will be more or less unused since the drivers should pass a delay of zero to make sure the bus code gets notified about the idle state straight away.
So? You are not getting a common code without a little overhead for some cases.
Quoted 5 lines
Basically, for my use case it would make more sense to let the
bus_typedirectly decide when a device should be suspended instead of using a timeout before calling thebus_typecode. I rather let thebus_typedecide if a timeout should be used or not instead of using it for allbus_types.
So call with a delay of 0.
Quoted 3 lines
So I guess the plan is that drivers directly should invoke
pm_request_suspend()to notify the bus that they are idle? (I guess similar to myplatform_device_idle()?)
Yes.
Quoted 4 lines
So yes, I'd like to do things in
dev->bus->pm->autosuspend(), and the code is quite close. I can't figure out why anyone would want the suspend delay at the current level though, but I guess other busses want to use that?
In your case resumption seems to cost almost no energy. In other cases you must avoid short sleeps, as you conserve less energy sleeping than it takes to resume.
Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Magnus DammAm Donnerstag, 11. Juni 2009 07:18:46 schrieb Magnus Damm:
Quoted 2 lines
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when
So you are saying that you have power dependencies independent of the device tree?
Quoted 5 lines
all devices are idle is simply that we don't get any power savings from the per device
autosuspend()callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.
Why can't you do this within the framework? You simply suspend when all a domain's devices have been autosuspended.
I suppose we could have a helper.
int pm_autosuspend_in_domain(struct device *dev)
{
int err;
mutex_lock(dev->power_domain);
if (! --dev->power_domain.active_devices)
err = dev->power_domain->power_down(dev->power_domain);
else
err = 0;
mutex_unlock(dev->power_domain);
return err;
} Regards
Oliver
Re: [patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiHi Rafael,
Quoted 11 lines · Rafael J. Wysocki
Quoted 2 lines
I tried to address your comments and the Oliver's comments too in the new version of the patch below. Please have a look and tell me what you think.
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
Quoted 6 lines
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use
-EAGAINand-EBUSYfor this purpose.Updated patch follows, sorry for the confusion.
Thanks for your work on this. I think the patch looks very good in general so I will not comment on the code itself. I do however have a few high level questions:
Q1) Regarding pm_request_suspend(), would it be possible to get a synchronous version or to make use of the completion somehow?
Q2) As pm_request_suspend() works today, the device is marked as RPM_IDLE and the delayed work is queued up. There is no real decision making going on except the time out. I'd like to let the bus code decide when to autosuspend a buch of devices. Maybe the idle handling should be broken out into a pm_request_idle() and pm_request_suspend() can be modified to synchronously suspend devices marked with pm_request_idle()?
Q3) Have you thought about how device drivers can inform the Runtime PM that the device are idle and that they need the hardware to be woken up? I'd like something similar to my "[PATCH 02/04] Driver Core:
Add idle and wakeup functions" patch but maybe not specific to platform devices. We talked about adding some hooks to the bus_type for this. Any ideas?
This is how I'm thinking of integrating your Runtime PM code with our SuperH platform devices:
Device Idle Handling:
1) Device drivers call pm_device_idle() (See Q3) which invokes arch specific platform bus code in the case of our SoC platform devices. This bus code marks the device as idle using pm_request_idle(). (See Q2). At this point light weight power management like clock stopping may be performed as well.
2) The arch specific bus code knows how the platform devices are grouped together (thanks to the data area in "[PATCH] Driver Core: Add platform device arch data V3"), and when all devices in one power domain are marked as idle the bus code calls the synchronous pm_request_suspend() (no delay).
3) When all devices in the power domain are suspended the bus code can turn off the power. The reason why I'd like to only autosuspend when all devices are idle is simply that we don't get any power savings from the per device autosuspend() callbacks, only from turning off power to the entire per-domain. So bindly autosuspending and autoresuming devices is just pure overhead unless we know we can do it for all devices in the domain.
4) Over time when the code in 2) should be extended to handle latencies.
Device Wakeup Handling:
1) Device drivers call pm_device_wakeup() (See Q3). This invokes arch specific bus code for our SoC platform devices. The bus code enables clocks if needed and also calls pm_resume_sync().
2) After the call to pm_resume_sync() the pm_device_wakeup() call returns and the device driver can access the hardware as usual.
That's it! Far from perfect but maybe a good start at least.
I have seen quite a few patches from you lately, nice work. To make tracking of the Runtime PM patches easier, can you pleae consider including the version of the patch in the subject when you post new versions?
Thanks!
/ magnus
[patch update] Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 86 lines · Rafael J. Wysocki
Quoted 8 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.I'm not sure what you mean exactly.
Quoted 8 lines
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
But no matter what the driver or bus type sets the state to, your
pm_autosuspend()will change it to one ofRPM_UNKNOWNorRPM_SUSPENDED. Neither might be right.The idea is that if ->autosuspend() or ->autoresume() returns an error code, this is a situation the PM core cannot recover from by itself, so it shouldn't pretend it knows what's happened. Instead, it marks the device as "I don't know if it is safe to touch this" and won't handle it until the device driver or bus type clears the status.
Quoted 5 lines
Quoted 1 line
The name of this constant may be confusing, but I didn't have any better ideas.
It's not clear what
RPM_ACTIVE,RPM_IDLE, andRPM_SUSPENDEDare supposed to mean; this should be documented in the code. Also, why isn't thereRPM_RESUMING?Yes, there should be. In fact it's in the current version of the patch, which is appended. Also, there's a comment explaining the meaning of the RPM_* constants in
pm.h.Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Shouldn't this happen after the device's state has changed to
RPM_SUSPENDED? That's not until after the callback returns.OK, I tried to address the issue of parent suspend/resume in the new version of the patch below (I'm not sure if I did the nesting of spinlocks in
pm_request_resume()correctly).Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
Quoted 17 lines
Quoted 16 lines
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
Quoted 6 lines
Quoted 1 line
This too should be documented in the code. Or in a Documentation file.
OK
I tried to address your comments and the Oliver's comments too in the new version of the patch below. Please have a look and tell me what you think.
Argh, I forgot about some important things.
First, there are devices with no parent (actually, it would be much easier if they had a default dummy parent, but that's a separate issue).
Second, the parent has to be taken into account in the asynchronous resume path too (which BTW is more complicated).
Finally, I decided to follow the Oliver's suggestion that some error codes returned by ->autosuspend() and ->autoresume() may be regarded as "go back to the previous state" information. I chose to use -EAGAIN and -EBUSY for this purpose.
Updated patch follows, sorry for the confusion.
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 2 drivers/base/power/runtime.c | 393 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 78 ++++++++ include/linux/pm_runtime.h | 50 +++++ kernel/power/Kconfig | 14 + kernel/power/main.c | 17 + 7 files changed, 553 insertions(+), 2 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 + responsibile 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 +76 -2
108 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 +393 -0
393 lines not on this page · raw message
include/linux/pm_runtime.h new file +50 -0
50 lines not on this page · raw message
drivers/base/power/main.c +2 -0
@@ -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Yes, by writing to the power/wakeup attribute.
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
I did think of one use for this feature. It's unique to USB, however...
In Windows, you're not supposed to unplug a hot-unpluggable device without first telling the OS -- there's a "Safely Remove Hardware" applet. When you tell the applet you want to remove a USB device, the system disables the device's port and then says it's okay to unplug the device. Now Linux doesn't have any user API for disabling USB ports, but suspending a port has the same effect (the device can't distinguish a disable from a suspend).
It turns out that some devices (MP3 players, for instance) have incorporated this into their design. They display a "Safe to unplug" message when their port is disabled or suspended. People like to see this message -- it makes them feel good about unplugging the device -- and the only way to get it under Linux is by forcing the device to be suspended. :-)
Quoted 3 lines
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
This falls into the category of "The user knows better". If the user specifically tells the kernel to suspend a device (rather than just letting it autosuspend), and this causes a problem, then it's the user's own fault.
After all, who's really the master? Us or the kernel?
Alan Stern
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 33 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Yes, by writing to the power/wakeup attribute.
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
I did think of one use for this feature. It's unique to USB, however...
In Windows, you're not supposed to unplug a hot-unpluggable device without first telling the OS -- there's a "Safely Remove Hardware" applet. When you tell the applet you want to remove a USB device, the system disables the device's port and then says it's okay to unplug the device. Now Linux doesn't have any user API for disabling USB ports, but suspending a port has the same effect (the device can't distinguish a disable from a suspend).
Quoted 6 lines
It turns out that some devices (MP3 players, for instance) have incorporated this into their design. They display a "Safe to unplug" message when their port is disabled or suspended. People like to see this message -- it makes them feel good about unplugging the device -- and the only way to get it under Linux is by forcing the device to be suspended. :-)
Well, I'd very much prefer to have a separate mechanism for that.
Quoted 10 lines
Quoted 3 lines
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
This falls into the category of "The user knows better". If the user specifically tells the kernel to suspend a device (rather than just letting it autosuspend), and this causes a problem, then it's the user's own fault.
After all, who's really the master? Us or the kernel?
Oh, that depends on who the user is. If I'm the user, I'm the master, but in case of a typical Windows user I'm afraid the kernel has to know better. ;-)
Best,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 33 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Yes, by writing to the power/wakeup attribute.
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
I did think of one use for this feature. It's unique to USB, however...
In Windows, you're not supposed to unplug a hot-unpluggable device without first telling the OS -- there's a "Safely Remove Hardware" applet. When you tell the applet you want to remove a USB device, the system disables the device's port and then says it's okay to unplug the device. Now Linux doesn't have any user API for disabling USB ports, but suspending a port has the same effect (the device can't distinguish a disable from a suspend).
Quoted 6 lines
It turns out that some devices (MP3 players, for instance) have incorporated this into their design. They display a "Safe to unplug" message when their port is disabled or suspended. People like to see this message -- it makes them feel good about unplugging the device -- and the only way to get it under Linux is by forcing the device to be suspended. :-)
Well, I'd very much prefer to have a separate mechanism for that.
Quoted 10 lines
Quoted 3 lines
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
This falls into the category of "The user knows better". If the user specifically tells the kernel to suspend a device (rather than just letting it autosuspend), and this causes a problem, then it's the user's own fault.
After all, who's really the master? Us or the kernel?
Oh, that depends on who the user is. If I'm the user, I'm the master, but in case of a typical Windows user I'm afraid the kernel has to know better. ;-)
Best,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 3 lines
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Do you mean the user has disabled the remote wakeup?
Yes, by writing to the power/wakeup attribute.
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
I did think of one use for this feature. It's unique to USB, however...
In Windows, you're not supposed to unplug a hot-unpluggable device without first telling the OS -- there's a "Safely Remove Hardware" applet. When you tell the applet you want to remove a USB device, the system disables the device's port and then says it's okay to unplug the device. Now Linux doesn't have any user API for disabling USB ports, but suspending a port has the same effect (the device can't distinguish a disable from a suspend).
It turns out that some devices (MP3 players, for instance) have incorporated this into their design. They display a "Safe to unplug" message when their port is disabled or suspended. People like to see this message -- it makes them feel good about unplugging the device -- and the only way to get it under Linux is by forcing the device to be suspended. :-)
Quoted 3 lines
The problem with it is that the user space may not know if it is safe to keep a device suspended and if it is not, the kernel will have to ignore the setting anyway, so I'm not sure what's the point (except for debugging).
This falls into the category of "The user knows better". If the user specifically tells the kernel to suspend a device (rather than just letting it autosuspend), and this causes a problem, then it's the user's own fault.
After all, who's really the master? Us or the kernel?
Alan Stern
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.I'm not sure what you mean exactly.
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
But no matter what the driver or bus type sets the state to, your pm_autosuspend() will change it to one of RPM_UNKNOWN or RPM_SUSPENDED. Neither might be right.
Quoted 1 line
The name of this constant may be confusing, but I didn't have any better ideas.
It's not clear what RPM_ACTIVE, RPM_IDLE, and RPM_SUSPENDED are supposed to mean; this should be documented in the code. Also, why isn't there RPM_RESUMING?
By the way, a legitimate reason for aborting an autosuspend is if the device's driver requires remote wakeup to be enabled during suspend but the user has disabled it.
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Shouldn't this happen after the device's state has changed to RPM_SUSPENDED? That's not until after the callback returns.
Quoted 6 lines
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.
I'm not sure either. Oliver Neukum requested it originally and it has been useful for debugging, but I haven't seen many places where it would come in useful in practice.
Quoted 10 lines
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
Quoted 6 lines
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
This too should be documented in the code. Or in a Documentation file.
Alan Stern
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Montag, 8. Juni 2009 23:31:58 schrieb Rafael J. Wysocki:
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
That is quite confusing. You'd better define error returns. One that would mean that the suspension has failed but the device is unaffected, and another one that means that the device is in an undefined state now.
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
That can't work because you have to operate between busses.
Quoted 5 lines
Quoted 3 lines
Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this?
Yes, that was the idea.
That is an important point. Can some subsytems operate with a parent still suspended?
Regards
Oliver
--
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
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 7 lines · Oliver Neukum
Am Montag, 8. Juni 2009 23:31:58 schrieb Rafael J. Wysocki:
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
That is quite confusing. You'd better define error returns.
That might work too, but the information need not be available to the driver immediately. It may need to schedule a reset of the device to recover from the error condition, for example.
Quoted 4 lines
One that would mean that the suspension has failed but the device is unaffected, and another one that means that the device is in an undefined state now.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
That can't work because you have to operate between busses.
OK, point taken.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this?
Yes, that was the idea.
That is an important point. Can some subsytems operate with a parent still suspended?
OK, I see the value of doing that at the core level.
I tried to address this in the new version of the patch, which has been sent in my last reply to Alan.
Thanks,
Rafael
Re: [linux-pm] Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 7 lines · Oliver Neukum
Am Montag, 8. Juni 2009 23:31:58 schrieb Rafael J. Wysocki:
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
That is quite confusing. You'd better define error returns.
That might work too, but the information need not be available to the driver immediately. It may need to schedule a reset of the device to recover from the error condition, for example.
Quoted 4 lines
One that would mean that the suspension has failed but the device is unaffected, and another one that means that the device is in an undefined state now.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
That can't work because you have to operate between busses.
OK, point taken.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this?
Yes, that was the idea.
That is an important point. Can some subsytems operate with a parent still suspended?
OK, I see the value of doing that at the core level.
I tried to address this in the new version of the patch, which has been sent in my last reply to Alan.
Thanks,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Montag, 8. Juni 2009 23:31:58 schrieb Rafael J. Wysocki:
Quoted 4 lines
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
That is quite confusing. You'd better define error returns. One that would mean that the suspension has failed but the device is unaffected, and another one that means that the device is in an undefined state now.
Quoted 6 lines
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
That can't work because you have to operate between busses.
Quoted 5 lines
Quoted 3 lines
Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this?
Yes, that was the idea.
That is an important point. Can some subsytems operate with a parent still suspended?
Regards
Oliver
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 14 lines · Alan Stern
Quoted 12 lines · Rafael J. Wysocki
Quoted 7 lines · Oliver Neukum
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)
Quoted 6 lines
Quoted 1 line
Anyway, below is a version with synchronous resume.
There are a few things here which need further thought:
The implementation of
pm_lock_device()assumes it will never be called with interrupts disabled. This is a bad assumption.
Indeed.
Quoted 3 lines
Use of the
RPM_UNKNOWNstate isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.
I'm not sure what you mean exactly.
If ->autosuspend() fails, the device power state may be known, but the core can't be sure if the device is active. This information is available to the driver and/or the bus type, which should change the status to whatever is appropriate.
The name of this constant may be confusing, but I didn't have any better ideas.
Quoted 4 lines
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent.
I thought the bus type's ->autosuspend() callback could take care of this.
Quoted 3 lines
Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this?
Yes, that was the idea.
Quoted 1 line
What about device's whose parent belongs to a different subsystem?
Good question. :-)
I think that requires some research. Probably a USB device attached to a PCI USB controller is a good example here, but we first need to have a prototype implementation for PCI to carry out some testing.
In fact I'd like to avoid the complexity for now and consider one bus type at a time. Especially that, for example, for PCI we won't autosuspend bridges initially, so this case is going to be really simple.
Quoted 3 lines
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
To prevent a device from being suspended - yes. To force it to stay suspended
- I'm not sure.
Anyway, that will be the next step.
Quoted 3 lines
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That has to be bus type-specific.
In the case of PCI all of the low power states (D1-D3) are in fact substates of "suspended", because we generally need to quiesce the device before putting it into any of these states.
I'm not sure if we can introduce more "levels of suspension", so to speak, at the core level, but in any case we can easily distinguish between "device quiesced and in a low power state" and "device fully active".
So, in this picture the device is "suspended" from the core's point of view once it's bus type's ->autosuspend() callback has been successfully executed.
Quoted 2 lines
That's what I come up with on a first reading. There may be more later on... :-)
Sure.
Thanks for your comments! :-)
Best,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Oliver Neukum
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
Quoted 8 lines
Quoted 3 lines
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
But I need to be able to call
__pm_schedule_resume()(at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)Anyway, below is a version with synchronous resume.
There are a few things here which need further thought:
The implementation of pm_lock_device() assumes it will never be called with interrupts disabled. This is a bad assumption.
Use of the RPM_UNKNOWN state isn't good. A bus may have valid reasons of its own for not carrying out an autosuspend. When this happens the device's state isn't unknown.
The scheme doesn't include any mechanism for communicating runtime power information up the device tree. When a device is autosuspended, its parent's driver should be told so that the driver can consider autosuspending the parent. Likewise, if we want to autoresume a device below an autosuspended parent, the parent should be autoresumed first. Did you want to make the bus subsystem responsible for all of this? What about device's whose parent belongs to a different subsystem?
There should be a sysfs interface (like the one in USB) to allow userspace to prevent a device from being autosuspended -- and perhaps also to force it to be suspended.
What about devices that have more than two runtime power states? For example, you can't squeeze PCI's {D0,D1,D2,D3hot} range into {running, suspended}.
That's what I come up with on a first reading. There may be more later on... :-)
Alan Stern
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 7 lines · Oliver Neukum
Am Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
But I need to be able to call __pm_schedule_resume() (at least) from interrupt context and I can't use a mutex from there. Otherwise I'd have used a mutex. :-)
Anyway, below is a version with synchronous resume.
Thanks,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 6 - drivers/base/power/runtime.c | 223 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 36 ++++++ include/linux/pm_runtime.h | 82 +++++++++++++++ kernel/power/Kconfig | 14 ++ kernel/power/main.c | 17 +++ 7 files changed, 376 insertions(+), 3 deletions(-)
kernel/power/Kconfig +14 -0
@@ -204,3 +204,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 + responsibile 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 +34 -2
@@ -22,6 +22,8 @@#define _LINUX_PM_H#include <linux/list.h> +#include <linux/workqueue.h> +#include <linux/spinlock.h> /* * Callbacks for platform drivers to implement.
@@ -165,6 +167,15 @@ typedef struct pm_message {* It is allowed to unregister devices while the above callbacks are being * executed. However, it is not allowed to unregister a device from within any * of its own callbacks. +* +* There also are two callbacks related to run-time power management of devices: +* +* @autosuspend: Save the device registers and put it into an energy-saving (low +* power) state at run-time, enable wake-up events as appropriate. +* +* @autoresume: Put the device into the full power state and restore its +* registers (if applicable) at run time, in response to a wake-up event +* generated by hardware or at a request of software. */ struct dev_pm_ops {
@@ -182,6 +193,10 @@ struct dev_pm_ops {int (*thaw_noirq)(struct device *dev);int (*poweroff_noirq)(struct device *dev);int (*restore_noirq)(struct device *dev); +#ifdef CONFIG_PM_RUNTIME +int (*autosuspend)(struct device *dev); +int (*autoresume)(struct device *dev); +#endif };/**
@@ -315,14 +330,31 @@ enum dpm_state { DPM_OFF_IRQ, }; +enum rpm_state { +RPM_UNKNOWN =-1 , +RPM_ACTIVE , +RPM_IDLE , +RPM_SUSPENDING , +RPM_SUSPENDED , +}; +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 struct list_head entry;#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; +struct work_struct resume_work; +unsigned int suspend_autocancel:1 ; +unsigned int resume_autocancel:1 ; +unsigned int suspend_aborted:1 ; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };/*
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 +223 -0
223 lines not on this page · raw message
include/linux/pm_runtime.h new file +82 -0
82 lines not on this page · raw message
drivers/base/power/main.c +5 -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
@@ -355,7 +357,7 @@ void dpm_resume_noirq(pm_message_t statestruct device *dev;mutex_lock (&dpm_list_mtx); -list_for_each_entry (dev, &dpm_list, power.entry) +list_for_each_entry (dev, &dpm_list, power.entry) {if (dev->power.status >DPM_OFF ) {int error;
@@ -364,6 +366,8 @@ void dpm_resume_noirq(pm_message_t stateif (error)pm_dev_err (dev, state," early" , error); } +pm_runtime_autocancel (dev); + }mutex_unlock (&dpm_list_mtx);resume_device_irqs (); }
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiAm Sonntag, 7. Juni 2009 23:46:59 schrieb Rafael J. Wysocki:
Quoted 2 lines
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
This will absolutely be the default. You resume a device because you want it to do something now. It seems to me that you making your problem worse by using a spinlock as a lock. A mutex would make it easier.
Regards
Oliver
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. Wysockikernel/power/Kconfig config APM_EMULATION · line 220
Quoted 13 lines · Rafael J. Wysocki
kernel/power/Kconfig +13
-0+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 + responsibile for the actual handling of the autosuspend requests and + wake-up events.
Halleluya! :-)
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 18 lines · Ingo Molnar
kernel/power/Kconfig config APM_EMULATION · line 220
Quoted 13 lines · Rafael J. Wysocki
kernel/power/Kconfig +13
-0+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 + responsibile for the actual handling of the autosuspend requests and + wake-up events.Halleluya! :-)
I guess this means you like the general idea. ;-)
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Best,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 20 lines · Rafael J. Wysocki
Quoted 18 lines · Ingo Molnar
kernel/power/Kconfig config APM_EMULATION · line 220
Quoted 13 lines · Rafael J. Wysocki
kernel/power/Kconfig +13
-0+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 + responsibile for the actual handling of the autosuspend requests and + wake-up events.Halleluya! :-)
Quoted 4 lines
I guess this means you like the general idea. ;-)
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Cool. I think that if within a few years we could achieve that every default distro (both on desktops and on servers) triggers PM functionality runtime on common hardware, we'd both have lower power consumption in general, and we'd have more robust suspend-resume code as well.
It would also be far more debuggable if the various suspend/resume bits were triggered and used independently and runtime, allowing bugs to be 'spread out'. Right now if they fail they fail in a very hard to debug spot (in the s2ram/s2disk codepaths), which makes their hacking rather challenging. (which i'm sure you are well aware of ;-)
So yes, i like the idea, a lot.
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. WysockiQuoted 20 lines · Rafael J. Wysocki
Quoted 18 lines · Ingo Molnar
kernel/power/Kconfig config APM_EMULATION · line 220
Quoted 13 lines · Rafael J. Wysocki
kernel/power/Kconfig +13
-0+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 + responsibile for the actual handling of the autosuspend requests and + wake-up events.Halleluya! :-)
Quoted 4 lines
I guess this means you like the general idea. ;-)
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Cool. I think that if within a few years we could achieve that every default distro (both on desktops and on servers) triggers PM functionality runtime on common hardware, we'd both have lower power consumption in general, and we'd have more robust suspend-resume code as well.
It would also be far more debuggable if the various suspend/resume bits were triggered and used independently and runtime, allowing bugs to be 'spread out'. Right now if they fail they fail in a very hard to debug spot (in the s2ram/s2disk codepaths), which makes their hacking rather challenging. (which i'm sure you are well aware of ;-)
So yes, i like the idea, a lot.
Ingo
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 10 lines · Ingo Molnar
Quoted 2 lines · Rafael J. Wysocki
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Cool. I think that if within a few years we could achieve that every default distro (both on desktops and on servers) triggers PM functionality runtime on common hardware, we'd both have lower power consumption in general, and we'd have more robust suspend-resume code as well.
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 10 lines · Ingo Molnar
Quoted 2 lines · Rafael J. Wysocki
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Cool. I think that if within a few years we could achieve that every default distro (both on desktops and on servers) triggers PM functionality runtime on common hardware, we'd both have lower power consumption in general, and we'd have more robust suspend-resume code as well.
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 12 lines · Matthew Garrett
Quoted 10 lines · Ingo Molnar
Quoted 2 lines · Rafael J. Wysocki
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Cool. I think that if within a few years we could achieve that every default distro (both on desktops and on servers) triggers PM functionality runtime on common hardware, we'd both have lower power consumption in general, and we'd have more robust suspend-resume code as well.
Quoted 8 lines
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
What will the 'user space policy' bit do what the kernel cannot?
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 12 lines · Matthew Garrett
Quoted 10 lines · Ingo Molnar
Quoted 2 lines · Rafael J. Wysocki
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Cool. I think that if within a few years we could achieve that every default distro (both on desktops and on servers) triggers PM functionality runtime on common hardware, we'd both have lower power consumption in general, and we'd have more robust suspend-resume code as well.
Quoted 8 lines
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
What will the 'user space policy' bit do what the kernel cannot?
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
Ingo
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Matthew Garrett
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
Quoted 1 line
What will the 'user space policy' bit do what the kernel cannot?
How does the kernel know whether the user cares about SATA hotplug or not?
Quoted 3 lines
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
It'll be up to the distributions to provide sane defaults and let them be reconfigured as necessary, depending on the information we have from the user and maybe platform-specific knowledge. But this is a difficult problem - we need to be smart about all the potential sources of information in order to pick an appropriate policy, and the kernel's not the right layer to do some of this information collection.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 11 lines · Ingo Molnar
Quoted 8 lines · Matthew Garrett
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
Quoted 1 line
What will the 'user space policy' bit do what the kernel cannot?
How does the kernel know whether the user cares about SATA hotplug or not?
Quoted 3 lines
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
It'll be up to the distributions to provide sane defaults and let them be reconfigured as necessary, depending on the information we have from the user and maybe platform-specific knowledge. But this is a difficult problem - we need to be smart about all the potential sources of information in order to pick an appropriate policy, and the kernel's not the right layer to do some of this information collection.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 12 lines · Matthew Garrett
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Matthew Garrett
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
Quoted 4 lines
Quoted 1 line
What will the 'user space policy' bit do what the kernel cannot?
How does the kernel know whether the user cares about SATA hotplug or not?
The typical user probably doesnt know what 'SATA' means, and probably has very vague concepts about 'hotplug' as well.
The kernel default should be: 'yes, if the kernel feature is enabled and if the hardware can support it' (it's not on a blacklist of some sort, etc., etc.).
Quoted 11 lines
Quoted 3 lines
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
It'll be up to the distributions to provide sane defaults and let them be reconfigured as necessary, depending on the information we have from the user and maybe platform-specific knowledge. But this is a difficult problem - we need to be smart about all the potential sources of information in order to pick an appropriate policy, and the kernel's not the right layer to do some of this information collection.
What sources of information exactly? Again, the user wont enter anything, in 95% of the cases - in the remaining 3% of cases what is entered is wrong and only in another 2% of cases is it correct ;-)
Sane kernel defaults are important and the kernel sure knows what kind of hardware it runs on. This 'let the user decide policy' for something as fundamental (and also as arcane) as power saving mode is really a disease that has caused a lot of unnecessary pain in Linux in the past 15 years.
Sure, there might be tradeoffs when a piece of hardware cannot be turned off sanely: obviously the monitor might not know it (currently) whether someone is watching it, and wake-on-packet-for-me is not commonly implemented in wireless and wired networking cards so turning off an active networking card might not be possible without the user asking allowing that imperfect mode of power saving.
But there are plenty of cases where turning off hardware is fine, and the broken special cases will go away as technology advances, and we should not design based on broken concepts.
( Providing a way to _override_ those defaults is of course natural,
via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 12 lines · Matthew Garrett
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Matthew Garrett
The difficulty is in determining when it's viable to autosuspend a given device. There's a limit to how much we can determine purely from kernel state (for instance, we could suspend ahci when there's no pending disk access, but we'd lose hotplug notifications) so there's going to have to be some level of userspace policy determination. Having the infrastructure in the kernel is an important part of this, but there'll be some distance to go after that.
Quoted 4 lines
Quoted 1 line
What will the 'user space policy' bit do what the kernel cannot?
How does the kernel know whether the user cares about SATA hotplug or not?
The typical user probably doesnt know what 'SATA' means, and probably has very vague concepts about 'hotplug' as well.
The kernel default should be: 'yes, if the kernel feature is enabled and if the hardware can support it' (it's not on a blacklist of some sort, etc., etc.).
Quoted 11 lines
Quoted 3 lines
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
It'll be up to the distributions to provide sane defaults and let them be reconfigured as necessary, depending on the information we have from the user and maybe platform-specific knowledge. But this is a difficult problem - we need to be smart about all the potential sources of information in order to pick an appropriate policy, and the kernel's not the right layer to do some of this information collection.
What sources of information exactly? Again, the user wont enter anything, in 95% of the cases - in the remaining 3% of cases what is entered is wrong and only in another 2% of cases is it correct ;-)
Sane kernel defaults are important and the kernel sure knows what kind of hardware it runs on. This 'let the user decide policy' for something as fundamental (and also as arcane) as power saving mode is really a disease that has caused a lot of unnecessary pain in Linux in the past 15 years.
Sure, there might be tradeoffs when a piece of hardware cannot be turned off sanely: obviously the monitor might not know it (currently) whether someone is watching it, and wake-on-packet-for-me is not commonly implemented in wireless and wired networking cards so turning off an active networking card might not be possible without the user asking allowing that imperfect mode of power saving.
But there are plenty of cases where turning off hardware is fine, and the broken special cases will go away as technology advances, and we should not design based on broken concepts.
( Providing a way to _override_ those defaults is of course natural,
via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
Ingo
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
How does the kernel know whether the user cares about SATA hotplug or not?
The typical user probably doesnt know what 'SATA' means, and probably has very vague concepts about 'hotplug' as well.
eSATA is pretty common now.
Quoted 3 lines
The kernel default should be: 'yes, if the kernel feature is enabled and if the hardware can support it' (it's not on a blacklist of some sort, etc., etc.).
The problem with this kind of default is that you get people who are confused that their hardware doesn't work. If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
Quoted 11 lines
Quoted 7 lines
It'll be up to the distributions to provide sane defaults and let them be reconfigured as necessary, depending on the information we have from the user and maybe platform-specific knowledge. But this is a difficult problem - we need to be smart about all the potential sources of information in order to pick an appropriate policy, and the kernel's not the right layer to do some of this information collection.
What sources of information exactly? Again, the user wont enter anything, in 95% of the cases - in the remaining 3% of cases what is entered is wrong and only in another 2% of cases is it correct ;-)
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Quoted 7 lines
Sure, there might be tradeoffs when a piece of hardware cannot be turned off sanely: obviously the monitor might not know it (currently) whether someone is watching it, and wake-on-packet-for-me is not commonly implemented in wireless and wired networking cards so turning off an active networking card might not be possible without the user asking allowing that imperfect mode of power saving.
These cases can all be handled with sufficiently intelligent userland, so I'm not worried about them.
Quoted 5 lines
( Providing a way to _override_ those defaults is of course natural,
via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 7 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
How does the kernel know whether the user cares about SATA hotplug or not?
The typical user probably doesnt know what 'SATA' means, and probably has very vague concepts about 'hotplug' as well.
eSATA is pretty common now.
Quoted 3 lines
The kernel default should be: 'yes, if the kernel feature is enabled and if the hardware can support it' (it's not on a blacklist of some sort, etc., etc.).
The problem with this kind of default is that you get people who are confused that their hardware doesn't work. If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
Quoted 11 lines
Quoted 7 lines
It'll be up to the distributions to provide sane defaults and let them be reconfigured as necessary, depending on the information we have from the user and maybe platform-specific knowledge. But this is a difficult problem - we need to be smart about all the potential sources of information in order to pick an appropriate policy, and the kernel's not the right layer to do some of this information collection.
What sources of information exactly? Again, the user wont enter anything, in 95% of the cases - in the remaining 3% of cases what is entered is wrong and only in another 2% of cases is it correct ;-)
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Quoted 7 lines
Sure, there might be tradeoffs when a piece of hardware cannot be turned off sanely: obviously the monitor might not know it (currently) whether someone is watching it, and wake-on-packet-for-me is not commonly implemented in wireless and wired networking cards so turning off an active networking card might not be possible without the user asking allowing that imperfect mode of power saving.
These cases can all be handled with sufficiently intelligent userland, so I'm not worried about them.
Quoted 5 lines
( Providing a way to _override_ those defaults is of course natural,
via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 11 lines · Matthew Garrett
Quoted 8 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
How does the kernel know whether the user cares about SATA hotplug or not?
The typical user probably doesnt know what 'SATA' means, and probably has very vague concepts about 'hotplug' as well.
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]
Quoted 6 lines
Quoted 3 lines
The kernel default should be: 'yes, if the kernel feature is enabled and if the hardware can support it' (it's not on a blacklist of some sort, etc., etc.).
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that _cannot be suspended_ safely (physically) should not be auto-suspended, of course.
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Quoted 10 lines
Quoted 4 lines
What sources of information exactly? Again, the user wont enter anything, in 95% of the cases - in the remaining 3% of cases what is entered is wrong and only in another 2% of cases is it correct ;-)
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
Quoted 17 lines
Quoted 7 lines
Sure, there might be tradeoffs when a piece of hardware cannot be turned off sanely: obviously the monitor might not know it (currently) whether someone is watching it, and wake-on-packet-for-me is not commonly implemented in wireless and wired networking cards so turning off an active networking card might not be possible without the user asking allowing that imperfect mode of power saving.
These cases can all be handled with sufficiently intelligent userland, so I'm not worried about them.
Quoted 5 lines
( Providing a way to _override_ those defaults is of course natural,
via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
Quoted 10 lines
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
See my reply to Oliver. This is really advocating a broken model of device usage. That volume key usage dependency is being hidden from the kernel, and then you want to kludge it around by pushing suspend functionality to user-space? That way lies madness. The proper way is to close the device if it's not used by anything. Then the kernel can auto-suspend it just like it could auto-suspend network interfaces that are not in use, or like it could auto-suspend a dislay port that has no monitor or other output device attached.
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 11 lines · Matthew Garrett
Quoted 8 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
How does the kernel know whether the user cares about SATA hotplug or not?
The typical user probably doesnt know what 'SATA' means, and probably has very vague concepts about 'hotplug' as well.
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]
Quoted 6 lines
Quoted 3 lines
The kernel default should be: 'yes, if the kernel feature is enabled and if the hardware can support it' (it's not on a blacklist of some sort, etc., etc.).
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that _cannot be suspended_ safely (physically) should not be auto-suspended, of course.
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Quoted 10 lines
Quoted 4 lines
What sources of information exactly? Again, the user wont enter anything, in 95% of the cases - in the remaining 3% of cases what is entered is wrong and only in another 2% of cases is it correct ;-)
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
Quoted 17 lines
Quoted 7 lines
Sure, there might be tradeoffs when a piece of hardware cannot be turned off sanely: obviously the monitor might not know it (currently) whether someone is watching it, and wake-on-packet-for-me is not commonly implemented in wireless and wired networking cards so turning off an active networking card might not be possible without the user asking allowing that imperfect mode of power saving.
These cases can all be handled with sufficiently intelligent userland, so I'm not worried about them.
Quoted 5 lines
( Providing a way to _override_ those defaults is of course natural,
via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
Quoted 10 lines
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
See my reply to Oliver. This is really advocating a broken model of device usage. That volume key usage dependency is being hidden from the kernel, and then you want to kludge it around by pushing suspend functionality to user-space? That way lies madness. The proper way is to close the device if it's not used by anything. Then the kernel can auto-suspend it just like it could auto-suspend network interfaces that are not in use, or like it could auto-suspend a dislay port that has no monitor or other output device attached.
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 5 lines · Ingo Molnar
Quoted 1 line · Matthew Garrett
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]
Users know that there's a socket on the front of their computer that they can plug a hard drive into, and if that doesn't work then they're going to be upset.
Quoted 6 lines
Quoted 2 lines
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that
_cannotbesuspended_safely (physically) should not be auto-suspended, of course.
So, like I said, the kernel can't automatically suspend AHCI unless it's received some information from elsewhere that tells it it's ok to. The kernel can't know if there's an eSATA port or not.
Quoted 10 lines
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Yes. And powersaving is a tradeoff between functionality and power consumption. The kernel doesn't know what level of functionality a given user requires. It *can't* know that itself.
Quoted 7 lines
Quoted 5 lines
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
To the best of my knowledge, yes.
Quoted 11 lines
Quoted 10 lines
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
Quoted 8 lines
See my reply to Oliver. This is really advocating a broken model of device usage. That volume key usage dependency is being hidden from the kernel, and then you want to kludge it around by pushing suspend functionality to user-space? That way lies madness. The proper way is to close the device if it's not used by anything. Then the kernel can auto-suspend it just like it could auto-suspend network interfaces that are not in use, or like it could auto-suspend a dislay port that has no monitor or other output device attached.
No, we can't just close it - then we won't get notification that a key's been hit in order to unlock the screensaver. Yes, we can greatly expand the userland-visible interface to every piece of hardware in order to make this work, but that's a huge amount of effort to avoid a model where userspace sets some tunables appropriately.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 68 lines · Matthew Garrett
Quoted 5 lines · Ingo Molnar
Quoted 1 line · Matthew Garrett
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]Users know that there's a socket on the front of their computer that they can plug a hard drive into, and if that doesn't work then they're going to be upset.
Quoted 6 lines
Quoted 2 lines
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that
_cannotbesuspended_safely (physically) should not be auto-suspended, of course.So, like I said, the kernel can't automatically suspend AHCI unless it's received some information from elsewhere that tells it it's ok to. The kernel can't know if there's an eSATA port or not.
Quoted 10 lines
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Yes. And powersaving is a tradeoff between functionality and power consumption. The kernel doesn't know what level of functionality a given user requires. It *can't* know that itself.
Quoted 7 lines
Quoted 5 lines
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
To the best of my knowledge, yes.
Quoted 11 lines
Quoted 10 lines
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
Quoted 9 lines
See my reply to Oliver. This is really advocating a broken model of device usage. That volume key usage dependency is being hidden from the kernel, and then you want to kludge it around by pushing suspend functionality to user-space? That way lies madness. The proper way is to close the device if it's not used by anything. Then the kernel can auto-suspend it just like it could auto-suspend network interfaces that are not in use, or like it could auto-suspend a dislay port that has no monitor or other output device attached.
Quoted 2 lines
No, we can't just close it - then we won't get notification that a key's been hit in order to unlock the screensaver. [...]
Looks like a broken notification model.
Quoted 4 lines
[...] Yes, we can greatly expand the userland-visible interface to every piece of hardware in order to make this work, but that's a huge amount of effort to avoid a model where userspace sets some tunables appropriately.
What huge amount of effort? All you are doing is to track the "is the device really used" state in user-space - and, if the current desktop experience is any measure, highly imperfectly so.
What i'm suggesting is to track it properly in the kernel. It's not like the kernel doesnt need to know whether a piece of hardware is under use or not ...
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 68 lines · Matthew Garrett
Quoted 5 lines · Ingo Molnar
Quoted 1 line · Matthew Garrett
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]Users know that there's a socket on the front of their computer that they can plug a hard drive into, and if that doesn't work then they're going to be upset.
Quoted 6 lines
Quoted 2 lines
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that
_cannotbesuspended_safely (physically) should not be auto-suspended, of course.So, like I said, the kernel can't automatically suspend AHCI unless it's received some information from elsewhere that tells it it's ok to. The kernel can't know if there's an eSATA port or not.
Quoted 10 lines
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Yes. And powersaving is a tradeoff between functionality and power consumption. The kernel doesn't know what level of functionality a given user requires. It *can't* know that itself.
Quoted 7 lines
Quoted 5 lines
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
To the best of my knowledge, yes.
Quoted 11 lines
Quoted 10 lines
My argument is "Hardware should work, and if the kernel default is for it to be broken then the default is wrong". We went through this for USB autosuspend. Userspace simply has more available information than the kernel, and it's not just a matter of static configuration (though that may be part of it). For instance, Oliver's example of screensavers and USB keyboards. If nothing's paying attention to volume keys (or if the keyboard doesn't have any) then you can enable remote wakeup and suspend the keyboard. If something /is/ paying attention to volume keys, you can't do that. That's the kind of case I'm discussing.
Quoted 9 lines
See my reply to Oliver. This is really advocating a broken model of device usage. That volume key usage dependency is being hidden from the kernel, and then you want to kludge it around by pushing suspend functionality to user-space? That way lies madness. The proper way is to close the device if it's not used by anything. Then the kernel can auto-suspend it just like it could auto-suspend network interfaces that are not in use, or like it could auto-suspend a dislay port that has no monitor or other output device attached.
Quoted 2 lines
No, we can't just close it - then we won't get notification that a key's been hit in order to unlock the screensaver. [...]
Looks like a broken notification model.
Quoted 4 lines
[...] Yes, we can greatly expand the userland-visible interface to every piece of hardware in order to make this work, but that's a huge amount of effort to avoid a model where userspace sets some tunables appropriately.
What huge amount of effort? All you are doing is to track the "is the device really used" state in user-space - and, if the current desktop experience is any measure, highly imperfectly so.
What i'm suggesting is to track it properly in the kernel. It's not like the kernel doesnt need to know whether a piece of hardware is under use or not ...
Ingo
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 6 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
No, we can't just close it - then we won't get notification that a key's been hit in order to unlock the screensaver. [...]
Looks like a broken notification model.
We've closed the input device. Where are we supposed to get the input event from?
Quoted 5 lines
Quoted 4 lines
[...] Yes, we can greatly expand the userland-visible interface to every piece of hardware in order to make this work, but that's a huge amount of effort to avoid a model where userspace sets some tunables appropriately.
Quoted 7 lines
What huge amount of effort? All you are doing is to track the "is the device really used" state in user-space - and, if the current desktop experience is any measure, highly imperfectly so.
What i'm suggesting is to track it properly in the kernel. It's not like the kernel doesnt need to know whether a piece of hardware is under use or not ...
So, for instance, we need to add interfaces like "I care about hotplug events on this SATA port" and "I'm listening for these keys so please don't suspend the device" and "The service bound to this port needs to maintain network connectivity and the one bound to this port doesn't, so only put the wireless card into deep powersave if the first exits", and then we need to wait for userspace to adopt these interfaces before we can enable any of the functionality because otherwise old userspace will be broken with new kernels.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 6 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
No, we can't just close it - then we won't get notification that a key's been hit in order to unlock the screensaver. [...]
Looks like a broken notification model.
We've closed the input device. Where are we supposed to get the input event from?
Quoted 5 lines
Quoted 4 lines
[...] Yes, we can greatly expand the userland-visible interface to every piece of hardware in order to make this work, but that's a huge amount of effort to avoid a model where userspace sets some tunables appropriately.
Quoted 7 lines
What huge amount of effort? All you are doing is to track the "is the device really used" state in user-space - and, if the current desktop experience is any measure, highly imperfectly so.
What i'm suggesting is to track it properly in the kernel. It's not like the kernel doesnt need to know whether a piece of hardware is under use or not ...
So, for instance, we need to add interfaces like "I care about hotplug events on this SATA port" and "I'm listening for these keys so please don't suspend the device" and "The service bound to this port needs to maintain network connectivity and the one bound to this port doesn't, so only put the wireless card into deep powersave if the first exits", and then we need to wait for userspace to adopt these interfaces before we can enable any of the functionality because otherwise old userspace will be broken with new kernels.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 14 lines
Quoted 6 lines
Quoted 5 lines
[...] Yes, we can greatly expand the userland-visible interface to every piece of hardware in order to make this work, but that's a huge amount of effort to avoid a model where userspace sets some tunables appropriately.
Quoted 7 lines
What huge amount of effort? All you are doing is to track the "is the device really used" state in user-space - and, if the current desktop experience is any measure, highly imperfectly so.
What i'm suggesting is to track it properly in the kernel. It's not like the kernel doesnt need to know whether a piece of hardware is under use or not ...
Quoted 8 lines
So, for instance, we need to add interfaces like "I care about hotplug events on this SATA port" and "I'm listening for these keys so please don't suspend the device" and "The service bound to this port needs to maintain network connectivity and the one bound to this port doesn't, so only put the wireless card into deep powersave if the first exits", and then we need to wait for userspace to adopt these interfaces before we can enable any of the functionality because otherwise old userspace will be broken with new kernels.
Yes, that's the way to go. It is not particulary easy way, but at least such userspace will work with upcoming hardware and kernel will be able to get features such as 'system autosuspend'...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 34 lines · Matthew Garrett
Quoted 4 lines · Ingo Molnar
Quoted 1 line · Matthew Garrett
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]Users know that there's a socket on the front of their computer that they can plug a hard drive into, and if that doesn't work then they're going to be upset.
Quoted 5 lines
Quoted 2 lines
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that
_cannotbesuspended_safely (physically) should not be auto-suspended, of course.So, like I said, the kernel can't automatically suspend AHCI unless it's received some information from elsewhere that tells it it's ok to. The kernel can't know if there's an eSATA port or not.
Quoted 9 lines
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Yes. And powersaving is a tradeoff between functionality and power consumption. The kernel doesn't know what level of functionality a given user requires. It *can't* know that itself.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
To the best of my knowledge, yes.
Well, in some cases we can get an idea - the current AHCI spec has bits in the PxCMD register (External SATA Port and Hot Plug Capable Port) which can indicate which ports are externally accessible and thus are likely to receive hotplug events. Of course, these are supposed to be programmed by the BIOS based on the particular motherboard/machine, and we all know how accurate BIOS-reported information can be..
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 34 lines · Matthew Garrett
Quoted 4 lines · Ingo Molnar
Quoted 1 line · Matthew Garrett
eSATA is pretty common now.
[ And 99% of the CPUs have an IDT still 99.9% of the users dont know
what it is :) ]Users know that there's a socket on the front of their computer that they can plug a hard drive into, and if that doesn't work then they're going to be upset.
Quoted 5 lines
Quoted 2 lines
The problem with this kind of default is that you get people who are confused that their hardware doesn't work.
If the hardware 'doesnt work' that is a kernel bug. Hardware that
_cannotbesuspended_safely (physically) should not be auto-suspended, of course.So, like I said, the kernel can't automatically suspend AHCI unless it's received some information from elsewhere that tells it it's ok to. The kernel can't know if there's an eSATA port or not.
Quoted 9 lines
Quoted 4 lines
If the kernel doesn't have enough information to make a decision it should err on the side of functionality - we're talking about fairly low-level power savings, but potentially several years of aggregate confusion on the part of users.
the difference between a 10W and a 1W footprint is a long series of 'low-level power savings'.
If users are getting confused and if hardware gets broken then tha's a plain bug and the wrong path is being walked.
Yes. And powersaving is a tradeoff between functionality and power consumption. The kernel doesn't know what level of functionality a given user requires. It *can't* know that itself.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Users are generally ok at realising correlation between a setting change and something no longer working, so as long as you provide that they'll be happy. I agree that this sucks. What we actually want is some means of reliably identifying whether a port is hotplug or not, but eSATA makes this very difficult.
Is it impossible?
To the best of my knowledge, yes.
Well, in some cases we can get an idea - the current AHCI spec has bits in the PxCMD register (External SATA Port and Hot Plug Capable Port) which can indicate which ports are externally accessible and thus are likely to receive hotplug events. Of course, these are supposed to be programmed by the BIOS based on the particular motherboard/machine, and we all know how accurate BIOS-reported information can be..
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarAm Montag, 8. Juni 2009 15:46:47 schrieb Ingo Molnar:
Quoted 5 lines
( Providing a way to _override_ those defaults is of course natural, via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
If we agree that the default shall be that the kernel doesn't switch off features of the hardware for power saving by default, does this make a practical difference to keeping the configuration in user space?
Regards
Oliver
--
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
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarAm Montag, 8. Juni 2009 15:46:47 schrieb Ingo Molnar:
Quoted 5 lines
( Providing a way to _override_ those defaults is of course natural, via /sysfs, should the user express an interest in tweaking it, or should the kernel get it so wrong that a distro wants to work it around. But your argument seems to be "push configuration and handling into user-space" which is really backwards. )
If we agree that the default shall be that the kernel doesn't switch off features of the hardware for power saving by default, does this make a practical difference to keeping the configuration in user space?
Regards
Oliver
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarAm Montag, 8. Juni 2009 15:22:35 schrieb Ingo Molnar:
Quoted 5 lines
What will the 'user space policy' bit do what the kernel cannot?
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
User space need not be the user. Currently user space doesn't tell the kernel how much functionality it needs. open/close give a binary opposition which badly maps onto the graduated capabilities devices have.
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
Regards
Oliver
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 3 lines · Oliver Neukum
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
Depends whether you have a media player running or not...
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 3 lines · Oliver Neukum
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
Depends whether you have a media player running or not...
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 4 lines · Oliver Neukum
Am Montag, 8. Juni 2009 15:22:35 schrieb Ingo Molnar:
Quoted 2 lines
What will the 'user space policy' bit do what the kernel cannot?
Quoted 8 lines
Quoted 3 lines
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
User space need not be the user. Currently user space doesn't tell the kernel how much functionality it needs. open/close give a binary opposition which badly maps onto the graduated capabilities devices have.
If the kernel isnt told what capabilities are used that's buggy code then.
Quoted 3 lines
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
The sane default here is to suspend the keyboard, except if an audio app is running that binds to the volume keys of the keyboard.
If the 'keyboard' is properly abstracted in the kernel and the kernel driver _knows_ that the volume keys are in use, this is not a problem.
Arguing otherwise is just saying the equivalent of: "we have a broken model to utilize hardware, and instead of fixing it properly, introduce an _even more broken_ model, because in the current model things cannot be made to work".
The kernel _needs_ to have precise information about whether a piece of hardware is in use or not.
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Oliver NeukumQuoted 4 lines · Oliver Neukum
Am Montag, 8. Juni 2009 15:22:35 schrieb Ingo Molnar:
Quoted 2 lines
What will the 'user space policy' bit do what the kernel cannot?
Quoted 8 lines
Quoted 3 lines
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
User space need not be the user. Currently user space doesn't tell the kernel how much functionality it needs. open/close give a binary opposition which badly maps onto the graduated capabilities devices have.
If the kernel isnt told what capabilities are used that's buggy code then.
Quoted 3 lines
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
The sane default here is to suspend the keyboard, except if an audio app is running that binds to the volume keys of the keyboard.
If the 'keyboard' is properly abstracted in the kernel and the kernel driver _knows_ that the volume keys are in use, this is not a problem.
Arguing otherwise is just saying the equivalent of: "we have a broken model to utilize hardware, and instead of fixing it properly, introduce an _even more broken_ model, because in the current model things cannot be made to work".
The kernel _needs_ to have precise information about whether a piece of hardware is in use or not.
Ingo
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 2 lines · Ingo Molnar
The kernel _needs_ to have precise information about whether a piece of hardware is in use or not.
The kernel can only have that information if userspace tells it. What we're quibbling over is whether the kernel should be explicitly told about the requirement (ie, every time an app makes a key grab in X the kernel gets told about it) or whether it should be implicit (userspace knows that a key grab has been made and so requests that the keyboard not be suspended).
We *can* put all of that complexity in the kernel. The question is whether it buys us anything. We'd have to modify huge chunks of userspace and in the process we'd end up limited to whatever policy happens to exist in the version of the kernel the user is running.
I'd like the kernel to expose this functionality but leave the policy decisions to userland.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 2 lines · Ingo Molnar
The kernel _needs_ to have precise information about whether a piece of hardware is in use or not.
The kernel can only have that information if userspace tells it. What we're quibbling over is whether the kernel should be explicitly told about the requirement (ie, every time an app makes a key grab in X the kernel gets told about it) or whether it should be implicit (userspace knows that a key grab has been made and so requests that the keyboard not be suspended).
We *can* put all of that complexity in the kernel. The question is whether it buys us anything. We'd have to modify huge chunks of userspace and in the process we'd end up limited to whatever policy happens to exist in the version of the kernel the user is running.
I'd like the kernel to expose this functionality but leave the policy decisions to userland.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 12 lines · Matthew Garrett
Quoted 2 lines · Ingo Molnar
The kernel _needs_ to have precise information about whether a piece of hardware is in use or not.
The kernel can only have that information if userspace tells it. What we're quibbling over is whether the kernel should be explicitly told about the requirement (ie, every time an app makes a key grab in X the kernel gets told about it) or whether it should be implicit (userspace knows that a key grab has been made and so requests that the keyboard not be suspended).
Quoted 8 lines
We *can* put all of that complexity in the kernel. The question is whether it buys us anything. We'd have to modify huge chunks of userspace and in the process we'd end up limited to whatever policy happens to exist in the version of the kernel the user is running.
I'd like the kernel to expose this functionality but leave the policy decisions to userland.
The thing is, suspending something that is being used and relied on by an app is a _bug_. This is rather fundamental: hardware state and usage tracking is _NOT POLICY_.
Having a global override of "dont ever suspend anything here, because i say so" _is_ policy.
Providing _essential_ functionality to not suspend a keyboard while an app relies on it is _NOT_ policy.
I will even buy the argument that most current hardware cannot be auto-suspended safely.
But if you think that tracking the usage state of the hardware is 'complexity', then you very much dont know what you are talking about. The main task of the kernel is to track hardware usage and to abstract away the fact that the same hardware is used by multiple tasks, and to do it safely. It's what the kernel does all day.
Ingo
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Matthew GarrettQuoted 12 lines · Matthew Garrett
Quoted 2 lines · Ingo Molnar
The kernel _needs_ to have precise information about whether a piece of hardware is in use or not.
The kernel can only have that information if userspace tells it. What we're quibbling over is whether the kernel should be explicitly told about the requirement (ie, every time an app makes a key grab in X the kernel gets told about it) or whether it should be implicit (userspace knows that a key grab has been made and so requests that the keyboard not be suspended).
Quoted 8 lines
We *can* put all of that complexity in the kernel. The question is whether it buys us anything. We'd have to modify huge chunks of userspace and in the process we'd end up limited to whatever policy happens to exist in the version of the kernel the user is running.
I'd like the kernel to expose this functionality but leave the policy decisions to userland.
The thing is, suspending something that is being used and relied on by an app is a _bug_. This is rather fundamental: hardware state and usage tracking is _NOT POLICY_.
Having a global override of "dont ever suspend anything here, because i say so" _is_ policy.
Providing _essential_ functionality to not suspend a keyboard while an app relies on it is _NOT_ policy.
I will even buy the argument that most current hardware cannot be auto-suspended safely.
But if you think that tracking the usage state of the hardware is 'complexity', then you very much dont know what you are talking about. The main task of the kernel is to track hardware usage and to abstract away the fact that the same hardware is used by multiple tasks, and to do it safely. It's what the kernel does all day.
Ingo
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
Quoted 5 lines · Ingo Molnar
But if you think that tracking the usage state of the hardware is 'complexity', then you very much dont know what you are talking about. The main task of the kernel is to track hardware usage and to abstract away the fact that the same hardware is used by multiple tasks, and to do it safely. It's what the kernel does all day.
What I'm saying is that you don't *know* what the usage state of the hardware is, and in many cases you can't know. A given user may be happy to sacrifice their SATA hotplug support. Another with identical hardware may not. A given network application may be mission critical and intolerant of the network interface being shut down. The same application in a different context may not. We'd need to provide a bewildering array of interfaces to distinguish between these situations, and we'd be unable to turn on autosuspend until the entirity of userspace had been ported to them.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 5 lines · Ingo Molnar
But if you think that tracking the usage state of the hardware is 'complexity', then you very much dont know what you are talking about. The main task of the kernel is to track hardware usage and to abstract away the fact that the same hardware is used by multiple tasks, and to do it safely. It's what the kernel does all day.
What I'm saying is that you don't *know* what the usage state of the hardware is, and in many cases you can't know. A given user may be happy to sacrifice their SATA hotplug support. Another with identical hardware may not. A given network application may be mission critical and intolerant of the network interface being shut down. The same application in a different context may not. We'd need to provide a bewildering array of interfaces to distinguish between these situations, and we'd be unable to turn on autosuspend until the entirity of userspace had been ported to them.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 9 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
I'd like the kernel to expose this functionality but leave the policy decisions to userland.
The thing is, suspending something that is being used and relied on by an app is a _bug_. This is rather fundamental: hardware state and usage tracking is
_NOTPOLICY_.
Yes. But, actual example time: what about the case where completely turning off a laptop's DVD drive saves extra power, but then also turns off kernel and userspace notification of a disc being inserted?
One of the Other OS's handles this by having a popup when the battery gets low, asking if it's okay to turn the drive off. This is part of what Matthew is talking about here.
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 9 lines · Ingo Molnar
Quoted 2 lines · Matthew Garrett
I'd like the kernel to expose this functionality but leave the policy decisions to userland.
The thing is, suspending something that is being used and relied on by an app is a _bug_. This is rather fundamental: hardware state and usage tracking is
_NOTPOLICY_.
Yes. But, actual example time: what about the case where completely turning off a laptop's DVD drive saves extra power, but then also turns off kernel and userspace notification of a disc being inserted?
One of the Other OS's handles this by having a popup when the battery gets low, asking if it's okay to turn the drive off. This is part of what Matthew is talking about here.
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 8 lines · Ingo Molnar
Quoted 3 lines
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
The sane default here is to suspend the keyboard, except if an audio app is running that binds to the volume keys of the keyboard. If the 'keyboard' is properly abstracted in the kernel and the kernel driver _knows_ that the volume keys are in use, this is not a problem.
So, if you want to abstract this properly, you are proposing that the application should in some sense "bind to keyboard keys"?
That has several drawbacks:
- applications in the current universe don't do that
- it's awful overhead:
+ it apparently wouldn't have any other use than for waking up from autosuspended mode (possibly while screensaver is running)
+ I believe that application writers will find it a little boring to have to start all their main() functions with explicit eunumeration of the keys the application is expecting :)
- even if we require applications to do so, there will be ones violating this rule (i.e. kernel only knows what userspace tells him, in this situation ... is this reliable enough?)
To sum it up -- I don't think that what you are proposing will work.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: Run-time PM idea (was: Re: [linux-pm] [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 8 lines · Ingo Molnar
Quoted 3 lines
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
The sane default here is to suspend the keyboard, except if an audio app is running that binds to the volume keys of the keyboard. If the 'keyboard' is properly abstracted in the kernel and the kernel driver _knows_ that the volume keys are in use, this is not a problem.
So, if you want to abstract this properly, you are proposing that the application should in some sense "bind to keyboard keys"?
That has several drawbacks:
- applications in the current universe don't do that
- it's awful overhead:
+ it apparently wouldn't have any other use than for waking up from autosuspended mode (possibly while screensaver is running)
+ I believe that application writers will find it a little boring to have to start all their main() functions with explicit eunumeration of the keys the application is expecting :)
- even if we require applications to do so, there will be ones violating this rule (i.e. kernel only knows what userspace tells him, in this situation ... is this reliable enough?)
To sum it up -- I don't think that what you are proposing will work.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarAm Montag, 8. Juni 2009 15:22:35 schrieb Ingo Molnar:
Quoted 5 lines
What will the 'user space policy' bit do what the kernel cannot?
If you mean the user has to configure something manually - that wont really happen in practice. We are happy if they know where to put those USB sticks in ;-)
User space need not be the user. Currently user space doesn't tell the kernel how much functionality it needs. open/close give a binary opposition which badly maps onto the graduated capabilities devices have.
For example do you really need every key pressed while the screen saver is running or is it enough for the keyboard to be able to generate a wakeup event?
Regards
Oliver
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Ingo MolnarQuoted 18 lines · Ingo Molnar
kernel/power/Kconfig config APM_EMULATION · line 220
Quoted 13 lines · Rafael J. Wysocki
kernel/power/Kconfig +13
-0+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 + responsibile for the actual handling of the autosuspend requests and + wake-up events.Halleluya! :-)
I guess this means you like the general idea. ;-)
Well, we've been discussing it for quite a while and since more and more people are interested, I'm giving it a high priority.
Best,
Rafael
Re: Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Rafael J. Wysockikernel/power/Kconfig config APM_EMULATION · line 220
Quoted 13 lines · Rafael J. Wysocki
kernel/power/Kconfig +13
-0+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 + responsibile for the actual handling of the autosuspend requests and + wake-up events.
Halleluya! :-)
Ingo
Run-time PM idea (was: Re: [RFC][PATCH 0/2] PM: Rearrange core suspend code)
In reply to Alan SternQuoted 12 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
Hi,
Here's something I wanted to do quite some time ago.
kernel/power/main.cbecomes more and more difficult to maintain over time, since it contains both the suspend to RAM core code and some common PM code that is also used for hibernation. For this reason [1/2] separates the suspend to RAM code frommain.cand puts it into two new files (the test facility is, again, separated from the core code for clarity).
Quoted 6 lines
Quoted 4 lines
[2/2] renames
kernel/power/disk.ctokernel/power/hibernate.c, because the role of this file is analogous tokernel/power/suspend.c(introduced by [1/2]).Comments welcome.
Looks like a good idea to me.
Great, thanks for your feedback! :-)
BTW, I've been considering the run-time PM a bit recently and the result is below (on top of this series).
I noticed that since resume can be scheduled while suspend is in progress, we need two work structures in struct device, one for suspend and one for resume. Also, in theory, we may want to resume the device before the suspend has a chance to run, so there should be some synchronization between them, which is done with the help of the spinlock in dev_pm_info.
The general idea is that drivers or bus types may use pm_schedule_suspend() to put a suspend request into the work queue and pm_schedule_resume() to queue a resume request or cancel a pending suspend request. There's no requirement to use these functions, but I think they may be helpful in some simple cases.
It may be necessary to resume a device synchronously, but I'm still thinking how to implement that.
Please have a look.
Best,
Rafael
--- drivers/base/power/Makefile | 1 drivers/base/power/main.c | 6 + drivers/base/power/runtime.c | 163 +++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 36 ++++++++- include/linux/pm_runtime.h | 82 +++++++++++++++++++++ kernel/power/Kconfig | 14 +++ kernel/power/main.c | 17 ++++ 7 files changed, 316 insertions(+), 3 deletions(-)
kernel/power/Kconfig +14 -0
@@ -204,3 +204,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 + responsibile 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 +34 -2
@@ -22,6 +22,8 @@#define _LINUX_PM_H#include <linux/list.h> +#include <linux/workqueue.h> +#include <linux/spinlock.h> /* * Callbacks for platform drivers to implement.
@@ -165,6 +167,15 @@ typedef struct pm_message {* It is allowed to unregister devices while the above callbacks are being * executed. However, it is not allowed to unregister a device from within any * of its own callbacks. +* +* There also are two callbacks related to run-time power management of devices: +* +* @autosuspend: Save the device registers and put it into an energy-saving (low +* power) state at run-time, enable wake-up events as appropriate. +* +* @autoresume: Put the device into the full power state and restore its +* registers (if applicable) at run time, in response to a wake-up event +* generated by hardware or at a request of software. */ struct dev_pm_ops {
@@ -182,6 +193,10 @@ struct dev_pm_ops {int (*thaw_noirq)(struct device *dev);int (*poweroff_noirq)(struct device *dev);int (*restore_noirq)(struct device *dev); +#ifdef CONFIG_PM_RUNTIME +int (*autosuspend)(struct device *dev); +int (*autoresume)(struct device *dev); +#endif };/**
@@ -315,14 +330,31 @@ enum dpm_state { DPM_OFF_IRQ, }; +enum rpm_state { +RPM_UNKNOWN =-1 , +RPM_ACTIVE , +RPM_IDLE , +RPM_SUSPENDING , +RPM_SUSPENDED , +}; +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 struct list_head entry;#endif +#ifdef CONFIG_PM_RUNTIME +struct delayed_work suspend_work; +struct work_struct resume_work; +unsigned int suspend_autocancel:1 ; +unsigned int resume_autocancel:1 ; +unsigned int suspend_aborted:1 ; +enum rpm_state runtime_status; +spinlock_t lock; +#endif };/*
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 +163 -0
163 lines not on this page · raw message
include/linux/pm_runtime.h new file +82 -0
82 lines not on this page · raw message
drivers/base/power/main.c +5 -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>
@@ -88,6 +89,7 @@ void device_pm_add(struct device *dev) }list_add_tail (&dev->power.entry, &dpm_list); +pm_runtime_init (dev);mutex_unlock (&dpm_list_mtx); }
@@ -355,7 +357,7 @@ void dpm_resume_noirq(pm_message_t statestruct device *dev;mutex_lock (&dpm_list_mtx); -list_for_each_entry (dev, &dpm_list, power.entry) +list_for_each_entry (dev, &dpm_list, power.entry) {if (dev->power.status >DPM_OFF ) {int error;
@@ -364,6 +366,8 @@ void dpm_resume_noirq(pm_message_t stateif (error)pm_dev_err (dev, state," early" , error); } +pm_runtime_autocancel (dev); + }mutex_unlock (&dpm_list_mtx);resume_device_irqs (); }
Quoted 10 lines · Rafael J. Wysocki
Hi,
Here's something I wanted to do quite some time ago.
kernel/power/main.cbecomes more and more difficult to maintain over time, since it contains both the suspend to RAM core code and some common PM code that is also used for hibernation. For this reason [1/2] separates the suspend to RAM code frommain.cand puts it into two new files (the test facility is, again, separated from the core code for clarity).
Quoted 4 lines
[2/2] renames
kernel/power/disk.ctokernel/power/hibernate.c, because the role of this file is analogous tokernel/power/suspend.c(introduced by [1/2]).Comments welcome.
Looks like a good idea to me.
Alan Stern