PM: Wakeup sources and async suspend error path bug fix
Subsystems (4)
cover PM: Wakeup sources and async suspend error path bug fix
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
Rafael
PATCH 1/2 PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
Introduce struct wakeup_source for representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functions pm_wakeup_event(), pm_stay_awake() and pm_relax() use struct wakeup_source objects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition of pm_relax() is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in /sys/devices/.../power for reporting the device wakeup statistics.
Change the global wakeup events counters event_count and events_in_progress into atomic variables, so that it is not necessary to acquire a global spinlock in pm_wakeup_event(), pm_stay_awake() and pm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.
---
Changes since v2:
* Use smp_mb__before_atomic_dec() instead of wmb() in wakeup_source_deactivate().
* Fix some copy-paste mistakes in sysfs-devices-power.
--- Documentation/ABI/testing/sysfs-devices-power | 70 +++ drivers/base/power/main.c | 4 drivers/base/power/power.h | 1 drivers/base/power/runtime.c | 2 drivers/base/power/sysfs.c | 121 +++++ drivers/base/power/wakeup.c | 534 ++++++++++++++++++++++---- include/linux/pm.h | 16 include/linux/pm_wakeup.h | 126 ++++-- include/linux/suspend.h | 4 kernel/power/main.c | 8 10 files changed, 757 insertions(+), 129 deletions(-)
include/linux/pm_wakeup.h +101 -25
@@ -2,6 +2,7 @@* pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern +* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -27,18 +28,39 @@#include <linux/types.h> -#ifdef CONFIG_PM - -/* Changes to device_may_wakeup take effect on the next pm state change. +/** +* struct wakeup_source - Representation of wakeup sources * -* By default, most devices should leave wakeup disabled. The exceptions -* are devices that everyone expects to be wakeup sources: keyboards, -* power buttons, possibly network interfaces, etc. +* @total_time: Total time this wakeup source has been active. +* @max_time: Maximum time this wakeup source has been continuously active. +* @last_time: Monotonic clock when the wakeup source's was activated last time. +* @event_count: Number of signaled wakeup events. +* @active_count: Number of times the wakeup sorce was activated. +* @relax_count: Number of times the wakeup sorce was deactivated. +* @hit_count: Number of times the wakeup sorce might abort system suspend. +* @active: Status of the wakeup source. +*/ +struct wakeup_source { +char *name; +struct list_head entry; +spinlock_t lock; +struct timer_list timer; +unsigned long timer_expires; +ktime_t total_time; +ktime_t max_time; +ktime_t last_time; +unsigned long event_count; +unsigned long active_count; +unsigned long relax_count; +unsigned long hit_count; +unsigned int active:1 ; +}; + +#ifdef CONFIG_PM_SLEEP + +/* +* Changes to device_may_wakeup take effect on the next pm state change. */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = dev->power.should_wakeup = val; -}static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -50,23 +72,32 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) -{ - dev->power.should_wakeup = enable; -} +static inline bool device_may_wakeup (struct device *dev) { -return dev->power.can_wakeup && dev->power.should_wakeup; +return dev->power.can_wakeup && !!dev->power.wakeup; } -#else /* !CONFIG_PM */ +/* drivers/base/power/wakeup.c */ +extern struct wakeup_source *wakeup_source_create (const char *name); +extern void wakeup_source_destroy (struct wakeup_source *ws); +extern void wakeup_source_add (struct wakeup_source *ws); +extern void wakeup_source_remove (struct wakeup_source *ws); +extern struct wakeup_source *wakeup_source_register (const char *name); +extern void wakeup_source_unregister (struct wakeup_source *ws); +extern int device_wakeup_enable (struct device *dev); +extern int device_wakeup_disable (struct device *dev); +extern int device_init_wakeup (struct device *dev,bool val); +extern int device_set_wakeup_enable (struct device *dev,bool enable); +extern void __pm_stay_awake (struct wakeup_source *ws); +extern void pm_stay_awake (struct device *dev); +extern void __pm_relax (struct wakeup_source *ws); +extern void pm_relax (struct device *dev); +extern void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec); +extern void pm_wakeup_event (struct device *dev,unsigned int msec); -/* For some reason the following routines work even without CONFIG_PM */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = val; -} +#else /* !CONFIG_PM_SLEEP */ static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -78,15 +109,60 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) +static inline bool device_may_wakeup (struct device *dev) { +return false; } -static inline bool device_may_wakeup (struct device *dev) +static inline struct wakeup_source *wakeup_source_create (const char *name) { -return false; +return NULL ; } -#endif /* !CONFIG_PM */ +static inline void wakeup_source_destroy (struct wakeup_source *ws) {} + +static inline void wakeup_source_add (struct wakeup_source *ws) {} + +static inline void wakeup_source_remove (struct wakeup_source *ws) {} + +static inline struct wakeup_source *wakeup_source_register (const char *name) +{ +return NULL ; +} + +static inline void wakeup_source_unregister (struct wakeup_source *ws) {} + +static inline int device_wakeup_enable (struct device *dev) +{ +return -EINVAL ; +} + +static inline int device_wakeup_disable (struct device *dev) {} + +static inline int device_init_wakeup (struct device *dev,bool val) +{ + dev->power.can_wakeup = val; +return val ? -EINVAL :0 ; +} + + +static inline int device_set_wakeup_enable (struct device *dev,bool enable) +{ +return -EINVAL ; +} + +static inline void __pm_stay_awake (struct wakeup_source *ws) {} + +static inline void pm_stay_awake (struct device *dev) {} + +static inline void __pm_relax (struct wakeup_source *ws) {} + +static inline void pm_relax (struct device *dev) {} + +static inline void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec) {} + +static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} + +#endif /* !CONFIG_PM_SLEEP */ #endif /* _LINUX_PM_WAKEUP_H */
include/linux/pm.h +4 -12
@@ -448,23 +448,24 @@ enum rpm_request { RPM_REQ_RESUME, }; +struct wakeup_source ; +struct dev_pm_info {pm_message_t power_state;unsigned int can_wakeup:1 ; -unsigned int should_wakeup:1 ;unsigned async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ +spinlock_t lock;#ifdef CONFIG_PM_SLEEP struct list_head entry;struct completion completion; -unsigned long wakeup_count; +struct wakeup_source *wakeup;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
@@ -559,11 +560,6 @@ extern void __suspend_report_result(cons } while (0) extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); - -/* drivers/base/power/wakeup.c */ -extern void pm_wakeup_event (struct device *dev,unsigned int msec); -extern void pm_stay_awake (struct device *dev); -extern void pm_relax (void );#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -577,10 +573,6 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0)static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} - -static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} -static inline void pm_stay_awake (struct device *dev) {} -static inline void pm_relax (void ) {}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
drivers/base/power/wakeup.c +453 -81
646 lines not on this page · raw message
drivers/base/power/main.c +3 -1
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev) dev->power.status =DPM_ON ;init_completion (&dev->power.completion);complete_all (&dev->power.completion); - dev->power.wakeup_count =0 ; + dev->power.wakeup =NULL ; +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
@@ -120,6 +121,7 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); +device_wakeup_disable (dev);pm_runtime_remove (dev); }
drivers/base/power/power.h +1 -0
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct dstatic inline void device_pm_init (struct device *dev) { +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/runtime.c +0 -2
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
include/linux/suspend.h +2 -2
@@ -302,8 +302,8 @@ extern int unregister_pm_notifier(structextern bool events_check_enabled;extern bool pm_check_wakeup_events (void ); -extern bool pm_get_wakeup_count (unsigned long *count); -extern bool pm_save_wakeup_count (unsigned long count); +extern bool pm_get_wakeup_count (unsigned int *count); +extern bool pm_save_wakeup_count (unsigned int count);#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
kernel/power/main.c +4 -4
@@ -237,18 +237,18 @@ static ssize_t wakeup_count_show(structstruct kobj_attribute *attr, char *buf) { - unsigned long val; + unsigned int val; -return pm_get_wakeup_count (&val) ?sprintf (buf,"%lu\n" , val) : -EINTR ; +return pm_get_wakeup_count (&val) ?sprintf (buf,"%u\n" , val) : -EINTR ; }static ssize_t wakeup_count_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t n) { -unsigned long val; +unsigned int val; -if (sscanf (buf,"%lu" , &val) ==1 ) { +if (sscanf (buf,"%u" , &val) ==1 ) {if (pm_save_wakeup_count (val))return n; }
drivers/base/power/sysfs.c +119 -2
136 lines not on this page · raw message
Documentation/ABI/testing/sysfs-devices-power +70 -0
73 lines not on this page · raw message
PATCH 1/2 PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
Introduce struct wakeup_source for representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functions pm_wakeup_event(), pm_stay_awake() and pm_relax() use struct wakeup_source objects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition of pm_relax() is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in /sys/devices/.../power for reporting the device wakeup statistics.
Change the global wakeup events counters event_count and events_in_progress into atomic variables, so that it is not necessary to acquire a global spinlock in pm_wakeup_event(), pm_stay_awake() and pm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.
---
Changes since v2:
* Use smp_mb__before_atomic_dec() instead of wmb() in wakeup_source_deactivate().
* Fix some copy-paste mistakes in sysfs-devices-power.
--- Documentation/ABI/testing/sysfs-devices-power | 70 +++ drivers/base/power/main.c | 4 drivers/base/power/power.h | 1 drivers/base/power/runtime.c | 2 drivers/base/power/sysfs.c | 121 +++++ drivers/base/power/wakeup.c | 534 ++++++++++++++++++++++---- include/linux/pm.h | 16 include/linux/pm_wakeup.h | 126 ++++-- include/linux/suspend.h | 4 kernel/power/main.c | 8 10 files changed, 757 insertions(+), 129 deletions(-)
include/linux/pm_wakeup.h +101 -25
@@ -2,6 +2,7 @@* pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern +* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -27,18 +28,39 @@#include <linux/types.h> -#ifdef CONFIG_PM - -/* Changes to device_may_wakeup take effect on the next pm state change. +/** +* struct wakeup_source - Representation of wakeup sources * -* By default, most devices should leave wakeup disabled. The exceptions -* are devices that everyone expects to be wakeup sources: keyboards, -* power buttons, possibly network interfaces, etc. +* @total_time: Total time this wakeup source has been active. +* @max_time: Maximum time this wakeup source has been continuously active. +* @last_time: Monotonic clock when the wakeup source's was activated last time. +* @event_count: Number of signaled wakeup events. +* @active_count: Number of times the wakeup sorce was activated. +* @relax_count: Number of times the wakeup sorce was deactivated. +* @hit_count: Number of times the wakeup sorce might abort system suspend. +* @active: Status of the wakeup source. +*/ +struct wakeup_source { +char *name; +struct list_head entry; +spinlock_t lock; +struct timer_list timer; +unsigned long timer_expires; +ktime_t total_time; +ktime_t max_time; +ktime_t last_time; +unsigned long event_count; +unsigned long active_count; +unsigned long relax_count; +unsigned long hit_count; +unsigned int active:1 ; +}; + +#ifdef CONFIG_PM_SLEEP + +/* +* Changes to device_may_wakeup take effect on the next pm state change. */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = dev->power.should_wakeup = val; -}static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -50,23 +72,32 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) -{ - dev->power.should_wakeup = enable; -} +static inline bool device_may_wakeup (struct device *dev) { -return dev->power.can_wakeup && dev->power.should_wakeup; +return dev->power.can_wakeup && !!dev->power.wakeup; } -#else /* !CONFIG_PM */ +/* drivers/base/power/wakeup.c */ +extern struct wakeup_source *wakeup_source_create (const char *name); +extern void wakeup_source_destroy (struct wakeup_source *ws); +extern void wakeup_source_add (struct wakeup_source *ws); +extern void wakeup_source_remove (struct wakeup_source *ws); +extern struct wakeup_source *wakeup_source_register (const char *name); +extern void wakeup_source_unregister (struct wakeup_source *ws); +extern int device_wakeup_enable (struct device *dev); +extern int device_wakeup_disable (struct device *dev); +extern int device_init_wakeup (struct device *dev,bool val); +extern int device_set_wakeup_enable (struct device *dev,bool enable); +extern void __pm_stay_awake (struct wakeup_source *ws); +extern void pm_stay_awake (struct device *dev); +extern void __pm_relax (struct wakeup_source *ws); +extern void pm_relax (struct device *dev); +extern void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec); +extern void pm_wakeup_event (struct device *dev,unsigned int msec); -/* For some reason the following routines work even without CONFIG_PM */ -static inline void device_init_wakeup (struct device *dev,bool val) -{ - dev->power.can_wakeup = val; -} +#else /* !CONFIG_PM_SLEEP */ static inline void device_set_wakeup_capable (struct device *dev,bool capable) {
@@ -78,15 +109,60 @@ static inline bool device_can_wakeup(strreturn dev->power.can_wakeup; } -static inline void device_set_wakeup_enable (struct device *dev,bool enable) +static inline bool device_may_wakeup (struct device *dev) { +return false; } -static inline bool device_may_wakeup (struct device *dev) +static inline struct wakeup_source *wakeup_source_create (const char *name) { -return false; +return NULL ; } -#endif /* !CONFIG_PM */ +static inline void wakeup_source_destroy (struct wakeup_source *ws) {} + +static inline void wakeup_source_add (struct wakeup_source *ws) {} + +static inline void wakeup_source_remove (struct wakeup_source *ws) {} + +static inline struct wakeup_source *wakeup_source_register (const char *name) +{ +return NULL ; +} + +static inline void wakeup_source_unregister (struct wakeup_source *ws) {} + +static inline int device_wakeup_enable (struct device *dev) +{ +return -EINVAL ; +} + +static inline int device_wakeup_disable (struct device *dev) {} + +static inline int device_init_wakeup (struct device *dev,bool val) +{ + dev->power.can_wakeup = val; +return val ? -EINVAL :0 ; +} + + +static inline int device_set_wakeup_enable (struct device *dev,bool enable) +{ +return -EINVAL ; +} + +static inline void __pm_stay_awake (struct wakeup_source *ws) {} + +static inline void pm_stay_awake (struct device *dev) {} + +static inline void __pm_relax (struct wakeup_source *ws) {} + +static inline void pm_relax (struct device *dev) {} + +static inline void __pm_wakeup_event (struct wakeup_source *ws,unsigned int msec) {} + +static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} + +#endif /* !CONFIG_PM_SLEEP */ #endif /* _LINUX_PM_WAKEUP_H */
include/linux/pm.h +4 -12
@@ -448,23 +448,24 @@ enum rpm_request { RPM_REQ_RESUME, }; +struct wakeup_source ; +struct dev_pm_info {pm_message_t power_state;unsigned int can_wakeup:1 ; -unsigned int should_wakeup:1 ;unsigned async_suspend:1 ;enum dpm_state status;/* Owned by the PM core */ +spinlock_t lock;#ifdef CONFIG_PM_SLEEP struct list_head entry;struct completion completion; -unsigned long wakeup_count; +struct wakeup_source *wakeup;#endif #ifdef CONFIG_PM_RUNTIME struct timer_list suspend_timer;unsigned long timer_expires;struct work_struct work;wait_queue_head_t wait_queue; -spinlock_t lock;atomic_t usage_count;atomic_t child_count;unsigned int disable_depth:3 ;
@@ -559,11 +560,6 @@ extern void __suspend_report_result(cons } while (0) extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); - -/* drivers/base/power/wakeup.c */ -extern void pm_wakeup_event (struct device *dev,unsigned int msec); -extern void pm_stay_awake (struct device *dev); -extern void pm_relax (void );#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -577,10 +573,6 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0)static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} - -static inline void pm_wakeup_event (struct device *dev,unsigned int msec) {} -static inline void pm_stay_awake (struct device *dev) {} -static inline void pm_relax (void ) {}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
drivers/base/power/wakeup.c +453 -81
646 lines not on this page · raw message
drivers/base/power/main.c +3 -1
@@ -60,7 +60,8 @@ void device_pm_init(struct device *dev) dev->power.status =DPM_ON ;init_completion (&dev->power.completion);complete_all (&dev->power.completion); - dev->power.wakeup_count =0 ; + dev->power.wakeup =NULL ; +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
@@ -120,6 +121,7 @@ void device_pm_remove(struct device *devmutex_lock (&dpm_list_mtx);list_del_init (&dev->power.entry);mutex_unlock (&dpm_list_mtx); +device_wakeup_disable (dev);pm_runtime_remove (dev); }
drivers/base/power/power.h +1 -0
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct dstatic inline void device_pm_init (struct device *dev) { +spin_lock_init (&dev->power.lock);pm_runtime_init (dev); }
drivers/base/power/runtime.c +0 -2
@@ -1099,8 +1099,6 @@ EXPORT_SYMBOL_GPL(pm_runtime_allow);*/ void pm_runtime_init (struct device *dev) { -spin_lock_init (&dev->power.lock); - dev->power.runtime_status =RPM_SUSPENDED ; dev->power.idle_notification = false;
include/linux/suspend.h +2 -2
@@ -302,8 +302,8 @@ extern int unregister_pm_notifier(structextern bool events_check_enabled;extern bool pm_check_wakeup_events (void ); -extern bool pm_get_wakeup_count (unsigned long *count); -extern bool pm_save_wakeup_count (unsigned long count); +extern bool pm_get_wakeup_count (unsigned int *count); +extern bool pm_save_wakeup_count (unsigned int count);#else /* !CONFIG_PM_SLEEP */ static inline int register_pm_notifier (struct notifier_block *nb)
kernel/power/main.c +4 -4
@@ -237,18 +237,18 @@ static ssize_t wakeup_count_show(structstruct kobj_attribute *attr, char *buf) { - unsigned long val; + unsigned int val; -return pm_get_wakeup_count (&val) ?sprintf (buf,"%lu\n" , val) : -EINTR ; +return pm_get_wakeup_count (&val) ?sprintf (buf,"%u\n" , val) : -EINTR ; }static ssize_t wakeup_count_store (struct kobject *kobj,struct kobj_attribute *attr,const char *buf,size_t n) { -unsigned long val; +unsigned int val; -if (sscanf (buf,"%lu" , &val) ==1 ) { +if (sscanf (buf,"%u" , &val) ==1 ) {if (pm_save_wakeup_count (val))return n; }
drivers/base/power/sysfs.c +119 -2
136 lines not on this page · raw message
Documentation/ABI/testing/sysfs-devices-power +70 -0
73 lines not on this page · raw message
Re: [PATCH 1/2] PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
Quoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v3)Introduce struct
wakeup_sourcefor representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functionspm_wakeup_event(),pm_stay_awake()andpm_relax()use structwakeup_sourceobjects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition ofpm_relax()is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in/sys/devices/.../powerfor reporting the device wakeup statistics.
Quoted 7 lines
Change the global wakeup events counters
event_countandevents_in_progressinto atomic variables, so that it is not necessary to acquire a global spinlock inpm_wakeup_event(),pm_stay_awake()andpm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.Signed-off-by Rafael J. Wysocki <[email protected]>
Nice job!
Re: [PATCH 1/2] PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
In reply to Rafael J. WysockiQuoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Wakeup: Introduce wakeup source objects and event statistics (v3)Introduce struct
wakeup_sourcefor representing system wakeup sources within the kernel and for collecting statistics related to them. Make the recently introduced helper functionspm_wakeup_event(),pm_stay_awake()andpm_relax()use structwakeup_sourceobjects internally, so that wakeup statistics associated with wakeup devices can be collected and reported in a consistent way (the definition ofpm_relax()is changed, which is harmless, because this function is not called directly by anyone yet). Introduce new wakeup-related sysfs device attributes in/sys/devices/.../powerfor reporting the device wakeup statistics.
Quoted 7 lines
Change the global wakeup events counters
event_countandevents_in_progressinto atomic variables, so that it is not necessary to acquire a global spinlock inpm_wakeup_event(),pm_stay_awake()andpm_relax(), which should allow us to avoid lock contention in these functions on SMP systems with many wakeup devices.Signed-off-by Rafael J. Wysocki <[email protected]>
Nice job!
PATCH 2/2 PM: Fix potential issue with failing asynchronous suspend
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Subject: PM: Fix potential issue with failing asynchronous suspend
There is a potential issue with the asynchronous suspend code that a device driver suspending asynchronously may not notice that it should back off. There are two failing scenarions, (1) when the driver is waiting for a driver suspending synchronously to complete and that second driver returns error code, in which case async_error won't be set and the waiting driver will continue suspending and (2) after the driver has called device_pm_wait_for_dev() and the waited for driver returns error code, in which case the caller of device_pm_wait_for_dev() will not know that there was an error and will continue suspending.
To fix this issue make __device_suspend() set async_error, so async_suspend() doesn't need to set it any more, and make device_pm_wait_for_dev() return async_error, so that its callers can check whether or not they should continue suspending.
No more changes are necessary, since device_pm_wait_for_dev() in not used by any drivers' suspend routines.
--- drivers/base/power/main.c | 15 +++++++++------ include/linux/pm.h | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/base/power/main.c +9 -6
@@ -51,6 +51,8 @@ static pm_message_t pm_transition;*/ static bool transition_started; +static int async_error; +/** * device_pm_init - Initialize the PM-related part of a device object. * @dev: Device object being initialized.
@@ -602,6 +604,7 @@ static void dpm_resume(pm_message_t statINIT_LIST_HEAD (&list);mutex_lock (&dpm_list_mtx); pm_transition = state; + async_error =0 ;list_for_each_entry (dev, &dpm_list, power.entry) {if (dev->power.status <DPM_OFF )
@@ -831,8 +834,6 @@ static int legacy_suspend(struct devicereturn error; } -static int async_error; -/** * device_suspend - Execute "suspend" callbacks for given device. * @dev: Device to handle.
@@ -887,6 +888,9 @@ static int __device_suspend(struct devicdevice_unlock (dev);complete_all (&dev->power.completion); +if (error) + async_error = error; +return error; }
@@ -896,10 +900,8 @@ static void async_suspend(void *data, asint error; error =__device_suspend (dev, pm_transition, true); -if (error) { +if (error)pm_dev_err (dev, pm_transition," async" , error); - async_error = error; - }put_device (dev); }
@@ -1087,8 +1089,9 @@ EXPORT_SYMBOL_GPL(__suspend_report_resul* @dev: Device to wait for. * @subordinate: Device that needs to wait for @dev. */ -void device_pm_wait_for_dev (struct device *subordinate,struct device *dev) +int device_pm_wait_for_dev (struct device *subordinate,struct device *dev) {dpm_wait (dev, subordinate->power.async_suspend); +return async_error; }EXPORT_SYMBOL_GPL (device_pm_wait_for_dev);
include/linux/pm.h +5 -2
@@ -559,7 +559,7 @@ extern void __suspend_report_result(cons__suspend_report_result (__func__, fn, ret); \ } while (0) -extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); +extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -572,7 +572,10 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0) -static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} +static inline int device_pm_wait_for_dev (struct device *a,struct device *b) +{ +return 0 ; +}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
PATCH 2/2 PM: Fix potential issue with failing asynchronous suspend
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Subject: PM: Fix potential issue with failing asynchronous suspend
There is a potential issue with the asynchronous suspend code that a device driver suspending asynchronously may not notice that it should back off. There are two failing scenarions, (1) when the driver is waiting for a driver suspending synchronously to complete and that second driver returns error code, in which case async_error won't be set and the waiting driver will continue suspending and (2) after the driver has called device_pm_wait_for_dev() and the waited for driver returns error code, in which case the caller of device_pm_wait_for_dev() will not know that there was an error and will continue suspending.
To fix this issue make __device_suspend() set async_error, so async_suspend() doesn't need to set it any more, and make device_pm_wait_for_dev() return async_error, so that its callers can check whether or not they should continue suspending.
No more changes are necessary, since device_pm_wait_for_dev() in not used by any drivers' suspend routines.
--- drivers/base/power/main.c | 15 +++++++++------ include/linux/pm.h | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/base/power/main.c +9 -6
@@ -51,6 +51,8 @@ static pm_message_t pm_transition;*/ static bool transition_started; +static int async_error; +/** * device_pm_init - Initialize the PM-related part of a device object. * @dev: Device object being initialized.
@@ -602,6 +604,7 @@ static void dpm_resume(pm_message_t statINIT_LIST_HEAD (&list);mutex_lock (&dpm_list_mtx); pm_transition = state; + async_error =0 ;list_for_each_entry (dev, &dpm_list, power.entry) {if (dev->power.status <DPM_OFF )
@@ -831,8 +834,6 @@ static int legacy_suspend(struct devicereturn error; } -static int async_error; -/** * device_suspend - Execute "suspend" callbacks for given device. * @dev: Device to handle.
@@ -887,6 +888,9 @@ static int __device_suspend(struct devicdevice_unlock (dev);complete_all (&dev->power.completion); +if (error) + async_error = error; +return error; }
@@ -896,10 +900,8 @@ static void async_suspend(void *data, asint error; error =__device_suspend (dev, pm_transition, true); -if (error) { +if (error)pm_dev_err (dev, pm_transition," async" , error); - async_error = error; - }put_device (dev); }
@@ -1087,8 +1089,9 @@ EXPORT_SYMBOL_GPL(__suspend_report_resul* @dev: Device to wait for. * @subordinate: Device that needs to wait for @dev. */ -void device_pm_wait_for_dev (struct device *subordinate,struct device *dev) +int device_pm_wait_for_dev (struct device *subordinate,struct device *dev) {dpm_wait (dev, subordinate->power.async_suspend); +return async_error; }EXPORT_SYMBOL_GPL (device_pm_wait_for_dev);
include/linux/pm.h +5 -2
@@ -559,7 +559,7 @@ extern void __suspend_report_result(cons__suspend_report_result (__func__, fn, ret); \ } while (0) -extern void device_pm_wait_for_dev(struct device *sub, struct device *dev); +extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);#else /* !CONFIG_PM_SLEEP */ #define device_pm_lock () do {} while (0)
@@ -572,7 +572,10 @@ static inline int dpm_suspend_start(pm_m#define suspend_report_result (fn, ret) do {} while (0) -static inline void device_pm_wait_for_dev (struct device *a,struct device *b) {} +static inline int device_pm_wait_for_dev (struct device *a,struct device *b) +{ +return 0 ; +}#endif /* !CONFIG_PM_SLEEP */ /* How to reorder dpm_list after device_move() */
Re: [PATCH 2/2] PM: Fix potential issue with failing asynchronous suspend
Quoted 19 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM: Fix potential issue with failing asynchronous suspendThere is a potential issue with the asynchronous suspend code that a device driver suspending asynchronously may not notice that it should back off. There are two failing scenarions, (1) when the driver is waiting for a driver suspending synchronously to complete and that second driver returns error code, in which case
async_errorwon't be set and the waiting driver will continue suspending and (2) after the driver has calleddevice_pm_wait_for_dev()and the waited for driver returns error code, in which case the caller ofdevice_pm_wait_for_dev()will not know that there was an error and will continue suspending.To fix this issue make
__device_suspend()setasync_error, soasync_suspend()doesn't need to set it any more, and makedevice_pm_wait_for_dev()returnasync_error, so that its callers can check whether or not they should continue suspending.
Quoted 5 lines
No more changes are necessary, since
device_pm_wait_for_dev()in not used by any drivers' suspend routines.Reported-by Colin Cross <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Re: [PATCH 2/2] PM: Fix potential issue with failing asynchronous suspend
In reply to Rafael J. WysockiQuoted 19 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Subject: PM: Fix potential issue with failing asynchronous suspendThere is a potential issue with the asynchronous suspend code that a device driver suspending asynchronously may not notice that it should back off. There are two failing scenarions, (1) when the driver is waiting for a driver suspending synchronously to complete and that second driver returns error code, in which case
async_errorwon't be set and the waiting driver will continue suspending and (2) after the driver has calleddevice_pm_wait_for_dev()and the waited for driver returns error code, in which case the caller ofdevice_pm_wait_for_dev()will not know that there was an error and will continue suspending.To fix this issue make
__device_suspend()setasync_error, soasync_suspend()doesn't need to set it any more, and makedevice_pm_wait_for_dev()returnasync_error, so that its callers can check whether or not they should continue suspending.
Quoted 5 lines
No more changes are necessary, since
device_pm_wait_for_dev()in not used by any drivers' suspend routines.Reported-by Colin Cross <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Quoted 8 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Due to the apparent lack of objections I applied the patches from this series to suspend-2.6/linux-next.
Thanks,
Rafael
Quoted 8 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Due to the apparent lack of objections I applied the patches from this series to suspend-2.6/linux-next.
Thanks,
Rafael
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
Rafael
Sorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Also, with this do we want to revisit a pm_qos class for "active" systems? Or do you think thats redundant now?
--mark
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
Rafael
Sorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Also, with this do we want to revisit a pm_qos class for "active" systems? Or do you think thats redundant now?
--mark
Quoted 22 lines · mark gross
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
RafaelSorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.
Quoted 7 lines
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
IMO it is more convenient to implement that in a different way, but generally I think you're right.
Quoted 2 lines
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Well, I'm not sure if I understand correctly, can you elaborate a bit, please?
Quoted 2 lines
Also, with this do we want to revisit a
pm_qosclass for "active" systems? Or do you think thats redundant now?
I don't really think the pm_qos for "active" systems is really necessary at this point.
Thanks,
Rafael
Quoted 22 lines · mark gross
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
RafaelSorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.
Quoted 7 lines
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
IMO it is more convenient to implement that in a different way, but generally I think you're right.
Quoted 2 lines
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Well, I'm not sure if I understand correctly, can you elaborate a bit, please?
Quoted 2 lines
Also, with this do we want to revisit a
pm_qosclass for "active" systems? Or do you think thats redundant now?
I don't really think the pm_qos for "active" systems is really necessary at this point.
Thanks,
Rafael
Quoted 31 lines · Rafael J. Wysocki
Quoted 22 lines · mark gross
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
RafaelSorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.Quoted 7 lines
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
Quoted 7 lines
IMO it is more convenient to implement that in a different way, but generally I think you're right.
Quoted 2 lines
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Well, I'm not sure if I understand correctly, can you elaborate a bit, please?
Well, before I saw your patch I was thinking about implementing an Android PM driver that would request a pm_qos active request that would be notified and interface with your wake event code. It would also expose a misc /dev/susped_blocked node that would be signaled when the pm_qos active request went to zero.
Now I'm sort of making things up as I go but, some sort of non-poling mechanism to re-attempt the suspend, for type 2, is needed but I'm not sure where to put it now.
Also, we may want to think about registering events that user mode will handle, and all others are treated as type 2 events.
Quoted 6 lines
Quoted 2 lines
Also, with this do we want to revisit a
pm_qosclass for "active" systems? Or do you think thats redundant now?I don't really think the
pm_qosfor "active" systems is really necessary at this point.
I'm still studying the patch but, you are likely right. I need to look at how much overhead changing the suspend blocking/unblocking is handled. I expect that some drivers will be hitting it on hot code paths.
--mark
Quoted 2 lines
Thanks,
Rafael
Quoted 31 lines · Rafael J. Wysocki
Quoted 22 lines · mark gross
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
RafaelSorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.Quoted 7 lines
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
Quoted 7 lines
IMO it is more convenient to implement that in a different way, but generally I think you're right.
Quoted 2 lines
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Well, I'm not sure if I understand correctly, can you elaborate a bit, please?
Well, before I saw your patch I was thinking about implementing an Android PM driver that would request a pm_qos active request that would be notified and interface with your wake event code. It would also expose a misc /dev/susped_blocked node that would be signaled when the pm_qos active request went to zero.
Now I'm sort of making things up as I go but, some sort of non-poling mechanism to re-attempt the suspend, for type 2, is needed but I'm not sure where to put it now.
Also, we may want to think about registering events that user mode will handle, and all others are treated as type 2 events.
Quoted 6 lines
Quoted 2 lines
Also, with this do we want to revisit a
pm_qosclass for "active" systems? Or do you think thats redundant now?I don't really think the
pm_qosfor "active" systems is really necessary at this point.
I'm still studying the patch but, you are likely right. I need to look at how much overhead changing the suspend blocking/unblocking is handled. I expect that some drivers will be hitting it on hot code paths.
--mark
Quoted 2 lines
Thanks,
Rafael
Quoted 46 lines · mark gross
Quoted 31 lines · Rafael J. Wysocki
Quoted 22 lines · mark gross
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
RafaelSorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.Quoted 7 lines
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
Quoted 7 lines
IMO it is more convenient to implement that in a different way, but generally I think you're right.
Quoted 2 lines
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Well, I'm not sure if I understand correctly, can you elaborate a bit, please?
Well, before I saw your patch I was thinking about implementing an Android PM driver that would request a
pm_qosactive request that would be notified and interface with your wake event code. It would also expose a misc/dev/susped_blockednode that would be signaled when thepm_qosactive request went to zero.
Quoted 3 lines
Now I'm sort of making things up as I go but, some sort of non-poling mechanism to re-attempt the suspend, for type 2, is needed but I'm not sure where to put it now.
There always will be some kind of "polling" involved, because some operations will have to be retried, but that should still be fine as long as the power manager puts itself to sleep whenever it sees that suspend is "blocked".
Reading from /sys/power/wakeup_count blocks until events_in_progress is zero and there should be some IPC between the power manager and the user space tasks allowed to "block suspend" that will put the power manager to sleep until it's OK to try suspending.
Quoted 7 lines
Also, we may want to think about registering events that user mode will handle, and all others are treated as type 2 events.
Quoted 3 lines
Quoted 2 lines
Also, with this do we want to revisit a
pm_qosclass for "active" systems? Or do you think thats redundant now?
Quoted 8 lines
Quoted 3 lines
I don't really think the
pm_qosfor "active" systems is really necessary at this point.I'm still studying the patch but, you are likely right. I need to look at how much overhead changing the suspend blocking/unblocking is handled. I expect that some drivers will be hitting it on hot code paths.
That involves taking two spinlocks that shouldn't be contended for (one in struct dev_pm_info and one in struct wakeup_source) and one (for
blocking) or two (for unblocking) atomic variables. For unblocking there
also is a spinlock to take in del_timer() if the timer is pending, but that only happens if there's a timeout.
Thanks,
Rafael
Quoted 46 lines · mark gross
Quoted 31 lines · Rafael J. Wysocki
Quoted 22 lines · mark gross
Quoted 11 lines · Rafael J. Wysocki
Hi,
The following two patches are ready to go into linux-next from my point of view, so please let me know if there are any objections:
[1/2] - PM / Wakeup: Introduce wakeup source objects and event statistics (v3)
[2/2] - PM: Fix potential issue with failing asynchronous suspend
Thanks,
RafaelSorry for the late response but, what user feed back will this provide to the OS stack looking to put the system in a low power state?
There are 2 cases I can think of:
1) system wakes from an event that user mode needs to handle (i.e. key press or phone ring or alarm events)
2) system wakes (or more likely, is blocked from suspending) by a kernel critical section, say if USB-OTG is connected.Quoted 7 lines
When wake's are of the type 1, then the power manager service could simply wait for a user mode wake lock be taken and released from the usermode before re-attempting to suspend.
When the wakes are of type 2, a power manager service thread would need to do a select on a system file and be woken up to re-try the suspend after the suspend-blocking is no longer needed.
Quoted 7 lines
IMO it is more convenient to implement that in a different way, but generally I think you're right.
Quoted 2 lines
Do you think I should cobble together an android PM driver that plugs into your code to expose an ABI for the 2 cases listed above?
Well, I'm not sure if I understand correctly, can you elaborate a bit, please?
Well, before I saw your patch I was thinking about implementing an Android PM driver that would request a
pm_qosactive request that would be notified and interface with your wake event code. It would also expose a misc/dev/susped_blockednode that would be signaled when thepm_qosactive request went to zero.
Quoted 3 lines
Now I'm sort of making things up as I go but, some sort of non-poling mechanism to re-attempt the suspend, for type 2, is needed but I'm not sure where to put it now.
There always will be some kind of "polling" involved, because some operations will have to be retried, but that should still be fine as long as the power manager puts itself to sleep whenever it sees that suspend is "blocked".
Reading from /sys/power/wakeup_count blocks until events_in_progress is zero and there should be some IPC between the power manager and the user space tasks allowed to "block suspend" that will put the power manager to sleep until it's OK to try suspending.
Quoted 7 lines
Also, we may want to think about registering events that user mode will handle, and all others are treated as type 2 events.
Quoted 3 lines
Quoted 2 lines
Also, with this do we want to revisit a
pm_qosclass for "active" systems? Or do you think thats redundant now?
Quoted 8 lines
Quoted 3 lines
I don't really think the
pm_qosfor "active" systems is really necessary at this point.I'm still studying the patch but, you are likely right. I need to look at how much overhead changing the suspend blocking/unblocking is handled. I expect that some drivers will be hitting it on hot code paths.
That involves taking two spinlocks that shouldn't be contended for (one in struct dev_pm_info and one in struct wakeup_source) and one (for
blocking) or two (for unblocking) atomic variables. For unblocking there
also is a spinlock to take in del_timer() if the timer is pending, but that only happens if there's a timeout.
Thanks,
Rafael