PM: Asynchronous suspend of devices
Subsystems (6)
cover PM: Asynchronous suspend of devices
Hi,
The following series of patches implements asynchronous suspend and resume of devices.
All of the patches have already been discussed, please refer to the changelogs for details.
The patches are targeted at 2.6.33, so if there are no major objections, I'll put them into the linux-next branch of the suspend-2.6 tree after .31-rc1 is out.
Thanks,
Rafael
PATCH 1/9 PM: Introduce PM links framework
From: Rafael J. Wysocki <[email protected]>
Introduce a framework for representing off-tree PM dependencies between devices.
There are PM dependencies between devices that are not reflected by the structure of the device tree. In other words, as far as PM is concerned, a device may depend on some other devices which are not its children and none of which is its parent.
Every such dependency involves two devices, one of which is a "master" and the other of which is a "slave", meaning that the "slave" have to be suspended before the "master" and cannot be woken up before it. Thus every device can be given two lists of "dependency objects", one for the dependencies where the device is the "master" and the other for the dependencies where the device is the "slave". Then, each "dependency object" can be represented as
struct pm_link {
struct device *master;
struct list_head master_hook;
struct device *slave;
struct list_head slave_hook;
};Add some synchronization, helpers for adding and removing 'struct pm_link' objects.
In addition to checking a device's parent, walk the list of its "masters", in addition to walking the list of a device's children, walk the list of its "slaves".
'struct pm_link' objects are created automatically for ACPI devices and "regular" devices associated with them. In the other cases such objects will have to be added directly by platforms / bus types / drivers etc.
--- drivers/acpi/glue.c | 3 drivers/base/core.c | 4 drivers/base/power/Makefile | 2 drivers/base/power/common.c | 280 +++++++++++++++++++++++++++++++++++++++++++ drivers/base/power/main.c | 27 ---- drivers/base/power/power.h | 31 ++-- drivers/base/power/runtime.c | 4 include/linux/pm.h | 4 include/linux/pm_link.h | 30 ++++ 9 files changed, 343 insertions(+), 42 deletions(-)
include/linux/pm.h +3 -1
@@ -408,6 +408,9 @@ enum rpm_request { };struct dev_pm_info { +spinlock_t lock; +struct list_head master_links; +struct list_head slave_links;pm_message_t power_state;unsigned int can_wakeup:1 ;unsigned int should_wakeup:1 ;
@@ -420,7 +423,6 @@ struct dev_pm_info {unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count; unsigned int disable_depth:3;
drivers/base/power/power.h +17 -14
@@ -1,3 +1,7 @@ +extern void device_pm_init (struct device *dev); +extern void device_pm_add (struct device *dev); +extern void device_pm_remove (struct device *dev); +#ifdef CONFIG_PM_RUNTIME extern void pm_runtime_init (struct device *dev);
@@ -23,7 +27,8 @@ static inline struct device *to_device(s return container_of(entry, struct device, power.entry); } -extern void device_pm_init (struct device *dev); +extern void device_pm_list_add (struct device *dev); +extern void device_pm_list_remove (struct device *dev);extern void device_pm_add (struct device *);extern void device_pm_remove (struct device *);extern void device_pm_move_before (struct device *,struct device *);
@@ -32,17 +37,8 @@ extern void device_pm_move_last(struct d#else /* !CONFIG_PM_SLEEP */ -static inline void device_pm_init (struct device *dev) -{ -pm_runtime_init (dev); -} - -static inline void device_pm_remove (struct device *dev) -{ -pm_runtime_remove (dev); -} - -static inline void device_pm_add (struct device *dev) {} +static inline void device_pm_list_add (struct device *dev) {} +static inline void device_pm_list_remove (struct device *dev) {}static inline void device_pm_move_before (struct device *deva,struct device *devb) {} static inline void device_pm_move_after(struct device *deva,
@@ -60,7 +56,11 @@ static inline void device_pm_move_last(sextern int dpm_sysfs_add (struct device *);extern void dpm_sysfs_remove (struct device *); -#else /* CONFIG_PM */ +/* drivers/base/power/link.c */ +extern int pm_link_init (void ); +extern void pm_link_remove_all (struct device *dev); + +#else /* !CONFIG_PM */ static inline int dpm_sysfs_add (struct device *dev) {
@@ -71,4 +71,7 @@ static inline void dpm_sysfs_remove(stru { } -#endif +static inline int pm_link_init (void ) {return 0 ; } +static inline void pm_link_remove_all (struct device *dev) {} + +#endif /* !CONFIG_PM */
drivers/base/core.c +4 -0
@@ -1252,9 +1252,13 @@ int __init devices_init(void) sysfs_dev_char_kobj =kobject_create_and_add ("char" , dev_kobj);if (!sysfs_dev_char_kobj) goto char_kobj_err; +if (pm_link_init ()) + goto pm_link_err;return 0 ; + pm_link_err: +kobject_put (sysfs_dev_char_kobj); char_kobj_err:kobject_put (sysfs_dev_block_kobj); block_kobj_err:
include/linux/pm_link.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* include/linux/pm_link.h - PM links manipulation core. +* +* Copyright (c) 2009 Rafael J. Wysocki <[email protected]>, Novell Inc. +* +* This file is released under the GPLv2. +*/ + +#ifndef _LINUX_PM_LINK_H +#define _LINUX_PM_LINK_H + +#include <linux/list.h> + +struct device ; + +struct pm_link { +struct device *master; +struct list_head master_hook; +struct device *slave; +struct list_head slave_hook; +}; + +extern int pm_link_add (struct device *slave,struct device *master); +extern void pm_link_remove (struct device *dev,struct device *master); +extern int device_for_each_master (struct device *slave,void *data, +int (*fn)(struct device *dev,void *data)); +extern int device_for_each_slave (struct device *master,void *data, +int (*fn)(struct device *dev,void *data)); + +#endif
drivers/base/power/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-$(CONFIG_PM) += sysfs.o +obj-$(CONFIG_PM) += sysfs.o common.o obj-$(CONFIG_PM_SLEEP) += main.o obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o
drivers/base/power/runtime.c +0 -4
@@ -972,8 +972,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_enable);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
@@ -993,8 +991,6 @@ void pm_runtime_init(struct device *dev) dev->power.timer_expires =0 ;setup_timer (&dev->power.suspend_timer, pm_suspend_timer_fn, (unsigned long )dev); - -init_waitqueue_head (&dev->power.wait_queue); }/**
drivers/base/power/main.c +5 -22
@@ -21,6 +21,7 @@#include <linux/kallsyms.h> #include <linux/mutex.h> #include <linux/pm.h> +#include <linux/pm_link.h> #include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/rwsem.h>
@@ -50,16 +51,6 @@ static DEFINE_MUTEX(dpm_list_mtx);static bool transition_started;/** -* device_pm_init - Initialize the PM-related part of a device object. -* @dev: Device object being initialized. -*/ -void device_pm_init (struct device *dev) -{ - dev->power.status =DPM_ON ; -pm_runtime_init (dev); -} - -/** * device_pm_lock - Lock the list of active devices used by the PM core. */ void device_pm_lock (void )
@@ -76,14 +67,11 @@ void device_pm_unlock(void) }/** -* device_pm_add - Add a device to the PM core's list of active devices. +* device_pm_list_add - Add a device to the PM core's list of active devices. * @dev: Device to add to the list. */ -void device_pm_add (struct device *dev) +void device_pm_list_add (struct device *dev) { -pr_debug ("PM: Adding info for %s:%s\n" , - dev->bus ? dev->bus->name :"No Bus" , -kobject_name (&dev->kobj));mutex_lock (&dpm_list_mtx);if (dev->parent) {if (dev->parent->power.status >=DPM_SUSPENDING )
@@ -97,24 +85,19 @@ void device_pm_add(struct device *dev)*/ dev_WARN (dev,"Parentless device registered during a PM transaction\n" ); } -list_add_tail (&dev->power.entry, &dpm_list);mutex_unlock (&dpm_list_mtx); }/** -* device_pm_remove - Remove a device from the PM core's list of active devices. +* device_pm_list_remove - Remove a device from the PM core's list of devices. * @dev: Device to be removed from the list. */ -void device_pm_remove (struct device *dev) +void device_pm_list_remove (struct device *dev) { -pr_debug ("PM: Removing info for %s:%s\n" , - dev->bus ? dev->bus->name :"No Bus" , -kobject_name (&dev->kobj));mutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); -pm_runtime_remove (dev); }/**
drivers/base/power/common.c new file +280 -0
280 lines not on this page · raw message
drivers/acpi/glue.c +3 -0
@@ -11,6 +11,7 @@#include <linux/device.h> #include <linux/rwsem.h> #include <linux/acpi.h> +#include <linux/pm_link.h> #define ACPI_GLUE_DEBUG 0#if ACPI_GLUE_DEBUG
@@ -170,6 +171,7 @@ static int acpi_bind_one(struct device *device_set_wakeup_enable (dev, acpi_dev->wakeup.state.enabled); } +pm_link_add (dev, &acpi_dev->dev); }return 0 ;
@@ -189,6 +191,7 @@ static int acpi_unbind_one(struct device &acpi_dev)) {sysfs_remove_link (&dev->kobj,"firmware_node" );sysfs_remove_link (&acpi_dev->dev.kobj,"physical_node" ); +pm_link_remove (dev, &acpi_dev->dev); } acpi_detach_data(dev->archdata.acpi_handle,
Re: [PATCH 1/9] PM: Introduce PM links framework
Hi Rafael,
What is the status of this patch? Wasn't it supposed to get into 2.6.32?
Regards,
Nithish Mahalingam
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Rafael J. Wysocki
Sent: Thursday, September 10, 2009 5:03 AM
To: linux-pm
Cc: Linux PCI; LKML; ACPI Devel Maling List; Arjan van de Ven; Ingo Molnar
Subject: [linux-pm] [PATCH 1/9] PM: Introduce PM links framework
From: Rafael J. Wysocki <[email protected]>
Introduce a framework for representing off-tree PM dependencies between devices.
There are PM dependencies between devices that are not reflected by the structure of the device tree. In other words, as far as PM is concerned, a device may depend on some other devices which are not its children and none of which is its parent.
Every such dependency involves two devices, one of which is a "master" and the other of which is a "slave", meaning that the "slave" have to be suspended before the "master" and cannot be woken up before it. Thus every device can be given two lists of "dependency objects", one for the dependencies where the device is the "master" and the other for the dependencies where the device is the "slave". Then, each "dependency object" can be represented as
struct pm_link {
struct device *master;
struct list_head master_hook;
struct device *slave;
struct list_head slave_hook;
};Add some synchronization, helpers for adding and removing 'struct pm_link' objects.
In addition to checking a device's parent, walk the list of its "masters", in addition to walking the list of a device's children, walk the list of its "slaves".
'struct pm_link' objects are created automatically for ACPI devices and "regular" devices associated with them. In the other cases such objects will have to be added directly by platforms / bus types / drivers etc.
--- drivers/acpi/glue.c | 3 drivers/base/core.c | 4 drivers/base/power/Makefile | 2 drivers/base/power/common.c | 280 +++++++++++++++++++++++++++++++++++++++++++ drivers/base/power/main.c | 27 ---- drivers/base/power/power.h | 31 ++-- drivers/base/power/runtime.c | 4 include/linux/pm.h | 4 include/linux/pm_link.h | 30 ++++ 9 files changed, 343 insertions(+), 42 deletions(-)
include/linux/pm.h +3 -1
@@ -408,6 +408,9 @@ enum rpm_request { };struct dev_pm_info { +spinlock_t lock; +struct list_head master_links; +struct list_head slave_links;pm_message_t power_state;unsigned int can_wakeup:1 ;unsigned int should_wakeup:1 ;
@@ -420,7 +423,6 @@ struct dev_pm_info {unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count; unsigned int disable_depth:3;
drivers/base/power/power.h +17 -14
@@ -1,3 +1,7 @@ +extern void device_pm_init (struct device *dev); +extern void device_pm_add (struct device *dev); +extern void device_pm_remove (struct device *dev); +#ifdef CONFIG_PM_RUNTIME extern void pm_runtime_init (struct device *dev);
@@ -23,7 +27,8 @@ static inline struct device *to_device(s return container_of(entry, struct device, power.entry); } -extern void device_pm_init (struct device *dev); +extern void device_pm_list_add (struct device *dev); +extern void device_pm_list_remove (struct device *dev);extern void device_pm_add (struct device *);extern void device_pm_remove (struct device *);extern void device_pm_move_before (struct device *,struct device *);
@@ -32,17 +37,8 @@ extern void device_pm_move_last(struct d#else /* !CONFIG_PM_SLEEP */ -static inline void device_pm_init (struct device *dev) -{ -pm_runtime_init (dev); -} - -static inline void device_pm_remove (struct device *dev) -{ -pm_runtime_remove (dev); -} - -static inline void device_pm_add (struct device *dev) {} +static inline void device_pm_list_add (struct device *dev) {} +static inline void device_pm_list_remove (struct device *dev) {}static inline void device_pm_move_before (struct device *deva,struct device *devb) {} static inline void device_pm_move_after(struct device *deva,
@@ -60,7 +56,11 @@ static inline void device_pm_move_last(sextern int dpm_sysfs_add (struct device *);extern void dpm_sysfs_remove (struct device *); -#else /* CONFIG_PM */ +/* drivers/base/power/link.c */ +extern int pm_link_init (void ); +extern void pm_link_remove_all (struct device *dev); + +#else /* !CONFIG_PM */ static inline int dpm_sysfs_add (struct device *dev) {
@@ -71,4 +71,7 @@ static inline void dpm_sysfs_remove(stru { } -#endif +static inline int pm_link_init (void ) {return 0 ; } +static inline void pm_link_remove_all (struct device *dev) {} + +#endif /* !CONFIG_PM */
drivers/base/core.c +4 -0
@@ -1252,9 +1252,13 @@ int __init devices_init(void) sysfs_dev_char_kobj =kobject_create_and_add ("char" , dev_kobj);if (!sysfs_dev_char_kobj) goto char_kobj_err; +if (pm_link_init ()) + goto pm_link_err;return 0 ; + pm_link_err: +kobject_put (sysfs_dev_char_kobj); char_kobj_err:kobject_put (sysfs_dev_block_kobj); block_kobj_err:
include/linux/pm_link.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* include/linux/pm_link.h - PM links manipulation core. +* +* Copyright (c) 2009 Rafael J. Wysocki <[email protected]>, Novell Inc. +* +* This file is released under the GPLv2. +*/ + +#ifndef _LINUX_PM_LINK_H +#define _LINUX_PM_LINK_H + +#include <linux/list.h> + +struct device ; + +struct pm_link { +struct device *master; +struct list_head master_hook; +struct device *slave; +struct list_head slave_hook; +}; + +extern int pm_link_add (struct device *slave,struct device *master); +extern void pm_link_remove (struct device *dev,struct device *master); +extern int device_for_each_master (struct device *slave,void *data, +int (*fn)(struct device *dev,void *data)); +extern int device_for_each_slave (struct device *master,void *data, +int (*fn)(struct device *dev,void *data)); + +#endif
drivers/base/power/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-$(CONFIG_PM) += sysfs.o +obj-$(CONFIG_PM) += sysfs.o common.o obj-$(CONFIG_PM_SLEEP) += main.o obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o
drivers/base/power/runtime.c +0 -4
@@ -972,8 +972,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_enable);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
@@ -993,8 +991,6 @@ void pm_runtime_init(struct device *dev) dev->power.timer_expires =0 ;setup_timer (&dev->power.suspend_timer, pm_suspend_timer_fn, (unsigned long )dev); - -init_waitqueue_head (&dev->power.wait_queue); }/**
drivers/base/power/main.c +5 -22
@@ -21,6 +21,7 @@#include <linux/kallsyms.h> #include <linux/mutex.h> #include <linux/pm.h> +#include <linux/pm_link.h> #include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/rwsem.h>
@@ -50,16 +51,6 @@ static DEFINE_MUTEX(dpm_list_mtx);static bool transition_started;/** -* device_pm_init - Initialize the PM-related part of a device object. -* @dev: Device object being initialized. -*/ -void device_pm_init (struct device *dev) -{ - dev->power.status =DPM_ON ; -pm_runtime_init (dev); -} - -/** * device_pm_lock - Lock the list of active devices used by the PM core. */ void device_pm_lock (void )
@@ -76,14 +67,11 @@ void device_pm_unlock(void) }/** -* device_pm_add - Add a device to the PM core's list of active devices. +* device_pm_list_add - Add a device to the PM core's list of active devices. * @dev: Device to add to the list. */ -void device_pm_add (struct device *dev) +void device_pm_list_add (struct device *dev) { -pr_debug ("PM: Adding info for %s:%s\n" , - dev->bus ? dev->bus->name :"No Bus" , -kobject_name (&dev->kobj));mutex_lock (&dpm_list_mtx);if (dev->parent) {if (dev->parent->power.status >=DPM_SUSPENDING )
@@ -97,24 +85,19 @@ void device_pm_add(struct device *dev)*/ dev_WARN (dev,"Parentless device registered during a PM transaction\n" ); } -list_add_tail (&dev->power.entry, &dpm_list);mutex_unlock (&dpm_list_mtx); }/** -* device_pm_remove - Remove a device from the PM core's list of active devices. +* device_pm_list_remove - Remove a device from the PM core's list of devices. * @dev: Device to be removed from the list. */ -void device_pm_remove (struct device *dev) +void device_pm_list_remove (struct device *dev) { -pr_debug ("PM: Removing info for %s:%s\n" , - dev->bus ? dev->bus->name :"No Bus" , -kobject_name (&dev->kobj));mutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); -pm_runtime_remove (dev); }/**
drivers/base/power/common.c new file +280 -0
280 lines not on this page · raw message
drivers/acpi/glue.c +3 -0
@@ -11,6 +11,7 @@#include <linux/device.h> #include <linux/rwsem.h> #include <linux/acpi.h> +#include <linux/pm_link.h> #define ACPI_GLUE_DEBUG 0#if ACPI_GLUE_DEBUG
@@ -170,6 +171,7 @@ static int acpi_bind_one(struct device *device_set_wakeup_enable (dev, acpi_dev->wakeup.state.enabled); } +pm_link_add (dev, &acpi_dev->dev); }return 0 ;
@@ -189,6 +191,7 @@ static int acpi_unbind_one(struct device &acpi_dev)) {sysfs_remove_link (&dev->kobj,"firmware_node" );sysfs_remove_link (&acpi_dev->dev.kobj,"physical_node" ); +pm_link_remove (dev, &acpi_dev->dev); } acpi_detach_data(dev->archdata.acpi_handle,
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 1/9 PM: Introduce PM links framework
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Introduce a framework for representing off-tree PM dependencies between devices.
There are PM dependencies between devices that are not reflected by the structure of the device tree. In other words, as far as PM is concerned, a device may depend on some other devices which are not its children and none of which is its parent.
Every such dependency involves two devices, one of which is a "master" and the other of which is a "slave", meaning that the "slave" have to be suspended before the "master" and cannot be woken up before it. Thus every device can be given two lists of "dependency objects", one for the dependencies where the device is the "master" and the other for the dependencies where the device is the "slave". Then, each "dependency object" can be represented as
struct pm_link {
struct device *master;
struct list_head master_hook;
struct device *slave;
struct list_head slave_hook;
};Add some synchronization, helpers for adding and removing 'struct pm_link' objects.
In addition to checking a device's parent, walk the list of its "masters", in addition to walking the list of a device's children, walk the list of its "slaves".
'struct pm_link' objects are created automatically for ACPI devices and "regular" devices associated with them. In the other cases such objects will have to be added directly by platforms / bus types / drivers etc.
--- drivers/acpi/glue.c | 3 drivers/base/core.c | 4 drivers/base/power/Makefile | 2 drivers/base/power/common.c | 280 +++++++++++++++++++++++++++++++++++++++++++ drivers/base/power/main.c | 27 ---- drivers/base/power/power.h | 31 ++-- drivers/base/power/runtime.c | 4 include/linux/pm.h | 4 include/linux/pm_link.h | 30 ++++ 9 files changed, 343 insertions(+), 42 deletions(-)
include/linux/pm.h +3 -1
@@ -408,6 +408,9 @@ enum rpm_request { };struct dev_pm_info { +spinlock_t lock; +struct list_head master_links; +struct list_head slave_links;pm_message_t power_state;unsigned int can_wakeup:1 ;unsigned int should_wakeup:1 ;
@@ -420,7 +423,6 @@ struct dev_pm_info {unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count; unsigned int disable_depth:3;
drivers/base/power/power.h +17 -14
@@ -1,3 +1,7 @@ +extern void device_pm_init (struct device *dev); +extern void device_pm_add (struct device *dev); +extern void device_pm_remove (struct device *dev); +#ifdef CONFIG_PM_RUNTIME extern void pm_runtime_init (struct device *dev);
@@ -23,7 +27,8 @@ static inline struct device *to_device(s return container_of(entry, struct device, power.entry); } -extern void device_pm_init (struct device *dev); +extern void device_pm_list_add (struct device *dev); +extern void device_pm_list_remove (struct device *dev);extern void device_pm_add (struct device *);extern void device_pm_remove (struct device *);extern void device_pm_move_before (struct device *,struct device *);
@@ -32,17 +37,8 @@ extern void device_pm_move_last(struct d#else /* !CONFIG_PM_SLEEP */ -static inline void device_pm_init (struct device *dev) -{ -pm_runtime_init (dev); -} - -static inline void device_pm_remove (struct device *dev) -{ -pm_runtime_remove (dev); -} - -static inline void device_pm_add (struct device *dev) {} +static inline void device_pm_list_add (struct device *dev) {} +static inline void device_pm_list_remove (struct device *dev) {}static inline void device_pm_move_before (struct device *deva,struct device *devb) {} static inline void device_pm_move_after(struct device *deva,
@@ -60,7 +56,11 @@ static inline void device_pm_move_last(sextern int dpm_sysfs_add (struct device *);extern void dpm_sysfs_remove (struct device *); -#else /* CONFIG_PM */ +/* drivers/base/power/link.c */ +extern int pm_link_init (void ); +extern void pm_link_remove_all (struct device *dev); + +#else /* !CONFIG_PM */ static inline int dpm_sysfs_add (struct device *dev) {
@@ -71,4 +71,7 @@ static inline void dpm_sysfs_remove(stru { } -#endif +static inline int pm_link_init (void ) {return 0 ; } +static inline void pm_link_remove_all (struct device *dev) {} + +#endif /* !CONFIG_PM */
drivers/base/core.c +4 -0
@@ -1252,9 +1252,13 @@ int __init devices_init(void) sysfs_dev_char_kobj =kobject_create_and_add ("char" , dev_kobj);if (!sysfs_dev_char_kobj) goto char_kobj_err; +if (pm_link_init ()) + goto pm_link_err;return 0 ; + pm_link_err: +kobject_put (sysfs_dev_char_kobj); char_kobj_err:kobject_put (sysfs_dev_block_kobj); block_kobj_err:
include/linux/pm_link.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* include/linux/pm_link.h - PM links manipulation core. +* +* Copyright (c) 2009 Rafael J. Wysocki <[email protected]>, Novell Inc. +* +* This file is released under the GPLv2. +*/ + +#ifndef _LINUX_PM_LINK_H +#define _LINUX_PM_LINK_H + +#include <linux/list.h> + +struct device ; + +struct pm_link { +struct device *master; +struct list_head master_hook; +struct device *slave; +struct list_head slave_hook; +}; + +extern int pm_link_add (struct device *slave,struct device *master); +extern void pm_link_remove (struct device *dev,struct device *master); +extern int device_for_each_master (struct device *slave,void *data, +int (*fn)(struct device *dev,void *data)); +extern int device_for_each_slave (struct device *master,void *data, +int (*fn)(struct device *dev,void *data)); + +#endif
drivers/base/power/Makefile +1 -1
@@ -1,4 +1,4 @@ -obj-$(CONFIG_PM) += sysfs.o +obj-$(CONFIG_PM) += sysfs.o common.o obj-$(CONFIG_PM_SLEEP) += main.o obj-$(CONFIG_PM_RUNTIME) += runtime.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o
drivers/base/power/runtime.c +0 -4
@@ -972,8 +972,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_enable);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
@@ -993,8 +991,6 @@ void pm_runtime_init(struct device *dev) dev->power.timer_expires =0 ;setup_timer (&dev->power.suspend_timer, pm_suspend_timer_fn, (unsigned long )dev); - -init_waitqueue_head (&dev->power.wait_queue); }/**
drivers/base/power/main.c +5 -22
@@ -21,6 +21,7 @@#include <linux/kallsyms.h> #include <linux/mutex.h> #include <linux/pm.h> +#include <linux/pm_link.h> #include <linux/pm_runtime.h> #include <linux/resume-trace.h> #include <linux/rwsem.h>
@@ -50,16 +51,6 @@ static DEFINE_MUTEX(dpm_list_mtx);static bool transition_started;/** -* device_pm_init - Initialize the PM-related part of a device object. -* @dev: Device object being initialized. -*/ -void device_pm_init (struct device *dev) -{ - dev->power.status =DPM_ON ; -pm_runtime_init (dev); -} - -/** * device_pm_lock - Lock the list of active devices used by the PM core. */ void device_pm_lock (void )
@@ -76,14 +67,11 @@ void device_pm_unlock(void) }/** -* device_pm_add - Add a device to the PM core's list of active devices. +* device_pm_list_add - Add a device to the PM core's list of active devices. * @dev: Device to add to the list. */ -void device_pm_add (struct device *dev) +void device_pm_list_add (struct device *dev) { -pr_debug ("PM: Adding info for %s:%s\n" , - dev->bus ? dev->bus->name :"No Bus" , -kobject_name (&dev->kobj));mutex_lock (&dpm_list_mtx);if (dev->parent) {if (dev->parent->power.status >=DPM_SUSPENDING )
@@ -97,24 +85,19 @@ void device_pm_add(struct device *dev)*/ dev_WARN (dev,"Parentless device registered during a PM transaction\n" ); } -list_add_tail (&dev->power.entry, &dpm_list);mutex_unlock (&dpm_list_mtx); }/** -* device_pm_remove - Remove a device from the PM core's list of active devices. +* device_pm_list_remove - Remove a device from the PM core's list of devices. * @dev: Device to be removed from the list. */ -void device_pm_remove (struct device *dev) +void device_pm_list_remove (struct device *dev) { -pr_debug ("PM: Removing info for %s:%s\n" , - dev->bus ? dev->bus->name :"No Bus" , -kobject_name (&dev->kobj));mutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); -pm_runtime_remove (dev); }/**
drivers/base/power/common.c new file +280 -0
280 lines not on this page · raw message
drivers/acpi/glue.c +3 -0
@@ -11,6 +11,7 @@#include <linux/device.h> #include <linux/rwsem.h> #include <linux/acpi.h> +#include <linux/pm_link.h> #define ACPI_GLUE_DEBUG 0#if ACPI_GLUE_DEBUG
@@ -170,6 +171,7 @@ static int acpi_bind_one(struct device *device_set_wakeup_enable (dev, acpi_dev->wakeup.state.enabled); } +pm_link_add (dev, &acpi_dev->dev); }return 0 ;
@@ -189,6 +191,7 @@ static int acpi_unbind_one(struct device &acpi_dev)) {sysfs_remove_link (&dev->kobj,"firmware_node" );sysfs_remove_link (&acpi_dev->dev.kobj,"physical_node" ); +pm_link_remove (dev, &acpi_dev->dev); } acpi_detach_data(dev->archdata.acpi_handle,
PATCH 2/9 PM: Asynchronous resume of devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Theoretically, the total time of system sleep transitions (suspend to RAM, hibernation) can be reduced by running suspend and resume callbacks of device drivers in parallel with each other. However, there are dependencies between devices such that, for example, we may not be allowed to put one device into a low power state before anohter one has been suspended (e.g. we cannot suspend a bridge before suspending all devices behind it). In particular, we're not allowed to suspend the parent of a device before suspending the device itself. Analogously, we're not allowed to resume a device before resuming its parent.
Thus, to make it possible to execute suspend and resume callbacks provided by device drivers in parallel with each other, we need to provide a synchronization mechanism preventing the dependencies between devices from being violated.
The patch below allows some devices to be resumed asynchronously, with the following rules:
(1) There is a wait queue head, dev->power.wait_queue, and an
"operation complete" flag, dev->power.op_complete for each device
object.(2) All of the power.op_complete flags are reset before suspend as well as after each resume stage (dpm_resume_noirq(), dpm_resume()).
(3) If power.async_suspend is set for dev or for one of devices it depends on, the PM core waits for the "master" device's power.op_complete flag to be set before attempting to run the resume callbacks, appropriate for this particular stage of resume, for dev.
(4) dev->power.op_complete is set for each device after running its resume callbacks at each stage of resume (dpm_resume_noirq(), dpm_resume()) and all threads waiting in the devices wait queue are woken up.
With this mechanism in place, the drivers wanting their resume callbacks to be executed asynchronously can set dev->power.async_suspend for them, with the help of device_enable_async_suspend(). In addition to that, the PM off-tree dependencies between devices have to be represented by 'struct pm_link' objects introduced by the previous patch.
In this version of the patch the async threads started to execute the resume callbacks of specific device don't exit immediately having done that, but search dpm_list for devices whose PM dependencies have already been satisfied and execute their callbacks without waiting.
--- drivers/base/power/common.c | 5 drivers/base/power/main.c | 327 ++++++++++++++++++++++++++++++++++++++++++-- include/linux/device.h | 6 include/linux/pm.h | 6 4 files changed, 329 insertions(+), 15 deletions(-)
include/linux/pm.h +5 -1
@@ -26,6 +26,7 @@#include <linux/spinlock.h> #include <linux/wait.h> #include <linux/timer.h> +#include <linux/completion.h> /* * Callbacks for platform drivers to implement.
@@ -409,20 +410,23 @@ enum rpm_request {struct dev_pm_info {spinlock_t lock; +wait_queue_head_t wait_queue;struct list_head master_links;struct list_head slave_links;pm_message_t power_state;unsigned int can_wakeup:1 ;unsigned int should_wakeup:1 ; +unsigned int async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ #ifdef CONFIG_PM_SLEEP struct list_head entry; +unsigned int op_started:1 ; +unsigned int op_complete:1 ;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work; -wait_queue_head_t wait_queue;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
include/linux/device.h +6 -0
@@ -472,6 +472,12 @@ static inline int device_is_registered(sreturn dev->kobj.state_in_sysfs; } +static inline void device_enable_async_suspend (struct device *dev,bool enable) +{ +if (dev->power.status ==DPM_ON ) + dev->power.async_suspend = enable; +} +void driver_init (void );/*
drivers/base/power/main.c +314 -13
436 lines not on this page · raw message
drivers/base/power/common.c +4 -1
@@ -19,10 +19,11 @@*/ void device_pm_init (struct device *dev) { - dev->power.status =DPM_ON ;spin_lock_init (&dev->power.lock); +init_waitqueue_head (&dev->power.wait_queue);INIT_LIST_HEAD (&dev->power.master_links);INIT_LIST_HEAD (&dev->power.slave_links); + dev->power.status =DPM_ON ;pm_runtime_init (dev); }
@@ -117,6 +118,8 @@ int pm_link_add(struct device *slave, streturn 0 ; err_link: + master->power.async_suspend = false; + slave->power.async_suspend = false; error = -ENOMEM ;put_device (slave);
PATCH 2/9 PM: Asynchronous resume of devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Theoretically, the total time of system sleep transitions (suspend to RAM, hibernation) can be reduced by running suspend and resume callbacks of device drivers in parallel with each other. However, there are dependencies between devices such that, for example, we may not be allowed to put one device into a low power state before anohter one has been suspended (e.g. we cannot suspend a bridge before suspending all devices behind it). In particular, we're not allowed to suspend the parent of a device before suspending the device itself. Analogously, we're not allowed to resume a device before resuming its parent.
Thus, to make it possible to execute suspend and resume callbacks provided by device drivers in parallel with each other, we need to provide a synchronization mechanism preventing the dependencies between devices from being violated.
The patch below allows some devices to be resumed asynchronously, with the following rules:
(1) There is a wait queue head, dev->power.wait_queue, and an
"operation complete" flag, dev->power.op_complete for each device
object.(2) All of the power.op_complete flags are reset before suspend as well as after each resume stage (dpm_resume_noirq(), dpm_resume()).
(3) If power.async_suspend is set for dev or for one of devices it depends on, the PM core waits for the "master" device's power.op_complete flag to be set before attempting to run the resume callbacks, appropriate for this particular stage of resume, for dev.
(4) dev->power.op_complete is set for each device after running its resume callbacks at each stage of resume (dpm_resume_noirq(), dpm_resume()) and all threads waiting in the devices wait queue are woken up.
With this mechanism in place, the drivers wanting their resume callbacks to be executed asynchronously can set dev->power.async_suspend for them, with the help of device_enable_async_suspend(). In addition to that, the PM off-tree dependencies between devices have to be represented by 'struct pm_link' objects introduced by the previous patch.
In this version of the patch the async threads started to execute the resume callbacks of specific device don't exit immediately having done that, but search dpm_list for devices whose PM dependencies have already been satisfied and execute their callbacks without waiting.
--- drivers/base/power/common.c | 5 drivers/base/power/main.c | 327 ++++++++++++++++++++++++++++++++++++++++++-- include/linux/device.h | 6 include/linux/pm.h | 6 4 files changed, 329 insertions(+), 15 deletions(-)
include/linux/pm.h +5 -1
@@ -26,6 +26,7 @@#include <linux/spinlock.h> #include <linux/wait.h> #include <linux/timer.h> +#include <linux/completion.h> /* * Callbacks for platform drivers to implement.
@@ -409,20 +410,23 @@ enum rpm_request {struct dev_pm_info {spinlock_t lock; +wait_queue_head_t wait_queue;struct list_head master_links;struct list_head slave_links;pm_message_t power_state;unsigned int can_wakeup:1 ;unsigned int should_wakeup:1 ; +unsigned int async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ #ifdef CONFIG_PM_SLEEP struct list_head entry; +unsigned int op_started:1 ; +unsigned int op_complete:1 ;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work; -wait_queue_head_t wait_queue;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
include/linux/device.h +6 -0
@@ -472,6 +472,12 @@ static inline int device_is_registered(sreturn dev->kobj.state_in_sysfs; } +static inline void device_enable_async_suspend (struct device *dev,bool enable) +{ +if (dev->power.status ==DPM_ON ) + dev->power.async_suspend = enable; +} +void driver_init (void );/*
drivers/base/power/main.c +314 -13
436 lines not on this page · raw message
drivers/base/power/common.c +4 -1
@@ -19,10 +19,11 @@*/ void device_pm_init (struct device *dev) { - dev->power.status =DPM_ON ;spin_lock_init (&dev->power.lock); +init_waitqueue_head (&dev->power.wait_queue);INIT_LIST_HEAD (&dev->power.master_links);INIT_LIST_HEAD (&dev->power.slave_links); + dev->power.status =DPM_ON ;pm_runtime_init (dev); }
@@ -117,6 +118,8 @@ int pm_link_add(struct device *slave, streturn 0 ; err_link: + master->power.async_suspend = false; + slave->power.async_suspend = false; error = -ENOMEM ;put_device (slave);
PATCH 3/9 PM: Asynchronous suspend of devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Extend the approach used in the previous patch to the suspend part of the PM core.
Asynchronous suspend is slightly more complicated, because if any of the suspend callbacks executed asynchronously returns error code, the entire suspend has to be terminated and rolled back. Apart from this, it's completely analogous to the asynchronous resume.
--- drivers/base/power/main.c | 225 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 214 insertions(+), 11 deletions(-)
drivers/base/power/main.c +214 -11
@@ -240,6 +240,15 @@ static void device_pm_wait_for_masters(s }/** +* device_pm_wait_for_slaves - Wait for all slaves of given device. +* @slave: Device to wait for the slaves of. +*/ +static void device_pm_wait_for_slaves (struct device *master) +{ +device_for_each_slave (master, master, device_pm_wait_fn); +} + +/** * device_pm_check - Check the power.op_complete flag of given device. * @dev: Device to check. */
@@ -273,6 +282,15 @@ static int device_pm_check_masters(struc }/** +* device_pm_check_slaves - Check power.op_complete for slaves of a device. +* @slave: Device to check the slaves of. +*/ +static int device_pm_check_slaves (struct device *master) +{ +return device_for_each_slave (master,NULL , device_pm_check_fn); +} + +/** * pm_op - Execute the PM operation appropriate for given PM event. * @dev: Device to handle. * @ops: PM operations to choose from.
@@ -832,6 +850,8 @@ EXPORT_SYMBOL_GPL(dpm_resume_end);/*------------------------- Suspend routines -------------------------*/ +static atomic_t async_error; +/** * resume_event - Return a "resume" message for given "suspend" sleep state. * @sleep_state: PM message representing a sleep state.
@@ -861,21 +881,100 @@ static pm_message_t resume_event(pm_mess* The driver of @dev will not receive interrupts while this function is being * executed. */ -static int device_suspend_noirq (struct device *dev,pm_message_t state) +static int __device_suspend_noirq (struct device *dev,pm_message_t state) {int error =0 ; -if (!dev->bus) -return 0 ; - -if (dev->bus->pm) { +if (dev->bus && dev->bus->pm) {pm_dev_dbg (dev, state,"LATE " ); error =pm_noirq_op (dev, dev->bus->pm, state); } + + dev->power.op_complete = true; +wake_up_all (&dev->power.wait_queue); +return error; }/** +* async_device_suspend_noirq - Wrapper of __device_suspend_noirq(). +* @dev: Device to suspend. +* +* Execute __device_suspend_noirq() for given device unless async_error is +* set and if that returns error code, copy it to async_error and change the +* PM status of @dev to DPM_OFF. +*/ +static void async_device_suspend_noirq (struct device *dev) +{ +int error =atomic_read (&async_error); + +if (error) +return ; +pm_dev_dbg (dev, pm_transition,"async LATE " ); + error =__device_suspend_noirq (dev, pm_transition); +if (!error) +return ; +pm_dev_err (dev, pm_transition," async LATE" , error); + dev->power.status =DPM_OFF ; +atomic_set (&async_error, error); +} + +/** +* async_suspend_noirq - Execute "late" suspend callbacks asynchronously. +* @data: Pointer to the first device to suspend. +* @cookie: Ignored. +* +* The execution of this function is scheduled with async_schedule(), so it runs +* in its own kernel thread. It first calls the "late" suspend callback for the +* device passed to it as @data. Next, it walks dpm_list looking for devices +* that can be suspended without waiting for their "slaves". If such a device +* is found, its "late" suspend callback is run. +*/ +static void async_suspend_noirq (void *data,async_cookie_t cookie) +{ +struct device *dev = (struct device *)data; + +device_pm_wait_for_slaves (dev); +async_device_suspend_noirq (dev); + +list_for_each_entry_continue_reverse (dev, &dpm_list, power.entry) { +if (!dev->power.async_suspend) +continue ; + +if (device_pm_check_slaves (dev)) +continue ; + +if (pm_op_started (dev)) +continue ; + +pm_dev_dbg (dev, pm_transition,"out of order LATE " ); +async_device_suspend_noirq (dev); + } +} + +/** +* device_suspend_noirq - Execute or schedule "late" suspend callback. +* @dev: Device to suspend. +* +* If @dev can be resumed asynchronously, schedule the execution of +* async_suspend_noirq() for it. Otherwise, execute its "late" suspend callback +* directly. +*/ +static int device_suspend_noirq (struct device *dev) +{ +if (pm_op_started (dev)) +return 0 ; + +if (dev->power.async_suspend) { +async_schedule (async_suspend_noirq, dev); +return 0 ; + } + +device_pm_wait_for_slaves (dev); +return __device_suspend_noirq (dev, pm_transition); +} + +/** * dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices. * @state: PM transition of the system being carried out. *
@@ -889,14 +988,20 @@ int dpm_suspend_noirq(pm_message_t statesuspend_device_irqs ();mutex_lock (&dpm_list_mtx); + pm_transition = state;list_for_each_entry_reverse (dev, &dpm_list, power.entry) { - error =device_suspend_noirq (dev, state); + dev->power.status =DPM_OFF_IRQ ; + error =device_suspend_noirq (dev);if (error) { -pm_dev_err (dev, state," late" , error); +pm_dev_err (dev, state," LATE" , error); + dev->power.status =DPM_OFF ;break ; } - dev->power.status =DPM_OFF_IRQ ; + error =atomic_read (&async_error); +if (error) +break ; } +dpm_synchronize_noirq ();mutex_unlock (&dpm_list_mtx);if (error)dpm_resume_noirq (resume_event (state));
@@ -909,7 +1014,7 @@ EXPORT_SYMBOL_GPL(dpm_suspend_noirq);* @dev: Device to handle. * @state: PM transition of the system being carried out. */ -static int device_suspend (struct device *dev,pm_message_t state) +static int __device_suspend (struct device *dev,pm_message_t state) {int error =0 ;
@@ -949,11 +1054,102 @@ static int device_suspend(struct device } End:up (&dev->sem); + dev->power.op_complete = true; +wake_up_all (&dev->power.wait_queue);return error; }/** +* async_device_suspend - Wrapper of __device_suspend(). +* @dev: Device to suspend. +* +* Execute __device_suspend() for given device unless async_error is set and if +* that returns error code, copy it to async_error and change the PM status of +* @dev to DPM_SUSPENDING. +*/ +static void async_device_suspend (struct device *dev) +{ +int error =atomic_read (&async_error); + +if (error) +return ; +pm_dev_dbg (dev, pm_transition,"async " ); + error =__device_suspend (dev, pm_transition); +if (!error) +return ; +pm_dev_err (dev, pm_transition," async" , error); +mutex_lock (&dpm_list_mtx); + dev->power.status =DPM_SUSPENDING ; +atomic_set (&async_error, error); +mutex_unlock (&dpm_list_mtx); +} + +/** +* async_suspend - Execute suspend callbacks asynchronously. +* @data: Pointer to the first device to resume. +* @cookie: Ignored. +* +* The execution of this function is scheduled with async_schedule(), so it runs +* in its own kernel thread. It first calls the suspend callbacks for the +* device passed to it as @data. Next, it walks dpm_list looking for devices +* that can be suspended without waiting for their "slaves". If such a device +* is found, its suspend callbacks are run. +*/ +static void async_suspend (void *data,async_cookie_t cookie) +{ +struct device *dev = (struct device *)data; + +device_pm_wait_for_slaves (dev); + + repeat: +async_device_suspend (dev); +put_device (dev); + +mutex_lock (&dpm_list_mtx); +if (dev->power.status >=DPM_OFF ) + dev =to_device (dpm_list.prev); +list_for_each_entry_continue_reverse (dev, &dpm_list, power.entry) { +if (!dev->power.async_suspend) +continue ; + +if (device_pm_check_slaves (dev)) +continue ; + +if (pm_op_started (dev)) +continue ; + +get_device (dev); +mutex_unlock (&dpm_list_mtx); +pm_dev_dbg (dev, pm_transition,"out of order " ); + goto repeat; + } +mutex_unlock (&dpm_list_mtx); +} + +/** +* device_suspend - Execute or schedule suspend callbacks for given device. +* @dev: Device to suspend. +* +* If @dev can be suspended asynchronously, schedule the execution of +* async_suspend() for it. Otherwise, execute its suspend callbacks directly. +*/ +static int device_suspend (struct device *dev) +{ +if (pm_op_started (dev)) +return 0 ; + +if (dev->power.async_suspend) { +get_device (dev); +async_schedule (async_suspend, dev); +return 0 ; + } + +device_pm_wait_for_slaves (dev); +return __device_suspend (dev, pm_transition); +} + +/** * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. * @state: PM transition of the system being carried out. */
@@ -964,27 +1160,33 @@ static int dpm_suspend(pm_message_t statINIT_LIST_HEAD (&list);mutex_lock (&dpm_list_mtx); + pm_transition = state;while (!list_empty (&dpm_list)) {struct device *dev =to_device (dpm_list.prev);get_device (dev); + dev->power.status =DPM_OFF ;mutex_unlock (&dpm_list_mtx); - error =device_suspend (dev, state); + error =device_suspend (dev);mutex_lock (&dpm_list_mtx);if (error) {pm_dev_err (dev, state,"" , error); + dev->power.status =DPM_SUSPENDING ;put_device (dev);break ; } - dev->power.status =DPM_OFF ;if (!list_empty (&dev->power.entry))list_move (&dev->power.entry, &list);put_device (dev); + error =atomic_read (&async_error); +if (error) +break ; }list_splice (&list, dpm_list.prev);mutex_unlock (&dpm_list_mtx); +dpm_synchronize ();return error; }
@@ -1043,6 +1245,7 @@ static int dpm_prepare(pm_message_t statINIT_LIST_HEAD (&list);mutex_lock (&dpm_list_mtx); transition_started = true; +atomic_set (&async_error,0 );while (!list_empty (&dpm_list)) {struct device *dev =to_device (dpm_list.next);
PATCH 3/9 PM: Asynchronous suspend of devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Extend the approach used in the previous patch to the suspend part of the PM core.
Asynchronous suspend is slightly more complicated, because if any of the suspend callbacks executed asynchronously returns error code, the entire suspend has to be terminated and rolled back. Apart from this, it's completely analogous to the asynchronous resume.
--- drivers/base/power/main.c | 225 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 214 insertions(+), 11 deletions(-)
drivers/base/power/main.c +214 -11
@@ -240,6 +240,15 @@ static void device_pm_wait_for_masters(s }/** +* device_pm_wait_for_slaves - Wait for all slaves of given device. +* @slave: Device to wait for the slaves of. +*/ +static void device_pm_wait_for_slaves (struct device *master) +{ +device_for_each_slave (master, master, device_pm_wait_fn); +} + +/** * device_pm_check - Check the power.op_complete flag of given device. * @dev: Device to check. */
@@ -273,6 +282,15 @@ static int device_pm_check_masters(struc }/** +* device_pm_check_slaves - Check power.op_complete for slaves of a device. +* @slave: Device to check the slaves of. +*/ +static int device_pm_check_slaves (struct device *master) +{ +return device_for_each_slave (master,NULL , device_pm_check_fn); +} + +/** * pm_op - Execute the PM operation appropriate for given PM event. * @dev: Device to handle. * @ops: PM operations to choose from.
@@ -832,6 +850,8 @@ EXPORT_SYMBOL_GPL(dpm_resume_end);/*------------------------- Suspend routines -------------------------*/ +static atomic_t async_error; +/** * resume_event - Return a "resume" message for given "suspend" sleep state. * @sleep_state: PM message representing a sleep state.
@@ -861,21 +881,100 @@ static pm_message_t resume_event(pm_mess* The driver of @dev will not receive interrupts while this function is being * executed. */ -static int device_suspend_noirq (struct device *dev,pm_message_t state) +static int __device_suspend_noirq (struct device *dev,pm_message_t state) {int error =0 ; -if (!dev->bus) -return 0 ; - -if (dev->bus->pm) { +if (dev->bus && dev->bus->pm) {pm_dev_dbg (dev, state,"LATE " ); error =pm_noirq_op (dev, dev->bus->pm, state); } + + dev->power.op_complete = true; +wake_up_all (&dev->power.wait_queue); +return error; }/** +* async_device_suspend_noirq - Wrapper of __device_suspend_noirq(). +* @dev: Device to suspend. +* +* Execute __device_suspend_noirq() for given device unless async_error is +* set and if that returns error code, copy it to async_error and change the +* PM status of @dev to DPM_OFF. +*/ +static void async_device_suspend_noirq (struct device *dev) +{ +int error =atomic_read (&async_error); + +if (error) +return ; +pm_dev_dbg (dev, pm_transition,"async LATE " ); + error =__device_suspend_noirq (dev, pm_transition); +if (!error) +return ; +pm_dev_err (dev, pm_transition," async LATE" , error); + dev->power.status =DPM_OFF ; +atomic_set (&async_error, error); +} + +/** +* async_suspend_noirq - Execute "late" suspend callbacks asynchronously. +* @data: Pointer to the first device to suspend. +* @cookie: Ignored. +* +* The execution of this function is scheduled with async_schedule(), so it runs +* in its own kernel thread. It first calls the "late" suspend callback for the +* device passed to it as @data. Next, it walks dpm_list looking for devices +* that can be suspended without waiting for their "slaves". If such a device +* is found, its "late" suspend callback is run. +*/ +static void async_suspend_noirq (void *data,async_cookie_t cookie) +{ +struct device *dev = (struct device *)data; + +device_pm_wait_for_slaves (dev); +async_device_suspend_noirq (dev); + +list_for_each_entry_continue_reverse (dev, &dpm_list, power.entry) { +if (!dev->power.async_suspend) +continue ; + +if (device_pm_check_slaves (dev)) +continue ; + +if (pm_op_started (dev)) +continue ; + +pm_dev_dbg (dev, pm_transition,"out of order LATE " ); +async_device_suspend_noirq (dev); + } +} + +/** +* device_suspend_noirq - Execute or schedule "late" suspend callback. +* @dev: Device to suspend. +* +* If @dev can be resumed asynchronously, schedule the execution of +* async_suspend_noirq() for it. Otherwise, execute its "late" suspend callback +* directly. +*/ +static int device_suspend_noirq (struct device *dev) +{ +if (pm_op_started (dev)) +return 0 ; + +if (dev->power.async_suspend) { +async_schedule (async_suspend_noirq, dev); +return 0 ; + } + +device_pm_wait_for_slaves (dev); +return __device_suspend_noirq (dev, pm_transition); +} + +/** * dpm_suspend_noirq - Execute "late suspend" callbacks for non-sysdev devices. * @state: PM transition of the system being carried out. *
@@ -889,14 +988,20 @@ int dpm_suspend_noirq(pm_message_t statesuspend_device_irqs ();mutex_lock (&dpm_list_mtx); + pm_transition = state;list_for_each_entry_reverse (dev, &dpm_list, power.entry) { - error =device_suspend_noirq (dev, state); + dev->power.status =DPM_OFF_IRQ ; + error =device_suspend_noirq (dev);if (error) { -pm_dev_err (dev, state," late" , error); +pm_dev_err (dev, state," LATE" , error); + dev->power.status =DPM_OFF ;break ; } - dev->power.status =DPM_OFF_IRQ ; + error =atomic_read (&async_error); +if (error) +break ; } +dpm_synchronize_noirq ();mutex_unlock (&dpm_list_mtx);if (error)dpm_resume_noirq (resume_event (state));
@@ -909,7 +1014,7 @@ EXPORT_SYMBOL_GPL(dpm_suspend_noirq);* @dev: Device to handle. * @state: PM transition of the system being carried out. */ -static int device_suspend (struct device *dev,pm_message_t state) +static int __device_suspend (struct device *dev,pm_message_t state) {int error =0 ;
@@ -949,11 +1054,102 @@ static int device_suspend(struct device } End:up (&dev->sem); + dev->power.op_complete = true; +wake_up_all (&dev->power.wait_queue);return error; }/** +* async_device_suspend - Wrapper of __device_suspend(). +* @dev: Device to suspend. +* +* Execute __device_suspend() for given device unless async_error is set and if +* that returns error code, copy it to async_error and change the PM status of +* @dev to DPM_SUSPENDING. +*/ +static void async_device_suspend (struct device *dev) +{ +int error =atomic_read (&async_error); + +if (error) +return ; +pm_dev_dbg (dev, pm_transition,"async " ); + error =__device_suspend (dev, pm_transition); +if (!error) +return ; +pm_dev_err (dev, pm_transition," async" , error); +mutex_lock (&dpm_list_mtx); + dev->power.status =DPM_SUSPENDING ; +atomic_set (&async_error, error); +mutex_unlock (&dpm_list_mtx); +} + +/** +* async_suspend - Execute suspend callbacks asynchronously. +* @data: Pointer to the first device to resume. +* @cookie: Ignored. +* +* The execution of this function is scheduled with async_schedule(), so it runs +* in its own kernel thread. It first calls the suspend callbacks for the +* device passed to it as @data. Next, it walks dpm_list looking for devices +* that can be suspended without waiting for their "slaves". If such a device +* is found, its suspend callbacks are run. +*/ +static void async_suspend (void *data,async_cookie_t cookie) +{ +struct device *dev = (struct device *)data; + +device_pm_wait_for_slaves (dev); + + repeat: +async_device_suspend (dev); +put_device (dev); + +mutex_lock (&dpm_list_mtx); +if (dev->power.status >=DPM_OFF ) + dev =to_device (dpm_list.prev); +list_for_each_entry_continue_reverse (dev, &dpm_list, power.entry) { +if (!dev->power.async_suspend) +continue ; + +if (device_pm_check_slaves (dev)) +continue ; + +if (pm_op_started (dev)) +continue ; + +get_device (dev); +mutex_unlock (&dpm_list_mtx); +pm_dev_dbg (dev, pm_transition,"out of order " ); + goto repeat; + } +mutex_unlock (&dpm_list_mtx); +} + +/** +* device_suspend - Execute or schedule suspend callbacks for given device. +* @dev: Device to suspend. +* +* If @dev can be suspended asynchronously, schedule the execution of +* async_suspend() for it. Otherwise, execute its suspend callbacks directly. +*/ +static int device_suspend (struct device *dev) +{ +if (pm_op_started (dev)) +return 0 ; + +if (dev->power.async_suspend) { +get_device (dev); +async_schedule (async_suspend, dev); +return 0 ; + } + +device_pm_wait_for_slaves (dev); +return __device_suspend (dev, pm_transition); +} + +/** * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. * @state: PM transition of the system being carried out. */
@@ -964,27 +1160,33 @@ static int dpm_suspend(pm_message_t statINIT_LIST_HEAD (&list);mutex_lock (&dpm_list_mtx); + pm_transition = state;while (!list_empty (&dpm_list)) {struct device *dev =to_device (dpm_list.prev);get_device (dev); + dev->power.status =DPM_OFF ;mutex_unlock (&dpm_list_mtx); - error =device_suspend (dev, state); + error =device_suspend (dev);mutex_lock (&dpm_list_mtx);if (error) {pm_dev_err (dev, state,"" , error); + dev->power.status =DPM_SUSPENDING ;put_device (dev);break ; } - dev->power.status =DPM_OFF ;if (!list_empty (&dev->power.entry))list_move (&dev->power.entry, &list);put_device (dev); + error =atomic_read (&async_error); +if (error) +break ; }list_splice (&list, dpm_list.prev);mutex_unlock (&dpm_list_mtx); +dpm_synchronize ();return error; }
@@ -1043,6 +1245,7 @@ static int dpm_prepare(pm_message_t statINIT_LIST_HEAD (&list);mutex_lock (&dpm_list_mtx); transition_started = true; +atomic_set (&async_error,0 );while (!list_empty (&dpm_list)) {struct device *dev =to_device (dpm_list.next);
PATCH 4/9 PM: Allow PCI devices to suspend/resume asynchronously
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Set async_suspend for all PCI devices and PCIe port services, so that they can be suspended and resumed asynchronously with other devices they don't depend on in a known way (i.e. devices which are not their parents or children and to which they are not connected via struct pm_link objects).
--- drivers/pci/pci.c | 1 + drivers/pci/pcie/portdrv_core.c | 1 + 2 files changed, 2 insertions(+)
drivers/pci/pci.c +1 -0
@@ -1373,6 +1373,7 @@ void pci_pm_init(struct pci_dev *dev)int pm;u16 pmc; +device_enable_async_suspend (&dev->dev, true); dev->wakeup_prepared = false; dev->pm_cap =0 ;
drivers/pci/pcie/portdrv_core.c +1 -0
@@ -280,6 +280,7 @@ static void pcie_device_init(struct pci_dev_set_name (device,"%s:pcie%02x" ,pci_name (parent),get_descriptor_id (port_type, service_type)); device->parent = &parent->dev; +device_enable_async_suspend (device, true); }/**
PATCH 4/9 PM: Allow PCI devices to suspend/resume asynchronously
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Set async_suspend for all PCI devices and PCIe port services, so that they can be suspended and resumed asynchronously with other devices they don't depend on in a known way (i.e. devices which are not their parents or children and to which they are not connected via struct pm_link objects).
--- drivers/pci/pci.c | 1 + drivers/pci/pcie/portdrv_core.c | 1 + 2 files changed, 2 insertions(+)
drivers/pci/pci.c +1 -0
@@ -1373,6 +1373,7 @@ void pci_pm_init(struct pci_dev *dev)int pm;u16 pmc; +device_enable_async_suspend (&dev->dev, true); dev->wakeup_prepared = false; dev->pm_cap =0 ;
drivers/pci/pcie/portdrv_core.c +1 -0
@@ -280,6 +280,7 @@ static void pcie_device_init(struct pci_dev_set_name (device,"%s:pcie%02x" ,pci_name (parent),get_descriptor_id (port_type, service_type)); device->parent = &parent->dev; +device_enable_async_suspend (device, true); }/**
PATCH 5/9 PM: Allow ACPI devices to suspend/resume asynchronously
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Set async_suspend for all ACPI devices, so that they can be suspended and resumed asynchronously with other devices they don't depend on in a known way (i.e. devices which are not their parents or children and to which they are not connected via struct pm_link objects).
--- drivers/acpi/scan.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/scan.c +1 -0
@@ -539,6 +539,7 @@ static int acpi_device_register(struct a dev_name(&device->dev)); device->removal_type =ACPI_BUS_REMOVAL_NORMAL ; +device_enable_async_suspend (&device->dev, true);return 0 ; end:mutex_lock (&acpi_device_lock);
PATCH 5/9 PM: Allow ACPI devices to suspend/resume asynchronously
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Set async_suspend for all ACPI devices, so that they can be suspended and resumed asynchronously with other devices they don't depend on in a known way (i.e. devices which are not their parents or children and to which they are not connected via struct pm_link objects).
--- drivers/acpi/scan.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/scan.c +1 -0
@@ -539,6 +539,7 @@ static int acpi_device_register(struct a dev_name(&device->dev)); device->removal_type =ACPI_BUS_REMOVAL_NORMAL ; +device_enable_async_suspend (&device->dev, true);return 0 ; end:mutex_lock (&acpi_device_lock);
PATCH 6/9 PM: Add a switch for disabling/enabling asynchronous suspend/resume
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Add sysfs attribute kernel/power/pm_async allowing the user space to disable and enable async suspend/resume of devices.
--- drivers/base/power/main.c | 13 +++++++------ drivers/base/power/power.h | 6 +++--- kernel/power/main.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-)
kernel/power/main.c +30 -1
@@ -44,6 +44,32 @@ int pm_notifier_call_chain(unsigned long == NOTIFY_BAD) ? -EINVAL : 0; } +/* If set, devices may be suspended and resumed asynchronously. */ +int pm_async_enabled =1 ; + +static ssize_t pm_async_show (struct kobject *kobj,struct kobj_attribute *attr, +char *buf) +{ +return sprintf (buf,"%d\n" , pm_async_enabled); +} + +static ssize_t pm_async_store (struct kobject *kobj,struct kobj_attribute *attr, +const char *buf,size_t n) +{ +unsigned long val; + +if (strict_strtoul (buf,10 , &val)) +return -EINVAL ; + +if (val >1 ) +return -EINVAL ; + + pm_async_enabled = val; +return n; +} + +power_attr (pm_async); +#ifdef CONFIG_PM_DEBUG int pm_test_level =TEST_NONE ;
@@ -208,9 +234,12 @@ static struct attribute * g[] = {#ifdef CONFIG_PM_TRACE &pm_trace_attr.attr,#endif -#if defined(CONFIG_PM_SLEEP ) && defined(CONFIG_PM_DEBUG ) +#ifdef CONFIG_PM_SLEEP + &pm_async_attr.attr, +#ifdef CONFIG_PM_DEBUG &pm_test_attr.attr, #endif +#endif NULL, };
drivers/base/power/main.c +7 -6
@@ -235,7 +235,7 @@ static int device_pm_wait_fn(struct devi*/ static void device_pm_wait_for_masters (struct device *slave) { -if (!pm_trace_enabled) +if (pm_async_enabled && !pm_trace_enabled)device_for_each_master (slave, slave, device_pm_wait_fn); }
@@ -245,7 +245,8 @@ static void device_pm_wait_for_masters(s*/ static void device_pm_wait_for_slaves (struct device *master) { -device_for_each_slave (master, master, device_pm_wait_fn); +if (pm_async_enabled) +device_for_each_slave (master, master, device_pm_wait_fn); }/**
@@ -560,7 +561,7 @@ static int device_resume_noirq(struct deif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {async_schedule (async_resume_noirq, dev);return 0 ; }
@@ -719,7 +720,7 @@ static int device_resume(struct device *if (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_resume, dev);return 0 ;
@@ -965,7 +966,7 @@ static int device_suspend_noirq(struct dif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {async_schedule (async_suspend_noirq, dev);return 0 ; }
@@ -1139,7 +1140,7 @@ static int device_suspend(struct deviceif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_suspend, dev);return 0 ;
drivers/base/power/power.h +3 -3
@@ -16,10 +16,10 @@ static inline void pm_runtime_remove(str#ifdef CONFIG_PM_SLEEP -/* -* main.c -*/ +/* kernel/power/main.c */ +extern int pm_async_enabled; +/* drivers/base/power/main.c */ extern struct list_head dpm_list;/* The active device list */ static inline struct device *to_device (struct list_head *entry)
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.
for bisect reasons, should this go before 5?
Quoted 136 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/base/power/main.c | 13 +++++++------ drivers/base/power/power.h | 6 +++--- kernel/power/main.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-)Index:
linux-2.6/kernel/power/main.c
===================================================================kernel/power/main.c +30
-1@@ -44,6 +44,32 @@ int pm_notifier_call_chain(unsigned long == NOTIFY_BAD) ? -EINVAL : 0; } +/* If set, devices may be suspended and resumed asynchronously. */ +int pm_async_enabled =1 ; + +static ssize_t pm_async_show (struct kobject *kobj,struct kobj_attribute *attr, +char *buf) +{ +return sprintf (buf,"%d\n" , pm_async_enabled); +} + +static ssize_t pm_async_store (struct kobject *kobj,struct kobj_attribute *attr, +const char *buf,size_t n) +{ +unsigned long val; + +if (strict_strtoul (buf,10 , &val)) +return -EINVAL ; + +if (val >1 ) +return -EINVAL ; + + pm_async_enabled = val; +return n; +} + +power_attr (pm_async); +#ifdef CONFIG_PM_DEBUG int pm_test_level =TEST_NONE ;@@ -208,9 +234,12 @@ static struct attribute * g[] = {#ifdef CONFIG_PM_TRACE &pm_trace_attr.attr,#endif -#if defined(CONFIG_PM_SLEEP ) && defined(CONFIG_PM_DEBUG ) +#ifdef CONFIG_PM_SLEEP + &pm_async_attr.attr, +#ifdef CONFIG_PM_DEBUG &pm_test_attr.attr, #endif +#endif NULL, };Index:
linux-2.6/drivers/base/power/main.c
===================================================================drivers/base/power/main.c +7
-6@@ -235,7 +235,7 @@ static int device_pm_wait_fn(struct devi*/ static void device_pm_wait_for_masters (struct device *slave) { -if (!pm_trace_enabled) +if (pm_async_enabled && !pm_trace_enabled)device_for_each_master (slave, slave, device_pm_wait_fn); }@@ -245,7 +245,8 @@ static void device_pm_wait_for_masters(s*/ static void device_pm_wait_for_slaves (struct device *master) { -device_for_each_slave (master, master, device_pm_wait_fn); +if (pm_async_enabled) +device_for_each_slave (master, master, device_pm_wait_fn); }/** @@ -560,7 +561,7 @@ static int device_resume_noirq(struct deif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {async_schedule (async_resume_noirq, dev);return 0 ; }@@ -719,7 +720,7 @@ static int device_resume(struct device *if (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_resume, dev);return 0 ;@@ -965,7 +966,7 @@ static int device_suspend_noirq(struct dif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {async_schedule (async_suspend_noirq, dev);return 0 ; }@@ -1139,7 +1140,7 @@ static int device_suspend(struct deviceif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_suspend, dev);return 0 ;Index:
linux-2.6/drivers/base/power/power.h
===================================================================drivers/base/power/power.h +3
-3@@ -16,10 +16,10 @@ static inline void pm_runtime_remove(str#ifdef CONFIG_PM_SLEEP -/* -* main.c -*/ +/* kernel/power/main.c */ +extern int pm_async_enabled; +/* drivers/base/power/main.c */ extern struct list_head dpm_list;/* The active device list */ static inline struct device *to_device (struct list_head *entry)
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
Quoted 6 lines · Pavel Machek
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.for bisect reasons, should this go before 5?
It is set to "enabled" by default, so it shouldn't change bisection results.
Thanks,
Rafael
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
Quoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Pavel Machek
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.for bisect reasons, should this go before 5?
It is set to "enabled" by default, so it shouldn't change bisection results.
Well, 5 enables it, 6 makes it configurable. So if you need async disabled for a bisect, hitting commit between 5 and 6 will enable it for you...
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
Quoted 7 lines · Pavel Machek
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · Pavel Machek
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
for bisect reasons, should this go before 5?
It is set to "enabled" by default, so it shouldn't change bisection results.
Well, 5 enables it, 6 makes it configurable. So if you need async disabled for a bisect, hitting commit between 5 and 6 will enable it for you...
OK, I'll move the patch before the [4/9].
Thanks,
Rafael
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
In reply to Pavel MachekQuoted 7 lines · Pavel Machek
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · Pavel Machek
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
for bisect reasons, should this go before 5?
It is set to "enabled" by default, so it shouldn't change bisection results.
Well, 5 enables it, 6 makes it configurable. So if you need async disabled for a bisect, hitting commit between 5 and 6 will enable it for you...
OK, I'll move the patch before the [4/9].
Thanks,
Rafael
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
Quoted 6 lines · Pavel Machek
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.for bisect reasons, should this go before 5?
It is set to "enabled" by default, so it shouldn't change bisection results.
Well, 5 enables it, 6 makes it configurable. So if you need async disabled for a bisect, hitting commit between 5 and 6 will enable it for you...
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
In reply to Pavel MachekQuoted 6 lines · Pavel Machek
Quoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.for bisect reasons, should this go before 5?
It is set to "enabled" by default, so it shouldn't change bisection results.
Thanks,
Rafael
Re: [PATCH 6/9] PM: Add a switch for disabling/enabling asynchronous suspend/resume
In reply to Rafael J. WysockiQuoted 4 lines
From: Rafael J. Wysocki <[email protected]>
Add sysfs attribute
kernel/power/pm_asyncallowing the user space to disable and enable async suspend/resume of devices.
for bisect reasons, should this go before 5?
Quoted 136 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/base/power/main.c | 13 +++++++------ drivers/base/power/power.h | 6 +++--- kernel/power/main.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-)Index:
linux-2.6/kernel/power/main.c
===================================================================kernel/power/main.c +30
-1@@ -44,6 +44,32 @@ int pm_notifier_call_chain(unsigned long == NOTIFY_BAD) ? -EINVAL : 0; } +/* If set, devices may be suspended and resumed asynchronously. */ +int pm_async_enabled =1 ; + +static ssize_t pm_async_show (struct kobject *kobj,struct kobj_attribute *attr, +char *buf) +{ +return sprintf (buf,"%d\n" , pm_async_enabled); +} + +static ssize_t pm_async_store (struct kobject *kobj,struct kobj_attribute *attr, +const char *buf,size_t n) +{ +unsigned long val; + +if (strict_strtoul (buf,10 , &val)) +return -EINVAL ; + +if (val >1 ) +return -EINVAL ; + + pm_async_enabled = val; +return n; +} + +power_attr (pm_async); +#ifdef CONFIG_PM_DEBUG int pm_test_level =TEST_NONE ;@@ -208,9 +234,12 @@ static struct attribute * g[] = {#ifdef CONFIG_PM_TRACE &pm_trace_attr.attr,#endif -#if defined(CONFIG_PM_SLEEP ) && defined(CONFIG_PM_DEBUG ) +#ifdef CONFIG_PM_SLEEP + &pm_async_attr.attr, +#ifdef CONFIG_PM_DEBUG &pm_test_attr.attr, #endif +#endif NULL, };Index:
linux-2.6/drivers/base/power/main.c
===================================================================drivers/base/power/main.c +7
-6@@ -235,7 +235,7 @@ static int device_pm_wait_fn(struct devi*/ static void device_pm_wait_for_masters (struct device *slave) { -if (!pm_trace_enabled) +if (pm_async_enabled && !pm_trace_enabled)device_for_each_master (slave, slave, device_pm_wait_fn); }@@ -245,7 +245,8 @@ static void device_pm_wait_for_masters(s*/ static void device_pm_wait_for_slaves (struct device *master) { -device_for_each_slave (master, master, device_pm_wait_fn); +if (pm_async_enabled) +device_for_each_slave (master, master, device_pm_wait_fn); }/** @@ -560,7 +561,7 @@ static int device_resume_noirq(struct deif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {async_schedule (async_resume_noirq, dev);return 0 ; }@@ -719,7 +720,7 @@ static int device_resume(struct device *if (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_resume, dev);return 0 ;@@ -965,7 +966,7 @@ static int device_suspend_noirq(struct dif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {async_schedule (async_suspend_noirq, dev);return 0 ; }@@ -1139,7 +1140,7 @@ static int device_suspend(struct deviceif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_suspend, dev);return 0 ;Index:
linux-2.6/drivers/base/power/power.h
===================================================================drivers/base/power/power.h +3
-3@@ -16,10 +16,10 @@ static inline void pm_runtime_remove(str#ifdef CONFIG_PM_SLEEP -/* -* main.c -*/ +/* kernel/power/main.c */ +extern int pm_async_enabled; +/* drivers/base/power/main.c */ extern struct list_head dpm_list;/* The active device list */ static inline struct device *to_device (struct list_head *entry)
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH 6/9 PM: Add a switch for disabling/enabling asynchronous suspend/resume
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Add sysfs attribute kernel/power/pm_async allowing the user space to disable and enable async suspend/resume of devices.
--- drivers/base/power/main.c | 13 +++++++------ drivers/base/power/power.h | 6 +++--- kernel/power/main.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-)
kernel/power/main.c +30 -1
@@ -44,6 +44,32 @@ int pm_notifier_call_chain(unsigned long == NOTIFY_BAD) ? -EINVAL : 0; } +/* If set, devices may be suspended and resumed asynchronously. */ +int pm_async_enabled =1 ; + +static ssize_t pm_async_show (struct kobject *kobj,struct kobj_attribute *attr, +char *buf) +{ +return sprintf (buf,"%d\n" , pm_async_enabled); +} + +static ssize_t pm_async_store (struct kobject *kobj,struct kobj_attribute *attr, +const char *buf,size_t n) +{ +unsigned long val; + +if (strict_strtoul (buf,10 , &val)) +return -EINVAL ; + +if (val >1 ) +return -EINVAL ; + + pm_async_enabled = val; +return n; +} + +power_attr (pm_async); +#ifdef CONFIG_PM_DEBUG int pm_test_level =TEST_NONE ;
@@ -208,9 +234,12 @@ static struct attribute * g[] = {#ifdef CONFIG_PM_TRACE &pm_trace_attr.attr,#endif -#if defined(CONFIG_PM_SLEEP ) && defined(CONFIG_PM_DEBUG ) +#ifdef CONFIG_PM_SLEEP + &pm_async_attr.attr, +#ifdef CONFIG_PM_DEBUG &pm_test_attr.attr, #endif +#endif NULL, };
drivers/base/power/main.c +7 -6
@@ -235,7 +235,7 @@ static int device_pm_wait_fn(struct devi*/ static void device_pm_wait_for_masters (struct device *slave) { -if (!pm_trace_enabled) +if (pm_async_enabled && !pm_trace_enabled)device_for_each_master (slave, slave, device_pm_wait_fn); }
@@ -245,7 +245,8 @@ static void device_pm_wait_for_masters(s*/ static void device_pm_wait_for_slaves (struct device *master) { -device_for_each_slave (master, master, device_pm_wait_fn); +if (pm_async_enabled) +device_for_each_slave (master, master, device_pm_wait_fn); }/**
@@ -560,7 +561,7 @@ static int device_resume_noirq(struct deif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {async_schedule (async_resume_noirq, dev);return 0 ; }
@@ -719,7 +720,7 @@ static int device_resume(struct device *if (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend && !pm_trace_enabled) { +if (pm_async_enabled && !pm_trace_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_resume, dev);return 0 ;
@@ -965,7 +966,7 @@ static int device_suspend_noirq(struct dif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {async_schedule (async_suspend_noirq, dev);return 0 ; }
@@ -1139,7 +1140,7 @@ static int device_suspend(struct deviceif (pm_op_started (dev))return 0 ; -if (dev->power.async_suspend) { +if (pm_async_enabled && dev->power.async_suspend) {get_device (dev);async_schedule (async_suspend, dev);return 0 ;
drivers/base/power/power.h +3 -3
@@ -16,10 +16,10 @@ static inline void pm_runtime_remove(str#ifdef CONFIG_PM_SLEEP -/* -* main.c -*/ +/* kernel/power/main.c */ +extern int pm_async_enabled; +/* drivers/base/power/main.c */ extern struct list_head dpm_list;/* The active device list */ static inline struct device *to_device (struct list_head *entry)
PATCH 7/9 PM: Measure device suspend and resume times
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Measure and print the time of suspending and resuming all devices.
--- drivers/base/power/main.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- include/linux/pm.h | 3 ++ kernel/power/swsusp.c | 6 ---- 3 files changed, 59 insertions(+), 6 deletions(-)
kernel/power/swsusp.c +1 -5
@@ -169,14 +169,10 @@ int swsusp_swap_in_use(void)void swsusp_show_speed (struct timeval *start,struct timeval *stop,unsigned nr_pages,char *msg) { -s64 elapsed_centisecs64; -int centisecs; +int centisecs =pm_time_elapsed (start, stop);int k;int kps; - elapsed_centisecs64 =timeval_to_ns (stop) -timeval_to_ns (start); -do_div (elapsed_centisecs64,NSEC_PER_SEC /100 ); - centisecs = elapsed_centisecs64;if (centisecs ==0 ) centisecs =1 ;/* avoid div-by-zero */ k = nr_pages * (PAGE_SIZE /1024 );
drivers/base/power/main.c +55 -1
127 lines not on this page · raw message
include/linux/pm.h +3 -0
@@ -505,6 +505,9 @@ extern int sysdev_suspend(pm_message_t sextern int dpm_suspend_noirq (pm_message_t state);extern int dpm_suspend_start (pm_message_t state); +struct timeval ; +extern int pm_time_elapsed (struct timeval *start,struct timeval *stop); +extern void __suspend_report_result (const char *function,void *fn,int ret);#define suspend_report_result (fn, ret) \
Re: [PATCH 7/9] PM: Measure device suspend and resume times
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Measure and print the time of suspending and resuming all devices.
Signed-off-by Rafael J. Wysocki <[email protected]>
Do you have any rough numbers describing actual suspend/resume times before and after this patch set? Of what order of magnitude is the improvement on standard x86 hardware? Just curious.
Thanks,
- Ben
Re: [PATCH 7/9] PM: Measure device suspend and resume times
Quoted 10 lines · Ben Gamari
Quoted 5 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Measure and print the time of suspending and resuming all devices.
Signed-off-by Rafael J. Wysocki <[email protected]>Do you have any rough numbers describing actual suspend/resume times before and after this patch set? Of what order of magnitude is the improvement on standard x86 hardware? Just curious.
Depending on the system on which it's run, it gives up to 15% speedup, but please note that only PCI and ACPI devices are now allowed to suspend/resume asynchronously, while on my test systems the most significant stalls are from USB, serio devices and (SATA) drives which are still suspended/resumed synchronously.
Thanks,
Rafael
PATCH 7/9 PM: Measure device suspend and resume times
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Measure and print the time of suspending and resuming all devices.
--- drivers/base/power/main.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- include/linux/pm.h | 3 ++ kernel/power/swsusp.c | 6 ---- 3 files changed, 59 insertions(+), 6 deletions(-)
kernel/power/swsusp.c +1 -5
@@ -169,14 +169,10 @@ int swsusp_swap_in_use(void)void swsusp_show_speed (struct timeval *start,struct timeval *stop,unsigned nr_pages,char *msg) { -s64 elapsed_centisecs64; -int centisecs; +int centisecs =pm_time_elapsed (start, stop);int k;int kps; - elapsed_centisecs64 =timeval_to_ns (stop) -timeval_to_ns (start); -do_div (elapsed_centisecs64,NSEC_PER_SEC /100 ); - centisecs = elapsed_centisecs64;if (centisecs ==0 ) centisecs =1 ;/* avoid div-by-zero */ k = nr_pages * (PAGE_SIZE /1024 );
drivers/base/power/main.c +55 -1
127 lines not on this page · raw message
include/linux/pm.h +3 -0
@@ -505,6 +505,9 @@ extern int sysdev_suspend(pm_message_t sextern int dpm_suspend_noirq (pm_message_t state);extern int dpm_suspend_start (pm_message_t state); +struct timeval ; +extern int pm_time_elapsed (struct timeval *start,struct timeval *stop); +extern void __suspend_report_result (const char *function,void *fn,int ret);#define suspend_report_result (fn, ret) \
PATCH 8/9 PM: Add facility for advanced testing of async suspend/resume
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Add configuration switch CONFIG_PM_ADVANCED_DEBUG for compiling in extra PM debugging/testing code allowing one to access some PM-related attributes of devices from the user space via sysfs.
If CONFIG_PM_ADVANCED_DEBUG is set, add sysfs attribute power/async for every device allowing the user space to access the device's power.async_suspend flag and modify it, if desired.
--- drivers/base/power/sysfs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 5 ++++ kernel/power/Kconfig | 14 +++++++++++++ 3 files changed, 66 insertions(+)
drivers/base/power/sysfs.c +47 -0
@@ -38,6 +38,22 @@* wakeup events internally (unless they are disabled), keeping * their hardware in low power modes whenever they're unused. This * saves runtime power, without requiring system-wide sleep states. +* +* async - Report/change current async suspend setting for the device +* +* If set, the PM core will attempt to suspend and resume the device during +* system power transitions (e.g. suspend to RAM, hibernation) in parallel +* with other devices it doesn't appear to depend on (to the PM core's +* knowledge). +* +* + "enabled\n" to permit the asynchronous suspend/resume of the device +* + "disabled\n" to forbid it +* +* NOTE: It generally is unsafe to permit the asynchronous suspend/resume +* of a device unless it is certain that all of the PM dependencies of the +* device are known to the PM core. However, for some devices this +* attribute is set to "enabled" by the kernel and in that cases it should +* be safe to leave the default value. */ static const char enabled[] ="enabled" ;
@@ -77,9 +93,40 @@ wake_store(struct device * dev, struct d static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); +#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG +static ssize_t async_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"%s\n" , +device_async_suspend_enabled (dev) ? enabled : disabled); +} + +static ssize_t async_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t n) +{ +char *cp; +int len = n; + + cp =memchr (buf,'\n' , n); +if (cp) + len = cp - buf; +if (len ==sizeof enabled -1 &&strncmp (buf, enabled, len) ==0 ) +device_enable_async_suspend (dev, true); +else if (len ==sizeof disabled -1 &&strncmp (buf, disabled, len) ==0 ) +device_enable_async_suspend (dev, false); +else +return -EINVAL ; +return n; +} + +static DEVICE_ATTR(async, 0644, async_show, async_store); +#endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */ static struct attribute * power_attrs[] = { &dev_attr_wakeup.attr, +#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG + &dev_attr_async.attr, +#endifNULL , };static struct attribute_group pm_attr_group = {
include/linux/device.h +5 -0
@@ -478,6 +478,11 @@ static inline void device_enable_async_s dev->power.async_suspend = enable; } +static inline bool device_async_suspend_enabled (struct device *dev) +{ +return !!dev->power.async_suspend; +} +void driver_init (void );/*
kernel/power/Kconfig +14 -0
@@ -27,6 +27,15 @@ config PM_DEBUG code. This is helpful when debugging and reporting PM bugs, like suspend support. +config PM_ADVANCED_DEBUG + bool "Extra PM attributes in sysfs for low-level debugging/testing" + depends on PM_DEBUG + default n + ---help--- + Add extra sysfs attributes allowing one to access some Power Management + fields of device objects from user space. If you are not a kernel + developer interested in debugging/testing Power Management, say "no". + config PM_VERBOSE bool "Verbose Power Management debugging" depends on PM_DEBUG
@@ -85,6 +94,11 @@ config PM_SLEEP depends on SUSPEND || HIBERNATION || XEN_SAVE_RESTORE default y +config PM_SLEEP_ADVANCED_DEBUG + bool + depends on PM_ADVANCED_DEBUG + default n + config SUSPEND bool "Suspend to RAM and standby" depends on PM && ARCH_SUSPEND_POSSIBLE
PATCH 8/9 PM: Add facility for advanced testing of async suspend/resume
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Add configuration switch CONFIG_PM_ADVANCED_DEBUG for compiling in extra PM debugging/testing code allowing one to access some PM-related attributes of devices from the user space via sysfs.
If CONFIG_PM_ADVANCED_DEBUG is set, add sysfs attribute power/async for every device allowing the user space to access the device's power.async_suspend flag and modify it, if desired.
--- drivers/base/power/sysfs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 5 ++++ kernel/power/Kconfig | 14 +++++++++++++ 3 files changed, 66 insertions(+)
drivers/base/power/sysfs.c +47 -0
@@ -38,6 +38,22 @@* wakeup events internally (unless they are disabled), keeping * their hardware in low power modes whenever they're unused. This * saves runtime power, without requiring system-wide sleep states. +* +* async - Report/change current async suspend setting for the device +* +* If set, the PM core will attempt to suspend and resume the device during +* system power transitions (e.g. suspend to RAM, hibernation) in parallel +* with other devices it doesn't appear to depend on (to the PM core's +* knowledge). +* +* + "enabled\n" to permit the asynchronous suspend/resume of the device +* + "disabled\n" to forbid it +* +* NOTE: It generally is unsafe to permit the asynchronous suspend/resume +* of a device unless it is certain that all of the PM dependencies of the +* device are known to the PM core. However, for some devices this +* attribute is set to "enabled" by the kernel and in that cases it should +* be safe to leave the default value. */ static const char enabled[] ="enabled" ;
@@ -77,9 +93,40 @@ wake_store(struct device * dev, struct d static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); +#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG +static ssize_t async_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +return sprintf (buf,"%s\n" , +device_async_suspend_enabled (dev) ? enabled : disabled); +} + +static ssize_t async_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t n) +{ +char *cp; +int len = n; + + cp =memchr (buf,'\n' , n); +if (cp) + len = cp - buf; +if (len ==sizeof enabled -1 &&strncmp (buf, enabled, len) ==0 ) +device_enable_async_suspend (dev, true); +else if (len ==sizeof disabled -1 &&strncmp (buf, disabled, len) ==0 ) +device_enable_async_suspend (dev, false); +else +return -EINVAL ; +return n; +} + +static DEVICE_ATTR(async, 0644, async_show, async_store); +#endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */ static struct attribute * power_attrs[] = { &dev_attr_wakeup.attr, +#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG + &dev_attr_async.attr, +#endifNULL , };static struct attribute_group pm_attr_group = {
include/linux/device.h +5 -0
@@ -478,6 +478,11 @@ static inline void device_enable_async_s dev->power.async_suspend = enable; } +static inline bool device_async_suspend_enabled (struct device *dev) +{ +return !!dev->power.async_suspend; +} +void driver_init (void );/*
kernel/power/Kconfig +14 -0
@@ -27,6 +27,15 @@ config PM_DEBUG code. This is helpful when debugging and reporting PM bugs, like suspend support. +config PM_ADVANCED_DEBUG + bool "Extra PM attributes in sysfs for low-level debugging/testing" + depends on PM_DEBUG + default n + ---help--- + Add extra sysfs attributes allowing one to access some Power Management + fields of device objects from user space. If you are not a kernel + developer interested in debugging/testing Power Management, say "no". + config PM_VERBOSE bool "Verbose Power Management debugging" depends on PM_DEBUG
@@ -85,6 +94,11 @@ config PM_SLEEP depends on SUSPEND || HIBERNATION || XEN_SAVE_RESTORE default y +config PM_SLEEP_ADVANCED_DEBUG + bool + depends on PM_ADVANCED_DEBUG + default n + config SUSPEND bool "Suspend to RAM and standby" depends on PM && ARCH_SUSPEND_POSSIBLE
PATCH 9/9 PM: Measure suspend and resume times for individual devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
If verbose PM debugging is enabled, measure and print the time of suspending and resuming of individual devices.
--- drivers/base/power/main.c | 50 +++++++++++++++++++++++++++++++++++++++++----- kernel/power/swsusp.c | 2 - 2 files changed, 46 insertions(+), 6 deletions(-)
drivers/base/power/main.c +45 -5
@@ -442,11 +442,11 @@ static bool pm_op_started(struct device*/ int pm_time_elapsed (struct timeval *start,struct timeval *stop) { -s64 elapsed_centisecs64; +s64 elapsed_msecs64; - elapsed_centisecs64 =timeval_to_ns (stop) -timeval_to_ns (start); -do_div (elapsed_centisecs64,NSEC_PER_SEC /100 ); -return elapsed_centisecs64; + elapsed_msecs64 =timeval_to_ns (stop) -timeval_to_ns (start); +do_div (elapsed_msecs64,NSEC_PER_SEC /MSEC_PER_SEC ); +return elapsed_msecs64; }static char *pm_verb (int event)
@@ -476,7 +476,7 @@ static char *pm_verb(int event)static void dpm_show_time (struct timeval *start,struct timeval *stop,pm_message_t state,const char *info) { -int centisecs =pm_time_elapsed (start, stop); +int centisecs =pm_time_elapsed (start, stop) /10 ; printk(KERN_INFO "PM: %s%s%s of devices complete in %d.%02d seconds\n", info ? info : "", info ? " " : "", pm_verb(state.event),
@@ -497,6 +497,32 @@ static void pm_dev_err(struct device *de kobject_name(&dev->kobj), pm_verb(state.event), info, error); } +#ifdef DEBUG +static inline void dbg_get_time (struct timeval *start) +{ +do_gettimeofday (start); +} + +static void dbg_show_time (struct timeval *start,struct device *dev, +pm_message_t state,char *info) +{ +struct timeval stop; +int msecs; + +do_gettimeofday (&stop); + msecs =pm_time_elapsed (start, &stop); +dev_dbg (dev,"PID %d: %s%s%s complete in %d.%03d seconds\n" , +task_pid_nr (current), info ? info :"" , info ?" " :"" , +pm_verb (state.event), msecs /1000 , msecs %1000 ); +} + +#else /* !DEBUG */ +static void dbg_get_time (struct timeval *start) {} +static void dbg_show_time (struct timeval *start,struct device *dev, +pm_message_t state,char *info) {} + +#endif /* !DEBUG */ +/*------------------------- Resume routines -------------------------*/ /**
@@ -510,7 +536,9 @@ static void pm_dev_err(struct device *destatic int __device_resume_noirq (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; +dbg_get_time (&start);TRACE_DEVICE (dev);TRACE_RESUME (0 );
@@ -523,6 +551,7 @@ static int __device_resume_noirq(structwake_up_all (&dev->power.wait_queue);TRACE_RESUME (error); +dbg_show_time (&start, dev, state,"EARLY" );return error; }
@@ -639,7 +668,9 @@ EXPORT_SYMBOL_GPL(dpm_resume_noirq);static int __device_resume (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; +dbg_get_time (&start);TRACE_DEVICE (dev);TRACE_RESUME (0 );
@@ -681,6 +712,7 @@ static int __device_resume(struct devicewake_up_all (&dev->power.wait_queue);TRACE_RESUME (error); +dbg_show_time (&start, dev, state,NULL );return error; }
@@ -923,6 +955,9 @@ static pm_message_t resume_event(pm_messstatic int __device_suspend_noirq (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; + +dbg_get_time (&start);if (dev->bus && dev->bus->pm) {pm_dev_dbg (dev, state,"LATE " );
@@ -932,6 +967,7 @@ static int __device_suspend_noirq(struct dev->power.op_complete = true;wake_up_all (&dev->power.wait_queue); +dbg_show_time (&start, dev, state,"LATE" );return error; }
@@ -1063,6 +1099,9 @@ EXPORT_SYMBOL_GPL(dpm_suspend_noirq);static int __device_suspend (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; + +dbg_get_time (&start);down (&dev->sem);
@@ -1103,6 +1142,7 @@ static int __device_suspend(struct devic dev->power.op_complete = true;wake_up_all (&dev->power.wait_queue); +dbg_show_time (&start, dev, state,NULL );return error; }
kernel/power/swsusp.c +1 -1
@@ -169,7 +169,7 @@ int swsusp_swap_in_use(void)void swsusp_show_speed (struct timeval *start,struct timeval *stop,unsigned nr_pages,char *msg) { -int centisecs =pm_time_elapsed (start, stop); +int centisecs =pm_time_elapsed (start, stop) /10 ;int k;int kps;
PATCH 9/9 PM: Measure suspend and resume times for individual devices
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
If verbose PM debugging is enabled, measure and print the time of suspending and resuming of individual devices.
--- drivers/base/power/main.c | 50 +++++++++++++++++++++++++++++++++++++++++----- kernel/power/swsusp.c | 2 - 2 files changed, 46 insertions(+), 6 deletions(-)
drivers/base/power/main.c +45 -5
@@ -442,11 +442,11 @@ static bool pm_op_started(struct device*/ int pm_time_elapsed (struct timeval *start,struct timeval *stop) { -s64 elapsed_centisecs64; +s64 elapsed_msecs64; - elapsed_centisecs64 =timeval_to_ns (stop) -timeval_to_ns (start); -do_div (elapsed_centisecs64,NSEC_PER_SEC /100 ); -return elapsed_centisecs64; + elapsed_msecs64 =timeval_to_ns (stop) -timeval_to_ns (start); +do_div (elapsed_msecs64,NSEC_PER_SEC /MSEC_PER_SEC ); +return elapsed_msecs64; }static char *pm_verb (int event)
@@ -476,7 +476,7 @@ static char *pm_verb(int event)static void dpm_show_time (struct timeval *start,struct timeval *stop,pm_message_t state,const char *info) { -int centisecs =pm_time_elapsed (start, stop); +int centisecs =pm_time_elapsed (start, stop) /10 ; printk(KERN_INFO "PM: %s%s%s of devices complete in %d.%02d seconds\n", info ? info : "", info ? " " : "", pm_verb(state.event),
@@ -497,6 +497,32 @@ static void pm_dev_err(struct device *de kobject_name(&dev->kobj), pm_verb(state.event), info, error); } +#ifdef DEBUG +static inline void dbg_get_time (struct timeval *start) +{ +do_gettimeofday (start); +} + +static void dbg_show_time (struct timeval *start,struct device *dev, +pm_message_t state,char *info) +{ +struct timeval stop; +int msecs; + +do_gettimeofday (&stop); + msecs =pm_time_elapsed (start, &stop); +dev_dbg (dev,"PID %d: %s%s%s complete in %d.%03d seconds\n" , +task_pid_nr (current), info ? info :"" , info ?" " :"" , +pm_verb (state.event), msecs /1000 , msecs %1000 ); +} + +#else /* !DEBUG */ +static void dbg_get_time (struct timeval *start) {} +static void dbg_show_time (struct timeval *start,struct device *dev, +pm_message_t state,char *info) {} + +#endif /* !DEBUG */ +/*------------------------- Resume routines -------------------------*/ /**
@@ -510,7 +536,9 @@ static void pm_dev_err(struct device *destatic int __device_resume_noirq (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; +dbg_get_time (&start);TRACE_DEVICE (dev);TRACE_RESUME (0 );
@@ -523,6 +551,7 @@ static int __device_resume_noirq(structwake_up_all (&dev->power.wait_queue);TRACE_RESUME (error); +dbg_show_time (&start, dev, state,"EARLY" );return error; }
@@ -639,7 +668,9 @@ EXPORT_SYMBOL_GPL(dpm_resume_noirq);static int __device_resume (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; +dbg_get_time (&start);TRACE_DEVICE (dev);TRACE_RESUME (0 );
@@ -681,6 +712,7 @@ static int __device_resume(struct devicewake_up_all (&dev->power.wait_queue);TRACE_RESUME (error); +dbg_show_time (&start, dev, state,NULL );return error; }
@@ -923,6 +955,9 @@ static pm_message_t resume_event(pm_messstatic int __device_suspend_noirq (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; + +dbg_get_time (&start);if (dev->bus && dev->bus->pm) {pm_dev_dbg (dev, state,"LATE " );
@@ -932,6 +967,7 @@ static int __device_suspend_noirq(struct dev->power.op_complete = true;wake_up_all (&dev->power.wait_queue); +dbg_show_time (&start, dev, state,"LATE" );return error; }
@@ -1063,6 +1099,9 @@ EXPORT_SYMBOL_GPL(dpm_suspend_noirq);static int __device_suspend (struct device *dev,pm_message_t state) {int error =0 ; +struct timeval start; + +dbg_get_time (&start);down (&dev->sem);
@@ -1103,6 +1142,7 @@ static int __device_suspend(struct devic dev->power.op_complete = true;wake_up_all (&dev->power.wait_queue); +dbg_show_time (&start, dev, state,NULL );return error; }
kernel/power/swsusp.c +1 -1
@@ -169,7 +169,7 @@ int swsusp_swap_in_use(void)void swsusp_show_speed (struct timeval *start,struct timeval *stop,unsigned nr_pages,char *msg) { -int centisecs =pm_time_elapsed (start, stop); +int centisecs =pm_time_elapsed (start, stop) /10 ;int k;int kps;
Hi!
Quoted 10 lines
The following series of patches implements asynchronous suspend and resume of devices.
All of the patches have already been discussed, please refer to the changelogs for details.
The patches are targeted at 2.6.33, so if there are no major objections, I'll put them into the linux-next branch of the suspend-2.6 tree after .31-rc1 is out.
Patches 1-6 look mostly ok to me, I guess you can add my Acked-by. The rest is fine, too, but I'm not sure if we really need so much of debugging infrastructure...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 5 lines · Pavel Machek
Hi!
Quoted 4 lines
The following series of patches implements asynchronous suspend and resume of devices.
Quoted 8 lines
Quoted 6 lines
All of the patches have already been discussed, please refer to the changelogs for details.
The patches are targeted at 2.6.33, so if there are no major objections, I'll put them into the linux-next branch of the suspend-2.6 tree after .31-rc1 is out.
Patches 1-6 look mostly ok to me, I guess you can add my Acked-by.
Thanks!
Quoted 2 lines
The rest is fine, too, but I'm not sure if we really need so much of debugging infrastructure...
I believe it will be useful.
Thanks,
Rafael
Quoted 5 lines · Pavel Machek
Hi!
Quoted 4 lines
The following series of patches implements asynchronous suspend and resume of devices.
Quoted 8 lines
Quoted 6 lines
All of the patches have already been discussed, please refer to the changelogs for details.
The patches are targeted at 2.6.33, so if there are no major objections, I'll put them into the linux-next branch of the suspend-2.6 tree after .31-rc1 is out.
Patches 1-6 look mostly ok to me, I guess you can add my Acked-by.
Thanks!
Quoted 2 lines
The rest is fine, too, but I'm not sure if we really need so much of debugging infrastructure...
I believe it will be useful.
Thanks,
Rafael
Hi!
Quoted 10 lines
The following series of patches implements asynchronous suspend and resume of devices.
All of the patches have already been discussed, please refer to the changelogs for details.
The patches are targeted at 2.6.33, so if there are no major objections, I'll put them into the linux-next branch of the suspend-2.6 tree after .31-rc1 is out.
Patches 1-6 look mostly ok to me, I guess you can add my Acked-by. The rest is fine, too, but I'm not sure if we really need so much of debugging infrastructure...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html