Suspend block api (version 6)
Subsystems (6)
PATCH 1/8 PM: Add suspend block api.
In reply to Arve HjønnevågAdds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
--- Documentation/power/opportunistic-suspend.txt | 119 +++++++++++ include/linux/suspend_blocker.h | 64 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 92 ++++++++- kernel/power/power.h | 9 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 261 +++++++++++++++++++++++++ 8 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/suspend_blocker.c
Documentation/power/opportunistic-suspend.txt new file +119 -0
@@ -0,0 +1,119 @@ +Opportunistic Suspend +===================== + +Opportunistic suspend is a feature allowing the system to be suspended (ie. put +into one of the available sleep states) automatically whenever it is regarded +as idle. The suspend blockers framework described below is used to determine +when that happens. + +The /sys/power/policy sysfs attribute is used to switch the system between the +opportunistic and "forced" suspend behavior, where in the latter case the +system is only suspended if a specific value, corresponding to one of the +available system sleep states, is written into /sys/power/state. However, in +the former, opportunistic, case the system is put into the sleep state +corresponding to the value written to /sys/power/state whenever there are no +active suspend blockers. The default policy is "forced". Also, suspend blockers +do not affect sleep states entered from idle. + +When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode. + +A suspend blocker is an object used to inform the PM subsystem when the system +can or cannot be suspended in the "opportunistic" mode (the "forced" mode +ignores suspend blockers). To use it, a device driver creates a struct +suspend_blocker that must be initialized with suspend_blocker_init(). Before +freeing the suspend_blocker structure or its name, suspend_blocker_destroy() +must be called on it. + +A suspend blocker is activated using suspend_block(), which prevents the PM +subsystem from putting the system into the requested sleep state in the +"opportunistic" mode until the suspend blocker is deactivated with +suspend_unblock(). Multiple suspend blockers may be active simultaneously, and +the system will not suspend as long as at least one of them is active. + +If opportunistic suspend is already in progress when suspend_block() is called, +it will abort the suspend, unless suspend_ops->enter has already been +executed. If suspend is aborted this way, the system is usually not fully +operational at that point. The suspend callbacks of some drivers may still be +running and it usually takes time to restore the system to the fully operational +state. + +Here's an example showing how a cell phone or other embedded system can handle +keystrokes (or other input events) in the presence of suspend blockers. Use +set_irq_wake or a platform specific api to make sure the keypad interrupt wakes +up the cpu. Once the keypad driver has resumed, the sequence of events can look +like this: + +- The Keypad driver gets an interrupt. It then calls suspend_block on the + keypad-scan suspend_blocker and starts scanning the keypad matrix. +- The keypad-scan code detects a key change and reports it to the input-event + driver. +- The input-event driver sees the key change, enqueues an event, and calls + suspend_block on the input-event-queue suspend_blocker. +- The keypad-scan code detects that no keys are held and calls suspend_unblock + on the keypad-scan suspend_blocker. +- The user-space input-event thread returns from select/poll, calls + suspend_block on the process-input-events suspend_blocker and then calls read + on the input-event device. +- The input-event driver dequeues the key-event and, since the queue is now + empty, it calls suspend_unblock on the input-event-queue suspend_blocker. +- The user-space input-event thread returns from read. If it determines that + the key should be ignored, it calls suspend_unblock on the + process_input_events suspend_blocker and then calls select or poll. The + system will automatically suspend again, since now no suspend blockers are + active. + +If the key that was pressed instead should preform a simple action (for example, +adjusting the volume), this action can be performed right before calling +suspend_unblock on the process_input_events suspend_blocker. However, if the key +triggers a longer-running action, that action needs its own suspend_blocker and +suspend_block must be called on that suspend blocker before calling +suspend_unblock on the process_input_events suspend_blocker. + + Key pressed Key released + | | +keypad-scan ++++++++++++++++++ +input-event-queue +++ +++ +process-input-events +++ +++ + + +Driver API +========== + +A driver can use the suspend block api by adding a suspend_blocker variable to +its state and calling suspend_blocker_init. For instance: +struct state { + struct suspend_blocker suspend_blocker; +} + +init() { + suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name"); +} + +Before freeing the memory, suspend_blocker_destroy must be called: + +uninit() { + suspend_blocker_destroy(&state->suspend_blocker); +} + +When the driver determines that it needs to run (usually in an interrupt +handler) it calls suspend_block: + suspend_block(&state->suspend_blocker); + +When it no longer needs to run it calls suspend_unblock: + suspend_unblock(&state->suspend_blocker); + +Calling suspend_block when the suspend blocker is active or suspend_unblock when +it is not active has no effect (i.e., these functions don't nest). This allows +drivers to update their state and call suspend suspend_block or suspend_unblock +based on the result. +For instance: + +if (list_empty(&state->pending_work)) + suspend_unblock(&state->suspend_blocker); +else + suspend_block(&state->suspend_blocker); +
include/linux/suspend_blocker.h new file +64 -0
64 lines not on this page · raw message
kernel/power/Kconfig +16 -0
@@ -130,6 +130,22 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. +config OPPORTUNISTIC_SUSPEND + bool "Suspend blockers" + depends on PM_SLEEP + select RTC_LIB + default n + ---help--- + Opportunistic sleep support. Allows the system to be put into a sleep + state opportunistically, if it doesn't do any useful work at the + moment. The PM subsystem is switched into this mode of operation by + writing "opportunistic" into /sys/power/policy, while writing + "forced" to this file turns the opportunistic suspend feature off. + In the "opportunistic" mode suspend blockers are used to determine + when to suspend the system and the value written to /sys/power/state + determines the sleep state the system will be put into when there are + no active suspend blockers. + config HIBERNATION_NVS bool
kernel/power/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.o
kernel/power/main.c +86 -6
162 lines not on this page · raw message
kernel/power/power.h +9 -0
@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void) { }#endif + +/* kernel/power/suspend_block.c */ +extern int request_suspend_state (suspend_state_t state); +extern bool request_suspend_valid_state (suspend_state_t state); +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +extern void __init suspend_block_init (void ); +#else +static inline void suspend_block_init (void ) {} +#endif
kernel/power/suspend.c +3 -1
@@ -16,10 +16,12 @@#include <linux/cpu.h> #include <linux/syscalls.h> #include <linux/gfp.h> +#include <linux/suspend_blocker.h> #include "power.h" const char *const pm_states[PM_SUSPEND_MAX ] = { + [PM_SUSPEND_ON ] ="on" , [PM_SUSPEND_STANDBY ] ="standby" , [PM_SUSPEND_MEM ] ="mem" , };
@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) error = suspend_ops->enter (state);sysdev_resume (); }
kernel/power/suspend_blocker.c new file +261 -0
261 lines not on this page · raw message
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 2/8 PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågAdd a misc device, "suspend_blocker", that allows user-space processes to block auto suspend. The device has ioctls to create a suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.
--- Documentation/ioctl/ioctl-number.txt | 3 +- Documentation/power/opportunistic-suspend.txt | 17 ++++ include/linux/suspend_block_dev.h | 25 +++++ kernel/power/Kconfig | 9 ++ kernel/power/Makefile | 1 + kernel/power/user_suspend_blocker.c | 128 +++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 1 deletions(-) create mode 100644 include/linux/suspend_block_dev.h create mode 100644 kernel/power/user_suspend_blocker.c
Documentation/ioctl/ioctl-number.txt +2 -1
@@ -254,7 +254,8 @@ Code Seq#(hex) Include File Comments 'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK linux/ixjuser.h <http://www.quicknet.net> 'r' 00-1F linux/msdos_fs.h and fs/fat/dir.c -'s' all linux/cdk.h +'s' all linux/cdk.h conflict! +'s' all linux/suspend_block_dev.h conflict! 't' 00-7F linux/if_ppp.h 't' 80-8F linux/isdn_ppp.h 't' 90 linux/toshiba.h
Documentation/power/opportunistic-suspend.txt +17 -0
@@ -117,3 +117,20 @@ if (list_empty(&state->pending_work)) else suspend_block(&state->suspend_blocker); +User-space API +============== + +To create a suspend_blocker from user-space, open the suspend_blocker device: + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); +then call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_INIT(strlen(name)), name); + +To activate a suspend_blocker call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To unblock call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend_blocker, close the device: + close(fd); +
include/linux/suspend_block_dev.h new file +25 -0
@@ -0,0 +1,25 @@ +/* include/linux/suspend_block_dev.h +* +* Copyright (C) 2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCK_DEV_H +#define _LINUX_SUSPEND_BLOCK_DEV_H + +#include <linux/ioctl.h> + +#define SUSPEND_BLOCKER_IOCTL_INIT (len) _IOC(_IOC_WRITE, 's', 0, len) +#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1) +#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 2) + +#endif
kernel/power/Kconfig +9 -0
@@ -146,6 +146,15 @@ config OPPORTUNISTIC_SUSPEND determines the sleep state the system will be put into when there are no active suspend blockers. +config USER_SUSPEND_BLOCKERS + bool "Userspace suspend blockers" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + User-space suspend block api. Creates a misc device with ioctls + to create, block and unblock a suspend_blocker. The suspend_blocker + will be deleted when the device is closed. + config HIBERNATION_NVS bool
kernel/power/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o +obj-$(CONFIG_USER_SUSPEND_BLOCKERS) += user_suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.o
kernel/power/user_suspend_blocker.c new file +128 -0
128 lines not on this page · raw message
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 3/8 PM: suspend_block: Abort task freezing if a suspend_blocker is active.
If a suspend_blocker is active, suspend will fail anyway. Since try_to_freeze_tasks can take up to 20 seconds to complete or fail, aborting as soon as someone blocks suspend (e.g. from an interrupt handler) improves the worst case wakeup latency.
On an older kernel where task freezing could fail for processes attached to a debugger, this fixed a problem where the device sometimes hung for 20 seconds before the screen turned on.
--- kernel/power/process.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
kernel/power/process.c +10 -2
@@ -15,6 +15,7 @@#include <linux/syscalls.h> #include <linux/freezer.h> #include <linux/delay.h> +#include <linux/suspend_blocker.h> /* * Timeout for stopping processes
@@ -38,6 +39,7 @@ static int try_to_freeze_tasks(bool sig_only)struct timeval start, end;u64 elapsed_csecs64;unsigned int elapsed_csecs; +bool wakeup = false;do_gettimeofday (&start);
@@ -63,6 +65,10 @@ static int try_to_freeze_tasks(bool sig_only) todo++; }while_each_thread (g, p);read_unlock (&tasklist_lock); +if (todo &&suspend_is_blocked ()) { + wakeup = true; +break ; + }if (!todo ||time_after (jiffies, end_time))break ;
@@ -85,13 +91,15 @@ static int try_to_freeze_tasks(bool sig_only)* but it cleans up leftover PF_FREEZE requests. */ printk ("\n" ); -printk (KERN_ERR "Freezing of tasks failed after %d.%02d seconds " +printk (KERN_ERR "Freezing of tasks %s after %d.%02d seconds " "(%d tasks refusing to freeze):\n" , + wakeup ?"aborted" :"failed" , elapsed_csecs /100 , elapsed_csecs %100 , todo);read_lock (&tasklist_lock); do_each_thread(g, p) {task_lock (p); -if (freezing (p) && !freezer_should_skip (p)) +if (freezing (p) && !freezer_should_skip (p) + && elapsed_csecs >100 )sched_show_task (p);cancel_freezing (p);task_unlock (p);
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 4/8 PM: suspend_block: Add debugfs file
Report active and inactive suspend blockers in/sys/kernel/debug/suspend_blockers.
--- kernel/power/suspend_blocker.c | 43 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 41 insertions(+), 2 deletions(-)
kernel/power/suspend_blocker.c +41 -2
@@ -17,6 +17,7 @@#include <linux/rtc.h> #include <linux/suspend.h> #include <linux/suspend_blocker.h> +#include <linux/debugfs.h> #include "power.h" extern struct workqueue_struct *pm_wq;
@@ -42,6 +43,7 @@ static int current_event_num;struct suspend_blocker main_suspend_blocker;static suspend_state_t requested_suspend_state =PM_SUSPEND_MEM ;static bool enable_suspend_blockers; +static struct dentry *suspend_blocker_stats_dentry; #define pr_info_time(fmt, args...) \ do { \
@@ -55,6 +57,21 @@ static bool enable_suspend_blockers; tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); \ }while (0 ); +static int suspend_blocker_stats_show (struct seq_file *m,void *unused) +{ +unsigned long irqflags; +struct suspend_blocker *blocker; + +seq_puts (m,"name\tactive\n" ); +spin_lock_irqsave (&list_lock, irqflags); +list_for_each_entry (blocker, &inactive_blockers, link) +seq_printf (m,"\"%s\"\t0\n" , blocker->name); +list_for_each_entry (blocker, &active_blockers, link) +seq_printf (m,"\"%s\"\t1\n" , blocker->name); +spin_unlock_irqrestore (&list_lock, irqflags); +return 0 ; +} +static void print_active_blockers_locked (void ) {struct suspend_blocker *blocker;
@@ -106,8 +123,8 @@ static DECLARE_WORK(suspend_work, suspend_worker);/** * suspend_blocker_init() - Initialize a suspend blocker * @blocker: The suspend blocker to initialize. -* @name: The name of the suspend blocker to show in debug messages. -* +* @name: The name of the suspend blocker to show in debug messages and +* /sys/kernel/debug/suspend_blockers. * The suspend blocker struct and name must not be freed before calling * suspend_blocker_destroy. */
@@ -254,8 +271,30 @@ int request_suspend_state(suspend_state_t state)return 0 ; } +static int suspend_blocker_stats_open (struct inode *inode,struct file *file) +{ +return single_open (file, suspend_blocker_stats_show,NULL ); +} + +static const struct file_operations suspend_blocker_stats_fops = { + .owner =THIS_MODULE , + .open = suspend_blocker_stats_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +void __init suspend_block_init (void ) {suspend_blocker_init (&main_suspend_blocker,"main" );suspend_block (&main_suspend_blocker); } + +static int __init suspend_block_postcore_init (void ) +{ + suspend_blocker_stats_dentry =debugfs_create_file ("suspend_blockers" , +S_IRUGO ,NULL ,NULL , &suspend_blocker_stats_fops); +return 0 ; +} + +postcore_initcall (suspend_block_postcore_init);
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 5/8 PM: suspend_block: Add suspend_blocker stats
Report suspend block stats in /sys/kernel/debug/suspend_blockers.
--- include/linux/suspend_blocker.h | 21 ++++- kernel/power/Kconfig | 7 ++ kernel/power/power.h | 5 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 190 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 218 insertions(+), 9 deletions(-)
include/linux/suspend_blocker.h +20 -1
@@ -17,12 +17,21 @@#define _LINUX_SUSPEND_BLOCKER_H#include <linux/list.h> +#include <linux/ktime.h> /** * struct suspend_blocker - the basic suspend_blocker structure * @link: List entry for active or inactive list. -* @flags: Tracks initialized and active state. +* @flags: Tracks initialized, active and stats state. * @name: Name used for debugging. +* @count: Number of times this blocker has been deacivated +* @wakeup_count: Number of times this blocker was the first to block suspend +* after resume. +* @total_time: Total time this suspend blocker has prevented suspend. +* @prevent_suspend_time: Time this suspend blocker has prevented suspend while +* user-space requested suspend. +* @max_time: Max time this suspend blocker has been continuously active +* @last_time: Monotonic clock when the active state last changed. * * When a suspend_blocker is active it prevents the system from entering * opportunistic suspend.
@@ -35,6 +44,16 @@ struct suspend_blocker {struct list_head link;int flags;const char *name; +#ifdef CONFIG_SUSPEND_BLOCKER_STATS +struct { +int count; +int wakeup_count; +ktime_t total_time; +ktime_t prevent_suspend_time; +ktime_t max_time; +ktime_t last_time; + } stat; +#endif #endif };
kernel/power/Kconfig +7 -0
@@ -146,6 +146,13 @@ config OPPORTUNISTIC_SUSPEND determines the sleep state the system will be put into when there are no active suspend blockers. +config SUSPEND_BLOCKER_STATS + bool "Suspend block stats" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + Report suspend block stats in /sys/kernel/debug/suspend_blockers + config USER_SUSPEND_BLOCKERS bool "Userspace suspend blockers" depends on OPPORTUNISTIC_SUSPEND
kernel/power/power.h +5 -0
@@ -245,3 +245,8 @@ extern void __init suspend_block_init(void);#else static inline void suspend_block_init (void ) {}#endif +#ifdef CONFIG_SUSPEND_BLOCKER_STATS +void about_to_enter_suspend (void ); +#else +static inline void about_to_enter_suspend (void ) {} +#endif
kernel/power/suspend.c +3 -1
@@ -159,8 +159,10 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) { +about_to_enter_suspend (); error = suspend_ops->enter (state); + }sysdev_resume (); }
kernel/power/suspend_blocker.c +183 -7
266 lines not on this page · raw message
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 6/8 PM: Add suspend blocking work.
Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate suspend_blocker for pending and executing work, or additional state and locking. This implementation does add additional state and locking, but this can be removed later if we add support for suspend blocking work to the core workqueue code.
--- include/linux/suspend_blocker.h | 67 ++++++++++++++++++++++++ kernel/power/suspend_blocker.c | 109 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 0 deletions(-)
include/linux/suspend_blocker.h +67 -0
@@ -18,6 +18,7 @@#include <linux/list.h> #include <linux/ktime.h> +#include <linux/workqueue.h> /** * struct suspend_blocker - the basic suspend_blocker structure
@@ -57,6 +58,38 @@ struct suspend_blocker {#endif }; +/** +* struct suspend_blocking_work - the basic suspend_blocking_work structure +* @work: Standard work struct. +* @suspend_blocker: Suspend blocker. +* @func: Callback. +* @lock: Spinlock protecting pending and running state. +* @active: Number of cpu workqueues where work is pending or +* callback is running. +* +* When suspend blocking work is pending or its callback is running it prevents +* the system from entering opportunistic suspend. +* +* The suspend_blocking_work structure must be initialized by +* suspend_blocking_work_init(). +*/ + +struct suspend_blocking_work { +struct work_struct work; +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +struct suspend_blocker suspend_blocker; +work_func_t func; +spinlock_t lock; +int active; +#endif +}; + +static inline struct suspend_blocking_work *to_suspend_blocking_work ( +struct work_struct *work) +{ + return container_of(work, struct suspend_blocking_work, work); +} +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND void suspend_blocker_init (struct suspend_blocker *blocker,const char *name);
@@ -66,6 +99,14 @@ void suspend_unblock(struct suspend_blocker *blocker);bool suspend_blocker_is_active (struct suspend_blocker *blocker);bool suspend_is_blocked (void ); +void suspend_blocking_work_init (struct suspend_blocking_work *work, +work_func_t func,const char *name); +void suspend_blocking_work_destroy (struct suspend_blocking_work *work); +int queue_suspend_blocking_work (struct workqueue_struct *wq, +struct suspend_blocking_work *work); +int schedule_suspend_blocking_work (struct suspend_blocking_work *work); +int cancel_suspend_blocking_work_sync (struct suspend_blocking_work *work); +#else static inline void suspend_blocker_init(struct suspend_blocker *blocker,
@@ -77,6 +118,32 @@ static inline bool suspend_blocker_is_active(struct suspend_blocker *bl) {return 0 ; }static inline bool suspend_is_blocked (void ) {return 0 ; } +static inline void suspend_blocking_work_init ( +struct suspend_blocking_work *work,work_func_t func,const char *name) +{ +INIT_WORK (&work->work, func); +} +static inline void suspend_blocking_work_destroy ( +struct suspend_blocking_work *work) +{ +cancel_work_sync (&work->work); +} +static inline int queue_suspend_blocking_work ( +struct workqueue_struct *wq,struct suspend_blocking_work *work) +{ +return queue_work (wq, &work->work); +} +static inline int schedule_suspend_blocking_work ( +struct suspend_blocking_work *work) +{ +return schedule_work (&work->work); +} +static inline int cancel_suspend_blocking_work_sync ( +struct suspend_blocking_work *work) +{ +return cancel_work_sync (&work->work); +} +#endif #endif
kernel/power/suspend_blocker.c +109 -0
112 lines not on this page · raw message
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 7/8 Input: Block suspend while event queue is not empty.
Add an ioctl, EVIOCSSUSPENDBLOCK, to enable a suspend_blocker that will block suspend while the event queue is not empty. This allows userspace code to process input events while the device appears to be asleep.
--- drivers/input/evdev.c | 22 ++++++++++++++++++++++ include/linux/input.h | 3 +++ 2 files changed, 25 insertions(+), 0 deletions(-)
drivers/input/evdev.c +22 -0
@@ -20,6 +20,7 @@#include <linux/input.h> #include <linux/major.h> #include <linux/device.h> +#include <linux/suspend_blocker.h> #include "input-compat.h" struct evdev {
@@ -43,6 +44,8 @@ struct evdev_client {struct fasync_struct *fasync;struct evdev *evdev;struct list_head node; +struct suspend_blocker suspend_blocker; +bool use_suspend_blocker; };static struct evdev *evdev_table[EVDEV_MINORS ];
@@ -55,6 +58,8 @@ static void evdev_pass_event(struct evdev_client *client,* Interrupts are disabled, just acquire the lock */ spin_lock (&client->buffer_lock); +if (client->use_suspend_blocker) +suspend_block (&client->suspend_blocker); client->buffer[client->head++] = *event; client->head &=EVDEV_BUFFER_SIZE -1 ;spin_unlock (&client->buffer_lock);
@@ -234,6 +239,8 @@ static int evdev_release(struct inode *inode, struct file *file)mutex_unlock (&evdev->mutex);evdev_detach_client (evdev, client); +if (client->use_suspend_blocker) +suspend_blocker_destroy (&client->suspend_blocker);kfree (client);evdev_close_device (evdev);
@@ -335,6 +342,8 @@ static int evdev_fetch_next_event(struct evdev_client *client,if (have_event) { *event = client->buffer[client->tail++]; client->tail &=EVDEV_BUFFER_SIZE -1 ; +if (client->use_suspend_blocker && client->head == client->tail) +suspend_unblock (&client->suspend_blocker); }spin_unlock_irq (&client->buffer_lock);
@@ -585,6 +594,19 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,else return evdev_ungrab (evdev, client); +case EVIOCGSUSPENDBLOCK : +return put_user (client->use_suspend_blocker, ip); + +case EVIOCSSUSPENDBLOCK : +spin_lock_irq (&client->buffer_lock); +if (!client->use_suspend_blocker && p) +suspend_blocker_init (&client->suspend_blocker,"evdev" ); +else if (client->use_suspend_blocker && !p) +suspend_blocker_destroy (&client->suspend_blocker); + client->use_suspend_blocker = !!p; +spin_unlock_irq (&client->buffer_lock); +return 0 ; +default :if (_IOC_TYPE (cmd) !='E' )
include/linux/input.h +3 -0
@@ -82,6 +82,9 @@ struct input_absinfo {#define EVIOCGRAB _IOW('E', 0x90, int)/* Grab/Release device */ +#define EVIOCGSUSPENDBLOCK _IOR('E', 0x91, int)/* get suspend block enable */ +#define EVIOCSSUSPENDBLOCK _IOW('E', 0x91, int)/* set suspend block enable */ +/* * Event types */
Signature · 1 line
1.6.5.1
PATCH 7/8 Input: Block suspend while event queue is not empty.
In reply to Arve HjønnevågAdd an ioctl, EVIOCSSUSPENDBLOCK, to enable a suspend_blocker that will block suspend while the event queue is not empty. This allows userspace code to process input events while the device appears to be asleep.
--- drivers/input/evdev.c | 22 ++++++++++++++++++++++ include/linux/input.h | 3 +++ 2 files changed, 25 insertions(+), 0 deletions(-)
drivers/input/evdev.c +22 -0
@@ -20,6 +20,7 @@#include <linux/input.h> #include <linux/major.h> #include <linux/device.h> +#include <linux/suspend_blocker.h> #include "input-compat.h" struct evdev {
@@ -43,6 +44,8 @@ struct evdev_client {struct fasync_struct *fasync;struct evdev *evdev;struct list_head node; +struct suspend_blocker suspend_blocker; +bool use_suspend_blocker; };static struct evdev *evdev_table[EVDEV_MINORS ];
@@ -55,6 +58,8 @@ static void evdev_pass_event(struct evdev_client *client,* Interrupts are disabled, just acquire the lock */ spin_lock (&client->buffer_lock); +if (client->use_suspend_blocker) +suspend_block (&client->suspend_blocker); client->buffer[client->head++] = *event; client->head &=EVDEV_BUFFER_SIZE -1 ;spin_unlock (&client->buffer_lock);
@@ -234,6 +239,8 @@ static int evdev_release(struct inode *inode, struct file *file)mutex_unlock (&evdev->mutex);evdev_detach_client (evdev, client); +if (client->use_suspend_blocker) +suspend_blocker_destroy (&client->suspend_blocker);kfree (client);evdev_close_device (evdev);
@@ -335,6 +342,8 @@ static int evdev_fetch_next_event(struct evdev_client *client,if (have_event) { *event = client->buffer[client->tail++]; client->tail &=EVDEV_BUFFER_SIZE -1 ; +if (client->use_suspend_blocker && client->head == client->tail) +suspend_unblock (&client->suspend_blocker); }spin_unlock_irq (&client->buffer_lock);
@@ -585,6 +594,19 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,else return evdev_ungrab (evdev, client); +case EVIOCGSUSPENDBLOCK : +return put_user (client->use_suspend_blocker, ip); + +case EVIOCSSUSPENDBLOCK : +spin_lock_irq (&client->buffer_lock); +if (!client->use_suspend_blocker && p) +suspend_blocker_init (&client->suspend_blocker,"evdev" ); +else if (client->use_suspend_blocker && !p) +suspend_blocker_destroy (&client->suspend_blocker); + client->use_suspend_blocker = !!p; +spin_unlock_irq (&client->buffer_lock); +return 0 ; +default :if (_IOC_TYPE (cmd) !='E' )
include/linux/input.h +3 -0
@@ -82,6 +82,9 @@ struct input_absinfo {#define EVIOCGRAB _IOW('E', 0x90, int)/* Grab/Release device */ +#define EVIOCGSUSPENDBLOCK _IOR('E', 0x91, int)/* get suspend block enable */ +#define EVIOCSSUSPENDBLOCK _IOW('E', 0x91, int)/* set suspend block enable */ +/* * Event types */
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 8/8 power_supply: Block suspend while power supply change notifications are pending
In reply to Arve HjønnevågWhen connecting usb or the charger the device would often go back to sleep before the charge led and screen turned on.
--- drivers/power/power_supply_core.c | 9 ++++++--- include/linux/power_supply.h | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/power/power_supply_core.c +6 -3
@@ -39,7 +39,7 @@ static int __power_supply_changed_work(struct device *dev, void *data)static void power_supply_changed_work (struct work_struct *work) { struct power_supply *psy = container_of(work, struct power_supply, - changed_work); + changed_work.work);dev_dbg (psy->dev,"%s\n" , __func__);
@@ -55,7 +55,7 @@ void power_supply_changed(struct power_supply *psy) {dev_dbg (psy->dev,"%s\n" , __func__); -schedule_work (&psy->changed_work); +schedule_suspend_blocking_work (&psy->changed_work); }EXPORT_SYMBOL_GPL (power_supply_changed);
@@ -155,7 +155,8 @@ int power_supply_register(struct device *parent, struct power_supply *psy) goto dev_create_failed; } -INIT_WORK (&psy->changed_work, power_supply_changed_work); +suspend_blocking_work_init (&psy->changed_work, + power_supply_changed_work,"power-supply" ); rc =power_supply_create_attrs (psy);if (rc)
@@ -172,6 +173,7 @@ int power_supply_register(struct device *parent, struct power_supply *psy) create_triggers_failed:power_supply_remove_attrs (psy); create_attrs_failed: +suspend_blocking_work_destroy (&psy->changed_work);device_unregister (psy->dev); dev_create_failed: success:
@@ -184,6 +186,7 @@ void power_supply_unregister(struct power_supply *psy)flush_scheduled_work ();power_supply_remove_triggers (psy);power_supply_remove_attrs (psy); +suspend_blocking_work_destroy (&psy->changed_work);device_unregister (psy->dev); }EXPORT_SYMBOL_GPL (power_supply_unregister);
include/linux/power_supply.h +2 -1
@@ -14,6 +14,7 @@#define __LINUX_POWER_SUPPLY_H__#include <linux/device.h> +#include <linux/suspend_blocker.h> #include <linux/workqueue.h> #include <linux/leds.h>
@@ -152,7 +153,7 @@ struct power_supply {/* private */ struct device *dev; -struct work_struct changed_work; +struct suspend_blocking_work changed_work;#ifdef CONFIG_LEDS_TRIGGERS struct led_trigger *charging_full_trig;
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
cover Suspend block api (version 6)
This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version fixes a race in suspend blocking work, has some documentation changes and opportunistic suspend now uses the same workqueue as runtime pm.
--
Arve Hjønnevåg <[email protected]>
PATCH 1/8 PM: Add suspend block api.
Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
--- Documentation/power/opportunistic-suspend.txt | 119 +++++++++++ include/linux/suspend_blocker.h | 64 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 92 ++++++++- kernel/power/power.h | 9 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 261 +++++++++++++++++++++++++ 8 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/suspend_blocker.c
Documentation/power/opportunistic-suspend.txt new file +119 -0
@@ -0,0 +1,119 @@ +Opportunistic Suspend +===================== + +Opportunistic suspend is a feature allowing the system to be suspended (ie. put +into one of the available sleep states) automatically whenever it is regarded +as idle. The suspend blockers framework described below is used to determine +when that happens. + +The /sys/power/policy sysfs attribute is used to switch the system between the +opportunistic and "forced" suspend behavior, where in the latter case the +system is only suspended if a specific value, corresponding to one of the +available system sleep states, is written into /sys/power/state. However, in +the former, opportunistic, case the system is put into the sleep state +corresponding to the value written to /sys/power/state whenever there are no +active suspend blockers. The default policy is "forced". Also, suspend blockers +do not affect sleep states entered from idle. + +When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode. + +A suspend blocker is an object used to inform the PM subsystem when the system +can or cannot be suspended in the "opportunistic" mode (the "forced" mode +ignores suspend blockers). To use it, a device driver creates a struct +suspend_blocker that must be initialized with suspend_blocker_init(). Before +freeing the suspend_blocker structure or its name, suspend_blocker_destroy() +must be called on it. + +A suspend blocker is activated using suspend_block(), which prevents the PM +subsystem from putting the system into the requested sleep state in the +"opportunistic" mode until the suspend blocker is deactivated with +suspend_unblock(). Multiple suspend blockers may be active simultaneously, and +the system will not suspend as long as at least one of them is active. + +If opportunistic suspend is already in progress when suspend_block() is called, +it will abort the suspend, unless suspend_ops->enter has already been +executed. If suspend is aborted this way, the system is usually not fully +operational at that point. The suspend callbacks of some drivers may still be +running and it usually takes time to restore the system to the fully operational +state. + +Here's an example showing how a cell phone or other embedded system can handle +keystrokes (or other input events) in the presence of suspend blockers. Use +set_irq_wake or a platform specific api to make sure the keypad interrupt wakes +up the cpu. Once the keypad driver has resumed, the sequence of events can look +like this: + +- The Keypad driver gets an interrupt. It then calls suspend_block on the + keypad-scan suspend_blocker and starts scanning the keypad matrix. +- The keypad-scan code detects a key change and reports it to the input-event + driver. +- The input-event driver sees the key change, enqueues an event, and calls + suspend_block on the input-event-queue suspend_blocker. +- The keypad-scan code detects that no keys are held and calls suspend_unblock + on the keypad-scan suspend_blocker. +- The user-space input-event thread returns from select/poll, calls + suspend_block on the process-input-events suspend_blocker and then calls read + on the input-event device. +- The input-event driver dequeues the key-event and, since the queue is now + empty, it calls suspend_unblock on the input-event-queue suspend_blocker. +- The user-space input-event thread returns from read. If it determines that + the key should be ignored, it calls suspend_unblock on the + process_input_events suspend_blocker and then calls select or poll. The + system will automatically suspend again, since now no suspend blockers are + active. + +If the key that was pressed instead should preform a simple action (for example, +adjusting the volume), this action can be performed right before calling +suspend_unblock on the process_input_events suspend_blocker. However, if the key +triggers a longer-running action, that action needs its own suspend_blocker and +suspend_block must be called on that suspend blocker before calling +suspend_unblock on the process_input_events suspend_blocker. + + Key pressed Key released + | | +keypad-scan ++++++++++++++++++ +input-event-queue +++ +++ +process-input-events +++ +++ + + +Driver API +========== + +A driver can use the suspend block api by adding a suspend_blocker variable to +its state and calling suspend_blocker_init. For instance: +struct state { + struct suspend_blocker suspend_blocker; +} + +init() { + suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name"); +} + +Before freeing the memory, suspend_blocker_destroy must be called: + +uninit() { + suspend_blocker_destroy(&state->suspend_blocker); +} + +When the driver determines that it needs to run (usually in an interrupt +handler) it calls suspend_block: + suspend_block(&state->suspend_blocker); + +When it no longer needs to run it calls suspend_unblock: + suspend_unblock(&state->suspend_blocker); + +Calling suspend_block when the suspend blocker is active or suspend_unblock when +it is not active has no effect (i.e., these functions don't nest). This allows +drivers to update their state and call suspend suspend_block or suspend_unblock +based on the result. +For instance: + +if (list_empty(&state->pending_work)) + suspend_unblock(&state->suspend_blocker); +else + suspend_block(&state->suspend_blocker); +
include/linux/suspend_blocker.h new file +64 -0
64 lines not on this page · raw message
kernel/power/Kconfig +16 -0
@@ -130,6 +130,22 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. +config OPPORTUNISTIC_SUSPEND + bool "Suspend blockers" + depends on PM_SLEEP + select RTC_LIB + default n + ---help--- + Opportunistic sleep support. Allows the system to be put into a sleep + state opportunistically, if it doesn't do any useful work at the + moment. The PM subsystem is switched into this mode of operation by + writing "opportunistic" into /sys/power/policy, while writing + "forced" to this file turns the opportunistic suspend feature off. + In the "opportunistic" mode suspend blockers are used to determine + when to suspend the system and the value written to /sys/power/state + determines the sleep state the system will be put into when there are + no active suspend blockers. + config HIBERNATION_NVS bool
kernel/power/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.o
kernel/power/main.c +86 -6
162 lines not on this page · raw message
kernel/power/power.h +9 -0
@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void) { }#endif + +/* kernel/power/suspend_block.c */ +extern int request_suspend_state (suspend_state_t state); +extern bool request_suspend_valid_state (suspend_state_t state); +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +extern void __init suspend_block_init (void ); +#else +static inline void suspend_block_init (void ) {} +#endif
kernel/power/suspend.c +3 -1
@@ -16,10 +16,12 @@#include <linux/cpu.h> #include <linux/syscalls.h> #include <linux/gfp.h> +#include <linux/suspend_blocker.h> #include "power.h" const char *const pm_states[PM_SUSPEND_MAX ] = { + [PM_SUSPEND_ON ] ="on" , [PM_SUSPEND_STANDBY ] ="standby" , [PM_SUSPEND_MEM ] ="mem" , };
@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) error = suspend_ops->enter (state);sysdev_resume (); }
kernel/power/suspend_blocker.c new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
1.6.5.1
Re: [PATCH 6/8] PM: Add suspend blocking work.
In reply to Arve HjønnevågQuoted 8 lines · Arve Hjønnevåg
Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate
suspend_blockerfor pending and executing work, or additional state and locking. This implementation does add additional state and locking, but this can be removed later if we add support for suspend blocking work to the core workqueue code.Signed-off-by Arve Hjønnevåg <[email protected]>
Thank you.
Signature · 5 lines
tejun _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Pavel Machek
NAKRe: [PATCH 1/8] PM: Add suspend block api.
In reply to Arve HjønnevågHi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>
NAK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Pavel Machek
NAKRe: [PATCH 1/8] PM: Add suspend block api.
In reply to Arve HjønnevågHi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>
NAK.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/8] PM: suspend_block: Abort task freezing if a suspend_blocker is active.
In reply to Arve HjønnevågHi!
Quoted 10 lines
If a
suspend_blockeris active, suspend will fail anyway. Sincetry_to_freeze_taskscan take up to 20 seconds to complete or fail, aborting as soon as someone blocks suspend (e.g. from an interrupt handler) improves the worst case wakeup latency.On an older kernel where task freezing could fail for processes attached to a debugger, this fixed a problem where the device sometimes hung for 20 seconds before the screen turned on.
Signed-off-by Arve Hj??nnev??g <[email protected]>
I acked this one before, please preserve such tags.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 3/8] PM: suspend_block: Abort task freezing if a suspend_blocker is active.
In reply to Arve HjønnevågHi!
Quoted 10 lines
If a
suspend_blockeris active, suspend will fail anyway. Sincetry_to_freeze_taskscan take up to 20 seconds to complete or fail, aborting as soon as someone blocks suspend (e.g. from an interrupt handler) improves the worst case wakeup latency.On an older kernel where task freezing could fail for processes attached to a debugger, this fixed a problem where the device sometimes hung for 20 seconds before the screen turned on.
Signed-off-by Arve Hj??nnev??g <[email protected]>
I acked this one before, please preserve such tags.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Arve HjønnevågQuoted 7 lines · Arve Hj??nnev??g
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.Signed-off-by Arve Hj??nnev??g <[email protected]>
Also note that this patch mixes up adding new in-kernel interface with adding new userland API.
The in-kernel interface seems to be sane and it would be nice to merge it soon, unfortunately the strange userland API is in the same patch :-(.
Quoted 735 lines
--- Documentation/power/opportunistic-suspend.txt | 119 +++++++++++ include/linux/suspend_blocker.h | 64 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 92 ++++++++- kernel/power/power.h | 9 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 261 +++++++++++++++++++++++++ 8 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/suspend_blocker.cDocumentation/power/opportunistic-suspend.txt new file +119
-0@@ -0,0 +1,119 @@ +Opportunistic Suspend +===================== + +Opportunistic suspend is a feature allowing the system to be suspended (ie. put +into one of the available sleep states) automatically whenever it is regarded +as idle. The suspend blockers framework described below is used to determine +when that happens. + +The /sys/power/policy sysfs attribute is used to switch the system between the +opportunistic and "forced" suspend behavior, where in the latter case the +system is only suspended if a specific value, corresponding to one of the +available system sleep states, is written into /sys/power/state. However, in +the former, opportunistic, case the system is put into the sleep state +corresponding to the value written to /sys/power/state whenever there are no +active suspend blockers. The default policy is "forced". Also, suspend blockers +do not affect sleep states entered from idle. + +When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode. + +A suspend blocker is an object used to inform the PM subsystem when the system +can or cannot be suspended in the "opportunistic" mode (the "forced" mode +ignores suspend blockers). To use it, a device driver creates a struct +suspend_blocker that must be initialized with suspend_blocker_init(). Before +freeing the suspend_blocker structure or its name, suspend_blocker_destroy() +must be called on it. + +A suspend blocker is activated using suspend_block(), which prevents the PM +subsystem from putting the system into the requested sleep state in the +"opportunistic" mode until the suspend blocker is deactivated with +suspend_unblock(). Multiple suspend blockers may be active simultaneously, and +the system will not suspend as long as at least one of them is active. + +If opportunistic suspend is already in progress when suspend_block() is called, +it will abort the suspend, unless suspend_ops->enter has already been +executed. If suspend is aborted this way, the system is usually not fully +operational at that point. The suspend callbacks of some drivers may still be +running and it usually takes time to restore the system to the fully operational +state. + +Here's an example showing how a cell phone or other embedded system can handle +keystrokes (or other input events) in the presence of suspend blockers. Use +set_irq_wake or a platform specific api to make sure the keypad interrupt wakes +up the cpu. Once the keypad driver has resumed, the sequence of events can look +like this: + +- The Keypad driver gets an interrupt. It then calls suspend_block on the + keypad-scan suspend_blocker and starts scanning the keypad matrix. +- The keypad-scan code detects a key change and reports it to the input-event + driver. +- The input-event driver sees the key change, enqueues an event, and calls + suspend_block on the input-event-queue suspend_blocker. +- The keypad-scan code detects that no keys are held and calls suspend_unblock + on the keypad-scan suspend_blocker. +- The user-space input-event thread returns from select/poll, calls + suspend_block on the process-input-events suspend_blocker and then calls read + on the input-event device. +- The input-event driver dequeues the key-event and, since the queue is now + empty, it calls suspend_unblock on the input-event-queue suspend_blocker. +- The user-space input-event thread returns from read. If it determines that + the key should be ignored, it calls suspend_unblock on the + process_input_events suspend_blocker and then calls select or poll. The + system will automatically suspend again, since now no suspend blockers are + active. + +If the key that was pressed instead should preform a simple action (for example, +adjusting the volume), this action can be performed right before calling +suspend_unblock on the process_input_events suspend_blocker. However, if the key +triggers a longer-running action, that action needs its own suspend_blocker and +suspend_block must be called on that suspend blocker before calling +suspend_unblock on the process_input_events suspend_blocker. + + Key pressed Key released + | | +keypad-scan ++++++++++++++++++ +input-event-queue +++ +++ +process-input-events +++ +++ + + +Driver API +========== + +A driver can use the suspend block api by adding a suspend_blocker variable to +its state and calling suspend_blocker_init. For instance: +struct state { + struct suspend_blocker suspend_blocker; +} + +init() { + suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name"); +} + +Before freeing the memory, suspend_blocker_destroy must be called: + +uninit() { + suspend_blocker_destroy(&state->suspend_blocker); +} + +When the driver determines that it needs to run (usually in an interrupt +handler) it calls suspend_block: + suspend_block(&state->suspend_blocker); + +When it no longer needs to run it calls suspend_unblock: + suspend_unblock(&state->suspend_blocker); + +Calling suspend_block when the suspend blocker is active or suspend_unblock when +it is not active has no effect (i.e., these functions don't nest). This allows +drivers to update their state and call suspend suspend_block or suspend_unblock +based on the result. +For instance: + +if (list_empty(&state->pending_work)) + suspend_unblock(&state->suspend_blocker); +else + suspend_block(&state->suspend_blocker); +include/linux/suspend_blocker.h new file +64
-0@@ -0,0 +1,64 @@ +/* include/linux/suspend_blocker.h +* +* Copyright (C) 2007-2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCKER_H +#define _LINUX_SUSPEND_BLOCKER_H + +#include <linux/list.h> + +/** +* struct suspend_blocker - the basic suspend_blocker structure +* @link: List entry for active or inactive list. +* @flags: Tracks initialized and active state. +* @name: Name used for debugging. +* +* When a suspend_blocker is active it prevents the system from entering +* opportunistic suspend. +* +* The suspend_blocker structure must be initialized by suspend_blocker_init() +*/ + +struct suspend_blocker { +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +struct list_head link; +int flags; +const char *name; +#endif +}; + +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name); +void suspend_blocker_destroy (struct suspend_blocker *blocker); +void suspend_block (struct suspend_blocker *blocker); +void suspend_unblock (struct suspend_blocker *blocker); +bool suspend_blocker_is_active (struct suspend_blocker *blocker); +bool suspend_is_blocked (void ); + +#else + +static inline void suspend_blocker_init (struct suspend_blocker *blocker, +const char *name) {} +static inline void suspend_blocker_destroy (struct suspend_blocker *blocker) {} +static inline void suspend_block (struct suspend_blocker *blocker) {} +static inline void suspend_unblock (struct suspend_blocker *blocker) {} +static inline bool suspend_blocker_is_active (struct suspend_blocker *bl) + {return 0 ; } +static inline bool suspend_is_blocked (void ) {return 0 ; } + +#endif + +#endif +kernel/power/Kconfig +16
-0@@ -130,6 +130,22 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. +config OPPORTUNISTIC_SUSPEND + bool "Suspend blockers" + depends on PM_SLEEP + select RTC_LIB + default n + ---help--- + Opportunistic sleep support. Allows the system to be put into a sleep + state opportunistically, if it doesn't do any useful work at the + moment. The PM subsystem is switched into this mode of operation by + writing "opportunistic" into /sys/power/policy, while writing + "forced" to this file turns the opportunistic suspend feature off. + In the "opportunistic" mode suspend blockers are used to determine + when to suspend the system and the value written to /sys/power/state + determines the sleep state the system will be put into when there are + no active suspend blockers. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/main.c +86
-6@@ -12,6 +12,7 @@#include <linux/string.h> #include <linux/resume-trace.h> #include <linux/workqueue.h> +#include <linux/suspend_blocker.h> #include "power.h" @@ -20,6 +21,27 @@ DEFINE_MUTEX(pm_mutex);unsigned int pm_flags;EXPORT_SYMBOL (pm_flags); +struct policy { +const char *name; +bool (*valid_state)(suspend_state_t state); +int (*set_state)(suspend_state_t state); +}; +static struct policy policies[] = { + { + .name ="forced" , + .valid_state = valid_state, + .set_state = enter_state, + }, +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + { + .name ="opportunistic" , + .valid_state = request_suspend_valid_state, + .set_state = request_suspend_state, + }, +#endif +}; +static int policy; +#ifdef CONFIG_PM_SLEEP /* Routines for PM-transition notifications */ @@ -146,6 +168,12 @@ struct kobject *power_kobj;* * store() accepts one of those strings, translates it into the * proper enumerated value, and initiates a suspend transition. +* +* If policy is set to opportunistic, store() does not block until the +* system resumes, and it will try to re-enter the state until another +* state is requested. Suspend blockers are respected and the requested +* state will only be entered when no suspend blockers are active. +* Write "on" to cancel. */ static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf)@@ -155,12 +183,13 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,int i;for (i =0 ; i <PM_SUSPEND_MAX ; i++) { -if (pm_states[i] &&valid_state (i)) +if (pm_states[i] && policies[policy].valid_state (i)) s +=sprintf (s,"%s " , pm_states[i]); }#endif #ifdef CONFIG_HIBERNATION - s +=sprintf (s,"%s\n" ,"disk" ); +if (!policy) + s +=sprintf (s,"%s\n" ,"disk" );#else if (s != buf)/* convert the last space to a newline */ @@ -173,7 +202,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) {#ifdef CONFIG_SUSPEND -suspend_state_t state =PM_SUSPEND_STANDBY ; +suspend_state_t state =PM_SUSPEND_ON ;const char *const *s;#endif char *p;@@ -184,7 +213,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, len = p ? p - buf : n;/* First, check if we are requested to hibernate */ -if (len ==4 && !strncmp (buf,"disk" , len)) { +if (len ==4 && !strncmp (buf,"disk" , len) && !policy) { error =hibernate (); goto Exit; }@@ -195,7 +224,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, break; }if (state <PM_SUSPEND_MAX && *s) - error =enter_state (state); + error = policies[policy].set_state (state);#endif Exit:@@ -204,6 +233,55 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,power_attr (state); +/** +* policy - set policy for state +*/ + +static ssize_t policy_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +char *s = buf; +int i; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { +if (i == policy) + s +=sprintf (s,"[%s] " , policies[i].name); +else + s +=sprintf (s,"%s " , policies[i].name); + } +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ; +return (s - buf); +} + +static ssize_t policy_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +const char *s; +char *p; +int len; +int i; + + p =memchr (buf,'\n' , n); + len = p ? p - buf : n; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { + s = policies[i].name; +if (s && len ==strlen (s) && !strncmp (buf, s, len)) { +mutex_lock (&pm_mutex); + policies[policy].set_state (PM_SUSPEND_ON ); + policy = i; +mutex_unlock (&pm_mutex); +return n; + } + } +return -EINVAL ; +} + +power_attr (policy); +#ifdef CONFIG_PM_TRACE int pm_trace_enabled;@@ -231,6 +309,7 @@ power_attr(pm_trace);static struct attribute * g[] = { &state_attr.attr, + &policy_attr.attr, #ifdef CONFIG_PM_TRACE &pm_trace_attr.attr, #endif@@ -247,7 +326,7 @@ static struct attribute_group attr_group = { .attrs = g, }; -#ifdef CONFIG_PM_RUNTIME +#if defined(CONFIG_PM_RUNTIME ) || defined(CONFIG_OPPORTUNISTIC_SUSPEND )struct workqueue_struct *pm_wq;EXPORT_SYMBOL_GPL (pm_wq);@@ -266,6 +345,7 @@ static int __init pm_init(void)int error =pm_start_workqueue ();if (error)return error; +suspend_block_init (); power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;kernel/power/power.h +9
-0@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void) { }#endif + +/* kernel/power/suspend_block.c */ +extern int request_suspend_state (suspend_state_t state); +extern bool request_suspend_valid_state (suspend_state_t state); +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +extern void __init suspend_block_init (void ); +#else +static inline void suspend_block_init (void ) {} +#endif kernel/power/suspend.c +3
-1@@ -16,10 +16,12 @@#include <linux/cpu.h> #include <linux/syscalls.h> #include <linux/gfp.h> +#include <linux/suspend_blocker.h> #include "power.h" const char *const pm_states[PM_SUSPEND_MAX ] = { + [PM_SUSPEND_ON ] ="on" , [PM_SUSPEND_STANDBY ] ="standby" , [PM_SUSPEND_MEM ] ="mem" , };@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) error = suspend_ops->enter (state);sysdev_resume (); }kernel/power/suspend_blocker.c new file +261
-0@@ -0,0 +1,261 @@ +/* kernel/power/suspend_blocker.c +* +* Copyright (C) 2005-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/rtc.h> +#include <linux/suspend.h> +#include <linux/suspend_blocker.h> +#include "power.h" + +extern struct workqueue_struct *pm_wq; + +enum { +DEBUG_EXIT_SUSPEND =1U <<0 , +DEBUG_WAKEUP =1U <<1 , +DEBUG_USER_STATE =1U <<2 , +DEBUG_SUSPEND =1U <<3 , +DEBUG_SUSPEND_BLOCKER =1U <<4 , +}; +static int debug_mask =DEBUG_EXIT_SUSPEND |DEBUG_WAKEUP |DEBUG_USER_STATE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +#define SB_INITIALIZED (1U << 8) +#define SB_ACTIVE (1U << 9) + +static DEFINE_SPINLOCK (list_lock); +static DEFINE_SPINLOCK (state_lock); +static LIST_HEAD (inactive_blockers); +static LIST_HEAD (active_blockers); +static int current_event_num; +struct suspend_blocker main_suspend_blocker; +static suspend_state_t requested_suspend_state =PM_SUSPEND_MEM ; +static bool enable_suspend_blockers; + +#define pr_info_time(fmt, args...) \ + do { \ + struct timespec ts; \ + struct rtc_time tm; \ + getnstimeofday(&ts); \ + rtc_time_to_tm(ts.tv_sec, &tm); \ + pr_info(fmt "(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n" , \ + args, \ + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, \ + tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); \ + } while (0); + +static void print_active_blockers_locked (void ) +{ +struct suspend_blocker *blocker; + +list_for_each_entry (blocker, &active_blockers, link) +pr_info ("active suspend blocker %s\n" , blocker->name); +} + +/** +* suspend_is_blocked() - Check if suspend should be blocked +* +* suspend_is_blocked can be used by generic power management code to abort +* suspend. +* +* To preserve backward compatibility suspend_is_blocked returns 0 unless it +* is called during suspend initiated from the suspend_block code. +*/ +bool suspend_is_blocked (void ) +{ +if (!enable_suspend_blockers) +return 0 ; +return !list_empty (&active_blockers); +} + +static void suspend_worker (struct work_struct *work) +{ +int ret; +int entry_event_num; + + enable_suspend_blockers = true; +while (!suspend_is_blocked ()) { + entry_event_num = current_event_num; + +if (debug_mask &DEBUG_SUSPEND ) +pr_info ("suspend: enter suspend\n" ); + + ret =pm_suspend (requested_suspend_state); + +if (debug_mask &DEBUG_EXIT_SUSPEND ) +pr_info_time ("suspend: exit suspend, ret = %d " , ret); + +if (current_event_num == entry_event_num) +pr_info ("suspend: pm_suspend returned with no event\n" ); + } + enable_suspend_blockers = false; +} +static DECLARE_WORK(suspend_work, suspend_worker); + +/** +* suspend_blocker_init() - Initialize a suspend blocker +* @blocker: The suspend blocker to initialize. +* @name: The name of the suspend blocker to show in debug messages. +* +* The suspend blocker struct and name must not be freed before calling +* suspend_blocker_destroy. +*/ +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name) +{ +unsigned long irqflags =0 ; + +WARN_ON (!name); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_init name=%s\n" , name); + + blocker->name = name; + blocker->flags =SB_INITIALIZED ; +INIT_LIST_HEAD (&blocker->link); + +spin_lock_irqsave (&list_lock, irqflags); +list_add (&blocker->link, &inactive_blockers); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_init); + +/** +* suspend_blocker_destroy() - Destroy a suspend blocker +* @blocker: The suspend blocker to destroy. +*/ +void suspend_blocker_destroy (struct suspend_blocker *blocker) +{ +unsigned long irqflags; +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_destroy name=%s\n" , blocker->name); + +spin_lock_irqsave (&list_lock, irqflags); + blocker->flags &= ~SB_INITIALIZED ; +list_del (&blocker->link); +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_destroy); + +/** +* suspend_block() - Block suspend +* @blocker: The suspend blocker to use +* +* It is safe to call this function from interrupt context. +*/ +void suspend_block (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_block: %s\n" , blocker->name); + + blocker->flags |=SB_ACTIVE ; +list_move (&blocker->link, &active_blockers); + current_event_num++; + +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_block); + +/** +* suspend_unblock() - Unblock suspend +* @blocker: The suspend blocker to unblock. +* +* If no other suspend blockers block suspend, the system will suspend. +* +* It is safe to call this function from interrupt context. +*/ +void suspend_unblock (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_unblock: %s\n" , blocker->name); + +list_move (&blocker->link, &inactive_blockers); + +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); + blocker->flags &= ~(SB_ACTIVE ); +if (blocker == &main_suspend_blocker) { +if (debug_mask &DEBUG_SUSPEND ) +print_active_blockers_locked (); + } +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_unblock); + +/** +* suspend_blocker_is_active() - Test if a suspend blocker is blocking suspend +* @blocker: The suspend blocker to check. +* +* Returns true if the suspend_blocker is currently active. +*/ +bool suspend_blocker_is_active (struct suspend_blocker *blocker) +{ +WARN_ON (!(blocker->flags &SB_INITIALIZED )); + +return !!(blocker->flags &SB_ACTIVE ); +} +EXPORT_SYMBOL (suspend_blocker_is_active); + +bool request_suspend_valid_state (suspend_state_t state) +{ +return (state ==PM_SUSPEND_ON ) ||valid_state (state); +} + +int request_suspend_state (suspend_state_t state) +{ +unsigned long irqflags; + +if (!request_suspend_valid_state (state)) +return -ENODEV ; + +spin_lock_irqsave (&state_lock, irqflags); + +if (debug_mask &DEBUG_USER_STATE ) +pr_info_time ("request_suspend_state: %s (%d->%d) at %lld " , + state !=PM_SUSPEND_ON ?"sleep" :"wakeup" , + requested_suspend_state, state, +ktime_to_ns (ktime_get ())); + + requested_suspend_state = state; +if (state ==PM_SUSPEND_ON ) +suspend_block (&main_suspend_blocker); +else +suspend_unblock (&main_suspend_blocker); +spin_unlock_irqrestore (&state_lock, irqflags); +return 0 ; +} + +void __init suspend_block_init (void ) +{ +suspend_blocker_init (&main_suspend_blocker,"main" ); +suspend_block (&main_suspend_blocker); +}
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Arve HjønnevågQuoted 7 lines · Arve Hj??nnev??g
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.Signed-off-by Arve Hj??nnev??g <[email protected]>
Also note that this patch mixes up adding new in-kernel interface with adding new userland API.
The in-kernel interface seems to be sane and it would be nice to merge it soon, unfortunately the strange userland API is in the same patch :-(.
Quoted 735 lines
--- Documentation/power/opportunistic-suspend.txt | 119 +++++++++++ include/linux/suspend_blocker.h | 64 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 92 ++++++++- kernel/power/power.h | 9 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 261 +++++++++++++++++++++++++ 8 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/suspend_blocker.cDocumentation/power/opportunistic-suspend.txt new file +119
-0@@ -0,0 +1,119 @@ +Opportunistic Suspend +===================== + +Opportunistic suspend is a feature allowing the system to be suspended (ie. put +into one of the available sleep states) automatically whenever it is regarded +as idle. The suspend blockers framework described below is used to determine +when that happens. + +The /sys/power/policy sysfs attribute is used to switch the system between the +opportunistic and "forced" suspend behavior, where in the latter case the +system is only suspended if a specific value, corresponding to one of the +available system sleep states, is written into /sys/power/state. However, in +the former, opportunistic, case the system is put into the sleep state +corresponding to the value written to /sys/power/state whenever there are no +active suspend blockers. The default policy is "forced". Also, suspend blockers +do not affect sleep states entered from idle. + +When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode. + +A suspend blocker is an object used to inform the PM subsystem when the system +can or cannot be suspended in the "opportunistic" mode (the "forced" mode +ignores suspend blockers). To use it, a device driver creates a struct +suspend_blocker that must be initialized with suspend_blocker_init(). Before +freeing the suspend_blocker structure or its name, suspend_blocker_destroy() +must be called on it. + +A suspend blocker is activated using suspend_block(), which prevents the PM +subsystem from putting the system into the requested sleep state in the +"opportunistic" mode until the suspend blocker is deactivated with +suspend_unblock(). Multiple suspend blockers may be active simultaneously, and +the system will not suspend as long as at least one of them is active. + +If opportunistic suspend is already in progress when suspend_block() is called, +it will abort the suspend, unless suspend_ops->enter has already been +executed. If suspend is aborted this way, the system is usually not fully +operational at that point. The suspend callbacks of some drivers may still be +running and it usually takes time to restore the system to the fully operational +state. + +Here's an example showing how a cell phone or other embedded system can handle +keystrokes (or other input events) in the presence of suspend blockers. Use +set_irq_wake or a platform specific api to make sure the keypad interrupt wakes +up the cpu. Once the keypad driver has resumed, the sequence of events can look +like this: + +- The Keypad driver gets an interrupt. It then calls suspend_block on the + keypad-scan suspend_blocker and starts scanning the keypad matrix. +- The keypad-scan code detects a key change and reports it to the input-event + driver. +- The input-event driver sees the key change, enqueues an event, and calls + suspend_block on the input-event-queue suspend_blocker. +- The keypad-scan code detects that no keys are held and calls suspend_unblock + on the keypad-scan suspend_blocker. +- The user-space input-event thread returns from select/poll, calls + suspend_block on the process-input-events suspend_blocker and then calls read + on the input-event device. +- The input-event driver dequeues the key-event and, since the queue is now + empty, it calls suspend_unblock on the input-event-queue suspend_blocker. +- The user-space input-event thread returns from read. If it determines that + the key should be ignored, it calls suspend_unblock on the + process_input_events suspend_blocker and then calls select or poll. The + system will automatically suspend again, since now no suspend blockers are + active. + +If the key that was pressed instead should preform a simple action (for example, +adjusting the volume), this action can be performed right before calling +suspend_unblock on the process_input_events suspend_blocker. However, if the key +triggers a longer-running action, that action needs its own suspend_blocker and +suspend_block must be called on that suspend blocker before calling +suspend_unblock on the process_input_events suspend_blocker. + + Key pressed Key released + | | +keypad-scan ++++++++++++++++++ +input-event-queue +++ +++ +process-input-events +++ +++ + + +Driver API +========== + +A driver can use the suspend block api by adding a suspend_blocker variable to +its state and calling suspend_blocker_init. For instance: +struct state { + struct suspend_blocker suspend_blocker; +} + +init() { + suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name"); +} + +Before freeing the memory, suspend_blocker_destroy must be called: + +uninit() { + suspend_blocker_destroy(&state->suspend_blocker); +} + +When the driver determines that it needs to run (usually in an interrupt +handler) it calls suspend_block: + suspend_block(&state->suspend_blocker); + +When it no longer needs to run it calls suspend_unblock: + suspend_unblock(&state->suspend_blocker); + +Calling suspend_block when the suspend blocker is active or suspend_unblock when +it is not active has no effect (i.e., these functions don't nest). This allows +drivers to update their state and call suspend suspend_block or suspend_unblock +based on the result. +For instance: + +if (list_empty(&state->pending_work)) + suspend_unblock(&state->suspend_blocker); +else + suspend_block(&state->suspend_blocker); +include/linux/suspend_blocker.h new file +64
-0@@ -0,0 +1,64 @@ +/* include/linux/suspend_blocker.h +* +* Copyright (C) 2007-2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCKER_H +#define _LINUX_SUSPEND_BLOCKER_H + +#include <linux/list.h> + +/** +* struct suspend_blocker - the basic suspend_blocker structure +* @link: List entry for active or inactive list. +* @flags: Tracks initialized and active state. +* @name: Name used for debugging. +* +* When a suspend_blocker is active it prevents the system from entering +* opportunistic suspend. +* +* The suspend_blocker structure must be initialized by suspend_blocker_init() +*/ + +struct suspend_blocker { +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +struct list_head link; +int flags; +const char *name; +#endif +}; + +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name); +void suspend_blocker_destroy (struct suspend_blocker *blocker); +void suspend_block (struct suspend_blocker *blocker); +void suspend_unblock (struct suspend_blocker *blocker); +bool suspend_blocker_is_active (struct suspend_blocker *blocker); +bool suspend_is_blocked (void ); + +#else + +static inline void suspend_blocker_init (struct suspend_blocker *blocker, +const char *name) {} +static inline void suspend_blocker_destroy (struct suspend_blocker *blocker) {} +static inline void suspend_block (struct suspend_blocker *blocker) {} +static inline void suspend_unblock (struct suspend_blocker *blocker) {} +static inline bool suspend_blocker_is_active (struct suspend_blocker *bl) + {return 0 ; } +static inline bool suspend_is_blocked (void ) {return 0 ; } + +#endif + +#endif +kernel/power/Kconfig +16
-0@@ -130,6 +130,22 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. +config OPPORTUNISTIC_SUSPEND + bool "Suspend blockers" + depends on PM_SLEEP + select RTC_LIB + default n + ---help--- + Opportunistic sleep support. Allows the system to be put into a sleep + state opportunistically, if it doesn't do any useful work at the + moment. The PM subsystem is switched into this mode of operation by + writing "opportunistic" into /sys/power/policy, while writing + "forced" to this file turns the opportunistic suspend feature off. + In the "opportunistic" mode suspend blockers are used to determine + when to suspend the system and the value written to /sys/power/state + determines the sleep state the system will be put into when there are + no active suspend blockers. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/main.c +86
-6@@ -12,6 +12,7 @@#include <linux/string.h> #include <linux/resume-trace.h> #include <linux/workqueue.h> +#include <linux/suspend_blocker.h> #include "power.h" @@ -20,6 +21,27 @@ DEFINE_MUTEX(pm_mutex);unsigned int pm_flags;EXPORT_SYMBOL (pm_flags); +struct policy { +const char *name; +bool (*valid_state)(suspend_state_t state); +int (*set_state)(suspend_state_t state); +}; +static struct policy policies[] = { + { + .name ="forced" , + .valid_state = valid_state, + .set_state = enter_state, + }, +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + { + .name ="opportunistic" , + .valid_state = request_suspend_valid_state, + .set_state = request_suspend_state, + }, +#endif +}; +static int policy; +#ifdef CONFIG_PM_SLEEP /* Routines for PM-transition notifications */ @@ -146,6 +168,12 @@ struct kobject *power_kobj;* * store() accepts one of those strings, translates it into the * proper enumerated value, and initiates a suspend transition. +* +* If policy is set to opportunistic, store() does not block until the +* system resumes, and it will try to re-enter the state until another +* state is requested. Suspend blockers are respected and the requested +* state will only be entered when no suspend blockers are active. +* Write "on" to cancel. */ static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf)@@ -155,12 +183,13 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,int i;for (i =0 ; i <PM_SUSPEND_MAX ; i++) { -if (pm_states[i] &&valid_state (i)) +if (pm_states[i] && policies[policy].valid_state (i)) s +=sprintf (s,"%s " , pm_states[i]); }#endif #ifdef CONFIG_HIBERNATION - s +=sprintf (s,"%s\n" ,"disk" ); +if (!policy) + s +=sprintf (s,"%s\n" ,"disk" );#else if (s != buf)/* convert the last space to a newline */ @@ -173,7 +202,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) {#ifdef CONFIG_SUSPEND -suspend_state_t state =PM_SUSPEND_STANDBY ; +suspend_state_t state =PM_SUSPEND_ON ;const char *const *s;#endif char *p;@@ -184,7 +213,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, len = p ? p - buf : n;/* First, check if we are requested to hibernate */ -if (len ==4 && !strncmp (buf,"disk" , len)) { +if (len ==4 && !strncmp (buf,"disk" , len) && !policy) { error =hibernate (); goto Exit; }@@ -195,7 +224,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, break; }if (state <PM_SUSPEND_MAX && *s) - error =enter_state (state); + error = policies[policy].set_state (state);#endif Exit:@@ -204,6 +233,55 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,power_attr (state); +/** +* policy - set policy for state +*/ + +static ssize_t policy_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +char *s = buf; +int i; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { +if (i == policy) + s +=sprintf (s,"[%s] " , policies[i].name); +else + s +=sprintf (s,"%s " , policies[i].name); + } +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ; +return (s - buf); +} + +static ssize_t policy_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +const char *s; +char *p; +int len; +int i; + + p =memchr (buf,'\n' , n); + len = p ? p - buf : n; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { + s = policies[i].name; +if (s && len ==strlen (s) && !strncmp (buf, s, len)) { +mutex_lock (&pm_mutex); + policies[policy].set_state (PM_SUSPEND_ON ); + policy = i; +mutex_unlock (&pm_mutex); +return n; + } + } +return -EINVAL ; +} + +power_attr (policy); +#ifdef CONFIG_PM_TRACE int pm_trace_enabled;@@ -231,6 +309,7 @@ power_attr(pm_trace);static struct attribute * g[] = { &state_attr.attr, + &policy_attr.attr, #ifdef CONFIG_PM_TRACE &pm_trace_attr.attr, #endif@@ -247,7 +326,7 @@ static struct attribute_group attr_group = { .attrs = g, }; -#ifdef CONFIG_PM_RUNTIME +#if defined(CONFIG_PM_RUNTIME ) || defined(CONFIG_OPPORTUNISTIC_SUSPEND )struct workqueue_struct *pm_wq;EXPORT_SYMBOL_GPL (pm_wq);@@ -266,6 +345,7 @@ static int __init pm_init(void)int error =pm_start_workqueue ();if (error)return error; +suspend_block_init (); power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;kernel/power/power.h +9
-0@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void) { }#endif + +/* kernel/power/suspend_block.c */ +extern int request_suspend_state (suspend_state_t state); +extern bool request_suspend_valid_state (suspend_state_t state); +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +extern void __init suspend_block_init (void ); +#else +static inline void suspend_block_init (void ) {} +#endif kernel/power/suspend.c +3
-1@@ -16,10 +16,12 @@#include <linux/cpu.h> #include <linux/syscalls.h> #include <linux/gfp.h> +#include <linux/suspend_blocker.h> #include "power.h" const char *const pm_states[PM_SUSPEND_MAX ] = { + [PM_SUSPEND_ON ] ="on" , [PM_SUSPEND_STANDBY ] ="standby" , [PM_SUSPEND_MEM ] ="mem" , };@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) error = suspend_ops->enter (state);sysdev_resume (); }kernel/power/suspend_blocker.c new file +261
-0@@ -0,0 +1,261 @@ +/* kernel/power/suspend_blocker.c +* +* Copyright (C) 2005-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/rtc.h> +#include <linux/suspend.h> +#include <linux/suspend_blocker.h> +#include "power.h" + +extern struct workqueue_struct *pm_wq; + +enum { +DEBUG_EXIT_SUSPEND =1U <<0 , +DEBUG_WAKEUP =1U <<1 , +DEBUG_USER_STATE =1U <<2 , +DEBUG_SUSPEND =1U <<3 , +DEBUG_SUSPEND_BLOCKER =1U <<4 , +}; +static int debug_mask =DEBUG_EXIT_SUSPEND |DEBUG_WAKEUP |DEBUG_USER_STATE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +#define SB_INITIALIZED (1U << 8) +#define SB_ACTIVE (1U << 9) + +static DEFINE_SPINLOCK (list_lock); +static DEFINE_SPINLOCK (state_lock); +static LIST_HEAD (inactive_blockers); +static LIST_HEAD (active_blockers); +static int current_event_num; +struct suspend_blocker main_suspend_blocker; +static suspend_state_t requested_suspend_state =PM_SUSPEND_MEM ; +static bool enable_suspend_blockers; + +#define pr_info_time(fmt, args...) \ + do { \ + struct timespec ts; \ + struct rtc_time tm; \ + getnstimeofday(&ts); \ + rtc_time_to_tm(ts.tv_sec, &tm); \ + pr_info(fmt "(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n" , \ + args, \ + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, \ + tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); \ + } while (0); + +static void print_active_blockers_locked (void ) +{ +struct suspend_blocker *blocker; + +list_for_each_entry (blocker, &active_blockers, link) +pr_info ("active suspend blocker %s\n" , blocker->name); +} + +/** +* suspend_is_blocked() - Check if suspend should be blocked +* +* suspend_is_blocked can be used by generic power management code to abort +* suspend. +* +* To preserve backward compatibility suspend_is_blocked returns 0 unless it +* is called during suspend initiated from the suspend_block code. +*/ +bool suspend_is_blocked (void ) +{ +if (!enable_suspend_blockers) +return 0 ; +return !list_empty (&active_blockers); +} + +static void suspend_worker (struct work_struct *work) +{ +int ret; +int entry_event_num; + + enable_suspend_blockers = true; +while (!suspend_is_blocked ()) { + entry_event_num = current_event_num; + +if (debug_mask &DEBUG_SUSPEND ) +pr_info ("suspend: enter suspend\n" ); + + ret =pm_suspend (requested_suspend_state); + +if (debug_mask &DEBUG_EXIT_SUSPEND ) +pr_info_time ("suspend: exit suspend, ret = %d " , ret); + +if (current_event_num == entry_event_num) +pr_info ("suspend: pm_suspend returned with no event\n" ); + } + enable_suspend_blockers = false; +} +static DECLARE_WORK(suspend_work, suspend_worker); + +/** +* suspend_blocker_init() - Initialize a suspend blocker +* @blocker: The suspend blocker to initialize. +* @name: The name of the suspend blocker to show in debug messages. +* +* The suspend blocker struct and name must not be freed before calling +* suspend_blocker_destroy. +*/ +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name) +{ +unsigned long irqflags =0 ; + +WARN_ON (!name); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_init name=%s\n" , name); + + blocker->name = name; + blocker->flags =SB_INITIALIZED ; +INIT_LIST_HEAD (&blocker->link); + +spin_lock_irqsave (&list_lock, irqflags); +list_add (&blocker->link, &inactive_blockers); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_init); + +/** +* suspend_blocker_destroy() - Destroy a suspend blocker +* @blocker: The suspend blocker to destroy. +*/ +void suspend_blocker_destroy (struct suspend_blocker *blocker) +{ +unsigned long irqflags; +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_destroy name=%s\n" , blocker->name); + +spin_lock_irqsave (&list_lock, irqflags); + blocker->flags &= ~SB_INITIALIZED ; +list_del (&blocker->link); +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_destroy); + +/** +* suspend_block() - Block suspend +* @blocker: The suspend blocker to use +* +* It is safe to call this function from interrupt context. +*/ +void suspend_block (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_block: %s\n" , blocker->name); + + blocker->flags |=SB_ACTIVE ; +list_move (&blocker->link, &active_blockers); + current_event_num++; + +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_block); + +/** +* suspend_unblock() - Unblock suspend +* @blocker: The suspend blocker to unblock. +* +* If no other suspend blockers block suspend, the system will suspend. +* +* It is safe to call this function from interrupt context. +*/ +void suspend_unblock (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_unblock: %s\n" , blocker->name); + +list_move (&blocker->link, &inactive_blockers); + +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); + blocker->flags &= ~(SB_ACTIVE ); +if (blocker == &main_suspend_blocker) { +if (debug_mask &DEBUG_SUSPEND ) +print_active_blockers_locked (); + } +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_unblock); + +/** +* suspend_blocker_is_active() - Test if a suspend blocker is blocking suspend +* @blocker: The suspend blocker to check. +* +* Returns true if the suspend_blocker is currently active. +*/ +bool suspend_blocker_is_active (struct suspend_blocker *blocker) +{ +WARN_ON (!(blocker->flags &SB_INITIALIZED )); + +return !!(blocker->flags &SB_ACTIVE ); +} +EXPORT_SYMBOL (suspend_blocker_is_active); + +bool request_suspend_valid_state (suspend_state_t state) +{ +return (state ==PM_SUSPEND_ON ) ||valid_state (state); +} + +int request_suspend_state (suspend_state_t state) +{ +unsigned long irqflags; + +if (!request_suspend_valid_state (state)) +return -ENODEV ; + +spin_lock_irqsave (&state_lock, irqflags); + +if (debug_mask &DEBUG_USER_STATE ) +pr_info_time ("request_suspend_state: %s (%d->%d) at %lld " , + state !=PM_SUSPEND_ON ?"sleep" :"wakeup" , + requested_suspend_state, state, +ktime_to_ns (ktime_get ())); + + requested_suspend_state = state; +if (state ==PM_SUSPEND_ON ) +suspend_block (&main_suspend_blocker); +else +suspend_unblock (&main_suspend_blocker); +spin_unlock_irqrestore (&state_lock, irqflags); +return 0 ; +} + +void __init suspend_block_init (void ) +{ +suspend_blocker_init (&main_suspend_blocker,"main" ); +suspend_block (&main_suspend_blocker); +}
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Pavel Machek
NAKRe: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 4 lines · Arve Hj??nnev??g
Add a misc device, "
suspend_blocker", that allows user-space processes to block auto suspend. The device has ioctls to create asuspend_blocker, and to block and unblock suspend. To delete thesuspend_blocker, close the device.
Yeah, this one is overly complex; instead of having 'open blocks suspend' semantics and lsof listing active blockers, it adds strange ioctl based interface passing names, and then adds debugfs infrastructure listing those back.
I guess this is why you are getying 'it should be in /proc, no in /sys, no in debugfs, no in /proc' kind of feedback. This should simply not exist in the first place...
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>
NAK.
Quoted 247 lines
--- Documentation/ioctl/ioctl-number.txt | 3 +- Documentation/power/opportunistic-suspend.txt | 17 ++++ include/linux/suspend_block_dev.h | 25 +++++ kernel/power/Kconfig | 9 ++ kernel/power/Makefile | 1 + kernel/power/user_suspend_blocker.c | 128 +++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 1 deletions(-) create mode 100644 include/linux/suspend_block_dev.h create mode 100644 kernel/power/user_suspend_blocker.cDocumentation/ioctl/ioctl-number.txt +2
-1@@ -254,7 +254,8 @@ Code Seq#(hex) Include File Comments 'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK linux/ixjuser.h <http://www.quicknet.net> 'r' 00-1F linux/msdos_fs.h and fs/fat/dir.c -'s' all linux/cdk.h +'s' all linux/cdk.h conflict! +'s' all linux/suspend_block_dev.h conflict! 't' 00-7F linux/if_ppp.h 't' 80-8F linux/isdn_ppp.h 't' 90 linux/toshiba.hDocumentation/power/opportunistic-suspend.txt +17
-0@@ -117,3 +117,20 @@ if (list_empty(&state->pending_work)) else suspend_block(&state->suspend_blocker); +User-space API +============== + +To create a suspend_blocker from user-space, open the suspend_blocker device: + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); +then call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_INIT(strlen(name)), name); + +To activate a suspend_blocker call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To unblock call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend_blocker, close the device: + close(fd); +include/linux/suspend_block_dev.h new file +25
-0@@ -0,0 +1,25 @@ +/* include/linux/suspend_block_dev.h +* +* Copyright (C) 2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCK_DEV_H +#define _LINUX_SUSPEND_BLOCK_DEV_H + +#include <linux/ioctl.h> + +#define SUSPEND_BLOCKER_IOCTL_INIT (len) _IOC(_IOC_WRITE, 's', 0, len) +#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1) +#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 2) + +#endif kernel/power/Kconfig +9
-0@@ -146,6 +146,15 @@ config OPPORTUNISTIC_SUSPEND determines the sleep state the system will be put into when there are no active suspend blockers. +config USER_SUSPEND_BLOCKERS + bool "Userspace suspend blockers" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + User-space suspend block api. Creates a misc device with ioctls + to create, block and unblock a suspend_blocker. The suspend_blocker + will be deleted when the device is closed. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -8,6 +8,7 @@ obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o +obj-$(CONFIG_USER_SUSPEND_BLOCKERS) += user_suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/user_suspend_blocker.c new file +128
-0@@ -0,0 +1,128 @@ +/* kernel/power/user_suspend_block.c +* +* Copyright (C) 2009-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/fs.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/uaccess.h> +#include <linux/slab.h> +#include <linux/suspend_blocker.h> +#include <linux/suspend_block_dev.h> + +enum { +DEBUG_FAILURE =BIT (0 ), +}; +static int debug_mask =DEBUG_FAILURE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +static DEFINE_MUTEX (ioctl_lock); + +struct user_suspend_blocker { +struct suspend_blocker blocker; +char name[0 ]; +}; + +static int create_user_suspend_blocker (struct file *file,void __user *name, +size_t name_len) +{ +struct user_suspend_blocker *bl; +if (file->private_data) +return -EBUSY ; +if (name_len >NAME_MAX ) +return -ENAMETOOLONG ; + bl =kzalloc (sizeof (*bl) + name_len +1 ,GFP_KERNEL ); +if (!bl) +return -ENOMEM ; +if (copy_from_user (bl->name, name, name_len)) + goto err_fault; +suspend_blocker_init (&bl->blocker, bl->name); + file->private_data = bl; +return 0 ; + +err_fault: +kfree (bl); +return -EFAULT ; +} + +static long user_suspend_blocker_ioctl (struct file *file,unsigned int cmd, +unsigned long _arg) +{ +void __user *arg = (void __user *)_arg; +struct user_suspend_blocker *bl; +long ret; + +mutex_lock (&ioctl_lock); +if ((cmd & ~IOCSIZE_MASK ) ==SUSPEND_BLOCKER_IOCTL_INIT (0 )) { + ret =create_user_suspend_blocker (file, arg,_IOC_SIZE (cmd)); + goto done; + } + bl = file->private_data; +if (!bl) { + ret = -ENOENT ; + goto done; + } +switch (cmd) { +case SUSPEND_BLOCKER_IOCTL_BLOCK : +suspend_block (&bl->blocker); + ret =0 ; +break ; +case SUSPEND_BLOCKER_IOCTL_UNBLOCK : +suspend_unblock (&bl->blocker); + ret =0 ; +break ; +default : + ret = -ENOTSUPP ; + } +done: +if (ret && (debug_mask &DEBUG_FAILURE )) +pr_err ("user_suspend_blocker_ioctl: cmd %x failed, %ld\n" , + cmd, ret); +mutex_unlock (&ioctl_lock); +return ret; +} + +static int user_suspend_blocker_release (struct inode *inode,struct file *file) +{ +struct user_suspend_blocker *bl = file->private_data; +if (!bl) +return 0 ; +suspend_blocker_destroy (&bl->blocker); +kfree (bl); +return 0 ; +} + +const struct file_operations user_suspend_blocker_fops = { + .release = user_suspend_blocker_release, + .unlocked_ioctl = user_suspend_blocker_ioctl, +}; + +struct miscdevice user_suspend_blocker_device = { + .minor =MISC_DYNAMIC_MINOR , + .name ="suspend_blocker" , + .fops = &user_suspend_blocker_fops, +}; + +static int __init user_suspend_blocker_init (void ) +{ +return misc_register (&user_suspend_blocker_device); +} + +static void __exit user_suspend_blocker_exit(void) +{ +misc_deregister (&user_suspend_blocker_device); +} + +module_init (user_suspend_blocker_init); +module_exit (user_suspend_blocker_exit);
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Pavel Machek
NAKRe: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 4 lines · Arve Hj??nnev??g
Add a misc device, "
suspend_blocker", that allows user-space processes to block auto suspend. The device has ioctls to create asuspend_blocker, and to block and unblock suspend. To delete thesuspend_blocker, close the device.
Yeah, this one is overly complex; instead of having 'open blocks suspend' semantics and lsof listing active blockers, it adds strange ioctl based interface passing names, and then adds debugfs infrastructure listing those back.
I guess this is why you are getying 'it should be in /proc, no in /sys, no in debugfs, no in /proc' kind of feedback. This should simply not exist in the first place...
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>
NAK.
Quoted 247 lines
--- Documentation/ioctl/ioctl-number.txt | 3 +- Documentation/power/opportunistic-suspend.txt | 17 ++++ include/linux/suspend_block_dev.h | 25 +++++ kernel/power/Kconfig | 9 ++ kernel/power/Makefile | 1 + kernel/power/user_suspend_blocker.c | 128 +++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 1 deletions(-) create mode 100644 include/linux/suspend_block_dev.h create mode 100644 kernel/power/user_suspend_blocker.cDocumentation/ioctl/ioctl-number.txt +2
-1@@ -254,7 +254,8 @@ Code Seq#(hex) Include File Comments 'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK linux/ixjuser.h <http://www.quicknet.net> 'r' 00-1F linux/msdos_fs.h and fs/fat/dir.c -'s' all linux/cdk.h +'s' all linux/cdk.h conflict! +'s' all linux/suspend_block_dev.h conflict! 't' 00-7F linux/if_ppp.h 't' 80-8F linux/isdn_ppp.h 't' 90 linux/toshiba.hDocumentation/power/opportunistic-suspend.txt +17
-0@@ -117,3 +117,20 @@ if (list_empty(&state->pending_work)) else suspend_block(&state->suspend_blocker); +User-space API +============== + +To create a suspend_blocker from user-space, open the suspend_blocker device: + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); +then call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_INIT(strlen(name)), name); + +To activate a suspend_blocker call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To unblock call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend_blocker, close the device: + close(fd); +include/linux/suspend_block_dev.h new file +25
-0@@ -0,0 +1,25 @@ +/* include/linux/suspend_block_dev.h +* +* Copyright (C) 2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCK_DEV_H +#define _LINUX_SUSPEND_BLOCK_DEV_H + +#include <linux/ioctl.h> + +#define SUSPEND_BLOCKER_IOCTL_INIT (len) _IOC(_IOC_WRITE, 's', 0, len) +#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1) +#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 2) + +#endif kernel/power/Kconfig +9
-0@@ -146,6 +146,15 @@ config OPPORTUNISTIC_SUSPEND determines the sleep state the system will be put into when there are no active suspend blockers. +config USER_SUSPEND_BLOCKERS + bool "Userspace suspend blockers" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + User-space suspend block api. Creates a misc device with ioctls + to create, block and unblock a suspend_blocker. The suspend_blocker + will be deleted when the device is closed. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -8,6 +8,7 @@ obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o +obj-$(CONFIG_USER_SUSPEND_BLOCKERS) += user_suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/user_suspend_blocker.c new file +128
-0@@ -0,0 +1,128 @@ +/* kernel/power/user_suspend_block.c +* +* Copyright (C) 2009-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/fs.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/uaccess.h> +#include <linux/slab.h> +#include <linux/suspend_blocker.h> +#include <linux/suspend_block_dev.h> + +enum { +DEBUG_FAILURE =BIT (0 ), +}; +static int debug_mask =DEBUG_FAILURE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +static DEFINE_MUTEX (ioctl_lock); + +struct user_suspend_blocker { +struct suspend_blocker blocker; +char name[0 ]; +}; + +static int create_user_suspend_blocker (struct file *file,void __user *name, +size_t name_len) +{ +struct user_suspend_blocker *bl; +if (file->private_data) +return -EBUSY ; +if (name_len >NAME_MAX ) +return -ENAMETOOLONG ; + bl =kzalloc (sizeof (*bl) + name_len +1 ,GFP_KERNEL ); +if (!bl) +return -ENOMEM ; +if (copy_from_user (bl->name, name, name_len)) + goto err_fault; +suspend_blocker_init (&bl->blocker, bl->name); + file->private_data = bl; +return 0 ; + +err_fault: +kfree (bl); +return -EFAULT ; +} + +static long user_suspend_blocker_ioctl (struct file *file,unsigned int cmd, +unsigned long _arg) +{ +void __user *arg = (void __user *)_arg; +struct user_suspend_blocker *bl; +long ret; + +mutex_lock (&ioctl_lock); +if ((cmd & ~IOCSIZE_MASK ) ==SUSPEND_BLOCKER_IOCTL_INIT (0 )) { + ret =create_user_suspend_blocker (file, arg,_IOC_SIZE (cmd)); + goto done; + } + bl = file->private_data; +if (!bl) { + ret = -ENOENT ; + goto done; + } +switch (cmd) { +case SUSPEND_BLOCKER_IOCTL_BLOCK : +suspend_block (&bl->blocker); + ret =0 ; +break ; +case SUSPEND_BLOCKER_IOCTL_UNBLOCK : +suspend_unblock (&bl->blocker); + ret =0 ; +break ; +default : + ret = -ENOTSUPP ; + } +done: +if (ret && (debug_mask &DEBUG_FAILURE )) +pr_err ("user_suspend_blocker_ioctl: cmd %x failed, %ld\n" , + cmd, ret); +mutex_unlock (&ioctl_lock); +return ret; +} + +static int user_suspend_blocker_release (struct inode *inode,struct file *file) +{ +struct user_suspend_blocker *bl = file->private_data; +if (!bl) +return 0 ; +suspend_blocker_destroy (&bl->blocker); +kfree (bl); +return 0 ; +} + +const struct file_operations user_suspend_blocker_fops = { + .release = user_suspend_blocker_release, + .unlocked_ioctl = user_suspend_blocker_ioctl, +}; + +struct miscdevice user_suspend_blocker_device = { + .minor =MISC_DYNAMIC_MINOR , + .name ="suspend_blocker" , + .fops = &user_suspend_blocker_fops, +}; + +static int __init user_suspend_blocker_init (void ) +{ +return misc_register (&user_suspend_blocker_device); +} + +static void __exit user_suspend_blocker_exit(void) +{ +misc_deregister (&user_suspend_blocker_device); +} + +module_init (user_suspend_blocker_init); +module_exit (user_suspend_blocker_exit);
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/8] PM: Add suspend blocking work.
In reply to Arve HjønnevågQuoted 8 lines · Arve Hj??nnev??g
Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate
suspend_blockerfor pending and executing work, or additional state and locking. This implementation does add additional state and locking, but this can be removed later if we add support for suspend blocking work to the core workqueue code.Signed-off-by Arve Hj??nnev??g <[email protected]>
Looks ok.
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/8] PM: Add suspend blocking work.
In reply to Arve HjønnevågQuoted 8 lines · Arve Hj??nnev??g
Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate
suspend_blockerfor pending and executing work, or additional state and locking. This implementation does add additional state and locking, but this can be removed later if we add support for suspend blocking work to the core workqueue code.Signed-off-by Arve Hj??nnev??g <[email protected]>
Looks ok.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Pavel MachekQuoted 10 lines · Pavel Machek
Hi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Quoted 3 lines
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>NAK.
Ignored.
Thanks,
Rafael
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Pavel MachekQuoted 10 lines · Pavel Machek
Hi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Quoted 3 lines
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>NAK.
Ignored.
Thanks,
Rafael
Re: [PATCH 1/8] PM: Add suspend block api.
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Hi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details, and neither you nor Arve explained why it is good solution.
I was not on LF Collab summit, so unfortunately I can't comment on that.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>NAK.
Ignored.
WTF?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Rafael J. WysockiQuoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Hi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details, and neither you nor Arve explained why it is good solution.
I was not on LF Collab summit, so unfortunately I can't comment on that.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>NAK.
Ignored.
WTF?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 166 lines · Arve Hjønnevåg
Add a misc device, "
suspend_blocker", that allows user-space processes to block auto suspend. The device has ioctls to create asuspend_blocker, and to block and unblock suspend. To delete thesuspend_blocker, close the device.Signed-off-by Arve Hjønnevåg <[email protected]>--- Documentation/ioctl/ioctl-number.txt | 3 +- Documentation/power/opportunistic-suspend.txt | 17 ++++ include/linux/suspend_block_dev.h | 25 +++++ kernel/power/Kconfig | 9 ++ kernel/power/Makefile | 1 + kernel/power/user_suspend_blocker.c | 128 +++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 1 deletions(-) create mode 100644 include/linux/suspend_block_dev.h create mode 100644 kernel/power/user_suspend_blocker.cDocumentation/ioctl/ioctl-number.txt +2
-1@@ -254,7 +254,8 @@ Code Seq#(hex) Include File Comments 'q' 80-FF linux/telephony.h Internet PhoneJACK, Internet LineJACK linux/ixjuser.h <http://www.quicknet.net> 'r' 00-1F linux/msdos_fs.h and fs/fat/dir.c -'s' all linux/cdk.h +'s' all linux/cdk.h conflict! +'s' all linux/suspend_block_dev.h conflict! 't' 00-7F linux/if_ppp.h 't' 80-8F linux/isdn_ppp.h 't' 90 linux/toshiba.hDocumentation/power/opportunistic-suspend.txt +17
-0@@ -117,3 +117,20 @@ if (list_empty(&state->pending_work)) else suspend_block(&state->suspend_blocker); +User-space API +============== + +To create a suspend_blocker from user-space, open the suspend_blocker device: + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); +then call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_INIT(strlen(name)), name); + +To activate a suspend_blocker call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To unblock call: + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend_blocker, close the device: + close(fd); +include/linux/suspend_block_dev.h new file +25
-0@@ -0,0 +1,25 @@ +/* include/linux/suspend_block_dev.h +* +* Copyright (C) 2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCK_DEV_H +#define _LINUX_SUSPEND_BLOCK_DEV_H + +#include <linux/ioctl.h> + +#define SUSPEND_BLOCKER_IOCTL_INIT (len) _IOC(_IOC_WRITE, 's', 0, len) +#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1) +#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 2) + +#endif kernel/power/Kconfig +9
-0@@ -146,6 +146,15 @@ config OPPORTUNISTIC_SUSPEND determines the sleep state the system will be put into when there are no active suspend blockers. +config USER_SUSPEND_BLOCKERS + bool "Userspace suspend blockers" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + User-space suspend block api. Creates a misc device with ioctls + to create, block and unblock a suspend_blocker. The suspend_blocker + will be deleted when the device is closed. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -8,6 +8,7 @@ obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o +obj-$(CONFIG_USER_SUSPEND_BLOCKERS) += user_suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/user_suspend_blocker.c new file +41
-0@@ -0,0 +1,128 @@ +/* kernel/power/user_suspend_block.c +* +* Copyright (C) 2009-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/fs.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/uaccess.h> +#include <linux/slab.h> +#include <linux/suspend_blocker.h> +#include <linux/suspend_block_dev.h> + +enum { +DEBUG_FAILURE =BIT (0 ), +}; +static int debug_mask =DEBUG_FAILURE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +static DEFINE_MUTEX (ioctl_lock); + +struct user_suspend_blocker { +struct suspend_blocker blocker; +char name[0 ]; +}; + +static int create_user_suspend_blocker (struct file *file,void __user *name, +size_t name_len) +{ +struct user_suspend_blocker *bl; +if (file->private_data)
kernel/power/user_suspend_blocker.c line 51
Quoted 10 lines
kernel/power/user_suspend_blocker.c new file +10
-0+return -EBUSY ; +if (name_len >NAME_MAX ) +return -ENAMETOOLONG ; + bl =kzalloc (sizeof (*bl) + name_len +1 ,GFP_KERNEL ); +if (!bl) +return -ENOMEM ; +if (copy_from_user (bl->name, name, name_len)) + goto err_fault; +suspend_blocker_init (&bl->blocker, bl->name); + file->private_data = bl;
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Rafael
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Pavel MachekQuoted 10 lines · Pavel Machek
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Hi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details,
We do exactly the same thing with 'pm_test', so I'm not sure what the problem is.
Quoted 1 line
and neither you nor Arve explained why it is good solution.
Because it's less confusing. Having two different attributes returning almost the same contents and working in a slightly different way wouldn't be too clean IMO.
Also it reduces code duplication slightly.
Quoted 9 lines
I was not on LF Collab summit, so unfortunately I can't comment on that.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>NAK.
Ignored.
WTF?
Literally. I'm not going to take that NAK into consideration.
Rafael
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Pavel MachekQuoted 10 lines · Pavel Machek
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Pavel Machek
Hi!
Quoted 5 lines
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details,
We do exactly the same thing with 'pm_test', so I'm not sure what the problem is.
Quoted 1 line
and neither you nor Arve explained why it is good solution.
Because it's less confusing. Having two different attributes returning almost the same contents and working in a slightly different way wouldn't be too clean IMO.
Also it reduces code duplication slightly.
Quoted 9 lines
I was not on LF Collab summit, so unfortunately I can't comment on that.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Arve Hj??nnev??g <[email protected]>NAK.
Ignored.
WTF?
Literally. I'm not going to take that NAK into consideration.
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Alan Stern
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Alan Stern
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if _open() created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.
Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Alan SternQuoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if _open() created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.
Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Rafael
Quoted 4 lines · Arve Hjønnevåg
This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version fixes a race in suspend blocking work, has some documentation changes and opportunistic suspend now uses the same workqueue as runtime pm.
Earlier this month, several folks intersted in embedded PM had a BoF as part of the Embedded Linux Conference[1] in San Francisco. Many of us had concerns about wakelocks/suspend-blockers and I wanted to share some of mine here, since I don't know if embedded folks (other than Google) were included in discussions during the LF Collab summmit.
I hope other embedded folks will chime in here as well. My background is in embedded as one of the kernel developers on the TI OMAP SoCs, and I work primarily on PM stuff.
My comments are not about this implementation of suspend blockers in particular, but rather on the potential implications of suspend blockers in general.
Sorry for the lengthy mail, it's broken up in to 3 parts:
- suspend blockers vs. runtime PM
- how to handle PM aware drivers?
- what about dumb or untrusted apps
Suspend blockers vs runtime PM
------------------------------
My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.
Currently in the kernel, we have two main forms of PM
- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)
And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.
The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.
It seems to me the keypad/screen example given in the doc can very easily be solved with runtime PM. The goal of that example is that the keypad not turn on the screen unless a specific key is pressed. That is rather easy to accomplish using runtime PM:
1. system is idle, all devices/drivers runtime suspended (display and keypad drivers are both runtime suspended)
- keypress triggers wakeup ->runtime_resume() of keypad (screen is still runtime suspended)
- key press trickles up to userspace - keypad driver is done, goes idle and is runtime supended - userspace decides whether or not to turn on screen based on key - if not, goto 1, (display is still runtime suspended) - if so, start using display and it will be runtime resumed
I realize this keypad example was only one example usage of suspend blockers, but I suspect the others would be solved similarily using runtime PM.
But anyways, to get back to the main point:
I feel the main problems tackled by _kernel_ suspend blockers (as I understand them) are the same problems already addressed by runtime PM. First and formost, both have the same guiding principle:
Rule #1: Always try for lowest power state, unless X
For runtime PM, X = "activity"
For suspend blockers, X = a held suspend_blocker
In addition, both have the same secondary goals:
- keep device PM independent of other devices (e.g. don't wake up screen just because keypad was pressed)
- wakeups/events can be handled in a device specific way, without affecting other devices or rest of the system, unless desired
So, the goals are the same, but the approaches are different. Runtime PM makes each of the drivers and subsystems do the work, where suspend blockers just forces the issue from on high. IMHO, the more flexible and generic approach of runtime PM is more suited to a general purpose kernel than the one-big-hammer approach currently taken by suspend blockers.
What about PM aware drivers?
----------------------------
All of this brings up a second major concern regarding how to write PM aware drivers.
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 1 line
From my experience with OMAP, we *really* do not want to care about
what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.
What about dumb or untrusted apps?
---------------------------------------
In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)
Again, since suspend blockers were designed, there have been major efforts to track and fix userspace as well as underlying timer issues (deferrable timers, coalescing, timer slack ...) that led to unnecessary wakeups from userspace. Wouldn't it be better to spend our collective efforts in continuing in that direction instead of just hiding the underlying problems by forcing suspend? Fixing the root causes will be better for everyone, not just those using Android.
And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?
Anyways, that's enough rambling for now. I hope that sheds some light on the concerns I have with suspend blockers.
Kevin
Quoted 4 lines · Arve Hjønnevåg
This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version fixes a race in suspend blocking work, has some documentation changes and opportunistic suspend now uses the same workqueue as runtime pm.
Earlier this month, several folks intersted in embedded PM had a BoF as part of the Embedded Linux Conference[1] in San Francisco. Many of us had concerns about wakelocks/suspend-blockers and I wanted to share some of mine here, since I don't know if embedded folks (other than Google) were included in discussions during the LF Collab summmit.
I hope other embedded folks will chime in here as well. My background is in embedded as one of the kernel developers on the TI OMAP SoCs, and I work primarily on PM stuff.
My comments are not about this implementation of suspend blockers in particular, but rather on the potential implications of suspend blockers in general.
Sorry for the lengthy mail, it's broken up in to 3 parts:
- suspend blockers vs. runtime PM
- how to handle PM aware drivers?
- what about dumb or untrusted apps
Suspend blockers vs runtime PM
------------------------------
My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.
Currently in the kernel, we have two main forms of PM
- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)
And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.
The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.
It seems to me the keypad/screen example given in the doc can very easily be solved with runtime PM. The goal of that example is that the keypad not turn on the screen unless a specific key is pressed. That is rather easy to accomplish using runtime PM:
1. system is idle, all devices/drivers runtime suspended (display and keypad drivers are both runtime suspended)
- keypress triggers wakeup ->runtime_resume() of keypad (screen is still runtime suspended)
- key press trickles up to userspace - keypad driver is done, goes idle and is runtime supended - userspace decides whether or not to turn on screen based on key - if not, goto 1, (display is still runtime suspended) - if so, start using display and it will be runtime resumed
I realize this keypad example was only one example usage of suspend blockers, but I suspect the others would be solved similarily using runtime PM.
But anyways, to get back to the main point:
I feel the main problems tackled by _kernel_ suspend blockers (as I understand them) are the same problems already addressed by runtime PM. First and formost, both have the same guiding principle:
Rule #1: Always try for lowest power state, unless X
For runtime PM, X = "activity"
For suspend blockers, X = a held suspend_blocker
In addition, both have the same secondary goals:
- keep device PM independent of other devices (e.g. don't wake up screen just because keypad was pressed)
- wakeups/events can be handled in a device specific way, without affecting other devices or rest of the system, unless desired
So, the goals are the same, but the approaches are different. Runtime PM makes each of the drivers and subsystems do the work, where suspend blockers just forces the issue from on high. IMHO, the more flexible and generic approach of runtime PM is more suited to a general purpose kernel than the one-big-hammer approach currently taken by suspend blockers.
What about PM aware drivers?
----------------------------
All of this brings up a second major concern regarding how to write PM aware drivers.
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 1 line
From my experience with OMAP, we *really* do not want to care about
what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.
What about dumb or untrusted apps?
---------------------------------------
In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)
Again, since suspend blockers were designed, there have been major efforts to track and fix userspace as well as underlying timer issues (deferrable timers, coalescing, timer slack ...) that led to unnecessary wakeups from userspace. Wouldn't it be better to spend our collective efforts in continuing in that direction instead of just hiding the underlying problems by forcing suspend? Fixing the root causes will be better for everyone, not just those using Android.
And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?
Anyways, that's enough rambling for now. I hope that sheds some light on the concerns I have with suspend blockers.
Kevin
Quoted 9 lines · Kevin Hilman
Suspend blockers vs runtime PM
------------------------------My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.
There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.
So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.
Quoted 9 lines
Currently in the kernel, we have two main forms of PM
- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)And with the addition of suspend blockers we have something in between. In my simple world, I think of
suspend_blockersas static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.
I wouldn't describe it like that. Consider dividing PM along a different axis:
- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)
Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.
Quoted 6 lines
The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.
The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.
Quoted 6 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 7 lines
From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.
That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.
Alan Stern
Quoted 9 lines · Kevin Hilman
Suspend blockers vs runtime PM
------------------------------My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.
There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.
So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.
Quoted 9 lines
Currently in the kernel, we have two main forms of PM
- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)And with the addition of suspend blockers we have something in between. In my simple world, I think of
suspend_blockersas static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.
I wouldn't describe it like that. Consider dividing PM along a different axis:
- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)
Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.
Quoted 6 lines
The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.
The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.
Quoted 6 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 7 lines
From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.
That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.
Alan Stern
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
Quoted 19 lines · Alan Stern
Quoted 9 lines · Kevin Hilman
Suspend blockers vs runtime PM
------------------------------My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.
There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.
Quoted 3 lines
So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.
Good point. However, adding CPUidle to runtime PM you indeed achieve a dynamic PM that affects the whole system.
The main difference then comes down to what prevents system-wide low-power state: activity vs. suspend blocker held.
Quoted 13 lines
Quoted 9 lines
Currently in the kernel, we have two main forms of PM
- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)And with the addition of suspend blockers we have something in between. In my simple world, I think of
suspend_blockersas static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.I wouldn't describe it like that. Consider dividing PM along a different axis:
Quoted 7 lines
- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.
Adding CPUidle to runtime PM (dynamic + single), you add 'entire' as well, as CPUidle manages the CPU states.
However, one problem I have with your proposed division is it doesn't seem to match well to the hardware available on modern embedded SoCs, mainly because these are not ACPI devices. The CPU is just another "independent" device whose runtime PM is managed by CPUidle.
IOW, The 'entire system' state is just a function of the CPU state and the state of all the on- and off-chip devices. With CPUidle managing the CPUs, and runtime PM managing the rest of the devices, you have a fully flexible dynamic PM for the entire system.
Quoted 9 lines
Quoted 6 lines
The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.
The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.
True, by iteslf, runtime PM does not shut down CPUs, but in combination with CPUidle the CPU(s) can be shut down based on activity. In a way, you could think of CPUidle as runtime PM for the CPU(s).
Again, the primary difference comes down to: why should I not enter a low-power state? activity (runtime PM + CPUidle) or suspend blocker.
Quoted 14 lines
Quoted 6 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 7 lines
From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.
Quoted 4 lines
That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.
Nor is it clear (to me) what drivers would/should look like that would need to do suspend blockers in addition to runtime PM.
Kevin
Quoted 19 lines · Alan Stern
Quoted 9 lines · Kevin Hilman
Suspend blockers vs runtime PM
------------------------------My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.
There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.
Quoted 3 lines
So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.
Good point. However, adding CPUidle to runtime PM you indeed achieve a dynamic PM that affects the whole system.
The main difference then comes down to what prevents system-wide low-power state: activity vs. suspend blocker held.
Quoted 13 lines
Quoted 9 lines
Currently in the kernel, we have two main forms of PM
- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)And with the addition of suspend blockers we have something in between. In my simple world, I think of
suspend_blockersas static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.I wouldn't describe it like that. Consider dividing PM along a different axis:
Quoted 7 lines
- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.
Adding CPUidle to runtime PM (dynamic + single), you add 'entire' as well, as CPUidle manages the CPU states.
However, one problem I have with your proposed division is it doesn't seem to match well to the hardware available on modern embedded SoCs, mainly because these are not ACPI devices. The CPU is just another "independent" device whose runtime PM is managed by CPUidle.
IOW, The 'entire system' state is just a function of the CPU state and the state of all the on- and off-chip devices. With CPUidle managing the CPUs, and runtime PM managing the rest of the devices, you have a fully flexible dynamic PM for the entire system.
Quoted 9 lines
Quoted 6 lines
The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.
The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.
True, by iteslf, runtime PM does not shut down CPUs, but in combination with CPUidle the CPU(s) can be shut down based on activity. In a way, you could think of CPUidle as runtime PM for the CPU(s).
Again, the primary difference comes down to: why should I not enter a low-power state? activity (runtime PM + CPUidle) or suspend blocker.
Quoted 14 lines
Quoted 6 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 7 lines
From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.
Quoted 4 lines
That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.
Nor is it clear (to me) what drivers would/should look like that would need to do suspend blockers in addition to runtime PM.
Kevin
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Rafael J. WysockiHi!
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details,
Quoted 7 lines
We do exactly the same thing with '
pm_test', so I'm not sure what the problem is.Quoted 1 line
and neither you nor Arve explained why it is good solution.
Because it's less confusing. Having two different attributes returning almost the same contents and working in a slightly different way wouldn't be too clean IMO.
No, I don't think it is similar to pm_test. pm_test is debug-only, and orthogonal to state -- all combinations make sense.
With 'oportunistic > policy', state changes from blocking to nonblocking (surprise!). Plus, it is not orthogonal:
(assume we added s-t-flash on android for powersaving... or imagine I get oportunistic suspend working on PC --I was there with limited config on x60).
policy: oportunistic forced
state: on mem disk
First disadvantage of proposed interface is that while 'opportunistic mem' is active, I can't do 'forced disk' to save bit more power.
Next, not all combinations make sense.
oportunistic on == forced <nothing>
oportunistic disk -- probably something that will not be implemented any time soon.
oportunistic mem -- makes sense.
forced on -- NOP
forced mem -- makes sense.
forced disk -- makes sense.
So we have matrix of 7 possibilities, but only 4 make sense... IMO its confusing.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Rafael J. WysockiHi!
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details,
Quoted 7 lines
We do exactly the same thing with '
pm_test', so I'm not sure what the problem is.Quoted 1 line
and neither you nor Arve explained why it is good solution.
Because it's less confusing. Having two different attributes returning almost the same contents and working in a slightly different way wouldn't be too clean IMO.
No, I don't think it is similar to pm_test. pm_test is debug-only, and orthogonal to state -- all combinations make sense.
With 'oportunistic > policy', state changes from blocking to nonblocking (surprise!). Plus, it is not orthogonal:
(assume we added s-t-flash on android for powersaving... or imagine I get oportunistic suspend working on PC --I was there with limited config on x60).
policy: oportunistic forced
state: on mem disk
First disadvantage of proposed interface is that while 'opportunistic mem' is active, I can't do 'forced disk' to save bit more power.
Next, not all combinations make sense.
oportunistic on == forced <nothing>
oportunistic disk -- probably something that will not be implemented any time soon.
oportunistic mem -- makes sense.
forced on -- NOP
forced mem -- makes sense.
forced disk -- makes sense.
So we have matrix of 7 possibilities, but only 4 make sense... IMO its confusing.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 3 lines
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
Thanks,
Rafael
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 3 lines
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
Thanks,
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
Quoted 8 lines
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
Quoted 8 lines
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Pavel MachekQuoted 30 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details,
Quoted 7 lines
We do exactly the same thing with '
pm_test', so I'm not sure what the problem is.Quoted 1 line
and neither you nor Arve explained why it is good solution.
Because it's less confusing. Having two different attributes returning almost the same contents and working in a slightly different way wouldn't be too clean IMO.
No, I don't think it is similar to
pm_test.pm_testis debug-only, and orthogonal to state -- all combinations make sense.With 'oportunistic > policy', state changes from blocking to nonblocking (surprise!). Plus, it is not orthogonal:
(assume we added s-t-flash on android for powersaving... or imagine I get oportunistic suspend working on PC --I was there with limited config on x60).
policy: oportunistic forced
Quoted 8 lines
state: on mem disk
First disadvantage of proposed interface is that while 'opportunistic mem' is active, I can't do 'forced disk' to save bit more power.
Next, not all combinations make sense.
oportunistic on == forced <nothing>
That's correct, but the "opportunistic on" thing is there to avoid switching back and forth from "opportunistic" to "forced". So that's a matter of convenience rather than anything else.
Quoted 2 lines
oportunistic disk -- probably something that will not be implemented any time soon.
Yes, and that's why "disk" won't work with "opportunistic" for now.
Quoted 3 lines
oportunistic mem -- makes sense.
forced on -- NOP
There won't be "on" with "forced" (that probably needs changing at the moment).
Quoted 5 lines
forced mem -- makes sense.
forced disk -- makes sense.
So we have matrix of 7 possibilities, but only 4 make sense... IMO its confusing.
The main problem is that the entire suspend subsystem is going to work in a different way when suspend blockers are enforced. Thus IMO it makes sense to provide a switch between the "opportunistic" and "forced" modes, because that clearly indicates to the user (or user space in general) how the whole suspend subsystem actually works at the moment.
As long as it's "opportunistic", the system will autosuspend if suspend blockers are not active and the behavior of "state" reflects that. If you want to enforce a transition, switch to "forced" first.
That's not at all confusing if you know what you're doing. The defailt mode is "forced", so the suspend subsystem works "as usual" by default. You have to directly switch it to "opportunistic" to change the behavior and once you've done that, you shouldn't really be surprised that the behavior has changed. That's what you've requested after all.
So no, I don't really think it's confusing.
Thanks,
Rafael
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Pavel MachekQuoted 30 lines · Pavel Machek
Hi!
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
As I explained before (and got no reply), the proposed interface is ugly. It uses one sysfs file to change semantics of another one.
In fact this behavior was discussed at the LF Collab Summit and no one involved had any problem with that.
Well, I explained why I disliked in previous mail in more details,
Quoted 7 lines
We do exactly the same thing with '
pm_test', so I'm not sure what the problem is.Quoted 1 line
and neither you nor Arve explained why it is good solution.
Because it's less confusing. Having two different attributes returning almost the same contents and working in a slightly different way wouldn't be too clean IMO.
No, I don't think it is similar to
pm_test.pm_testis debug-only, and orthogonal to state -- all combinations make sense.With 'oportunistic > policy', state changes from blocking to nonblocking (surprise!). Plus, it is not orthogonal:
(assume we added s-t-flash on android for powersaving... or imagine I get oportunistic suspend working on PC --I was there with limited config on x60).
policy: oportunistic forced
Quoted 8 lines
state: on mem disk
First disadvantage of proposed interface is that while 'opportunistic mem' is active, I can't do 'forced disk' to save bit more power.
Next, not all combinations make sense.
oportunistic on == forced <nothing>
That's correct, but the "opportunistic on" thing is there to avoid switching back and forth from "opportunistic" to "forced". So that's a matter of convenience rather than anything else.
Quoted 2 lines
oportunistic disk -- probably something that will not be implemented any time soon.
Yes, and that's why "disk" won't work with "opportunistic" for now.
Quoted 3 lines
oportunistic mem -- makes sense.
forced on -- NOP
There won't be "on" with "forced" (that probably needs changing at the moment).
Quoted 5 lines
forced mem -- makes sense.
forced disk -- makes sense.
So we have matrix of 7 possibilities, but only 4 make sense... IMO its confusing.
The main problem is that the entire suspend subsystem is going to work in a different way when suspend blockers are enforced. Thus IMO it makes sense to provide a switch between the "opportunistic" and "forced" modes, because that clearly indicates to the user (or user space in general) how the whole suspend subsystem actually works at the moment.
As long as it's "opportunistic", the system will autosuspend if suspend blockers are not active and the behavior of "state" reflects that. If you want to enforce a transition, switch to "forced" first.
That's not at all confusing if you know what you're doing. The defailt mode is "forced", so the suspend subsystem works "as usual" by default. You have to directly switch it to "opportunistic" to change the behavior and once you've done that, you shouldn't really be surprised that the behavior has changed. That's what you've requested after all.
So no, I don't really think it's confusing.
Thanks,
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 17 lines · Arve Hjønnevåg
Quoted 16 lines · Rafael J. Wysocki
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.
Quoted 7 lines
Quoted 3 lines
Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Well, the problem is the only purpose of this is user space debugging, isn't it?
Now, while I don't think it's generally bad to provide kernel interfaces helping to debug user space, I'm not quite sure if that should be done at the expense of the clarity of kernel-user space interfaces.
I wonder how many cases there are in which distinguishing between suspend blockers used by the same user space task is practically relevant.
Thanks,
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 17 lines · Arve Hjønnevåg
Quoted 16 lines · Rafael J. Wysocki
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.
Quoted 7 lines
Quoted 3 lines
Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Well, the problem is the only purpose of this is user space debugging, isn't it?
Now, while I don't think it's generally bad to provide kernel interfaces helping to debug user space, I'm not quite sure if that should be done at the expense of the clarity of kernel-user space interfaces.
I wonder how many cases there are in which distinguishing between suspend blockers used by the same user space task is practically relevant.
Thanks,
Rafael
Quoted 5 lines · Kevin Hilman
In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)
I'd say that this is certainly the main issue, though the remaining periodic timers in the kernel are also inconvenient.
Quoted 5 lines
And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?
I considered this. The problem is that not all of your wakeup events pass through trusted code. Assume we've used a freezer cgroup and the applications are now frozen. One of them is blocking on a network socket. A packet arrives and triggers a wakeup of the hardware. How do we unfreeze the userspace app?
I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace. The use-cases that Google have provided are valid and they have an implementation that addresses them, and while we're unable to provide an alternative that provides the same level of functionality I think we're in a poor position to prevent this from going in.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Kevin Hilman
In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)
I'd say that this is certainly the main issue, though the remaining periodic timers in the kernel are also inconvenient.
Quoted 5 lines
And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?
I considered this. The problem is that not all of your wakeup events pass through trusted code. Assume we've used a freezer cgroup and the applications are now frozen. One of them is blocking on a network socket. A packet arrives and triggers a wakeup of the hardware. How do we unfreeze the userspace app?
I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace. The use-cases that Google have provided are valid and they have an implementation that addresses them, and while we're unable to provide an alternative that provides the same level of functionality I think we're in a poor position to prevent this from going in.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. Wysocki2010/5/3 Rafael J. Wysocki <[email protected]>:
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 19 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Quoted 6 lines
Quoted 3 lines
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Well, the problem is the only purpose of this is user space debugging, isn't it?
At the moment, yes. But having an explicit init call also simplifies future expansion. If we ever need to add back multiple types of suspend blockers, we can add an init call with a type argument and have the current init call use the default type. If the past we have had types that keeps the screen on and prevented idle sleep modes. In the future we could for instance want to specify if a suspend blocker should prevent suspend when the battery is low or when the lid is closed.
Quoted 7 lines
Now, while I don't think it's generally bad to provide kernel interfaces helping to debug user space, I'm not quite sure if that should be done at the expense of the clarity of kernel-user space interfaces.
I wonder how many cases there are in which distinguishing between suspend blockers used by the same user space task is practically relevant.
I think all of them (when more than one suspend blocker is used).
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. Wysocki2010/5/3 Rafael J. Wysocki <[email protected]>:
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 19 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Quoted 6 lines
Quoted 3 lines
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Well, the problem is the only purpose of this is user space debugging, isn't it?
At the moment, yes. But having an explicit init call also simplifies future expansion. If we ever need to add back multiple types of suspend blockers, we can add an init call with a type argument and have the current init call use the default type. If the past we have had types that keeps the screen on and prevented idle sleep modes. In the future we could for instance want to specify if a suspend blocker should prevent suspend when the battery is low or when the lid is closed.
Quoted 7 lines
Now, while I don't think it's generally bad to provide kernel interfaces helping to debug user space, I'm not quite sure if that should be done at the expense of the clarity of kernel-user space interfaces.
I wonder how many cases there are in which distinguishing between suspend blockers used by the same user space task is practically relevant.
I think all of them (when more than one suspend blocker is used).
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
The main problem is that the entire suspend subsystem is going to work in a different way when suspend blockers are enforced. Thus IMO it makes sense to provide a switch between the "opportunistic" and "forced" modes, because that clearly indicates to the user (or user space in general) how the whole suspend subsystem actually works at the moment.
As long as it's "opportunistic", the system will autosuspend if suspend blockers are not active and the behavior of "state" reflects that. If you want to enforce a transition, switch to "forced" first.
Quoted 5 lines
That's not at all confusing if you know what you're doing. The defailt mode is "forced", so the suspend subsystem works "as usual" by default. You have to directly switch it to "opportunistic" to change the behavior and once you've done that, you shouldn't really be surprised that the behavior has changed. That's what you've requested after all.
How about changing the contents of /sys/power/state depending on the current policy? When the policy is "forced" it should look the same as it does now. When the policy is "opportunistic" it should contain "mem" and "on".
Alan Stern
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
The main problem is that the entire suspend subsystem is going to work in a different way when suspend blockers are enforced. Thus IMO it makes sense to provide a switch between the "opportunistic" and "forced" modes, because that clearly indicates to the user (or user space in general) how the whole suspend subsystem actually works at the moment.
As long as it's "opportunistic", the system will autosuspend if suspend blockers are not active and the behavior of "state" reflects that. If you want to enforce a transition, switch to "forced" first.
Quoted 5 lines
That's not at all confusing if you know what you're doing. The defailt mode is "forced", so the suspend subsystem works "as usual" by default. You have to directly switch it to "opportunistic" to change the behavior and once you've done that, you shouldn't really be surprised that the behavior has changed. That's what you've requested after all.
How about changing the contents of /sys/power/state depending on the current policy? When the policy is "forced" it should look the same as it does now. When the policy is "opportunistic" it should contain "mem" and "on".
Alan Stern
Re: [PATCH 1/8] PM: Add suspend block api.
Quoted 18 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
The main problem is that the entire suspend subsystem is going to work in a different way when suspend blockers are enforced. Thus IMO it makes sense to provide a switch between the "opportunistic" and "forced" modes, because that clearly indicates to the user (or user space in general) how the whole suspend subsystem actually works at the moment.
As long as it's "opportunistic", the system will autosuspend if suspend blockers are not active and the behavior of "state" reflects that. If you want to enforce a transition, switch to "forced" first.
Quoted 5 lines
That's not at all confusing if you know what you're doing. The defailt mode is "forced", so the suspend subsystem works "as usual" by default. You have to directly switch it to "opportunistic" to change the behavior and once you've done that, you shouldn't really be surprised that the behavior has changed. That's what you've requested after all.
Quoted 4 lines
How about changing the contents of
/sys/power/statedepending on the current policy? When the policy is "forced" it should look the same as it does now. When the policy is "opportunistic" it should contain "mem" and "on".
It already does this.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Alan SternQuoted 18 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
The main problem is that the entire suspend subsystem is going to work in a different way when suspend blockers are enforced. Thus IMO it makes sense to provide a switch between the "opportunistic" and "forced" modes, because that clearly indicates to the user (or user space in general) how the whole suspend subsystem actually works at the moment.
As long as it's "opportunistic", the system will autosuspend if suspend blockers are not active and the behavior of "state" reflects that. If you want to enforce a transition, switch to "forced" first.
Quoted 5 lines
That's not at all confusing if you know what you're doing. The defailt mode is "forced", so the suspend subsystem works "as usual" by default. You have to directly switch it to "opportunistic" to change the behavior and once you've done that, you shouldn't really be surprised that the behavior has changed. That's what you've requested after all.
Quoted 4 lines
How about changing the contents of
/sys/power/statedepending on the current policy? When the policy is "forced" it should look the same as it does now. When the policy is "opportunistic" it should contain "mem" and "on".
It already does this.
Signature · 1 line
Arve Hjønnevåg
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 6 lines
Quoted 3 lines
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 7 lines
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
From the use cases presented, the *usage* of suspend blockers is aimed
at power management of individual devices or subsystems, just like usage of runtime PM.
So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except
- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)
In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Kevin
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 6 lines
Quoted 3 lines
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 7 lines
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
From the use cases presented, the *usage* of suspend blockers is aimed
at power management of individual devices or subsystems, just like usage of runtime PM.
So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except
- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)
In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Kevin
Quoted 37 lines · Kevin Hilman
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 6 lines
Quoted 3 lines
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.
Quoted 7 lines
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
I'm not that familiar with ACPI either, but I think the S-states entered by suspend are much lower power than the C-states entered by idle.
Quoted 10 lines
Quoted 5 lines
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.
No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.
Quoted 4 lines
So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except
Quoted 8 lines
- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
Why? If a device is not in use it should be off regardless of what state the rest of the system is in.
Quoted 7 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Kevin
Signature · 1 line
Arve Hjønnevåg
Quoted 37 lines · Kevin Hilman
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman
At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.
The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.
Quoted 5 lines
To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.
Quoted 6 lines
Quoted 3 lines
I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.
I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.
Quoted 7 lines
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
I'm not that familiar with ACPI either, but I think the S-states entered by suspend are much lower power than the C-states entered by idle.
Quoted 10 lines
Quoted 5 lines
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.
No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.
Quoted 4 lines
So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except
Quoted 8 lines
- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
Why? If a device is not in use it should be off regardless of what state the rest of the system is in.
Quoted 7 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Kevin
Signature · 1 line
Arve Hjønnevåg
Quoted 14 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 6 lines
In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
Why? If a device is not in use it should be off regardless of what state the rest of the system is in.
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 14 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 6 lines
In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
Why? If a device is not in use it should be off regardless of what state the rest of the system is in.
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
Brian
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
Quoted 8 lines
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Yes please.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to Arve HjønnevågQuoted 39 lines · Arve Hjønnevåg
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.Signed-off-by Arve Hjønnevåg <[email protected]>--- Documentation/power/opportunistic-suspend.txt | 119 +++++++++++ include/linux/suspend_blocker.h | 64 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 92 ++++++++- kernel/power/power.h | 9 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 261 +++++++++++++++++++++++++ 8 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/suspend_blocker.cDocumentation/power/opportunistic-suspend.txt new file +12
-0@@ -0,0 +1,119 @@ +Opportunistic Suspend +===================== + +Opportunistic suspend is a feature allowing the system to be suspended (ie. put +into one of the available sleep states) automatically whenever it is regarded +as idle. The suspend blockers framework described below is used to determine +when that happens. + +The /sys/power/policy sysfs attribute is used to switch the system between the +opportunistic and "forced" suspend behavior, where in the latter case the +system is only suspended if a specific value, corresponding to one of the +available system sleep states, is written into /sys/power/state. However, in
Documentation/power/opportunistic-suspend.txt line 22
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt new file +10
-0+the former, opportunistic, case the system is put into the sleep state +corresponding to the value written to /sys/power/state whenever there are no +active suspend blockers. The default policy is "forced". Also, suspend blockers +do not affect sleep states entered from idle. + +When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode.
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
--mgross
Quoted 700 lines
Documentation/power/opportunistic-suspend.txt new file +97
-0+ +A suspend blocker is an object used to inform the PM subsystem when the system +can or cannot be suspended in the "opportunistic" mode (the "forced" mode +ignores suspend blockers). To use it, a device driver creates a struct +suspend_blocker that must be initialized with suspend_blocker_init(). Before +freeing the suspend_blocker structure or its name, suspend_blocker_destroy() +must be called on it. + +A suspend blocker is activated using suspend_block(), which prevents the PM +subsystem from putting the system into the requested sleep state in the +"opportunistic" mode until the suspend blocker is deactivated with +suspend_unblock(). Multiple suspend blockers may be active simultaneously, and +the system will not suspend as long as at least one of them is active. + +If opportunistic suspend is already in progress when suspend_block() is called, +it will abort the suspend, unless suspend_ops->enter has already been +executed. If suspend is aborted this way, the system is usually not fully +operational at that point. The suspend callbacks of some drivers may still be +running and it usually takes time to restore the system to the fully operational +state. + +Here's an example showing how a cell phone or other embedded system can handle +keystrokes (or other input events) in the presence of suspend blockers. Use +set_irq_wake or a platform specific api to make sure the keypad interrupt wakes +up the cpu. Once the keypad driver has resumed, the sequence of events can look +like this: + +- The Keypad driver gets an interrupt. It then calls suspend_block on the + keypad-scan suspend_blocker and starts scanning the keypad matrix. +- The keypad-scan code detects a key change and reports it to the input-event + driver. +- The input-event driver sees the key change, enqueues an event, and calls + suspend_block on the input-event-queue suspend_blocker. +- The keypad-scan code detects that no keys are held and calls suspend_unblock + on the keypad-scan suspend_blocker. +- The user-space input-event thread returns from select/poll, calls + suspend_block on the process-input-events suspend_blocker and then calls read + on the input-event device. +- The input-event driver dequeues the key-event and, since the queue is now + empty, it calls suspend_unblock on the input-event-queue suspend_blocker. +- The user-space input-event thread returns from read. If it determines that + the key should be ignored, it calls suspend_unblock on the + process_input_events suspend_blocker and then calls select or poll. The + system will automatically suspend again, since now no suspend blockers are + active. + +If the key that was pressed instead should preform a simple action (for example, +adjusting the volume), this action can be performed right before calling +suspend_unblock on the process_input_events suspend_blocker. However, if the key +triggers a longer-running action, that action needs its own suspend_blocker and +suspend_block must be called on that suspend blocker before calling +suspend_unblock on the process_input_events suspend_blocker. + + Key pressed Key released + | | +keypad-scan ++++++++++++++++++ +input-event-queue +++ +++ +process-input-events +++ +++ + + +Driver API +========== + +A driver can use the suspend block api by adding a suspend_blocker variable to +its state and calling suspend_blocker_init. For instance: +struct state { + struct suspend_blocker suspend_blocker; +} + +init() { + suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name"); +} + +Before freeing the memory, suspend_blocker_destroy must be called: + +uninit() { + suspend_blocker_destroy(&state->suspend_blocker); +} + +When the driver determines that it needs to run (usually in an interrupt +handler) it calls suspend_block: + suspend_block(&state->suspend_blocker); + +When it no longer needs to run it calls suspend_unblock: + suspend_unblock(&state->suspend_blocker); + +Calling suspend_block when the suspend blocker is active or suspend_unblock when +it is not active has no effect (i.e., these functions don't nest). This allows +drivers to update their state and call suspend suspend_block or suspend_unblock +based on the result. +For instance: + +if (list_empty(&state->pending_work)) + suspend_unblock(&state->suspend_blocker); +else + suspend_block(&state->suspend_blocker); +include/linux/suspend_blocker.h new file +64
-0@@ -0,0 +1,64 @@ +/* include/linux/suspend_blocker.h +* +* Copyright (C) 2007-2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCKER_H +#define _LINUX_SUSPEND_BLOCKER_H + +#include <linux/list.h> + +/** +* struct suspend_blocker - the basic suspend_blocker structure +* @link: List entry for active or inactive list. +* @flags: Tracks initialized and active state. +* @name: Name used for debugging. +* +* When a suspend_blocker is active it prevents the system from entering +* opportunistic suspend. +* +* The suspend_blocker structure must be initialized by suspend_blocker_init() +*/ + +struct suspend_blocker { +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +struct list_head link; +int flags; +const char *name; +#endif +}; + +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name); +void suspend_blocker_destroy (struct suspend_blocker *blocker); +void suspend_block (struct suspend_blocker *blocker); +void suspend_unblock (struct suspend_blocker *blocker); +bool suspend_blocker_is_active (struct suspend_blocker *blocker); +bool suspend_is_blocked (void ); + +#else + +static inline void suspend_blocker_init (struct suspend_blocker *blocker, +const char *name) {} +static inline void suspend_blocker_destroy (struct suspend_blocker *blocker) {} +static inline void suspend_block (struct suspend_blocker *blocker) {} +static inline void suspend_unblock (struct suspend_blocker *blocker) {} +static inline bool suspend_blocker_is_active (struct suspend_blocker *bl) + {return 0 ; } +static inline bool suspend_is_blocked (void ) {return 0 ; } + +#endif + +#endif +kernel/power/Kconfig +16
-0@@ -130,6 +130,22 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. +config OPPORTUNISTIC_SUSPEND + bool "Suspend blockers" + depends on PM_SLEEP + select RTC_LIB + default n + ---help--- + Opportunistic sleep support. Allows the system to be put into a sleep + state opportunistically, if it doesn't do any useful work at the + moment. The PM subsystem is switched into this mode of operation by + writing "opportunistic" into /sys/power/policy, while writing + "forced" to this file turns the opportunistic suspend feature off. + In the "opportunistic" mode suspend blockers are used to determine + when to suspend the system and the value written to /sys/power/state + determines the sleep state the system will be put into when there are + no active suspend blockers. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/main.c +86
-6@@ -12,6 +12,7 @@#include <linux/string.h> #include <linux/resume-trace.h> #include <linux/workqueue.h> +#include <linux/suspend_blocker.h> #include "power.h" @@ -20,6 +21,27 @@ DEFINE_MUTEX(pm_mutex);unsigned int pm_flags;EXPORT_SYMBOL (pm_flags); +struct policy { +const char *name; +bool (*valid_state)(suspend_state_t state); +int (*set_state)(suspend_state_t state); +}; +static struct policy policies[] = { + { + .name ="forced" , + .valid_state = valid_state, + .set_state = enter_state, + }, +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + { + .name ="opportunistic" , + .valid_state = request_suspend_valid_state, + .set_state = request_suspend_state, + }, +#endif +}; +static int policy; +#ifdef CONFIG_PM_SLEEP /* Routines for PM-transition notifications */ @@ -146,6 +168,12 @@ struct kobject *power_kobj;* * store() accepts one of those strings, translates it into the * proper enumerated value, and initiates a suspend transition. +* +* If policy is set to opportunistic, store() does not block until the +* system resumes, and it will try to re-enter the state until another +* state is requested. Suspend blockers are respected and the requested +* state will only be entered when no suspend blockers are active. +* Write "on" to cancel. */ static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf)@@ -155,12 +183,13 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,int i;for (i =0 ; i <PM_SUSPEND_MAX ; i++) { -if (pm_states[i] &&valid_state (i)) +if (pm_states[i] && policies[policy].valid_state (i)) s +=sprintf (s,"%s " , pm_states[i]); }#endif #ifdef CONFIG_HIBERNATION - s +=sprintf (s,"%s\n" ,"disk" ); +if (!policy) + s +=sprintf (s,"%s\n" ,"disk" );#else if (s != buf)/* convert the last space to a newline */ @@ -173,7 +202,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) {#ifdef CONFIG_SUSPEND -suspend_state_t state =PM_SUSPEND_STANDBY ; +suspend_state_t state =PM_SUSPEND_ON ;const char *const *s;#endif char *p;@@ -184,7 +213,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, len = p ? p - buf : n;/* First, check if we are requested to hibernate */ -if (len ==4 && !strncmp (buf,"disk" , len)) { +if (len ==4 && !strncmp (buf,"disk" , len) && !policy) { error =hibernate (); goto Exit; }@@ -195,7 +224,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, break; }if (state <PM_SUSPEND_MAX && *s) - error =enter_state (state); + error = policies[policy].set_state (state);#endif Exit:@@ -204,6 +233,55 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,power_attr (state); +/** +* policy - set policy for state +*/ + +static ssize_t policy_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +char *s = buf; +int i; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { +if (i == policy) + s +=sprintf (s,"[%s] " , policies[i].name); +else + s +=sprintf (s,"%s " , policies[i].name); + } +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ; +return (s - buf); +} + +static ssize_t policy_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +const char *s; +char *p; +int len; +int i; + + p =memchr (buf,'\n' , n); + len = p ? p - buf : n; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { + s = policies[i].name; +if (s && len ==strlen (s) && !strncmp (buf, s, len)) { +mutex_lock (&pm_mutex); + policies[policy].set_state (PM_SUSPEND_ON ); + policy = i; +mutex_unlock (&pm_mutex); +return n; + } + } +return -EINVAL ; +} + +power_attr (policy); +#ifdef CONFIG_PM_TRACE int pm_trace_enabled;@@ -231,6 +309,7 @@ power_attr(pm_trace);static struct attribute * g[] = { &state_attr.attr, + &policy_attr.attr, #ifdef CONFIG_PM_TRACE &pm_trace_attr.attr, #endif@@ -247,7 +326,7 @@ static struct attribute_group attr_group = { .attrs = g, }; -#ifdef CONFIG_PM_RUNTIME +#if defined(CONFIG_PM_RUNTIME ) || defined(CONFIG_OPPORTUNISTIC_SUSPEND )struct workqueue_struct *pm_wq;EXPORT_SYMBOL_GPL (pm_wq);@@ -266,6 +345,7 @@ static int __init pm_init(void)int error =pm_start_workqueue ();if (error)return error; +suspend_block_init (); power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;kernel/power/power.h +9
-0@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void) { }#endif + +/* kernel/power/suspend_block.c */ +extern int request_suspend_state (suspend_state_t state); +extern bool request_suspend_valid_state (suspend_state_t state); +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +extern void __init suspend_block_init (void ); +#else +static inline void suspend_block_init (void ) {} +#endif kernel/power/suspend.c +3
-1@@ -16,10 +16,12 @@#include <linux/cpu.h> #include <linux/syscalls.h> #include <linux/gfp.h> +#include <linux/suspend_blocker.h> #include "power.h" const char *const pm_states[PM_SUSPEND_MAX ] = { + [PM_SUSPEND_ON ] ="on" , [PM_SUSPEND_STANDBY ] ="standby" , [PM_SUSPEND_MEM ] ="mem" , };@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) error = suspend_ops->enter (state);sysdev_resume (); }kernel/power/suspend_blocker.c new file +261
-0@@ -0,0 +1,261 @@ +/* kernel/power/suspend_blocker.c +* +* Copyright (C) 2005-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/rtc.h> +#include <linux/suspend.h> +#include <linux/suspend_blocker.h> +#include "power.h" + +extern struct workqueue_struct *pm_wq; + +enum { +DEBUG_EXIT_SUSPEND =1U <<0 , +DEBUG_WAKEUP =1U <<1 , +DEBUG_USER_STATE =1U <<2 , +DEBUG_SUSPEND =1U <<3 , +DEBUG_SUSPEND_BLOCKER =1U <<4 , +}; +static int debug_mask =DEBUG_EXIT_SUSPEND |DEBUG_WAKEUP |DEBUG_USER_STATE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +#define SB_INITIALIZED (1U << 8) +#define SB_ACTIVE (1U << 9) + +static DEFINE_SPINLOCK (list_lock); +static DEFINE_SPINLOCK (state_lock); +static LIST_HEAD (inactive_blockers); +static LIST_HEAD (active_blockers); +static int current_event_num; +struct suspend_blocker main_suspend_blocker; +static suspend_state_t requested_suspend_state =PM_SUSPEND_MEM ; +static bool enable_suspend_blockers; + +#define pr_info_time(fmt, args...) \ + do { \ + struct timespec ts; \ + struct rtc_time tm; \ + getnstimeofday(&ts); \ + rtc_time_to_tm(ts.tv_sec, &tm); \ + pr_info(fmt "(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n" , \ + args, \ + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, \ + tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); \ + } while (0); + +static void print_active_blockers_locked (void ) +{ +struct suspend_blocker *blocker; + +list_for_each_entry (blocker, &active_blockers, link) +pr_info ("active suspend blocker %s\n" , blocker->name); +} + +/** +* suspend_is_blocked() - Check if suspend should be blocked +* +* suspend_is_blocked can be used by generic power management code to abort +* suspend. +* +* To preserve backward compatibility suspend_is_blocked returns 0 unless it +* is called during suspend initiated from the suspend_block code. +*/ +bool suspend_is_blocked (void ) +{ +if (!enable_suspend_blockers) +return 0 ; +return !list_empty (&active_blockers); +} + +static void suspend_worker (struct work_struct *work) +{ +int ret; +int entry_event_num; + + enable_suspend_blockers = true; +while (!suspend_is_blocked ()) { + entry_event_num = current_event_num; + +if (debug_mask &DEBUG_SUSPEND ) +pr_info ("suspend: enter suspend\n" ); + + ret =pm_suspend (requested_suspend_state); + +if (debug_mask &DEBUG_EXIT_SUSPEND ) +pr_info_time ("suspend: exit suspend, ret = %d " , ret); + +if (current_event_num == entry_event_num) +pr_info ("suspend: pm_suspend returned with no event\n" ); + } + enable_suspend_blockers = false; +} +static DECLARE_WORK(suspend_work, suspend_worker); + +/** +* suspend_blocker_init() - Initialize a suspend blocker +* @blocker: The suspend blocker to initialize. +* @name: The name of the suspend blocker to show in debug messages. +* +* The suspend blocker struct and name must not be freed before calling +* suspend_blocker_destroy. +*/ +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name) +{ +unsigned long irqflags =0 ; + +WARN_ON (!name); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_init name=%s\n" , name); + + blocker->name = name; + blocker->flags =SB_INITIALIZED ; +INIT_LIST_HEAD (&blocker->link); + +spin_lock_irqsave (&list_lock, irqflags); +list_add (&blocker->link, &inactive_blockers); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_init); + +/** +* suspend_blocker_destroy() - Destroy a suspend blocker +* @blocker: The suspend blocker to destroy. +*/ +void suspend_blocker_destroy (struct suspend_blocker *blocker) +{ +unsigned long irqflags; +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_destroy name=%s\n" , blocker->name); + +spin_lock_irqsave (&list_lock, irqflags); + blocker->flags &= ~SB_INITIALIZED ; +list_del (&blocker->link); +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_destroy); + +/** +* suspend_block() - Block suspend +* @blocker: The suspend blocker to use +* +* It is safe to call this function from interrupt context. +*/ +void suspend_block (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_block: %s\n" , blocker->name); + + blocker->flags |=SB_ACTIVE ; +list_move (&blocker->link, &active_blockers); + current_event_num++; + +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_block); + +/** +* suspend_unblock() - Unblock suspend +* @blocker: The suspend blocker to unblock. +* +* If no other suspend blockers block suspend, the system will suspend. +* +* It is safe to call this function from interrupt context. +*/ +void suspend_unblock (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_unblock: %s\n" , blocker->name); + +list_move (&blocker->link, &inactive_blockers); + +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); + blocker->flags &= ~(SB_ACTIVE ); +if (blocker == &main_suspend_blocker) { +if (debug_mask &DEBUG_SUSPEND ) +print_active_blockers_locked (); + } +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_unblock); + +/** +* suspend_blocker_is_active() - Test if a suspend blocker is blocking suspend +* @blocker: The suspend blocker to check. +* +* Returns true if the suspend_blocker is currently active. +*/ +bool suspend_blocker_is_active (struct suspend_blocker *blocker) +{ +WARN_ON (!(blocker->flags &SB_INITIALIZED )); + +return !!(blocker->flags &SB_ACTIVE ); +} +EXPORT_SYMBOL (suspend_blocker_is_active); + +bool request_suspend_valid_state (suspend_state_t state) +{ +return (state ==PM_SUSPEND_ON ) ||valid_state (state); +} + +int request_suspend_state (suspend_state_t state) +{ +unsigned long irqflags; + +if (!request_suspend_valid_state (state)) +return -ENODEV ; + +spin_lock_irqsave (&state_lock, irqflags); + +if (debug_mask &DEBUG_USER_STATE ) +pr_info_time ("request_suspend_state: %s (%d->%d) at %lld " , + state !=PM_SUSPEND_ON ?"sleep" :"wakeup" , + requested_suspend_state, state, +ktime_to_ns (ktime_get ())); + + requested_suspend_state = state; +if (state ==PM_SUSPEND_ON ) +suspend_block (&main_suspend_blocker); +else +suspend_unblock (&main_suspend_blocker); +spin_unlock_irqrestore (&state_lock, irqflags); +return 0 ; +} + +void __init suspend_block_init (void ) +{ +suspend_blocker_init (&main_suspend_blocker,"main" ); +suspend_block (&main_suspend_blocker); +}Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Arve HjønnevågQuoted 39 lines · Arve Hjønnevåg
Adds
/sys/power/policythat selects the behaviour of/sys/power/state. After setting the policy to opportunistic, writes to/sys/power/statebecome non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.Signed-off-by Arve Hjønnevåg <[email protected]>--- Documentation/power/opportunistic-suspend.txt | 119 +++++++++++ include/linux/suspend_blocker.h | 64 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 92 ++++++++- kernel/power/power.h | 9 + kernel/power/suspend.c | 4 +- kernel/power/suspend_blocker.c | 261 +++++++++++++++++++++++++ 8 files changed, 559 insertions(+), 7 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/suspend_blocker.cDocumentation/power/opportunistic-suspend.txt new file +12
-0@@ -0,0 +1,119 @@ +Opportunistic Suspend +===================== + +Opportunistic suspend is a feature allowing the system to be suspended (ie. put +into one of the available sleep states) automatically whenever it is regarded +as idle. The suspend blockers framework described below is used to determine +when that happens. + +The /sys/power/policy sysfs attribute is used to switch the system between the +opportunistic and "forced" suspend behavior, where in the latter case the +system is only suspended if a specific value, corresponding to one of the +available system sleep states, is written into /sys/power/state. However, in
Documentation/power/opportunistic-suspend.txt line 22
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt new file +10
-0+the former, opportunistic, case the system is put into the sleep state +corresponding to the value written to /sys/power/state whenever there are no +active suspend blockers. The default policy is "forced". Also, suspend blockers +do not affect sleep states entered from idle. + +When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode.
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
--mgross
Quoted 700 lines
Documentation/power/opportunistic-suspend.txt new file +97
-0+ +A suspend blocker is an object used to inform the PM subsystem when the system +can or cannot be suspended in the "opportunistic" mode (the "forced" mode +ignores suspend blockers). To use it, a device driver creates a struct +suspend_blocker that must be initialized with suspend_blocker_init(). Before +freeing the suspend_blocker structure or its name, suspend_blocker_destroy() +must be called on it. + +A suspend blocker is activated using suspend_block(), which prevents the PM +subsystem from putting the system into the requested sleep state in the +"opportunistic" mode until the suspend blocker is deactivated with +suspend_unblock(). Multiple suspend blockers may be active simultaneously, and +the system will not suspend as long as at least one of them is active. + +If opportunistic suspend is already in progress when suspend_block() is called, +it will abort the suspend, unless suspend_ops->enter has already been +executed. If suspend is aborted this way, the system is usually not fully +operational at that point. The suspend callbacks of some drivers may still be +running and it usually takes time to restore the system to the fully operational +state. + +Here's an example showing how a cell phone or other embedded system can handle +keystrokes (or other input events) in the presence of suspend blockers. Use +set_irq_wake or a platform specific api to make sure the keypad interrupt wakes +up the cpu. Once the keypad driver has resumed, the sequence of events can look +like this: + +- The Keypad driver gets an interrupt. It then calls suspend_block on the + keypad-scan suspend_blocker and starts scanning the keypad matrix. +- The keypad-scan code detects a key change and reports it to the input-event + driver. +- The input-event driver sees the key change, enqueues an event, and calls + suspend_block on the input-event-queue suspend_blocker. +- The keypad-scan code detects that no keys are held and calls suspend_unblock + on the keypad-scan suspend_blocker. +- The user-space input-event thread returns from select/poll, calls + suspend_block on the process-input-events suspend_blocker and then calls read + on the input-event device. +- The input-event driver dequeues the key-event and, since the queue is now + empty, it calls suspend_unblock on the input-event-queue suspend_blocker. +- The user-space input-event thread returns from read. If it determines that + the key should be ignored, it calls suspend_unblock on the + process_input_events suspend_blocker and then calls select or poll. The + system will automatically suspend again, since now no suspend blockers are + active. + +If the key that was pressed instead should preform a simple action (for example, +adjusting the volume), this action can be performed right before calling +suspend_unblock on the process_input_events suspend_blocker. However, if the key +triggers a longer-running action, that action needs its own suspend_blocker and +suspend_block must be called on that suspend blocker before calling +suspend_unblock on the process_input_events suspend_blocker. + + Key pressed Key released + | | +keypad-scan ++++++++++++++++++ +input-event-queue +++ +++ +process-input-events +++ +++ + + +Driver API +========== + +A driver can use the suspend block api by adding a suspend_blocker variable to +its state and calling suspend_blocker_init. For instance: +struct state { + struct suspend_blocker suspend_blocker; +} + +init() { + suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name"); +} + +Before freeing the memory, suspend_blocker_destroy must be called: + +uninit() { + suspend_blocker_destroy(&state->suspend_blocker); +} + +When the driver determines that it needs to run (usually in an interrupt +handler) it calls suspend_block: + suspend_block(&state->suspend_blocker); + +When it no longer needs to run it calls suspend_unblock: + suspend_unblock(&state->suspend_blocker); + +Calling suspend_block when the suspend blocker is active or suspend_unblock when +it is not active has no effect (i.e., these functions don't nest). This allows +drivers to update their state and call suspend suspend_block or suspend_unblock +based on the result. +For instance: + +if (list_empty(&state->pending_work)) + suspend_unblock(&state->suspend_blocker); +else + suspend_block(&state->suspend_blocker); +include/linux/suspend_blocker.h new file +64
-0@@ -0,0 +1,64 @@ +/* include/linux/suspend_blocker.h +* +* Copyright (C) 2007-2009 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _LINUX_SUSPEND_BLOCKER_H +#define _LINUX_SUSPEND_BLOCKER_H + +#include <linux/list.h> + +/** +* struct suspend_blocker - the basic suspend_blocker structure +* @link: List entry for active or inactive list. +* @flags: Tracks initialized and active state. +* @name: Name used for debugging. +* +* When a suspend_blocker is active it prevents the system from entering +* opportunistic suspend. +* +* The suspend_blocker structure must be initialized by suspend_blocker_init() +*/ + +struct suspend_blocker { +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +struct list_head link; +int flags; +const char *name; +#endif +}; + +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name); +void suspend_blocker_destroy (struct suspend_blocker *blocker); +void suspend_block (struct suspend_blocker *blocker); +void suspend_unblock (struct suspend_blocker *blocker); +bool suspend_blocker_is_active (struct suspend_blocker *blocker); +bool suspend_is_blocked (void ); + +#else + +static inline void suspend_blocker_init (struct suspend_blocker *blocker, +const char *name) {} +static inline void suspend_blocker_destroy (struct suspend_blocker *blocker) {} +static inline void suspend_block (struct suspend_blocker *blocker) {} +static inline void suspend_unblock (struct suspend_blocker *blocker) {} +static inline bool suspend_blocker_is_active (struct suspend_blocker *bl) + {return 0 ; } +static inline bool suspend_is_blocked (void ) {return 0 ; } + +#endif + +#endif +kernel/power/Kconfig +16
-0@@ -130,6 +130,22 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. +config OPPORTUNISTIC_SUSPEND + bool "Suspend blockers" + depends on PM_SLEEP + select RTC_LIB + default n + ---help--- + Opportunistic sleep support. Allows the system to be put into a sleep + state opportunistically, if it doesn't do any useful work at the + moment. The PM subsystem is switched into this mode of operation by + writing "opportunistic" into /sys/power/policy, while writing + "forced" to this file turns the opportunistic suspend feature off. + In the "opportunistic" mode suspend blockers are used to determine + when to suspend the system and the value written to /sys/power/state + determines the sleep state the system will be put into when there are + no active suspend blockers. + config HIBERNATION_NVS boolkernel/power/Makefile +1
-0@@ -7,6 +7,7 @@ obj-$(CONFIG_PM) += main.o obj-$(CONFIG_PM_SLEEP) += console.o obj-$(CONFIG_FREEZER) += process.o obj-$(CONFIG_SUSPEND) += suspend.o +obj-$(CONFIG_OPPORTUNISTIC_SUSPEND) += suspend_blocker.o obj-$(CONFIG_PM_TEST_SUSPEND) += suspend_test.o obj-$(CONFIG_HIBERNATION) += hibernate.o snapshot.o swap.o user.o obj-$(CONFIG_HIBERNATION_NVS) += hibernate_nvs.okernel/power/main.c +86
-6@@ -12,6 +12,7 @@#include <linux/string.h> #include <linux/resume-trace.h> #include <linux/workqueue.h> +#include <linux/suspend_blocker.h> #include "power.h" @@ -20,6 +21,27 @@ DEFINE_MUTEX(pm_mutex);unsigned int pm_flags;EXPORT_SYMBOL (pm_flags); +struct policy { +const char *name; +bool (*valid_state)(suspend_state_t state); +int (*set_state)(suspend_state_t state); +}; +static struct policy policies[] = { + { + .name ="forced" , + .valid_state = valid_state, + .set_state = enter_state, + }, +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND + { + .name ="opportunistic" , + .valid_state = request_suspend_valid_state, + .set_state = request_suspend_state, + }, +#endif +}; +static int policy; +#ifdef CONFIG_PM_SLEEP /* Routines for PM-transition notifications */ @@ -146,6 +168,12 @@ struct kobject *power_kobj;* * store() accepts one of those strings, translates it into the * proper enumerated value, and initiates a suspend transition. +* +* If policy is set to opportunistic, store() does not block until the +* system resumes, and it will try to re-enter the state until another +* state is requested. Suspend blockers are respected and the requested +* state will only be entered when no suspend blockers are active. +* Write "on" to cancel. */ static ssize_t state_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf)@@ -155,12 +183,13 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,int i;for (i =0 ; i <PM_SUSPEND_MAX ; i++) { -if (pm_states[i] &&valid_state (i)) +if (pm_states[i] && policies[policy].valid_state (i)) s +=sprintf (s,"%s " , pm_states[i]); }#endif #ifdef CONFIG_HIBERNATION - s +=sprintf (s,"%s\n" ,"disk" ); +if (!policy) + s +=sprintf (s,"%s\n" ,"disk" );#else if (s != buf)/* convert the last space to a newline */ @@ -173,7 +202,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) {#ifdef CONFIG_SUSPEND -suspend_state_t state =PM_SUSPEND_STANDBY ; +suspend_state_t state =PM_SUSPEND_ON ;const char *const *s;#endif char *p;@@ -184,7 +213,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, len = p ? p - buf : n;/* First, check if we are requested to hibernate */ -if (len ==4 && !strncmp (buf,"disk" , len)) { +if (len ==4 && !strncmp (buf,"disk" , len) && !policy) { error =hibernate (); goto Exit; }@@ -195,7 +224,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, break; }if (state <PM_SUSPEND_MAX && *s) - error =enter_state (state); + error = policies[policy].set_state (state);#endif Exit:@@ -204,6 +233,55 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,power_attr (state); +/** +* policy - set policy for state +*/ + +static ssize_t policy_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +char *s = buf; +int i; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { +if (i == policy) + s +=sprintf (s,"[%s] " , policies[i].name); +else + s +=sprintf (s,"%s " , policies[i].name); + } +if (s != buf) +/* convert the last space to a newline */ + *(s-1 ) ='\n' ; +return (s - buf); +} + +static ssize_t policy_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t n) +{ +const char *s; +char *p; +int len; +int i; + + p =memchr (buf,'\n' , n); + len = p ? p - buf : n; + +for (i =0 ; i <ARRAY_SIZE (policies); i++) { + s = policies[i].name; +if (s && len ==strlen (s) && !strncmp (buf, s, len)) { +mutex_lock (&pm_mutex); + policies[policy].set_state (PM_SUSPEND_ON ); + policy = i; +mutex_unlock (&pm_mutex); +return n; + } + } +return -EINVAL ; +} + +power_attr (policy); +#ifdef CONFIG_PM_TRACE int pm_trace_enabled;@@ -231,6 +309,7 @@ power_attr(pm_trace);static struct attribute * g[] = { &state_attr.attr, + &policy_attr.attr, #ifdef CONFIG_PM_TRACE &pm_trace_attr.attr, #endif@@ -247,7 +326,7 @@ static struct attribute_group attr_group = { .attrs = g, }; -#ifdef CONFIG_PM_RUNTIME +#if defined(CONFIG_PM_RUNTIME ) || defined(CONFIG_OPPORTUNISTIC_SUSPEND )struct workqueue_struct *pm_wq;EXPORT_SYMBOL_GPL (pm_wq);@@ -266,6 +345,7 @@ static int __init pm_init(void)int error =pm_start_workqueue ();if (error)return error; +suspend_block_init (); power_kobj =kobject_create_and_add ("power" ,NULL );if (!power_kobj)return -ENOMEM ;kernel/power/power.h +9
-0@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void) { }#endif + +/* kernel/power/suspend_block.c */ +extern int request_suspend_state (suspend_state_t state); +extern bool request_suspend_valid_state (suspend_state_t state); +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +extern void __init suspend_block_init (void ); +#else +static inline void suspend_block_init (void ) {} +#endif kernel/power/suspend.c +3
-1@@ -16,10 +16,12 @@#include <linux/cpu.h> #include <linux/syscalls.h> #include <linux/gfp.h> +#include <linux/suspend_blocker.h> #include "power.h" const char *const pm_states[PM_SUSPEND_MAX ] = { + [PM_SUSPEND_ON ] ="on" , [PM_SUSPEND_STANDBY ] ="standby" , [PM_SUSPEND_MEM ] ="mem" , };@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state) error =sysdev_suspend (PMSG_SUSPEND );if (!error) { -if (!suspend_test (TEST_CORE )) +if (!suspend_is_blocked () && !suspend_test (TEST_CORE )) error = suspend_ops->enter (state);sysdev_resume (); }kernel/power/suspend_blocker.c new file +261
-0@@ -0,0 +1,261 @@ +/* kernel/power/suspend_blocker.c +* +* Copyright (C) 2005-2010 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/rtc.h> +#include <linux/suspend.h> +#include <linux/suspend_blocker.h> +#include "power.h" + +extern struct workqueue_struct *pm_wq; + +enum { +DEBUG_EXIT_SUSPEND =1U <<0 , +DEBUG_WAKEUP =1U <<1 , +DEBUG_USER_STATE =1U <<2 , +DEBUG_SUSPEND =1U <<3 , +DEBUG_SUSPEND_BLOCKER =1U <<4 , +}; +static int debug_mask =DEBUG_EXIT_SUSPEND |DEBUG_WAKEUP |DEBUG_USER_STATE ; +module_param_named (debug_mask, debug_mask, int,S_IRUGO |S_IWUSR |S_IWGRP ); + +#define SB_INITIALIZED (1U << 8) +#define SB_ACTIVE (1U << 9) + +static DEFINE_SPINLOCK (list_lock); +static DEFINE_SPINLOCK (state_lock); +static LIST_HEAD (inactive_blockers); +static LIST_HEAD (active_blockers); +static int current_event_num; +struct suspend_blocker main_suspend_blocker; +static suspend_state_t requested_suspend_state =PM_SUSPEND_MEM ; +static bool enable_suspend_blockers; + +#define pr_info_time(fmt, args...) \ + do { \ + struct timespec ts; \ + struct rtc_time tm; \ + getnstimeofday(&ts); \ + rtc_time_to_tm(ts.tv_sec, &tm); \ + pr_info(fmt "(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n" , \ + args, \ + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, \ + tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); \ + } while (0); + +static void print_active_blockers_locked (void ) +{ +struct suspend_blocker *blocker; + +list_for_each_entry (blocker, &active_blockers, link) +pr_info ("active suspend blocker %s\n" , blocker->name); +} + +/** +* suspend_is_blocked() - Check if suspend should be blocked +* +* suspend_is_blocked can be used by generic power management code to abort +* suspend. +* +* To preserve backward compatibility suspend_is_blocked returns 0 unless it +* is called during suspend initiated from the suspend_block code. +*/ +bool suspend_is_blocked (void ) +{ +if (!enable_suspend_blockers) +return 0 ; +return !list_empty (&active_blockers); +} + +static void suspend_worker (struct work_struct *work) +{ +int ret; +int entry_event_num; + + enable_suspend_blockers = true; +while (!suspend_is_blocked ()) { + entry_event_num = current_event_num; + +if (debug_mask &DEBUG_SUSPEND ) +pr_info ("suspend: enter suspend\n" ); + + ret =pm_suspend (requested_suspend_state); + +if (debug_mask &DEBUG_EXIT_SUSPEND ) +pr_info_time ("suspend: exit suspend, ret = %d " , ret); + +if (current_event_num == entry_event_num) +pr_info ("suspend: pm_suspend returned with no event\n" ); + } + enable_suspend_blockers = false; +} +static DECLARE_WORK(suspend_work, suspend_worker); + +/** +* suspend_blocker_init() - Initialize a suspend blocker +* @blocker: The suspend blocker to initialize. +* @name: The name of the suspend blocker to show in debug messages. +* +* The suspend blocker struct and name must not be freed before calling +* suspend_blocker_destroy. +*/ +void suspend_blocker_init (struct suspend_blocker *blocker,const char *name) +{ +unsigned long irqflags =0 ; + +WARN_ON (!name); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_init name=%s\n" , name); + + blocker->name = name; + blocker->flags =SB_INITIALIZED ; +INIT_LIST_HEAD (&blocker->link); + +spin_lock_irqsave (&list_lock, irqflags); +list_add (&blocker->link, &inactive_blockers); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_init); + +/** +* suspend_blocker_destroy() - Destroy a suspend blocker +* @blocker: The suspend blocker to destroy. +*/ +void suspend_blocker_destroy (struct suspend_blocker *blocker) +{ +unsigned long irqflags; +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_blocker_destroy name=%s\n" , blocker->name); + +spin_lock_irqsave (&list_lock, irqflags); + blocker->flags &= ~SB_INITIALIZED ; +list_del (&blocker->link); +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_blocker_destroy); + +/** +* suspend_block() - Block suspend +* @blocker: The suspend blocker to use +* +* It is safe to call this function from interrupt context. +*/ +void suspend_block (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_block: %s\n" , blocker->name); + + blocker->flags |=SB_ACTIVE ; +list_move (&blocker->link, &active_blockers); + current_event_num++; + +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_block); + +/** +* suspend_unblock() - Unblock suspend +* @blocker: The suspend blocker to unblock. +* +* If no other suspend blockers block suspend, the system will suspend. +* +* It is safe to call this function from interrupt context. +*/ +void suspend_unblock (struct suspend_blocker *blocker) +{ +unsigned long irqflags; + +if (WARN_ON (!(blocker->flags &SB_INITIALIZED ))) +return ; + +spin_lock_irqsave (&list_lock, irqflags); + +if (debug_mask &DEBUG_SUSPEND_BLOCKER ) +pr_info ("suspend_unblock: %s\n" , blocker->name); + +list_move (&blocker->link, &inactive_blockers); + +if ((blocker->flags &SB_ACTIVE ) &&list_empty (&active_blockers)) +queue_work (pm_wq, &suspend_work); + blocker->flags &= ~(SB_ACTIVE ); +if (blocker == &main_suspend_blocker) { +if (debug_mask &DEBUG_SUSPEND ) +print_active_blockers_locked (); + } +spin_unlock_irqrestore (&list_lock, irqflags); +} +EXPORT_SYMBOL (suspend_unblock); + +/** +* suspend_blocker_is_active() - Test if a suspend blocker is blocking suspend +* @blocker: The suspend blocker to check. +* +* Returns true if the suspend_blocker is currently active. +*/ +bool suspend_blocker_is_active (struct suspend_blocker *blocker) +{ +WARN_ON (!(blocker->flags &SB_INITIALIZED )); + +return !!(blocker->flags &SB_ACTIVE ); +} +EXPORT_SYMBOL (suspend_blocker_is_active); + +bool request_suspend_valid_state (suspend_state_t state) +{ +return (state ==PM_SUSPEND_ON ) ||valid_state (state); +} + +int request_suspend_state (suspend_state_t state) +{ +unsigned long irqflags; + +if (!request_suspend_valid_state (state)) +return -ENODEV ; + +spin_lock_irqsave (&state_lock, irqflags); + +if (debug_mask &DEBUG_USER_STATE ) +pr_info_time ("request_suspend_state: %s (%d->%d) at %lld " , + state !=PM_SUSPEND_ON ?"sleep" :"wakeup" , + requested_suspend_state, state, +ktime_to_ns (ktime_get ())); + + requested_suspend_state = state; +if (state ==PM_SUSPEND_ON ) +suspend_block (&main_suspend_blocker); +else +suspend_unblock (&main_suspend_blocker); +spin_unlock_irqrestore (&state_lock, irqflags); +return 0 ; +} + +void __init suspend_block_init (void ) +{ +suspend_blocker_init (&main_suspend_blocker,"main" ); +suspend_block (&main_suspend_blocker); +}Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Alan Stern
Quoted 3 lines · Rafael J. Wysocki
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
Quoted 8 lines
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Yes please.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH 4/8] PM: suspend_block: Add debugfs file
In reply to Arve Hjønnevågkernel/power/suspend_blocker.c static bool enable_suspend_blockers; · line 71
Quoted 13 lines · Arve Hjønnevåg
kernel/power/suspend_blocker.c +12
-0+static int suspend_blocker_stats_show (struct seq_file *m,void *unused) +{ +unsigned long irqflags; +struct suspend_blocker *blocker; + +seq_puts (m,"name\tactive\n" ); +spin_lock_irqsave (&list_lock, irqflags); +list_for_each_entry (blocker, &inactive_blockers, link) +seq_printf (m,"\"%s\"\t0\n" , blocker->name); +list_for_each_entry (blocker, &active_blockers, link) +seq_printf (m,"\"%s\"\t1\n" , blocker->name); +spin_unlock_irqrestore (&list_lock, irqflags);
Could you report the pid here too?
The name set by the application might be meaningless or duplicated.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Re: [PATCH 4/8] PM: suspend_block: Add debugfs file
In reply to Arve Hjønnevågkernel/power/suspend_blocker.c static bool enable_suspend_blockers; · line 71
Quoted 13 lines · Arve Hjønnevåg
kernel/power/suspend_blocker.c +12
-0+static int suspend_blocker_stats_show (struct seq_file *m,void *unused) +{ +unsigned long irqflags; +struct suspend_blocker *blocker; + +seq_puts (m,"name\tactive\n" ); +spin_lock_irqsave (&list_lock, irqflags); +list_for_each_entry (blocker, &inactive_blockers, link) +seq_printf (m,"\"%s\"\t0\n" , blocker->name); +list_for_each_entry (blocker, &active_blockers, link) +seq_printf (m,"\"%s\"\t1\n" , blocker->name); +spin_unlock_irqrestore (&list_lock, irqflags);
Could you report the pid here too?
The name set by the application might be meaningless or duplicated.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
Alan Stern
Quoted 10 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.
Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Quoted 6 lines
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
Quoted 6 lines
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
There's definite work to be done here, yes.
Quoted 10 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.
Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Quoted 6 lines
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
Quoted 6 lines
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
There's definite work to be done here, yes.
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
Alan Stern
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
Alan Stern
Quoted 16 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Quoted 5 lines
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
In an embedded system I'd expect that these other system devices would fall naturally out through the management of the CPUs and devices - for example, the drivers for the individual devices could use the regulator API to manage their supplies and runtime PM is being used to manage CPU core stuff - or could at least readily be handled in a similar fashion.
This isn't to say that we're there yet from an implementation point of view, of course.
Quoted 16 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Quoted 5 lines
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
In an embedded system I'd expect that these other system devices would fall naturally out through the management of the CPUs and devices - for example, the drivers for the individual devices could use the regulator API to manage their supplies and runtime PM is being used to manage CPU core stuff - or could at least readily be handled in a similar fashion.
This isn't to say that we're there yet from an implementation point of view, of course.
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
OK, that's a major difference with embedded SoCs where the kernel must directly manage the power state of all devices using runtime PM.
So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.
Kevin
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
OK, that's a major difference with embedded SoCs where the kernel must directly manage the power state of all devices using runtime PM.
So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.
Kevin
Quoted 17 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Quoted 5 lines
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
I consider all of those things devices.
On non-ACPI systems where the kernel has to manage all of the above directly, we have drivers for all of them using runtime PM as well as the regulator framework for dynamic PM power supplies.
Kevin
Quoted 17 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman
Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?
Quoted 5 lines
ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.
Quoted 5 lines
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
I consider all of those things devices.
On non-ACPI systems where the kernel has to manage all of the above directly, we have drivers for all of them using runtime PM as well as the regulator framework for dynamic PM power supplies.
Kevin
Quoted 5 lines · Alan Stern
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
Somewhat true - machines with C1E support will put the RAM into self refresh when the cpu is idle, but you're right that there are various components that we simply don't have control over in the desktop world at present.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Alan Stern
Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.
Somewhat true - machines with C1E support will put the RAM into self refresh when the cpu is idle, but you're right that there are various components that we simply don't have control over in the desktop world at present.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines · Kevin Hilman
So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.
I'd say it does for most devices, but the power savings may not be as great as they would be with fine-grained control over power rails.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines · Kevin Hilman
So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.
I'd say it does for most devices, but the power savings may not be as great as they would be with fine-grained control over power rails.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Alan SternQuoted 16 lines · Alan Stern
Quoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Quoted 7 lines
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
What? If the suspend blocker API was a one shot styled api, after the suspend, the one shot is over and the behavior is that you do not fall back into suspend again until user mode re-enables the one-shot behavior.
With what I am proposing the next suspend would not happen until the user mode code re-enables the suspend blocking behavior. It would much cleaner for everyone and I see zero down side WRT the example you just posted.
If user mode triggers a suspend by releasing the last blocker, you have until pm_suspend('mem') turns off interrupts to cancel it. That race will never go away.
Let me think this through, please check that I'm understanding the issue please:
1) one-shot policy enable blocker PM suspend behavior;
2) release last blocker and call pm_suspend('mem') and suspend all the way down.
3) get wake up event, one-shot policy over, no-blockers in list
4) go all the way to user mode,
5) user mode decides to not grab a blocker, and re-enables one-shot policy
6) pm_suspend('mem') called
7) interrupt comes in (say the modem rings)
8) modem driver handler needs to returns fail from pm_suspend call back, device resumes (I am proposing changing the posted api for doing this.)
9) user mode figures out one-shot needs to be re-enabled and it grabs a blocker to handle the call and re-enables the one-shot.
So the real problem grabbing blockers from ISR's trying to solve is to reduce the window of time where a pm_suspend('mem') can be canceled.
My proposal is to;
1) change the kernel blocker api to be "cancel-one-shot-policy-enable" that can be called from the ISR's for the wake up devices before the IRQ's are disabled to cancel an in-flight suspend. I would make it 2 macros one goes in the pm_suspend callback to return fail, and the other in the ISR to disable the one-shot-policy.
2) make the policy a one shot that user mode must re-enable after each suspend attempted.
Would it help if I coded up the above proposal as patch to the current (rev-6) of the blocker patchset? I'm offering.
Because this part of the current design is broken, in that it demands the sprinkling of blocker critical sections from the hardware up to the user mode. Its ugly, hard to get right and if more folks would take a look at how well it worked out for the existing kernels on android.git.kernel.org/kernels/ perhaps it would get more attention.
Finally, as an aside, lets look at the problem with the posted rev-6 patches:
1) enable suspend blocker policy
2) release user-mode blocker
3) start suspend
4) get a modem interrupt (incoming call)
5) ooops, IRQ came in after pm_suspend('mem') turned off interrupts. bummer for you, thats life with this design. Better hope your modem hardware is modified to keep pulling on that wake up line because you're past the point of no return now and going to suspend.
Grabbing a blocker in the ISR doesn't solve this. So your hardware needs to have a persistent wake up trigger that is robust against this scenario. And, if you have such hardware then why are we killing ourselves to maximize the window of time between pm_suspend('mem') and platform suspend where you can cancel the suspend? The hardware will simply wake up anyway.
(further, on my hardware I would modify the platform suspend call back to make one last check to see if an IRQ came in, and cancel the suspend there as a last chance.)
--mgross
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to Alan SternQuoted 16 lines · Alan Stern
Quoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Quoted 7 lines
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
What? If the suspend blocker API was a one shot styled api, after the suspend, the one shot is over and the behavior is that you do not fall back into suspend again until user mode re-enables the one-shot behavior.
With what I am proposing the next suspend would not happen until the user mode code re-enables the suspend blocking behavior. It would much cleaner for everyone and I see zero down side WRT the example you just posted.
If user mode triggers a suspend by releasing the last blocker, you have until pm_suspend('mem') turns off interrupts to cancel it. That race will never go away.
Let me think this through, please check that I'm understanding the issue please:
1) one-shot policy enable blocker PM suspend behavior;
2) release last blocker and call pm_suspend('mem') and suspend all the way down.
3) get wake up event, one-shot policy over, no-blockers in list
4) go all the way to user mode,
5) user mode decides to not grab a blocker, and re-enables one-shot policy
6) pm_suspend('mem') called
7) interrupt comes in (say the modem rings)
8) modem driver handler needs to returns fail from pm_suspend call back, device resumes (I am proposing changing the posted api for doing this.)
9) user mode figures out one-shot needs to be re-enabled and it grabs a blocker to handle the call and re-enables the one-shot.
So the real problem grabbing blockers from ISR's trying to solve is to reduce the window of time where a pm_suspend('mem') can be canceled.
My proposal is to;
1) change the kernel blocker api to be "cancel-one-shot-policy-enable" that can be called from the ISR's for the wake up devices before the IRQ's are disabled to cancel an in-flight suspend. I would make it 2 macros one goes in the pm_suspend callback to return fail, and the other in the ISR to disable the one-shot-policy.
2) make the policy a one shot that user mode must re-enable after each suspend attempted.
Would it help if I coded up the above proposal as patch to the current (rev-6) of the blocker patchset? I'm offering.
Because this part of the current design is broken, in that it demands the sprinkling of blocker critical sections from the hardware up to the user mode. Its ugly, hard to get right and if more folks would take a look at how well it worked out for the existing kernels on android.git.kernel.org/kernels/ perhaps it would get more attention.
Finally, as an aside, lets look at the problem with the posted rev-6 patches:
1) enable suspend blocker policy
2) release user-mode blocker
3) start suspend
4) get a modem interrupt (incoming call)
5) ooops, IRQ came in after pm_suspend('mem') turned off interrupts. bummer for you, thats life with this design. Better hope your modem hardware is modified to keep pulling on that wake up line because you're past the point of no return now and going to suspend.
Grabbing a blocker in the ISR doesn't solve this. So your hardware needs to have a persistent wake up trigger that is robust against this scenario. And, if you have such hardware then why are we killing ourselves to maximize the window of time between pm_suspend('mem') and platform suspend where you can cancel the suspend? The hardware will simply wake up anyway.
(further, on my hardware I would modify the platform suspend call back to make one last check to see if an IRQ came in, and cancel the suspend there as a last chance.)
--mgross
Re: [PATCH 1/8] PM: Add suspend block api.
Quoted 25 lines · mark gross
Quoted 16 lines · Alan Stern
Quoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Quoted 7 lines
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
Quoted 4 lines
What? If the suspend blocker API was a one shot styled api, after the suspend, the one shot is over and the behavior is that you do not fall back into suspend again until user mode re-enables the one-shot behavior.
I was referring to your sentence: "That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode..." The problem arises when kernel handlers don't do _something_ to prevent another suspend from occurring too soon.
Quoted 8 lines
With what I am proposing the next suspend would not happen until the user mode code re-enables the suspend blocking behavior. It would much cleaner for everyone and I see zero down side WRT the example you just posted.
If user mode triggers a suspend by releasing the last blocker, you have until
pm_suspend('mem')turns off interrupts to cancel it. That race will never go away.
(Actually the kernel can cancel the suspend even after interrupts are turned off, if it has a reason to do so.)
In theory the race between interrupts and suspend don't need to be a problem. In practice it still is -- the PM core needs a few changes to allow wakeup interrupts to cancel a suspend in progress. Regardless, that's not what I was talking about.
Quoted 7 lines
Let me think this through, please check that I'm understanding the issue please:
1) one-shot policy enable blocker PM suspend behavior;
2) release last blocker and callpm_suspend('mem')and suspend all the way down.
3) get wake up event, one-shot policy over, no-blockers in list
4) go all the way to user mode,
Quoted 8 lines
5) user mode decides to not grab a blocker, and re-enables one-shot policy
6)pm_suspend('mem')called
7) interrupt comes in (say the modem rings)
8) modem driver handler needs to returns fail frompm_suspendcall back, device resumes (I am proposing changing the posted api for doing this.)
9) user mode figures out one-shot needs to be re-enabled and it grabs a blocker to handle the call and re-enables the one-shot.
This is not the scenario I was describing. Here's what I had in mind:
1) The system is asleep
2) Wakeup event occurs, one-shot policy over
3) Go all the way to user mode
4) A second wakeup interrupt occurs (say the modem rings)
5) The modem driver does not enable any suspend blockers
6) The modem driver queues an input event for userspace
7) The userspace handler invoked during 3) finishes and re-enables the one-shot policy
8) No suspend blockers are enabled, so the system goes to sleep
9) The userspace handler for the input event in 6) doesn't get to run
Quoted 2 lines
So the real problem grabbing blockers from ISR's trying to solve is to reduce the window of time where a
pm_suspend('mem')can be canceled.
No. The real problem is how ISRs should prevent the system from suspending before the events they generate can be handled by userspace.
Quoted 9 lines
My proposal is to;
1) change the kernel blocker api to be "cancel-one-shot-policy-enable" that can be called from the ISR's for the wake up devices before the IRQ's are disabled to cancel an in-flight suspend. I would make it 2 macros one goes in thepm_suspendcallback to return fail, and the other in the ISR to disable the one-shot-policy.2) make the policy a one shot that user mode must re-enable after each suspend attempted.
Neither of these solves the race I described.
Quoted 8 lines
Would it help if I coded up the above proposal as patch to the current (rev-6) of the blocker patchset? I'm offering.
Because this part of the current design is broken, in that it demands the sprinkling of blocker critical sections from the hardware up to the user mode. Its ugly, hard to get right and if more folks would take a look at how well it worked out for the existing kernels on android.git.kernel.org/kernels/ perhaps it would get more attention.
I agree, it is ugly and probably hard to get right. But something like it is necessary to solve this race.
Quoted 10 lines
Finally, as an aside, lets look at the problem with the posted rev-6 patches:
1) enable suspend blocker policy
2) release user-mode blocker
3) start suspend
4) get a modem interrupt (incoming call)
5) ooops, IRQ came in afterpm_suspend('mem')turned off interrupts. bummer for you, thats life with this design. Better hope your modem hardware is modified to keep pulling on that wake up line because you're past the point of no return now and going to suspend.
That is not a problem for level-sensitive IRQs. If interrupts have been turned off then the modem will not receive any commands telling it to stop requesting an interrupt. So the IRQ line will remain active until the system goes to sleep, at which point it will immediately wake up the system.
For edge-sensitive interrupts the situation isn't as simple. The low-level IRQ code must handle this somehow.
Quoted 6 lines
Grabbing a blocker in the ISR doesn't solve this. So your hardware needs to have a persistent wake up trigger that is robust against this scenario. And, if you have such hardware then why are we killing ourselves to maximize the window of time between
pm_suspend('mem')and platform suspend where you can cancel the suspend? The hardware will simply wake up anyway.
That's not what we are killing ourselves for. The point of suspend blockers is not to prevent races with the hardware. It is to prevent userspace from being frozen while there's still work to be done.
Alan Stern
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 25 lines · mark gross
Quoted 16 lines · Alan Stern
Quoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Quoted 7 lines
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
Quoted 4 lines
What? If the suspend blocker API was a one shot styled api, after the suspend, the one shot is over and the behavior is that you do not fall back into suspend again until user mode re-enables the one-shot behavior.
I was referring to your sentence: "That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode..." The problem arises when kernel handlers don't do _something_ to prevent another suspend from occurring too soon.
Quoted 8 lines
With what I am proposing the next suspend would not happen until the user mode code re-enables the suspend blocking behavior. It would much cleaner for everyone and I see zero down side WRT the example you just posted.
If user mode triggers a suspend by releasing the last blocker, you have until
pm_suspend('mem')turns off interrupts to cancel it. That race will never go away.
(Actually the kernel can cancel the suspend even after interrupts are turned off, if it has a reason to do so.)
In theory the race between interrupts and suspend don't need to be a problem. In practice it still is -- the PM core needs a few changes to allow wakeup interrupts to cancel a suspend in progress. Regardless, that's not what I was talking about.
Quoted 7 lines
Let me think this through, please check that I'm understanding the issue please:
1) one-shot policy enable blocker PM suspend behavior;
2) release last blocker and callpm_suspend('mem')and suspend all the way down.
3) get wake up event, one-shot policy over, no-blockers in list
4) go all the way to user mode,
Quoted 8 lines
5) user mode decides to not grab a blocker, and re-enables one-shot policy
6)pm_suspend('mem')called
7) interrupt comes in (say the modem rings)
8) modem driver handler needs to returns fail frompm_suspendcall back, device resumes (I am proposing changing the posted api for doing this.)
9) user mode figures out one-shot needs to be re-enabled and it grabs a blocker to handle the call and re-enables the one-shot.
This is not the scenario I was describing. Here's what I had in mind:
1) The system is asleep
2) Wakeup event occurs, one-shot policy over
3) Go all the way to user mode
4) A second wakeup interrupt occurs (say the modem rings)
5) The modem driver does not enable any suspend blockers
6) The modem driver queues an input event for userspace
7) The userspace handler invoked during 3) finishes and re-enables the one-shot policy
8) No suspend blockers are enabled, so the system goes to sleep
9) The userspace handler for the input event in 6) doesn't get to run
Quoted 2 lines
So the real problem grabbing blockers from ISR's trying to solve is to reduce the window of time where a
pm_suspend('mem')can be canceled.
No. The real problem is how ISRs should prevent the system from suspending before the events they generate can be handled by userspace.
Quoted 9 lines
My proposal is to;
1) change the kernel blocker api to be "cancel-one-shot-policy-enable" that can be called from the ISR's for the wake up devices before the IRQ's are disabled to cancel an in-flight suspend. I would make it 2 macros one goes in thepm_suspendcallback to return fail, and the other in the ISR to disable the one-shot-policy.2) make the policy a one shot that user mode must re-enable after each suspend attempted.
Neither of these solves the race I described.
Quoted 8 lines
Would it help if I coded up the above proposal as patch to the current (rev-6) of the blocker patchset? I'm offering.
Because this part of the current design is broken, in that it demands the sprinkling of blocker critical sections from the hardware up to the user mode. Its ugly, hard to get right and if more folks would take a look at how well it worked out for the existing kernels on android.git.kernel.org/kernels/ perhaps it would get more attention.
I agree, it is ugly and probably hard to get right. But something like it is necessary to solve this race.
Quoted 10 lines
Finally, as an aside, lets look at the problem with the posted rev-6 patches:
1) enable suspend blocker policy
2) release user-mode blocker
3) start suspend
4) get a modem interrupt (incoming call)
5) ooops, IRQ came in afterpm_suspend('mem')turned off interrupts. bummer for you, thats life with this design. Better hope your modem hardware is modified to keep pulling on that wake up line because you're past the point of no return now and going to suspend.
That is not a problem for level-sensitive IRQs. If interrupts have been turned off then the modem will not receive any commands telling it to stop requesting an interrupt. So the IRQ line will remain active until the system goes to sleep, at which point it will immediately wake up the system.
For edge-sensitive interrupts the situation isn't as simple. The low-level IRQ code must handle this somehow.
Quoted 6 lines
Grabbing a blocker in the ISR doesn't solve this. So your hardware needs to have a persistent wake up trigger that is robust against this scenario. And, if you have such hardware then why are we killing ourselves to maximize the window of time between
pm_suspend('mem')and platform suspend where you can cancel the suspend? The hardware will simply wake up anyway.
That's not what we are killing ourselves for. The point of suspend blockers is not to prevent races with the hardware. It is to prevent userspace from being frozen while there's still work to be done.
Alan Stern
Quoted 4 lines · Arve Hjønnevåg
Quoted 2 lines · Kevin Hilman
"Rafael J. Wysocki" <[email protected]> writes:
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
Quoted 7 lines
Quoted 4 lines
From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.
No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.
OK, but my point was that their *usage* is at the level of inidividual devices and subsystems, just like runtime PM. Hence, duplicate work.
Quoted 7 lines
Quoted 7 lines
So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except
- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)
Quoted 8 lines
Quoted 5 lines
In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
Why? If a device is not in use it should be off regardless of what state the rest of the system is in.
Not necessarily.
If a device is not in use, what power state it goes into depends on many device/subsystem specific things. For example, recent activity (timeouts), whether it will be busy soon (pending transfers), latency/throughput constraints, dependency on other devices, or any other device/subsystem specific reason.
All of these can be handled with runtime PM. None of which are taken into consideration with opportunistic suspend.
Kevin
Quoted 4 lines · Arve Hjønnevåg
Quoted 2 lines · Kevin Hilman
"Rafael J. Wysocki" <[email protected]> writes:
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.
To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.
Quoted 7 lines
Quoted 4 lines
From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.
No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.
OK, but my point was that their *usage* is at the level of inidividual devices and subsystems, just like runtime PM. Hence, duplicate work.
Quoted 7 lines
Quoted 7 lines
So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except
- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)
Quoted 8 lines
Quoted 5 lines
In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.
Why? If a device is not in use it should be off regardless of what state the rest of the system is in.
Not necessarily.
If a device is not in use, what power state it goes into depends on many device/subsystem specific things. For example, recent activity (timeouts), whether it will be busy soon (pending transfers), latency/throughput constraints, dependency on other devices, or any other device/subsystem specific reason.
All of these can be handled with runtime PM. None of which are taken into consideration with opportunistic suspend.
Kevin
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Quoted 8 lines
Quoted 3 lines
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Exactly.
With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Quoted 7 lines
Quoted 6 lines
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
Quoted 7 lines
I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.
Agreed, and because of this, part of my concern is that opportunistic suspend will take the place of doing the "right thing" which (IMHO) would be to improve runtime PM for devices.
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I think there needs to be more discussion on the indended usage of suspend blockers by drivers/subsystems, especially those PM aware drivers and subsystems already doing runtime PM with constraints etc.
Quoted 8 lines
Quoted 6 lines
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
There's definite work to be done here, yes.
And I've admitted this to be the only compelling reason for opportunistic suspend so far.
But the driver/subsystem implications of opportunistic suspend still need some fleshing out IMO.
Kevin
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Quoted 8 lines
Quoted 3 lines
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Exactly.
With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Quoted 7 lines
Quoted 6 lines
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
Quoted 7 lines
I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.
Agreed, and because of this, part of my concern is that opportunistic suspend will take the place of doing the "right thing" which (IMHO) would be to improve runtime PM for devices.
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I think there needs to be more discussion on the indended usage of suspend blockers by drivers/subsystems, especially those PM aware drivers and subsystems already doing runtime PM with constraints etc.
Quoted 8 lines
Quoted 6 lines
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
There's definite work to be done here, yes.
And I've admitted this to be the only compelling reason for opportunistic suspend so far.
But the driver/subsystem implications of opportunistic suspend still need some fleshing out IMO.
Kevin
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 23 lines · Arve Hjønnevåg
2010/5/3 Rafael J. Wysocki <[email protected]>:
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 19 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Well, the problem is the only purpose of this is user space debugging, isn't it?
At the moment, yes.
OK
Quoted 1 line
But having an explicit init call also simplifies future expansion.
That's irrelevant. Let's focus _only_ on the "at the moment" part, please.
And BTW, a "future expansion" is not relevant at all to the patchset at hand and let's work with this assumption from now on. OK?
Quoted 7 lines
If we ever need to add back multiple types of
suspend blockers, we can add an init call with a type argument and have the current init call use the default type. If the past we have had types that keeps the screen on and prevented idle sleep modes. In the future we could for instance want to specify if a suspend blocker should prevent suspend when the battery is low or when the lid is closed.
_If_ we ever do anything like thie, _then_ we will extend the interface.
Quoted 9 lines
Quoted 7 lines
Now, while I don't think it's generally bad to provide kernel interfaces helping to debug user space, I'm not quite sure if that should be done at the expense of the clarity of kernel-user space interfaces.
I wonder how many cases there are in which distinguishing between suspend blockers used by the same user space task is practically relevant.
I think all of them (when more than one suspend blocker is used).
So how many user space processes use more than one suspend blocker right now on Android? I'm interested only in the order of magnitude.
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 23 lines · Arve Hjønnevåg
2010/5/3 Rafael J. Wysocki <[email protected]>:
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Rafael J. Wysocki
Quoted 19 lines · Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines
Hmm. It doesn't seem to be possible to create two different suspend blockers using the same file handle. So, what exactly is a process supposed to do to use two suspend blockers at the same time?
Open the file twice, thereby obtaining two file handles.
Well, that's what I thought.
I must admit I'm not really comfortable with this interface. IMO it would be better if
_open()created the suspend blocker giving it a name based on the name of the process that called it. Something like "<process name>_<timestamp>" might work at first sight.Alternatively, "<process_name><number>", where <number> is 0 for the first suspend blocker created by the given process, 1 for the second one etc., also seems to be doable.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
I think it is important to let user-space specify the name. If a process uses multiple suspend blockers, it is impossible to tell what each one is used for if they are automatically named.
Well, the problem is the only purpose of this is user space debugging, isn't it?
At the moment, yes.
OK
Quoted 1 line
But having an explicit init call also simplifies future expansion.
That's irrelevant. Let's focus _only_ on the "at the moment" part, please.
And BTW, a "future expansion" is not relevant at all to the patchset at hand and let's work with this assumption from now on. OK?
Quoted 7 lines
If we ever need to add back multiple types of
suspend blockers, we can add an init call with a type argument and have the current init call use the default type. If the past we have had types that keeps the screen on and prevented idle sleep modes. In the future we could for instance want to specify if a suspend blocker should prevent suspend when the battery is low or when the lid is closed.
_If_ we ever do anything like thie, _then_ we will extend the interface.
Quoted 9 lines
Quoted 7 lines
Now, while I don't think it's generally bad to provide kernel interfaces helping to debug user space, I'm not quite sure if that should be done at the expense of the clarity of kernel-user space interfaces.
I wonder how many cases there are in which distinguishing between suspend blockers used by the same user space task is practically relevant.
I think all of them (when more than one suspend blocker is used).
So how many user space processes use more than one suspend blocker right now on Android? I'm interested only in the order of magnitude.
Rafael
Quoted 21 lines · Kevin Hilman
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Quoted 8 lines
Quoted 3 lines
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Exactly.
Quoted 7 lines
With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Guys, please.
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
However, there are situations in which runtime PM is clearly insufficient. The idea behind runtime PM is that subsystems and device drivers will know when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.
Quoted 7 lines
I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.
Quoted 3 lines
Agreed, and because of this, part of my concern is that opportunistic suspend will take the place of doing the "right thing" which (IMHO) would be to improve runtime PM for devices.
It really can't, at least on some platforms. For example, resuming a PC notebook from suspend to RAM takes more than 1s (with an SSD; rotational disks add more latency here) which is way too much for such a replacement.
Besides, there also is room for runtime PM in the Android framework, because it needs to suspend certain devices without freezing processes, for example.
The freezing of processes is the most important difference to me. Runtime PM works with the assumption that processes are not frozen (hence the name), but arguably energy savings you can get without going behind that point are naturally limited.
Quoted 8 lines
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I'm not sure. Why _exactly_ would you need that?
Quoted 11 lines
I think there needs to be more discussion on the indended usage of suspend blockers by
drivers/subsystems, especially those PM aware drivers and subsystems already doing runtime PM with constraints etc.Quoted 7 lines
Quoted 6 lines
In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.
Quoted 7 lines
Quoted 1 line
There's definite work to be done here, yes.
And I've admitted this to be the only compelling reason for opportunistic suspend so far.
But the driver/subsystem implications of opportunistic suspend still need some fleshing out IMO.
At the moment, if you're not on Android, there are none.
Thanks,
Rafael
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Quoted 6 lines
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.
However, since Android is a legitimate user of the Linux kernel, I see no reason to reject this feature right away. There are many kernel features that aren't used by all platforms.
Rafael
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Quoted 6 lines
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.
However, since Android is a legitimate user of the Linux kernel, I see no reason to reject this feature right away. There are many kernel features that aren't used by all platforms.
Rafael
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to mark gross2010/5/3 mark gross <[email protected]>:
Quoted 1 line · Arve Hjønnevåg
...
Quoted 16 lines
Documentation/power/opportunistic-suspend.txt line 22
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt new file +5
-0+When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode.You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 4 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Making it one shot does not change where kernel code needs to block suspend, but it does force user space to poll trying to suspend while suspend is blocked by a driver.
Signature · 1 line
Arve Hjønnevåg
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to mark gross2010/5/3 mark gross <[email protected]>:
Quoted 1 line · Arve Hjønnevåg
...
Quoted 16 lines
Documentation/power/opportunistic-suspend.txt line 22
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt new file +5
-0+When the policy is "opportunisic", there is a special value, "on", that can be +written to /sys/power/state. This will block the automatic sleep request, as if +a suspend blocker was used by a device driver. This way the opportunistic +suspend may be blocked by user space whithout switching back to the "forced" +mode.You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 4 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Making it one shot does not change where kernel code needs to block suspend, but it does force user space to poll trying to suspend while suspend is blocked by a driver.
Signature · 1 line
Arve Hjønnevåg
Quoted 32 lines · Rafael J. Wysocki
Quoted 21 lines · Kevin Hilman
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Quoted 8 lines
Quoted 3 lines
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Exactly.
Quoted 7 lines
With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Guys, please.
Quoted 8 lines
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
However, there are situations in which runtime PM is clearly insufficient. The idea behind runtime PM is that subsystems and device drivers will know when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
s/can/can't/; s/reach/go/
Rafael
Quoted 32 lines · Rafael J. Wysocki
Quoted 21 lines · Kevin Hilman
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg
On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman
Quoted 3 lines
This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.
Quoted 8 lines
Quoted 3 lines
I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that
suspend_blockis a substitute for that.Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.
Exactly.
Quoted 7 lines
With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Guys, please.
Quoted 8 lines
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
However, there are situations in which runtime PM is clearly insufficient. The idea behind runtime PM is that subsystems and device drivers will know when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
s/can/can't/; s/reach/go/
Rafael
Re: [PATCH 4/8] PM: suspend_block: Add debugfs file
In reply to Andi Kleen2010/5/4 Andi Kleen <[email protected]>:
Quoted 17 lines
kernel/power/suspend_blocker.c static bool enable_suspend_blockers; · line 71
Quoted 13 lines · Arve Hjønnevåg
kernel/power/suspend_blocker.c +12
-0+static int suspend_blocker_stats_show (struct seq_file *m,void *unused) +{ + unsigned long irqflags; + struct suspend_blocker *blocker; + + seq_puts(m, "name\tactive\n"); + spin_lock_irqsave(&list_lock, irqflags); + list_for_each_entry(blocker, &inactive_blockers, link) + seq_printf(m, "\"%s\"\t0\n", blocker->name); + list_for_each_entry(blocker, &active_blockers, link) + seq_printf(m, "\"%s\"\t1\n", blocker->name); + spin_unlock_irqrestore(&list_lock, irqflags);Could you report the pid here too?
Most of the suspend blockers are in the kernel, and does not have a pid.
Quoted 2 lines
The name set by the application might be meaningless or duplicated.
Currently all the names set by android user-space are unique but the pids are not. We can add columns, or extend the name of user space suspend blockers in the ioctl interface, later if needed.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 4/8] PM: suspend_block: Add debugfs file
In reply to Andi Kleen2010/5/4 Andi Kleen <[email protected]>:
Quoted 17 lines
kernel/power/suspend_blocker.c static bool enable_suspend_blockers; · line 71
Quoted 13 lines · Arve Hjønnevåg
kernel/power/suspend_blocker.c +12
-0+static int suspend_blocker_stats_show (struct seq_file *m,void *unused) +{ + unsigned long irqflags; + struct suspend_blocker *blocker; + + seq_puts(m, "name\tactive\n"); + spin_lock_irqsave(&list_lock, irqflags); + list_for_each_entry(blocker, &inactive_blockers, link) + seq_printf(m, "\"%s\"\t0\n", blocker->name); + list_for_each_entry(blocker, &active_blockers, link) + seq_printf(m, "\"%s\"\t1\n", blocker->name); + spin_unlock_irqrestore(&list_lock, irqflags);Could you report the pid here too?
Most of the suspend blockers are in the kernel, and does not have a pid.
Quoted 2 lines
The name set by the application might be meaningless or duplicated.
Currently all the names set by android user-space are unique but the pids are not. We can add columns, or extend the name of user space suspend blockers in the ioctl interface, later if needed.
Signature · 1 line
Arve Hjønnevåg
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Quoted 6 lines
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
Quoted 3 lines
At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.
Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.
As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.
IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.
Kevin
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Quoted 6 lines
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
Quoted 3 lines
At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.
Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.
As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.
IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.
Kevin
Quoted 31 lines · Kevin Hilman
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Quoted 6 lines
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
Quoted 3 lines
At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.
Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.
Quoted 7 lines
As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.
IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.
I agree, but "working on towards a world where ..." need not mean "be there from day one" IMO. Also, I guess you'll agree that using the same _binary_ kernel with Android and non-Android user spaces doesn't necessarily make sense (regardless of the fact that Android kernels have hardware-specific board files included), so probably you'll still disable opportunistic suspend building the kernel for non-Android systems (at least for the time being).
It looks like you're thinking the opportunistic suspend somehow is (or can be used as) a replacement for runtime PM, but this is not the case. The reason why it's not the case is that runtime PM works with the assumption that user space is not frozen and it works on individual devices.
OTOH, generally, there is a limit on the amount of energy savings you can achieve with runtime PM alone and something like the opportunistic suspend is necessary to go beyond that limit.
Now, I can easily imagine using suspend blockers and runtime PM in the same driver with the general rule that you'll probably want to call suspend_unblock() whenever the device is suspended with the help of the runtime PM framework. That really depends on the device and the driver in question, though.
Rafael
Quoted 31 lines · Kevin Hilman
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman
With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.
Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.
Quoted 6 lines
Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.
Quoted 3 lines
At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.
Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.
Quoted 7 lines
As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.
IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.
I agree, but "working on towards a world where ..." need not mean "be there from day one" IMO. Also, I guess you'll agree that using the same _binary_ kernel with Android and non-Android user spaces doesn't necessarily make sense (regardless of the fact that Android kernels have hardware-specific board files included), so probably you'll still disable opportunistic suspend building the kernel for non-Android systems (at least for the time being).
It looks like you're thinking the opportunistic suspend somehow is (or can be used as) a replacement for runtime PM, but this is not the case. The reason why it's not the case is that runtime PM works with the assumption that user space is not frozen and it works on individual devices.
OTOH, generally, there is a limit on the amount of energy savings you can achieve with runtime PM alone and something like the opportunistic suspend is necessary to go beyond that limit.
Now, I can easily imagine using suspend blockers and runtime PM in the same driver with the general rule that you'll probably want to call suspend_unblock() whenever the device is suspended with the help of the runtime PM framework. That really depends on the device and the driver in question, though.
Rafael
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman
Mark Brown <[email protected]> writes:
Guys, please.
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.
Quoted 4 lines
when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I'm not sure. Why _exactly_ would you need that?
The use case that causes serious issues with this at the minute in the domains I work is this:
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.
Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman
Mark Brown <[email protected]> writes:
Guys, please.
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.
Quoted 4 lines
when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I'm not sure. Why _exactly_ would you need that?
The use case that causes serious issues with this at the minute in the domains I work is this:
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.
Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Quoted 17 lines · Mark Brown
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman
Mark Brown <[email protected]> writes:
Guys, please.
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.
Quoted 4 lines
when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
Quoted 4 lines
Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.
Evidently, the Android developers had a problem with that. Of course, you can argue that they didn't consider using runtime PM for this purpose, but the real question is how much time it would take to achieve the same level of energy saving using runtime PM without opportunistic suspend.
Quoted 14 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I'm not sure. Why _exactly_ would you need that?
The use case that causes serious issues with this at the minute in the domains I work is this:
Quoted 12 lines
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.
In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.
Quoted 8 lines
Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas.
My understanding is that on Android suspend blockers are used for this purpose.
Quoted 9 lines
I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.
What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).
Rafael
Quoted 17 lines · Mark Brown
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman
Mark Brown <[email protected]> writes:
Guys, please.
The opportunistic suspend feature is _not_ to replace runtime PM by any means!
Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.
Quoted 4 lines
when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.
Quoted 4 lines
Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.
Evidently, the Android developers had a problem with that. Of course, you can argue that they didn't consider using runtime PM for this purpose, but the real question is how much time it would take to achieve the same level of energy saving using runtime PM without opportunistic suspend.
Quoted 14 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.
I agree.
I'm not sure. Why _exactly_ would you need that?
The use case that causes serious issues with this at the minute in the domains I work is this:
Quoted 12 lines
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.
In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.
Quoted 8 lines
Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas.
My understanding is that on Android suspend blockers are used for this purpose.
Quoted 9 lines
I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.
What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).
Rafael
Quoted 12 lines · Rafael J. Wysocki
Quoted 5 lines
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.
Quoted 5 lines
What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).
We actually do use opportunistic suspend for cases like this on Android today. It mostly comes down to a question of latency for return from full suspend. For example:
Some MSM7201 based devices typically resume from power collapse in 3-5ms, but absolute worst case (because the L1 radio services are higher priority than the wake-the-apps-cpu services) is ~90ms. On these devices we hold a suspend_blocker while playing audio. Before discovery of this we went into full suspend while playing audio which worked fine, but in certain network conditions we would drop buffers if we could not wake fast enough.
So, it's somewhat system dependent, but it can be very helpful in a lot of cases.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 12 lines · Rafael J. Wysocki
Quoted 5 lines
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.
Quoted 5 lines
What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).
We actually do use opportunistic suspend for cases like this on Android today. It mostly comes down to a question of latency for return from full suspend. For example:
Some MSM7201 based devices typically resume from power collapse in 3-5ms, but absolute worst case (because the L1 radio services are higher priority than the wake-the-apps-cpu services) is ~90ms. On these devices we hold a suspend_blocker while playing audio. Before discovery of this we went into full suspend while playing audio which worked fine, but in certain network conditions we would drop buffers if we could not wake fast enough.
So, it's somewhat system dependent, but it can be very helpful in a lot of cases.
Brian
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to Alan SternQuoted 72 lines · Alan Stern
Quoted 25 lines · mark gross
Quoted 16 lines · Alan Stern
Quoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Quoted 7 lines
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
Quoted 4 lines
What? If the suspend blocker API was a one shot styled api, after the suspend, the one shot is over and the behavior is that you do not fall back into suspend again until user mode re-enables the one-shot behavior.
I was referring to your sentence: "That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode..." The problem arises when kernel handlers don't do _something_ to prevent another suspend from occurring too soon.
Quoted 8 lines
With what I am proposing the next suspend would not happen until the user mode code re-enables the suspend blocking behavior. It would much cleaner for everyone and I see zero down side WRT the example you just posted.
If user mode triggers a suspend by releasing the last blocker, you have until
pm_suspend('mem')turns off interrupts to cancel it. That race will never go away.(Actually the kernel can cancel the suspend even after interrupts are turned off, if it has a reason to do so.)
In theory the race between interrupts and suspend don't need to be a problem. In practice it still is -- the PM core needs a few changes to allow wakeup interrupts to cancel a suspend in progress. Regardless, that's not what I was talking about.
Quoted 7 lines
Let me think this through, please check that I'm understanding the issue please:
1) one-shot policy enable blocker PM suspend behavior;
2) release last blocker and callpm_suspend('mem')and suspend all the way down.
3) get wake up event, one-shot policy over, no-blockers in list
4) go all the way to user mode,Quoted 8 lines
5) user mode decides to not grab a blocker, and re-enables one-shot policy
6)pm_suspend('mem')called
7) interrupt comes in (say the modem rings)
8) modem driver handler needs to returns fail frompm_suspendcall back, device resumes (I am proposing changing the posted api for doing this.)
9) user mode figures out one-shot needs to be re-enabled and it grabs a blocker to handle the call and re-enables the one-shot.This is not the scenario I was describing. Here's what I had in mind:
Quoted 9 lines
1) The system is asleep
2) Wakeup event occurs, one-shot policy over
3) Go all the way to user mode
4) A second wakeup interrupt occurs (say the modem rings)
5) The modem driver does not enable any suspend blockers
6) The modem driver queues an input event for userspace
7) The userspace handler invoked during 3) finishes and re-enables the one-shot policy
8) No suspend blockers are enabled, so the system goes to sleep
In my sequence above I had the modem driver "magically" knowing to fail this suspend attempt. (that "magic" wasn't fully thought out though.)
Quoted 7 lines
9) The userspace handler for the input event in 6) doesn't get to run
Quoted 2 lines
So the real problem grabbing blockers from ISR's trying to solve is to reduce the window of time where a
pm_suspend('mem')can be canceled.No. The real problem is how ISRs should prevent the system from suspending before the events they generate can be handled by userspace.
Thanks, I think I'm starting to get it. From this it seems that the system integrator needs to identify those wake up sources that need to be able to block a suspend, and figure out a way of acknowledging from user mode, that its now ok to allow a suspend to happen.
The rev-6 proposed way is for the integrator to implement overlapping blocker sections from ISR up to user mode for selected wake up devices (i.e. the modem)
There *has* to be a better way.
Can't we have some notification based thing that supports user mode
acks through a misc device or sysfs thing? Anything to avoid the
overlapping blocker sections.
Quoted 11 lines
Quoted 9 lines
My proposal is to;
1) change the kernel blocker api to be "cancel-one-shot-policy-enable" that can be called from the ISR's for the wake up devices before the IRQ's are disabled to cancel an in-flight suspend. I would make it 2 macros one goes in thepm_suspendcallback to return fail, and the other in the ISR to disable the one-shot-policy.2) make the policy a one shot that user mode must re-enable after each suspend attempted.
Neither of these solves the race I described.
True, you need an ack back from user mode for when its ok to allow suspend to happen. This ack is device specific and needs to be custom built per product to its wake up sources.
Quoted 40 lines
Quoted 9 lines
Would it help if I coded up the above proposal as patch to the current (rev-6) of the blocker patchset? I'm offering.
Because this part of the current design is broken, in that it demands the sprinkling of blocker critical sections from the hardware up to the user mode. Its ugly, hard to get right and if more folks would take a look at how well it worked out for the existing kernels on android.git.kernel.org/kernels/ perhaps it would get more attention.
I agree, it is ugly and probably hard to get right. But something like it is necessary to solve this race.
Quoted 10 lines
Finally, as an aside, lets look at the problem with the posted rev-6 patches:
1) enable suspend blocker policy
2) release user-mode blocker
3) start suspend
4) get a modem interrupt (incoming call)
5) ooops, IRQ came in afterpm_suspend('mem')turned off interrupts. bummer for you, thats life with this design. Better hope your modem hardware is modified to keep pulling on that wake up line because you're past the point of no return now and going to suspend.That is not a problem for level-sensitive IRQs. If interrupts have been turned off then the modem will not receive any commands telling it to stop requesting an interrupt. So the IRQ line will remain active until the system goes to sleep, at which point it will immediately wake up the system.
For edge-sensitive interrupts the situation isn't as simple. The low-level IRQ code must handle this somehow.
Quoted 6 lines
Grabbing a blocker in the ISR doesn't solve this. So your hardware needs to have a persistent wake up trigger that is robust against this scenario. And, if you have such hardware then why are we killing ourselves to maximize the window of time between
pm_suspend('mem')and platform suspend where you can cancel the suspend? The hardware will simply wake up anyway.
Quoted 3 lines
That's not what we are killing ourselves for. The point of suspend blockers is not to prevent races with the hardware. It is to prevent userspace from being frozen while there's still work to be done.
ok.
I'm going to think on this some more. There must be a cleaner way to do this.
--mgross
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to Alan SternQuoted 72 lines · Alan Stern
Quoted 25 lines · mark gross
Quoted 16 lines · Alan Stern
Quoted 10 lines · mark gross
You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.
Quoted 3 lines
Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.
Quoted 7 lines
This won't work right if a second IRQ arrives while the first is being processed. Suppose the kernel driver for the second IRQ doesn't activate a suspend blocker, and suppose all the userspace handlers for the first IRQ end (and the opportunistic policy is re-enabled) before the userspace handler for the second IRQ can start. Then the system will go back to sleep before userspace can handle the second IRQ.
Quoted 4 lines
What? If the suspend blocker API was a one shot styled api, after the suspend, the one shot is over and the behavior is that you do not fall back into suspend again until user mode re-enables the one-shot behavior.
I was referring to your sentence: "That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode..." The problem arises when kernel handlers don't do _something_ to prevent another suspend from occurring too soon.
Quoted 8 lines
With what I am proposing the next suspend would not happen until the user mode code re-enables the suspend blocking behavior. It would much cleaner for everyone and I see zero down side WRT the example you just posted.
If user mode triggers a suspend by releasing the last blocker, you have until
pm_suspend('mem')turns off interrupts to cancel it. That race will never go away.(Actually the kernel can cancel the suspend even after interrupts are turned off, if it has a reason to do so.)
In theory the race between interrupts and suspend don't need to be a problem. In practice it still is -- the PM core needs a few changes to allow wakeup interrupts to cancel a suspend in progress. Regardless, that's not what I was talking about.
Quoted 7 lines
Let me think this through, please check that I'm understanding the issue please:
1) one-shot policy enable blocker PM suspend behavior;
2) release last blocker and callpm_suspend('mem')and suspend all the way down.
3) get wake up event, one-shot policy over, no-blockers in list
4) go all the way to user mode,Quoted 8 lines
5) user mode decides to not grab a blocker, and re-enables one-shot policy
6)pm_suspend('mem')called
7) interrupt comes in (say the modem rings)
8) modem driver handler needs to returns fail frompm_suspendcall back, device resumes (I am proposing changing the posted api for doing this.)
9) user mode figures out one-shot needs to be re-enabled and it grabs a blocker to handle the call and re-enables the one-shot.This is not the scenario I was describing. Here's what I had in mind:
Quoted 9 lines
1) The system is asleep
2) Wakeup event occurs, one-shot policy over
3) Go all the way to user mode
4) A second wakeup interrupt occurs (say the modem rings)
5) The modem driver does not enable any suspend blockers
6) The modem driver queues an input event for userspace
7) The userspace handler invoked during 3) finishes and re-enables the one-shot policy
8) No suspend blockers are enabled, so the system goes to sleep
In my sequence above I had the modem driver "magically" knowing to fail this suspend attempt. (that "magic" wasn't fully thought out though.)
Quoted 7 lines
9) The userspace handler for the input event in 6) doesn't get to run
Quoted 2 lines
So the real problem grabbing blockers from ISR's trying to solve is to reduce the window of time where a
pm_suspend('mem')can be canceled.No. The real problem is how ISRs should prevent the system from suspending before the events they generate can be handled by userspace.
Thanks, I think I'm starting to get it. From this it seems that the system integrator needs to identify those wake up sources that need to be able to block a suspend, and figure out a way of acknowledging from user mode, that its now ok to allow a suspend to happen.
The rev-6 proposed way is for the integrator to implement overlapping blocker sections from ISR up to user mode for selected wake up devices (i.e. the modem)
There *has* to be a better way.
Can't we have some notification based thing that supports user mode
acks through a misc device or sysfs thing? Anything to avoid the
overlapping blocker sections.
Quoted 11 lines
Quoted 9 lines
My proposal is to;
1) change the kernel blocker api to be "cancel-one-shot-policy-enable" that can be called from the ISR's for the wake up devices before the IRQ's are disabled to cancel an in-flight suspend. I would make it 2 macros one goes in thepm_suspendcallback to return fail, and the other in the ISR to disable the one-shot-policy.2) make the policy a one shot that user mode must re-enable after each suspend attempted.
Neither of these solves the race I described.
True, you need an ack back from user mode for when its ok to allow suspend to happen. This ack is device specific and needs to be custom built per product to its wake up sources.
Quoted 40 lines
Quoted 9 lines
Would it help if I coded up the above proposal as patch to the current (rev-6) of the blocker patchset? I'm offering.
Because this part of the current design is broken, in that it demands the sprinkling of blocker critical sections from the hardware up to the user mode. Its ugly, hard to get right and if more folks would take a look at how well it worked out for the existing kernels on android.git.kernel.org/kernels/ perhaps it would get more attention.
I agree, it is ugly and probably hard to get right. But something like it is necessary to solve this race.
Quoted 10 lines
Finally, as an aside, lets look at the problem with the posted rev-6 patches:
1) enable suspend blocker policy
2) release user-mode blocker
3) start suspend
4) get a modem interrupt (incoming call)
5) ooops, IRQ came in afterpm_suspend('mem')turned off interrupts. bummer for you, thats life with this design. Better hope your modem hardware is modified to keep pulling on that wake up line because you're past the point of no return now and going to suspend.That is not a problem for level-sensitive IRQs. If interrupts have been turned off then the modem will not receive any commands telling it to stop requesting an interrupt. So the IRQ line will remain active until the system goes to sleep, at which point it will immediately wake up the system.
For edge-sensitive interrupts the situation isn't as simple. The low-level IRQ code must handle this somehow.
Quoted 6 lines
Grabbing a blocker in the ISR doesn't solve this. So your hardware needs to have a persistent wake up trigger that is robust against this scenario. And, if you have such hardware then why are we killing ourselves to maximize the window of time between
pm_suspend('mem')and platform suspend where you can cancel the suspend? The hardware will simply wake up anyway.
Quoted 3 lines
That's not what we are killing ourselves for. The point of suspend blockers is not to prevent races with the hardware. It is to prevent userspace from being frozen while there's still work to be done.
ok.
I'm going to think on this some more. There must be a cleaner way to do this.
--mgross
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,
In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.
That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.
Honestly I don't think that's a very good solution for actual systems, though. A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.
Quoted 10 lines
Quoted 4 lines
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.
On the one hand that's the answer that works well with the existing Linux design here so great. On the other hand as discussed above that doesn't match so well with user expectations.
Quoted 5 lines
What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).
Remember that even in your full system suspend the system is not actually fully idle - the baseband is still sitting there looking after itself, keeping the phone on the network. The only difference between on call and off call from the point of view of the Linux system is that there is an active audio path which happens to have been set up by the Linux system.
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,
In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.
That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.
Honestly I don't think that's a very good solution for actual systems, though. A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.
Quoted 10 lines
Quoted 4 lines
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.
On the one hand that's the answer that works well with the existing Linux design here so great. On the other hand as discussed above that doesn't match so well with user expectations.
Quoted 5 lines
What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).
Remember that even in your full system suspend the system is not actually fully idle - the baseband is still sitting there looking after itself, keeping the phone on the network. The only difference between on call and off call from the point of view of the Linux system is that there is an active audio path which happens to have been set up by the Linux system.
Quoted 15 lines · Mark Brown
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,
In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.
That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.
Quoted 7 lines
Honestly I don't think that's a very good solution for actual systems, though. A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.
Yup. And that's exactly what happens on the platforms we've shipped on so far -- the apps side of the world fully suspends while in a voice call. Some events (prox sensor, buttons, modem sending a state notification) will wake it up, of course.
I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.
The suspend_block system gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).
Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use suspend_block or not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsolete suspend_blockers, awesome, we remove 'em.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 15 lines · Mark Brown
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown
On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,
In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.
That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.
Quoted 7 lines
Honestly I don't think that's a very good solution for actual systems, though. A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.
Yup. And that's exactly what happens on the platforms we've shipped on so far -- the apps side of the world fully suspends while in a voice call. Some events (prox sensor, buttons, modem sending a state notification) will wake it up, of course.
I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.
The suspend_block system gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).
Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use suspend_block or not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsolete suspend_blockers, awesome, we remove 'em.
Brian
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 2 lines · mark gross
In my sequence above I had the modem driver "magically" knowing to fail this suspend attempt. (that "magic" wasn't fully thought out though.)
If the modem driver knows to "magically" fail a suspend attempt until it knows that userspace has consumed the event, you have something that looks awfully like suspend blockers.
Quoted 1 line
There *has* to be a better way.
But nobody has reasonably proposed one and demonstrated that it works. We've had over a year to do so and failed, and I think it's pretty unreasonable to ask Google to attempt to rearchitect based on a hypothetical.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 2 lines · mark gross
In my sequence above I had the modem driver "magically" knowing to fail this suspend attempt. (that "magic" wasn't fully thought out though.)
If the modem driver knows to "magically" fail a suspend attempt until it knows that userspace has consumed the event, you have something that looks awfully like suspend blockers.
Quoted 1 line
There *has* to be a better way.
But nobody has reasonably proposed one and demonstrated that it works. We've had over a year to do so and failed, and I think it's pretty unreasonable to ask Google to attempt to rearchitect based on a hypothetical.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Brian Swetland
I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.
Yup, that'd be good - even with the AP/CP/CODEC SoCs like the MSM devices we really need to get ASoC integration since systems are being built hanging external components such as speaker drivers off the line outputs, and some of those have registers so really do benefit from the sequencing, automated PM and so on that ASoC offers.
There was some work on MSM ASoC support posted last year back but there were a number of review issues with it. Daniel Walker also talked about submitting stuff just before Christmas, quite possibly independently of the other work which looked like a community effort, but I've not seen anything through from that yet.
Quoted 8 lines
The
suspend_blocksystem gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).
Quoted 6 lines
Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use
suspend_blockor not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsoletesuspend_blockers, awesome, we remove 'em.
Like I've said a few times here I broadly agree with your goals - they seem to be a reasonable solution to the engineering problems we face presently, even though they're not where we actually want to be. What I do miss from the current proposal is more consideration of how things that do need to ignore the suspend should integrate.
If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.
This hasn't been a pressing issue while the Android code is out of tree since we can just say it's an out of tree patch that has a different design approach to current mainline and it's fairly straightforward for users to introduce suitable system-specific changes. Once it's mainline and part of the standard Linux PM toolkit then obviously subsystems and drivers need to support opportunistic suspend properly in mainline.
Quoted 5 lines · Brian Swetland
I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.
Yup, that'd be good - even with the AP/CP/CODEC SoCs like the MSM devices we really need to get ASoC integration since systems are being built hanging external components such as speaker drivers off the line outputs, and some of those have registers so really do benefit from the sequencing, automated PM and so on that ASoC offers.
There was some work on MSM ASoC support posted last year back but there were a number of review issues with it. Daniel Walker also talked about submitting stuff just before Christmas, quite possibly independently of the other work which looked like a community effort, but I've not seen anything through from that yet.
Quoted 8 lines
The
suspend_blocksystem gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).
Quoted 6 lines
Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use
suspend_blockor not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsoletesuspend_blockers, awesome, we remove 'em.
Like I've said a few times here I broadly agree with your goals - they seem to be a reasonable solution to the engineering problems we face presently, even though they're not where we actually want to be. What I do miss from the current proposal is more consideration of how things that do need to ignore the suspend should integrate.
If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.
This hasn't been a pressing issue while the Android code is out of tree since we can just say it's an out of tree patch that has a different design approach to current mainline and it's fairly straightforward for users to introduce suitable system-specific changes. Once it's mainline and part of the standard Linux PM toolkit then obviously subsystems and drivers need to support opportunistic suspend properly in mainline.
Quoted 13 lines · Mark Brown
Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.
Quoted 4 lines
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Android must already include some solution to this problem. Why not use that solution more generally?
Alan Stern
Quoted 13 lines · Mark Brown
Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.
Quoted 4 lines
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Android must already include some solution to this problem. Why not use that solution more generally?
Alan Stern
Re: [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 4 lines · mark gross
Thanks, I think I'm starting to get it. From this it seems that the system integrator needs to identify those wake up sources that need to be able to block a suspend, and figure out a way of acknowledging from user mode, that its now ok to allow a suspend to happen.
The second part is easy. Userspace doesn't need to do anything special to acknowledge that a suspend is now okay; it just has to remove the conditions that led the driver to block suspends in the first place.
For example, if suspends are blocked because some input event has been queued, emptying the input event queue should unblock suspends.
Quoted 5 lines
The rev-6 proposed way is for the integrator to implement overlapping blocker sections from ISR up to user mode for selected wake up devices (i.e. the modem)
There *has* to be a better way.
Why? What's wrong with overlapping blockers? It's a very common idiom. For example, the same sort of thing is used when locking subtrees of a tree: You lock the root node, and then use overlapping locks on the nodes leading down to the subtree you're interested in.
Quoted 3 lines
Can't we have some notification based thing that supports user mode
acks through a misc device or sysfs thing? Anything to avoid the
overlapping blocker sections.
Userspace acks aren't the issue; the issue is how (and when) kernel drivers should initiate a blocker. Switching to notifications, misc devices, or sysfs won't help solve this issue.
Quoted 3 lines
True, you need an ack back from user mode for when its ok to allow suspend to happen. This ack is device specific and needs to be custom built per product to its wake up sources.
No and no. Nothing special is needed. All userspace needs to do is remove the condition that led to the blocker being enabled initially -- which is exactly what userspace would do normally anyway.
Alan Stern
Re: [linux-pm] [PATCH 1/8] PM: Add suspend block api.
In reply to mark grossQuoted 4 lines · mark gross
Thanks, I think I'm starting to get it. From this it seems that the system integrator needs to identify those wake up sources that need to be able to block a suspend, and figure out a way of acknowledging from user mode, that its now ok to allow a suspend to happen.
The second part is easy. Userspace doesn't need to do anything special to acknowledge that a suspend is now okay; it just has to remove the conditions that led the driver to block suspends in the first place.
For example, if suspends are blocked because some input event has been queued, emptying the input event queue should unblock suspends.
Quoted 5 lines
The rev-6 proposed way is for the integrator to implement overlapping blocker sections from ISR up to user mode for selected wake up devices (i.e. the modem)
There *has* to be a better way.
Why? What's wrong with overlapping blockers? It's a very common idiom. For example, the same sort of thing is used when locking subtrees of a tree: You lock the root node, and then use overlapping locks on the nodes leading down to the subtree you're interested in.
Quoted 3 lines
Can't we have some notification based thing that supports user mode
acks through a misc device or sysfs thing? Anything to avoid the
overlapping blocker sections.
Userspace acks aren't the issue; the issue is how (and when) kernel drivers should initiate a blocker. Switching to notifications, misc devices, or sysfs won't help solve this issue.
Quoted 3 lines
True, you need an ack back from user mode for when its ok to allow suspend to happen. This ack is device specific and needs to be custom built per product to its wake up sources.
No and no. Nothing special is needed. All userspace needs to do is remove the condition that led to the blocker being enabled initially -- which is exactly what userspace would do normally anyway.
Alan Stern
Quoted 9 lines · Alan Stern
Quoted 4 lines · Mark Brown
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Android must already include some solution to this problem. Why not use that solution more generally?
Not so much; at least for audio it's being handled with platform specific bodges as far as I've seen so far. If there had been a standard way of doing this I'd have expected to see it in this patch series. The Google systems all use Qualcomm chipsets which aren't affected by this since the audio CODEC is hidden from Linux and none of the audio actually uses ALSA at all in the BSPs I looked at.
It's entirely possible I'm missing something here, everything I know has come from either talking to users or trawling code on the internet.
Quoted 9 lines · Alan Stern
Quoted 4 lines · Mark Brown
In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.
Android must already include some solution to this problem. Why not use that solution more generally?
Not so much; at least for audio it's being handled with platform specific bodges as far as I've seen so far. If there had been a standard way of doing this I'd have expected to see it in this patch series. The Google systems all use Qualcomm chipsets which aren't affected by this since the audio CODEC is hidden from Linux and none of the audio actually uses ALSA at all in the BSPs I looked at.
It's entirely possible I'm missing something here, everything I know has come from either talking to users or trawling code on the internet.
Quoted 9 lines · Mark Brown
If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.
We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Mark Brown
If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.
We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 12 lines · Matthew Garrett
Quoted 9 lines · Mark Brown
If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.
Quoted 7 lines
We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.
This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.
Alan Stern
Quoted 12 lines · Matthew Garrett
Quoted 9 lines · Mark Brown
If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.
Quoted 7 lines
We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.
This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.
Alan Stern
Quoted 7 lines · Matthew Garrett
We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.
Right, the big issue for me is that there's likely to be some form of userspace API visible for controlling this. I think I can keep it mostly in-kernel for audio (by providing new APIs to mark some inputs and outputs as being live during suspend) but need to check.
Quoted 7 lines · Matthew Garrett
We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.
Right, the big issue for me is that there's likely to be some form of userspace API visible for controlling this. I think I can keep it mostly in-kernel for audio (by providing new APIs to mark some inputs and outputs as being live during suspend) but need to check.
Quoted 8 lines · Alan Stern
This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
Yeah, ok. We probably do need to figure this out.
(Cc:ing Rebecca to see how this got handled on Droid)
The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.
Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Alan Stern
This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
Yeah, ok. We probably do need to figure this out.
(Cc:ing Rebecca to see how this got handled on Droid)
The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.
Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines · Alan Stern
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
Aside from things where the CODEC is acting as a wake source (for stuff like jack detect) which are obviously already handled it's basically just when you've got an external audio source flowing through the device which is going to continue to function during suspend. Things like FM radios, for example. I'm not aware of non-audio examples that are use case specific and don't just involve utterly ignoring AP suspends.
Quoted 2 lines
In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.
It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.
When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.
Quoted 3 lines · Alan Stern
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
Aside from things where the CODEC is acting as a wake source (for stuff like jack detect) which are obviously already handled it's basically just when you've got an external audio source flowing through the device which is going to continue to function during suspend. Things like FM radios, for example. I'm not aware of non-audio examples that are use case specific and don't just involve utterly ignoring AP suspends.
Quoted 2 lines
In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.
It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.
When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.
Quoted 17 lines · Matthew Garrett
Quoted 3 lines
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
Yeah, ok. We probably do need to figure this out.
(Cc:ing Rebecca to see how this got handled on Droid)
The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.
Quoted 5 lines
Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?
Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?
Or only during opportunistic suspends while a call is in progress?
Does it know when a call is in progress?
Does Android use forced suspends?
If it does, are they supposed to shut down the codec?
Alan Stern
Quoted 17 lines · Matthew Garrett
Quoted 3 lines
Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?
Yeah, ok. We probably do need to figure this out.
(Cc:ing Rebecca to see how this got handled on Droid)
The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.
Quoted 5 lines
Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?
Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?
Or only during opportunistic suspends while a call is in progress?
Does it know when a call is in progress?
Does Android use forced suspends?
If it does, are they supposed to shut down the codec?
Alan Stern
Quoted 6 lines · Mark Brown
Quoted 2 lines
In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.
It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.
Then the underlying problem should be solved -- hopefully in a nice, system-independent way. But I'm still trying to understand exactly what that underlying problem _is_.
That means understanding when the codec needs to be shut down and when it doesn't, and knowing how much of this information is available to the driver.
Quoted 2 lines
When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.
One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.
For this reason I don't see how using runtime PM instead of suspend blockers would solve anything.
Alan Stern
Quoted 6 lines · Mark Brown
Quoted 2 lines
In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.
It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.
Then the underlying problem should be solved -- hopefully in a nice, system-independent way. But I'm still trying to understand exactly what that underlying problem _is_.
That means understanding when the codec needs to be shut down and when it doesn't, and knowing how much of this information is available to the driver.
Quoted 2 lines
When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.
One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.
For this reason I don't see how using runtime PM instead of suspend blockers would solve anything.
Alan Stern
Quoted 4 lines · Alan Stern
Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?
Or only during opportunistic suspends while a call is in progress?
The latter is obviously preferable...
Quoted 1 line
Does it know when a call is in progress?
Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.
Quoted 1 line
Does Android use forced suspends?
No.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines · Alan Stern
Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?
Or only during opportunistic suspends while a call is in progress?
The latter is obviously preferable...
Quoted 1 line
Does it know when a call is in progress?
Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.
Quoted 1 line
Does Android use forced suspends?
No.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Alan Stern
One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.
Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Alan Stern
One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.
Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines · Alan Stern
Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?
Or only during opportunistic suspends while a call is in progress?
I think for simplicity and maximum flexibility we should just ignore the reason for suspend here, if I'm adding support for this in the drivers the suspend reason is not going to be terribly useful and it makes the feature more widely useful should people come up with other applications.
Note that we already have advanced runtime PM for embedded audio which will drive modern CODECs into full off state when the device is idle anyway, independently of any suspend or runtime PM that the system does. Older CODECs need their bias levels maintaining but we can ignore the difference there from this point of view.
Quoted 1 line
Does it know when a call is in progress?
Not at present. This is relatively straightforward to add within ASoC, especially for analogue links, if not completely trivial. Digital basebands are a bit more fun but not insurmountable (and need cleaning up anyway, there's some ongoing work which should hit soon).
We currently drive everything into off state when we're told to suspend since it's the right thing to do for most non-phone devices. We'll still need to drive some of the system into an off state (eg, some of the drivers in the CPU) even when this is handled.
Quoted 1 line
Does Android use forced suspends?
Pass, but it's not been an issue users have raised with me - but then we can't tell why the suspend happens and need to handle opportunistic suspend anyway.
Quoted 1 line
If it does, are they supposed to shut down the codec?
I suspect it's a non-issue; if we're not actually using audio then ASoC will drive a modern CODEC into power off anyway as part of its runtime PM. However, I believe some non-Android phone stacks are doing something along that line.