Suspend block api (version 8)
Subsystems (6)
cover Suspend block api (version 8)
This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.
--
Arve Hjønnevåg <[email protected]>
PATCH 1/8 PM: Opportunistic suspend support.
Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android. The problem is that to save maximum amount of energy all system hardware components need to be in the lowest-power states available for as long as reasonably possible, but at the same time the system must always respond to certain events, regardless of the current state of the hardware.
The first goal can be achieved either by using device runtime PM and cpuidle to put all hardware into low-power states, transparently from the user space point of view, or by suspending the whole system. However, system suspend, in its current form, does not guarantee that the events of interest will always be responded to, since wakeup events (events that wake the CPU from idle and the system from suspend) that occur right after initiating suspend will not be processed until another possibly unrelated event wakes the system up again.
On hardware where idle can enter the same power state as suspend, idle combined with runtime PM can be used, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. There also are systems where some devices cannot be put into low-power states without suspending the entire system (or the low-power states available to them without suspending the entire system are substantially shallower than the low-power states they are put into when the entire system is suspended), so the system has to be suspended as a whole to achieve the maximum energy savings.
To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing work that's immediately useful to the user, called opportunistic suspend.
For this purpose introduce the suspend blockers framework allowing the kernel's power management subsystem to decide when it is desirable to suspend the system (i.e. when the system is not doing anything the user really cares about at the moment and therefore it may be suspended). Add an API that that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.
Add /sys/power/policy that selects the behavior 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 | 129 +++++++++++ include/linux/suspend.h | 1 + include/linux/suspend_blocker.h | 74 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 128 ++++++++++- kernel/power/opportunistic_suspend.c | 298 +++++++++++++++++++++++++ kernel/power/power.h | 9 + kernel/power/suspend.c | 3 +- 9 files changed, 651 insertions(+), 8 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/opportunistic_suspend.c
Documentation/power/opportunistic-suspend.txt new file +129 -0
@@ -0,0 +1,129 @@ +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_unregister() +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, name); +} + +If the suspend_blocker variable is allocated statically, +DEFINE_SUSPEND_BLOCKER() should be used to initialize it, for example: + +static DEFINE_SUSPEND_BLOCKER(blocker, name); + +and suspend_blocker_register(&blocker) has to be called to make the suspend +blocker usable. + +Before freeing the memory in which a suspend_blocker variable is located, +suspend_blocker_unregister() must be called, for instance: + +uninit() { + suspend_blocker_unregister(&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.h +1 -0
@@ -6,6 +6,7 @@#include <linux/init.h> #include <linux/pm.h> #include <linux/mm.h> +#include <linux/suspend_blocker.h> #include <asm/errno.h> #if defined(CONFIG_PM_SLEEP ) && defined(CONFIG_VT ) && defined(CONFIG_VT_CONSOLE )
include/linux/suspend_blocker.h new file +74 -0
74 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 "Opportunistic suspend" + depends on SUSPEND + 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) += opportunistic_suspend.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 +121 -7
192 lines not on this page · raw message
kernel/power/opportunistic_suspend.c new file +298 -0
298 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 + +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +/* kernel/power/opportunistic_suspend.c */ +extern int opportunistic_suspend_state (suspend_state_t state); +extern bool opportunistic_suspend_valid_state (suspend_state_t state); +extern void __init opportunistic_suspend_init (void ); +#else +static inline void opportunistic_suspend_init (void ) {} +#endif
kernel/power/suspend.c +2 -1
@@ -20,6 +20,7 @@#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 +158,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 (); }
Signature · 6 lines
1.6.5.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 1/8 PM: Opportunistic suspend support.
In reply to Arve HjønnevågPower management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android. The problem is that to save maximum amount of energy all system hardware components need to be in the lowest-power states available for as long as reasonably possible, but at the same time the system must always respond to certain events, regardless of the current state of the hardware.
The first goal can be achieved either by using device runtime PM and cpuidle to put all hardware into low-power states, transparently from the user space point of view, or by suspending the whole system. However, system suspend, in its current form, does not guarantee that the events of interest will always be responded to, since wakeup events (events that wake the CPU from idle and the system from suspend) that occur right after initiating suspend will not be processed until another possibly unrelated event wakes the system up again.
On hardware where idle can enter the same power state as suspend, idle combined with runtime PM can be used, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. There also are systems where some devices cannot be put into low-power states without suspending the entire system (or the low-power states available to them without suspending the entire system are substantially shallower than the low-power states they are put into when the entire system is suspended), so the system has to be suspended as a whole to achieve the maximum energy savings.
To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing work that's immediately useful to the user, called opportunistic suspend.
For this purpose introduce the suspend blockers framework allowing the kernel's power management subsystem to decide when it is desirable to suspend the system (i.e. when the system is not doing anything the user really cares about at the moment and therefore it may be suspended). Add an API that that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.
Add /sys/power/policy that selects the behavior 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 | 129 +++++++++++ include/linux/suspend.h | 1 + include/linux/suspend_blocker.h | 74 ++++++ kernel/power/Kconfig | 16 ++ kernel/power/Makefile | 1 + kernel/power/main.c | 128 ++++++++++- kernel/power/opportunistic_suspend.c | 298 +++++++++++++++++++++++++ kernel/power/power.h | 9 + kernel/power/suspend.c | 3 +- 9 files changed, 651 insertions(+), 8 deletions(-) create mode 100644 Documentation/power/opportunistic-suspend.txt create mode 100755 include/linux/suspend_blocker.h create mode 100644 kernel/power/opportunistic_suspend.c
Documentation/power/opportunistic-suspend.txt new file +129 -0
@@ -0,0 +1,129 @@ +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_unregister() +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, name); +} + +If the suspend_blocker variable is allocated statically, +DEFINE_SUSPEND_BLOCKER() should be used to initialize it, for example: + +static DEFINE_SUSPEND_BLOCKER(blocker, name); + +and suspend_blocker_register(&blocker) has to be called to make the suspend +blocker usable. + +Before freeing the memory in which a suspend_blocker variable is located, +suspend_blocker_unregister() must be called, for instance: + +uninit() { + suspend_blocker_unregister(&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.h +1 -0
@@ -6,6 +6,7 @@#include <linux/init.h> #include <linux/pm.h> #include <linux/mm.h> +#include <linux/suspend_blocker.h> #include <asm/errno.h> #if defined(CONFIG_PM_SLEEP ) && defined(CONFIG_VT ) && defined(CONFIG_VT_CONSOLE )
include/linux/suspend_blocker.h new file +74 -0
74 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 "Opportunistic suspend" + depends on SUSPEND + 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) += opportunistic_suspend.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 +121 -7
192 lines not on this page · raw message
kernel/power/opportunistic_suspend.c new file +298 -0
298 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 + +#ifdef CONFIG_OPPORTUNISTIC_SUSPEND +/* kernel/power/opportunistic_suspend.c */ +extern int opportunistic_suspend_state (suspend_state_t state); +extern bool opportunistic_suspend_valid_state (suspend_state_t state); +extern void __init opportunistic_suspend_init (void ); +#else +static inline void opportunistic_suspend_init (void ) {} +#endif
kernel/power/suspend.c +2 -1
@@ -20,6 +20,7 @@#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 +158,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 (); }
Signature · 1 line
1.6.5.1
PATCH 2/8 PM: suspend_block: Add driver to access suspend blockers from user-space
Add a misc device, "suspend_blocker", that allows user-space processes to block automatic suspend.
Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring. There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name. Closing the device special file causes the suspend blocker to be destroyed.
For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.
By careful use of suspend blockers in drivers and user space system code, one can arrange for the system to stay awake for extremely short periods of time in reaction to events, rapidly returning to a fully suspended state.
--- Documentation/ioctl/ioctl-number.txt | 3 +- Documentation/power/opportunistic-suspend.txt | 27 +++++ include/linux/suspend_ioctls.h | 4 + kernel/power/Kconfig | 7 ++ kernel/power/Makefile | 1 + kernel/power/user_suspend_blocker.c | 143 +++++++++++++++++++++++++ 6 files changed, 184 insertions(+), 1 deletions(-) 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 +27 -0
@@ -127,3 +127,30 @@ if (list_empty(&state->pending_work)) suspend_unblock(&state->suspend_blocker); else suspend_block(&state->suspend_blocker); + +User space API +============== + +To create a suspend blocker from user space, open the suspend_blocker special +device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd); + +If the first ioctl called is not SUSPEND_BLOCKER_IOCTL_SET_NAME the suspend +blocker will get the default name "(userspace)".
include/linux/suspend_ioctls.h +4 -0
@@ -30,4 +30,8 @@ struct resume_swap_area {#define SNAPSHOT_ALLOC_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 20, __kernel_loff_t)#define SNAPSHOT_IOC_MAXNR 20 +#define SUSPEND_BLOCKER_IOCTL_SET_NAME (len) _IOC(_IOC_WRITE, 's', 0, len) +#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1) +#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 2) +#endif /* _LINUX_SUSPEND_IOCTLS_H */
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 USER_SUSPEND_BLOCKERS + bool "User space suspend blockers" + depends on OPPORTUNISTIC_SUSPEND + ---help--- + User space suspend blockers API. Creates a misc device allowing user + space to create, use and destroy suspend blockers. + 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) += opportunistic_suspend.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 +143 -0
143 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 automatic suspend.
Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring. There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name. Closing the device special file causes the suspend blocker to be destroyed.
For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.
By careful use of suspend blockers in drivers and user space system code, one can arrange for the system to stay awake for extremely short periods of time in reaction to events, rapidly returning to a fully suspended state.
--- Documentation/ioctl/ioctl-number.txt | 3 +- Documentation/power/opportunistic-suspend.txt | 27 +++++ include/linux/suspend_ioctls.h | 4 + kernel/power/Kconfig | 7 ++ kernel/power/Makefile | 1 + kernel/power/user_suspend_blocker.c | 143 +++++++++++++++++++++++++ 6 files changed, 184 insertions(+), 1 deletions(-) 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 +27 -0
@@ -127,3 +127,30 @@ if (list_empty(&state->pending_work)) suspend_unblock(&state->suspend_blocker); else suspend_block(&state->suspend_blocker); + +User space API +============== + +To create a suspend blocker from user space, open the suspend_blocker special +device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd); + +If the first ioctl called is not SUSPEND_BLOCKER_IOCTL_SET_NAME the suspend +blocker will get the default name "(userspace)".
include/linux/suspend_ioctls.h +4 -0
@@ -30,4 +30,8 @@ struct resume_swap_area {#define SNAPSHOT_ALLOC_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 20, __kernel_loff_t)#define SNAPSHOT_IOC_MAXNR 20 +#define SUSPEND_BLOCKER_IOCTL_SET_NAME (len) _IOC(_IOC_WRITE, 's', 0, len) +#define SUSPEND_BLOCKER_IOCTL_BLOCK _IO('s', 1) +#define SUSPEND_BLOCKER_IOCTL_UNBLOCK _IO('s', 2) +#endif /* _LINUX_SUSPEND_IOCTLS_H */
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 USER_SUSPEND_BLOCKERS + bool "User space suspend blockers" + depends on OPPORTUNISTIC_SUSPEND + ---help--- + User space suspend blockers API. Creates a misc device allowing user + space to create, use and destroy suspend blockers. + 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) += opportunistic_suspend.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 +143 -0
143 lines not on this page · raw message
Signature · 1 line
1.6.5.1
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 | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
kernel/power/process.c +9 -2
@@ -38,6 +38,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 +64,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 +90,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 3/8 PM: suspend_block: Abort task freezing if a suspend_blocker is active.
In reply to Arve HjønnevågIf 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 | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
kernel/power/process.c +9 -2
@@ -38,6 +38,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 +64,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 +90,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 · 1 line
1.6.5.1
PATCH 4/8 PM: suspend_block: Add debugfs file
Report active and inactive suspend blockers in/sys/kernel/debug/suspend_blockers.
--- kernel/power/opportunistic_suspend.c | 43 +++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-)
kernel/power/opportunistic_suspend.c +42 -1
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/rtc.h> #include <linux/suspend.h> +#include <linux/debugfs.h> #include "power.h"
@@ -151,7 +152,8 @@ EXPORT_SYMBOL(suspend_blocker_register);/** * suspend_blocker_init - Initialize a suspend blocker's name and register it. * @blocker: 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_unregister().
@@ -296,3 +298,42 @@ void __init opportunistic_suspend_init(void)suspend_block (&main_suspend_blocker);suspend_blocker_register (&unknown_wakeup); } + +static struct dentry *suspend_blocker_stats_dentry; + +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 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, +}; + +static int __init suspend_blocker_debugfs_init (void ) +{ + suspend_blocker_stats_dentry =debugfs_create_file ("suspend_blockers" , +S_IRUGO ,NULL ,NULL , &suspend_blocker_stats_fops); +return 0 ; +} + +postcore_initcall (suspend_blocker_debugfs_init);
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
In reply to Arve HjønnevågReport active and inactive suspend blockers in/sys/kernel/debug/suspend_blockers.
--- kernel/power/opportunistic_suspend.c | 43 +++++++++++++++++++++++++++++++++- 1 files changed, 42 insertions(+), 1 deletions(-)
kernel/power/opportunistic_suspend.c +42 -1
@@ -17,6 +17,7 @@#include <linux/module.h> #include <linux/rtc.h> #include <linux/suspend.h> +#include <linux/debugfs.h> #include "power.h"
@@ -151,7 +152,8 @@ EXPORT_SYMBOL(suspend_blocker_register);/** * suspend_blocker_init - Initialize a suspend blocker's name and register it. * @blocker: 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_unregister().
@@ -296,3 +298,42 @@ void __init opportunistic_suspend_init(void)suspend_block (&main_suspend_blocker);suspend_blocker_register (&unknown_wakeup); } + +static struct dentry *suspend_blocker_stats_dentry; + +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 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, +}; + +static int __init suspend_blocker_debugfs_init (void ) +{ + suspend_blocker_stats_dentry =debugfs_create_file ("suspend_blockers" , +S_IRUGO ,NULL ,NULL , &suspend_blocker_stats_fops); +return 0 ; +} + +postcore_initcall (suspend_blocker_debugfs_init);
Signature · 1 line
1.6.5.1
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 | 27 +++++- kernel/power/Kconfig | 8 ++ kernel/power/opportunistic_suspend.c | 195 +++++++++++++++++++++++++++++++++- kernel/power/power.h | 5 + kernel/power/suspend.c | 4 +- 5 files changed, 235 insertions(+), 4 deletions(-)
include/linux/suspend_blocker.h +26 -1
@@ -17,11 +17,35 @@#define _LINUX_SUSPEND_BLOCKER_H#include <linux/list.h> +#include <linux/ktime.h> + +/** +* struct suspend_blocker_stats - statistics for a suspend blocker +* +* @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. +*/ +struct suspend_blocker_stats { +#ifdef CONFIG_SUSPEND_BLOCKER_STATS +unsigned int count; +unsigned int wakeup_count; +ktime_t total_time; +ktime_t prevent_suspend_time; +ktime_t max_time; +ktime_t last_time; +#endif +};/** * 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 and active state and statistics. * @name: Suspend blocker name used for debugging. * * When a suspend_blocker is active it prevents the system from entering
@@ -34,6 +58,7 @@ struct suspend_blocker {struct list_head link;int flags;const char *name; +struct suspend_blocker_stats stat;#endif };
kernel/power/Kconfig +8 -0
@@ -146,6 +146,14 @@ 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 blockers statistics" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + Use /sys/kernel/debug/suspend_blockers to report suspend blockers + statistics. + config USER_SUSPEND_BLOCKERS bool "User space suspend blockers" depends on OPPORTUNISTIC_SUSPEND
kernel/power/opportunistic_suspend.c +193 -2
257 lines not on this page · raw message
kernel/power/power.h +5 -0
@@ -245,3 +245,8 @@ extern void __init opportunistic_suspend_init(void);#else static inline void opportunistic_suspend_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
@@ -158,8 +158,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 (); }
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
In reply to Arve HjønnevågReport suspend block stats in /sys/kernel/debug/suspend_blockers.
--- include/linux/suspend_blocker.h | 27 +++++- kernel/power/Kconfig | 8 ++ kernel/power/opportunistic_suspend.c | 195 +++++++++++++++++++++++++++++++++- kernel/power/power.h | 5 + kernel/power/suspend.c | 4 +- 5 files changed, 235 insertions(+), 4 deletions(-)
include/linux/suspend_blocker.h +26 -1
@@ -17,11 +17,35 @@#define _LINUX_SUSPEND_BLOCKER_H#include <linux/list.h> +#include <linux/ktime.h> + +/** +* struct suspend_blocker_stats - statistics for a suspend blocker +* +* @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. +*/ +struct suspend_blocker_stats { +#ifdef CONFIG_SUSPEND_BLOCKER_STATS +unsigned int count; +unsigned int wakeup_count; +ktime_t total_time; +ktime_t prevent_suspend_time; +ktime_t max_time; +ktime_t last_time; +#endif +};/** * 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 and active state and statistics. * @name: Suspend blocker name used for debugging. * * When a suspend_blocker is active it prevents the system from entering
@@ -34,6 +58,7 @@ struct suspend_blocker {struct list_head link;int flags;const char *name; +struct suspend_blocker_stats stat;#endif };
kernel/power/Kconfig +8 -0
@@ -146,6 +146,14 @@ 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 blockers statistics" + depends on OPPORTUNISTIC_SUSPEND + default y + ---help--- + Use /sys/kernel/debug/suspend_blockers to report suspend blockers + statistics. + config USER_SUSPEND_BLOCKERS bool "User space suspend blockers" depends on OPPORTUNISTIC_SUSPEND
kernel/power/opportunistic_suspend.c +193 -2
257 lines not on this page · raw message
kernel/power/power.h +5 -0
@@ -245,3 +245,8 @@ extern void __init opportunistic_suspend_init(void);#else static inline void opportunistic_suspend_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
@@ -158,8 +158,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 (); }
Signature · 1 line
1.6.5.1
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/opportunistic_suspend.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_stats - statistics for a suspend blocker
@@ -62,6 +63,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 #define __SUSPEND_BLOCKER_INITIALIZER (blocker_name) \ { .name = #blocker_name, }
@@ -78,6 +111,14 @@ extern void suspend_unblock(struct suspend_blocker *blocker);extern bool suspend_blocker_is_active (struct suspend_blocker *blocker);extern 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 #define DEFINE_SUSPEND_BLOCKER (blocker, name) \
@@ -94,6 +135,32 @@ static inline bool suspend_blocker_is_active(struct suspend_blocker *bl)return false; }static inline bool suspend_is_blocked (void ) {return false; } + +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/opportunistic_suspend.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 6/8 PM: Add suspend blocking work.
In reply to Arve HjønnevågAllow 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/opportunistic_suspend.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_stats - statistics for a suspend blocker
@@ -62,6 +63,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 #define __SUSPEND_BLOCKER_INITIALIZER (blocker_name) \ { .name = #blocker_name, }
@@ -78,6 +111,14 @@ extern void suspend_unblock(struct suspend_blocker *blocker);extern bool suspend_blocker_is_active (struct suspend_blocker *blocker);extern 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 #define DEFINE_SUSPEND_BLOCKER (blocker, name) \
@@ -94,6 +135,32 @@ static inline bool suspend_blocker_is_active(struct suspend_blocker *bl)return false; }static inline bool suspend_is_blocked (void ) {return false; } + +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/opportunistic_suspend.c +109 -0
112 lines not on this page · raw message
Signature · 1 line
1.6.5.1
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.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_unregister (&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_unregister (&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 8/8 power_supply: Block suspend while power supply change notifications are pending
When 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.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
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.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 · 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.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_unregister (&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_unregister (&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
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 11 lines · Arve Hjønnevåg
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +9
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call:
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt +10
-0+ + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);
Urgh, please let the open() be BLOCK, the close() be UNBLOCK, and keep the SET_NAME thing if you really care.
_______________________________________________
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 Arve HjønnevågQuoted 11 lines · Arve Hjønnevåg
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +9
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call:
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt +10
-0+ + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);
Urgh, please let the open() be BLOCK, the close() be UNBLOCK, and keep the SET_NAME thing if you really care.
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 16 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +
Quoted 9 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
+ ioctl(fd,
SUSPEND_BLOCKER_IOCTL_UNBLOCK);Documentation/power/opportunistic-suspend.txt +4
-0+ +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
That would be very inefficient.
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 Peter Zijlstra2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 16 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +
Quoted 9 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
+ ioctl(fd,
SUSPEND_BLOCKER_IOCTL_UNBLOCK);Documentation/power/opportunistic-suspend.txt +4
-0+ +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
That would be very inefficient.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 28 lines · Arve Hjønnevåg
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 16 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 9 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 1 line
That would be very inefficient.
How so? Anyway, since you admitted this thing isn't needed at all, I say we remove it altogether.
_______________________________________________
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 Arve HjønnevågQuoted 28 lines · Arve Hjønnevåg
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 16 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 9 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 1 line
That would be very inefficient.
How so? Anyway, since you admitted this thing isn't needed at all, I say we remove it altogether.
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 29 lines · Arve Hjønnevåg
Quoted 28 lines
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 26 lines · Arve Hjønnevåg
Quoted 11 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +9
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call:Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt +10
-0+ + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 5 lines
Quoted 1 line
That would be very inefficient.
How so? Anyway, since you admitted this thing isn't needed at all, I say we remove it altogether.
I also said it was useful. I don't think we should drop it just because we can work around its absence.
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 Peter Zijlstra2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 29 lines · Arve Hjønnevåg
Quoted 28 lines
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 26 lines · Arve Hjønnevåg
Quoted 11 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +9
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call:Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt +10
-0+ + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 5 lines
Quoted 1 line
That would be very inefficient.
How so? Anyway, since you admitted this thing isn't needed at all, I say we remove it altogether.
I also said it was useful. I don't think we should drop it just because we can work around its absence.
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 Arve HjønnevågQuoted 28 lines · On Wed, 26 May 2010 03:47:27 -0700 Arve Hjønnevåg <[email protected]> wrote:
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 16 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 9 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
+ ioctl(fd,
SUSPEND_BLOCKER_IOCTL_UNBLOCK);Documentation/power/opportunistic-suspend.txt +4
-0+ +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 2 lines
That would be very inefficient.
Also I think it is intended to enforce named suspend blockers. (For debugging/accounting purposes).
Cheers,
Flo
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Arve HjønnevågQuoted 28 lines · On Wed, 26 May 2010 03:47:27 -0700 Arve Hjønnevåg <[email protected]> wrote:
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 17 lines · Arve Hjønnevåg
Quoted 16 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 9 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
+ ioctl(fd,
SUSPEND_BLOCKER_IOCTL_UNBLOCK);Documentation/power/opportunistic-suspend.txt +4
-0+ +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 2 lines
That would be very inefficient.
Also I think it is intended to enforce named suspend blockers. (For debugging/accounting purposes).
Cheers,
Flo
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 31 lines · Florian Mickler
Quoted 28 lines · On Wed, 26 May 2010 03:47:27 -0700 Arve Hjønnevåg <[email protected]> wrote:
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 26 lines · Arve Hjønnevåg
Quoted 11 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +9
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call:Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt +10
-0+ + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 5 lines
Quoted 2 lines
That would be very inefficient.
Also I think it is intended to enforce named suspend blockers. (For debugging/accounting purposes).
I don't think the code as proposed mandates you SET_NAME, and I didn't propose killing that off, you can still SET_NAME after you open() and acquire the thing.
Anyway, the whole point is moot since its simply not needed at all.
_______________________________________________
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 Florian MicklerQuoted 31 lines · Florian Mickler
Quoted 28 lines · On Wed, 26 May 2010 03:47:27 -0700 Arve Hjønnevåg <[email protected]> wrote:
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 26 lines · Arve Hjønnevåg
Quoted 11 lines
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +9
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call:Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 10 lines
Documentation/power/opportunistic-suspend.txt +10
-0+ + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
Quoted 5 lines
Quoted 2 lines
That would be very inefficient.
Also I think it is intended to enforce named suspend blockers. (For debugging/accounting purposes).
I don't think the code as proposed mandates you SET_NAME, and I didn't propose killing that off, you can still SET_NAME after you open() and acquire the thing.
Anyway, the whole point is moot since its simply not needed at all.
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Peter ZijlstraQuoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve Hjønnevåg
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +
Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAME wouldn't serve any purpose in that case.
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
Thanks,
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 4 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
If he wants to collect stats about misbehaving code then presumably he needs reliable stats. Arbitary user set names are not reliable and judging by app vendor behaviour in the proprietary space with other such examples they will actively name their blockers in a manner specifically intended to hide the cause so as to 'reduce support costs'.
Its a waste of memory (especially if I create a million of them with a long name for fun).
It's all an economic system, proprietary app vendors are in it to make money, some will therefore game the system and the rest will be forced to follow to keep their playing field fair.
Alan
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 5 lines · Alan Cox
Quoted 4 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
Quoted 8 lines
If he wants to collect stats about misbehaving code then presumably he needs reliable stats. Arbitary user set names are not reliable and judging by app vendor behaviour in the proprietary space with other such examples they will actively name their blockers in a manner specifically intended to hide the cause so as to 'reduce support costs'.
Its a waste of memory (especially if I create a million of them with a long name for fun).
You are limited to one per open fd of the device, and a max name size which could be further shrunk to something pretty small (32?) if desired. The device node interface came about after discussions last year and concerns that userspace could create an unbounded number of suspend blockers.
Quoted 3 lines
It's all an economic system, proprietary app vendors are in it to make money, some will therefore game the system and the rest will be forced to follow to keep their playing field fair.
Untrusted (non-system) code can't directly access the device node from userspace in the Android world -- so directly created suspend blockers from userspace are only created by a couple system processes (3-4 typically). Applications are sandboxed by UID and there is (much more) per-application accounting in the userspace application manager process (other resource consumption such as sensors, CPU, etc is tracked here as well).
For suspend blockers created by drivers and by trusted userspace processes, having a meaningful name significantly helps statistics gathering.
Brian
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 3 lines
desired. The device node interface came about after discussions last year and concerns that userspace could create an unbounded number of suspend blockers.
Surely you only need one block per task (or better yet one expression of latency per task). If not can you explain why a setup which has a per task expression of latency needs (and a 'hard limit' set which you can't then bump back down except as root) isn't enough ?
I'd really like this lot to also fix the hard real time and power management problem we have today and to try an fix the "suspend is special and different" mentality in the kernel, which is getting less and less true on a variety of chips.
Quoted 6 lines
Quoted 3 lines
It's all an economic system, proprietary app vendors are in it to make money, some will therefore game the system and the rest will be forced to follow to keep their playing field fair.
Untrusted (non-system) code can't directly access the device node from userspace in the Android world -- so directly created suspend blockers
Great - but the world is not Android and even if they can't access it directly but get passed a handle they can play.
Quoted 3 lines
For suspend blockers created by drivers and by trusted userspace processes, having a meaningful name significantly helps statistics gathering.
By drivers I agree but in the driver case the cost is minimal because there should not be many and it is bounded clearly. Again I really think 'suspend blocking' is the wrong expression.
A driver needs to express
'Don't go below this latency'
and
'Don't go below this state'
This is more generic and helps our power management do the right thing on all boxes. For example a serial port can meaningfully say 'I want X latency worst case' based upon the fact the fifo is 64 bytes and the user space just asked for 115,200 baud.
The don't go below for states out of which the device must wake but cannot. Eg if your device is being told by user space to set wake on lan and can only wake on lan from a higher state than 'off' it needs to say so.
Alan
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 5 lines · Alan Cox
Quoted 3 lines
desired. The device node interface came about after discussions last year and concerns that userspace could create an unbounded number of suspend blockers.
Surely you only need one block per task (or better yet one expression of
No, many suspend blockers protect data, not tasks. We block suspend when there are unprocessed input events in the kernel queue. User-space then blocks suspend before reading those events, and it blocks suspend using a different suspend blocker when its queue of processed events become not-empty.
Quoted 48 lines
latency per task). If not can you explain why a setup which has a per task expression of latency needs (and a 'hard limit' set which you can't then bump back down except as root) isn't enough ?
I'd really like this lot to also fix the hard real time and power management problem we have today and to try an fix the "suspend is special and different" mentality in the kernel, which is getting less and less true on a variety of chips.
Quoted 6 lines
Quoted 3 lines
It's all an economic system, proprietary app vendors are in it to make money, some will therefore game the system and the rest will be forced to follow to keep their playing field fair.
Untrusted (non-system) code can't directly access the device node from userspace in the Android world -- so directly created suspend blockers
Great - but the world is not Android and even if they can't access it directly but get passed a handle they can play.
Quoted 3 lines
For suspend blockers created by drivers and by trusted userspace processes, having a meaningful name significantly helps statistics gathering.
By drivers I agree but in the driver case the cost is minimal because there should not be many and it is bounded clearly. Again I really think 'suspend blocking' is the wrong expression.
A driver needs to express
'Don't go below this latency'
and
'Don't go below this state'
This is more generic and helps our power management do the right thing on all boxes. For example a serial port can meaningfully say 'I want X latency worst case' based upon the fact the fifo is 64 bytes and the user space just asked for 115,200 baud.
The don't go below for states out of which the device must wake but cannot. Eg if your device is being told by user space to set wake on lan and can only wake on lan from a higher state than 'off' it needs to say so.
Alan
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 5 lines
No, many suspend blockers protect data, not tasks. We block suspend when there are unprocessed input events in the kernel queue. User-space then blocks suspend before reading those events, and it blocks suspend using a different suspend blocker when its queue of processed events become not-empty.
That sounds to me like higher level user space implementation plus a kernel driver imposing a power level limit.
The fact your suspend blockers as a user construct are tied to data isn't neccessarily what the kernel needs to provide.
That aside we could equally provide latency constraints using a file handle based semantic like your suspend blockers. That would make it easier to do suspend blockers in those terms and provide an interface that can be used for more elegant expression of desire.
I suggested setpidle() to keep resources tied and bounded to tasks and to make SMP work nicely. I have no problem with the latency constraints being floating file handles, although some thought would be needed as to how that is then mapped to SMP.
The problem with an arbitary mapping is that if I have an 8 processor system I might want to use the latency info to stuff tasks onto different cores so that most of them are in a deeper idle than the others. I can't do that unless I know who the latency constraint applies to. But hopefully someone in scheduler land has bright ideas - eg could we keep a per task variable and adjust it when people open/close blockers with the assumption being anyone who has open a given constraint is bound by it and nobody else is.
Might need it to be a constraintfs so you can open other people's constraints but all the framework for that is there in the kernel too.
Alan
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Alan CoxQuoted 5 lines · Alan Cox
Quoted 4 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
Quoted 8 lines
If he wants to collect stats about misbehaving code then presumably he needs reliable stats. Arbitary user set names are not reliable and judging by app vendor behaviour in the proprietary space with other such examples they will actively name their blockers in a manner specifically intended to hide the cause so as to 'reduce support costs'.
Its a waste of memory (especially if I create a million of them with a long name for fun).
Well, I won't argue with that. :-)
Quoted 3 lines
It's all an economic system, proprietary app vendors are in it to make money, some will therefore game the system and the rest will be forced to follow to keep their playing field fair.
Good point.
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve HjønnevÃ¥g
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAMEwouldn't serve any purpose in that case.
Quoted 8 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
There's also Arve's other main point: These suspend blockers tend to get used quite a lot. Opening and closing a file each time has much higher overhead than a simple ioctl.
All these topics have been covered earlier in this discussion. Peter should go back and read the emails in the linux-pm archive.
Alan Stern
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve HjønnevÃ¥g
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAMEwouldn't serve any purpose in that case.
Quoted 8 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
There's also Arve's other main point: These suspend blockers tend to get used quite a lot. Opening and closing a file each time has much higher overhead than a simple ioctl.
All these topics have been covered earlier in this discussion. Peter should go back and read the emails in the linux-pm archive.
Alan Stern
Re: [linux-pm] [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Rafael J. WysockiQuoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve HjønnevÃ¥g
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAMEwouldn't serve any purpose in that case.
Quoted 8 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
There's also Arve's other main point: These suspend blockers tend to get used quite a lot. Opening and closing a file each time has much higher overhead than a simple ioctl.
All these topics have been covered earlier in this discussion. Peter should go back and read the emails in the linux-pm archive.
Alan Stern
Re: [linux-pm] [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
Quoted 40 lines · Alan Stern
Quoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve HjønnevÃ¥g
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAMEwouldn't serve any purpose in that case.Quoted 8 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
Quoted 6 lines
There's also Arve's other main point: These suspend blockers tend to get used quite a lot. Opening and closing a file each time has much higher overhead than a simple ioctl.
All these topics have been covered earlier in this discussion. Peter should go back and read the emails in the linux-pm archive.
Yeah.
Although with a reference counter the special device file won't be necessary.
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Alan SternQuoted 40 lines · Alan Stern
Quoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve HjønnevÃ¥g
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAMEwouldn't serve any purpose in that case.Quoted 8 lines
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
Quoted 6 lines
There's also Arve's other main point: These suspend blockers tend to get used quite a lot. Opening and closing a file each time has much higher overhead than a simple ioctl.
All these topics have been covered earlier in this discussion. Peter should go back and read the emails in the linux-pm archive.
Yeah.
Although with a reference counter the special device file won't be necessary.
Rafael
Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space
In reply to Peter ZijlstraQuoted 17 lines · Peter Zijlstra
Quoted 16 lines · Arve Hjønnevåg
+To create a suspend blocker from user space, open the
suspend_blockerspecialDocumentation/power/opportunistic-suspend.txt +14
-0+device file: + + fd = open("/dev/suspend_blocker", O_RDWR | O_CLOEXEC); + +then optionally call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_SET_NAME(strlen(name)), name); + +To activate the suspend blocker call: + + ioctl(fd, SUSPEND_BLOCKER_IOCTL_BLOCK); + +To deactivate it call: +
Quoted 8 lines
Documentation/power/opportunistic-suspend.txt if (list_empty(&state->pending_work)) · line 153
Quoted 5 lines
Documentation/power/opportunistic-suspend.txt +5
-0+ ioctl(fd, SUSPEND_BLOCKER_IOCTL_UNBLOCK); + +To destroy the suspend blocker, close the device: + + close(fd);Urgh, please let the
open()be BLOCK, theclose()be UNBLOCK, and keep theSET_NAMEthing if you really care.
SET_NAME wouldn't serve any purpose in that case.
This whole thing is related to the statistics part, which Arve says is essential to him. He wants to collect statistics for each suspend blocker activated and deactivated so that he can tell who's causing problems by blocking suspend too often. The name also is a part of this.
In fact, without the statistics part the whole thing might be implemented as a single reference counter such that suspend would happen when it went down to zero.
Thanks,
Rafael
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 9 lines · On Fri, 21 May 2010, [UTF-8] Arve HjønnevÃ¥g wrote:
The first goal can be achieved either by using device runtime PM and cpuidle to put all hardware into low-power states, transparently from the user space point of view, or by suspending the whole system. However, system suspend, in its current form, does not guarantee that the events of interest will always be responded to, since wakeup events (events that wake the CPU from idle and the system from suspend) that occur right after initiating suspend will not be processed until another possibly unrelated event wakes the system up again.
Minor point of clarification here. I'm not requesting that the patch description be rewritten. But this issue of lost wakeup events is more subtle than it appears.
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
IMO, we should strive to fix the existing type-2 failure modes. However it is worth pointing out that they are basically separate from the suspend-blocker mechanism.
And it might be a good idea to point out somewhere in the patch descriptions that suspend blockers are really meant to handle type-3 wakeup losses.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 9 lines · On Fri, 21 May 2010, [UTF-8] Arve HjønnevÃ¥g wrote:
The first goal can be achieved either by using device runtime PM and cpuidle to put all hardware into low-power states, transparently from the user space point of view, or by suspending the whole system. However, system suspend, in its current form, does not guarantee that the events of interest will always be responded to, since wakeup events (events that wake the CPU from idle and the system from suspend) that occur right after initiating suspend will not be processed until another possibly unrelated event wakes the system up again.
Minor point of clarification here. I'm not requesting that the patch description be rewritten. But this issue of lost wakeup events is more subtle than it appears.
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
IMO, we should strive to fix the existing type-2 failure modes. However it is worth pointing out that they are basically separate from the suspend-blocker mechanism.
And it might be a good idea to point out somewhere in the patch descriptions that suspend blockers are really meant to handle type-3 wakeup losses.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/21 Alan Stern <[email protected]>:
Quoted 42 lines · On Fri, 21 May 2010, [UTF-8] Arve Hjønnevåg wrote:
Quoted 10 lines
The first goal can be achieved either by using device runtime PM and cpuidle to put all hardware into low-power states, transparently from the user space point of view, or by suspending the whole system. However, system suspend, in its current form, does not guarantee that the events of interest will always be responded to, since wakeup events (events that wake the CPU from idle and the system from suspend) that occur right after initiating suspend will not be processed until another possibly unrelated event wakes the system up again.
Minor point of clarification here. I'm not requesting that the patch description be rewritten. But this issue of lost wakeup events is more subtle than it appears.
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
Quoted 8 lines
IMO, we should strive to fix the existing type-2 failure modes. However it is worth pointing out that they are basically separate from the suspend-blocker mechanism.
And it might be a good idea to point out somewhere in the patch descriptions that suspend blockers are really meant to handle type-3 wakeup losses.
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan Stern2010/5/21 Alan Stern <[email protected]>:
Quoted 42 lines · On Fri, 21 May 2010, [UTF-8] Arve Hjønnevåg wrote:
Quoted 10 lines
The first goal can be achieved either by using device runtime PM and cpuidle to put all hardware into low-power states, transparently from the user space point of view, or by suspending the whole system. However, system suspend, in its current form, does not guarantee that the events of interest will always be responded to, since wakeup events (events that wake the CPU from idle and the system from suspend) that occur right after initiating suspend will not be processed until another possibly unrelated event wakes the system up again.
Minor point of clarification here. I'm not requesting that the patch description be rewritten. But this issue of lost wakeup events is more subtle than it appears.
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
Quoted 8 lines
IMO, we should strive to fix the existing type-2 failure modes. However it is worth pointing out that they are basically separate from the suspend-blocker mechanism.
And it might be a good idea to point out somewhere in the patch descriptions that suspend blockers are really meant to handle type-3 wakeup losses.
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 23 lines · Arve Hjønnevåg
Quoted 23 lines
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
Quoted 5 lines
Quoted 2 lines
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 23 lines · Arve Hjønnevåg
Quoted 23 lines
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
Quoted 5 lines
Quoted 2 lines
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Alan Stern
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 31 lines · Alan Stern
Quoted 23 lines · Arve Hjønnevåg
Quoted 23 lines
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
Quoted 5 lines
Quoted 2 lines
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
Quoted 7 lines
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 31 lines · Alan Stern
Quoted 23 lines · Arve Hjønnevåg
Quoted 23 lines
Wakeup events can be lost in at least three different ways:
1. A hardware signal (such as an IRQ) gets ignored.
2. The hardware event occurs, but without effect since the kernel thread that would handle the event has been frozen. The event just ends up sitting in a queue somewhere until something else wakes up the system.
3. The hardware event occurs and the kernel handles it fully, but the event propagates to userspace for further handling and the user program is already frozen.
1 is a hardware configuration failure (for example, it might happen as a result of using edge-triggered IRQs instead of level-triggered) and is outside the scope of this discussion.
2 generally represents a failure of the core PM subsystem, or a failure of some other part of the kernel to use the PM core correctly. In theory we should be able to fix such mistakes. Right now I'm aware of at least one possible failure scenario that could be fixed fairly easily.
Quoted 5 lines
Quoted 2 lines
3 is the type of failure that suspend blockers were really meant to handle, particularly the userspace suspend-blocker API.
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
Quoted 7 lines
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 11 lines · Dmitry Torokhov
Quoted 10 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Alan Stern
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Maybe I'm missing something here... No doubt someone will point it out if I am.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Maybe I'm missing something here... No doubt someone will point it out if I am.
Alan Stern
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 25 lines · Dmitry Torokhov
Quoted 21 lines
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 8 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
I agree that simplifying the user API would be an advantage. Instead of the full-blown suspend-blocker interface, we would need only a way to initiate an opportunistic suspend. For example:
echo opportunistic >/sys/power/state
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 25 lines · Dmitry Torokhov
Quoted 21 lines
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 8 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
I agree that simplifying the user API would be an advantage. Instead of the full-blown suspend-blocker interface, we would need only a way to initiate an opportunistic suspend. For example:
echo opportunistic >/sys/power/state
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 65 lines · Arve Hjønnevåg
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 65 lines · Arve Hjønnevåg
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 82 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 82 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 88 lines · Arve Hjønnevåg
Quoted 82 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 5 lines
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key, or releases the currently held key.
Quoted 8 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Quoted 5 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That does not sound right.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 88 lines · Arve Hjønnevåg
Quoted 82 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 5 lines
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key, or releases the currently held key.
Quoted 8 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Quoted 5 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That does not sound right.
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 91 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 90 lines · Arve Hjønnevåg
Quoted 82 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
If your userpsace is that stupid - sure. However, you can:
Quoted 7 lines
Quoted 3 lines
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Employ reasonable timeout.
Quoted 3 lines
or releases the
currently held key.
Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
Quoted 4 lines
Quoted 4 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
Quoted 8 lines
Quoted 4 lines
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
Quoted 8 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 91 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 90 lines · Arve Hjønnevåg
Quoted 82 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
If your userpsace is that stupid - sure. However, you can:
Quoted 7 lines
Quoted 3 lines
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Employ reasonable timeout.
Quoted 3 lines
or releases the
currently held key.
Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
Quoted 4 lines
Quoted 4 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
Quoted 8 lines
Quoted 4 lines
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
Quoted 8 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 96 lines · Arve Hjønnevåg
Quoted 95 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 93 lines · Arve Hjønnevåg
Quoted 82 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
Quoted 5 lines
Quoted 3 lines
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Employ reasonable timeout.
Timeout for what? Stop trying to suspend altogether, stop scanning for key changes, or a more "reasonable" poll interval?
Quoted 8 lines
Quoted 4 lines
or releases the
currently held key.Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
No it should not. User-space does not know if the key is coming from a keypad driver that needs to actively scan the matrix while keys are pressed.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Quoted 8 lines
Quoted 3 lines
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
A driver prevents suspend if suspend would prevent it from working. For instance, the gpio keypad matrix code prevents suspend when a key is help down, since it has to activly scan the keypad for changes. Only no-keys-pressed versus one-or-more-keys-pressed can be detected with an interrupt.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
Quoted 5 lines
Quoted 1 line
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
If the device implements runtime PM it should already be powered-down if it is not in use.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 96 lines · Arve Hjønnevåg
Quoted 95 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 93 lines · Arve Hjønnevåg
Quoted 82 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
Quoted 5 lines
Quoted 3 lines
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Employ reasonable timeout.
Timeout for what? Stop trying to suspend altogether, stop scanning for key changes, or a more "reasonable" poll interval?
Quoted 8 lines
Quoted 4 lines
or releases the
currently held key.Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
No it should not. User-space does not know if the key is coming from a keypad driver that needs to actively scan the matrix while keys are pressed.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Quoted 8 lines
Quoted 3 lines
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
A driver prevents suspend if suspend would prevent it from working. For instance, the gpio keypad matrix code prevents suspend when a key is help down, since it has to activly scan the keypad for changes. Only no-keys-pressed versus one-or-more-keys-pressed can be detected with an interrupt.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
Quoted 5 lines
Quoted 1 line
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
If the device implements runtime PM it should already be powered-down if it is not in use.
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 11 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 7 lines · Arve Hjønnevåg
Quoted 4 lines
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Employ reasonable timeout.
Timeout for what? Stop trying to suspend altogether, stop scanning for key changes, or a more "reasonable" poll interval?
Stop trying to suspend for a fraction of a second to see if user wants to press another key.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
or releases the
currently held key.
Quoted 7 lines
Quoted 3 lines
Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
No it should not. User-space does not know if the key is coming from a keypad driver that needs to actively scan the matrix while keys are pressed.
OTOH nor does kernel driver know whether system suspend should be blocked while it is scanning. What should happen in I press KEY_SUSPEND? Do we always want to wait till user releases it?
Quoted 32 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Quoted 8 lines
Quoted 3 lines
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
A driver prevents suspend if suspend would prevent it from working. For instance, the gpio keypad matrix code prevents suspend when a key is help down, since it has to activly scan the keypad for changes. Only no-keys-pressed versus one-or-more-keys-pressed can be detected with an interrupt.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
If the device implements runtime PM it should already be powered-down if it is not in use.
It could have been in use but userspace-initiated suspend accelerated it entering low power state.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 11 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 7 lines · Arve Hjønnevåg
Quoted 4 lines
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Employ reasonable timeout.
Timeout for what? Stop trying to suspend altogether, stop scanning for key changes, or a more "reasonable" poll interval?
Stop trying to suspend for a fraction of a second to see if user wants to press another key.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
or releases the
currently held key.
Quoted 7 lines
Quoted 3 lines
Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
No it should not. User-space does not know if the key is coming from a keypad driver that needs to actively scan the matrix while keys are pressed.
OTOH nor does kernel driver know whether system suspend should be blocked while it is scanning. What should happen in I press KEY_SUSPEND? Do we always want to wait till user releases it?
Quoted 32 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Quoted 8 lines
Quoted 3 lines
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
A driver prevents suspend if suspend would prevent it from working. For instance, the gpio keypad matrix code prevents suspend when a key is help down, since it has to activly scan the keypad for changes. Only no-keys-pressed versus one-or-more-keys-pressed can be detected with an interrupt.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
If the device implements runtime PM it should already be powered-down if it is not in use.
It could have been in use but userspace-initiated suspend accelerated it entering low power state.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Employ reasonable timeout.
Timeout for what? Stop trying to suspend altogether, stop scanning for key changes, or a more "reasonable" poll interval?
Stop trying to suspend for a fraction of a second to see if user wants to press another key.
In other words, try to suspend several times a second until it succeeds.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
or releases the
currently held key.Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
Quoted 6 lines
Quoted 3 lines
No it should not. User-space does not know if the key is coming from a keypad driver that needs to actively scan the matrix while keys are pressed.
OTOH nor does kernel driver know whether system suspend should be blocked while it is scanning.
Yes it does, it cannot deliver wakeup keys if it suspends.
Quoted 2 lines
What should happen in I press
KEY_SUSPEND?
Do we always want to wait till user releases it?
If KEY_SUSPEND is part of the keypad matrix, then yes.
Quoted 39 lines
Quoted 39 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Quoted 8 lines
Quoted 3 lines
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
A driver prevents suspend if suspend would prevent it from working. For instance, the gpio keypad matrix code prevents suspend when a key is help down, since it has to activly scan the keypad for changes. Only no-keys-pressed versus one-or-more-keys-pressed can be detected with an interrupt.
Quoted 12 lines
Quoted 8 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
Quoted 6 lines
Quoted 2 lines
If the device implements runtime PM it should already be powered-down if it is not in use.
It could have been in use but userspace-initiated suspend accelerated it entering low power state.
So you are suggesting we should repeatedly try to suspend the whole system to accelerate runtime PM powering down devices? Why not power the device down as soon as it is not in use?
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines
You are missing the point. There are no event pending. The kernel reported the key down event, it was handled, but the keypad driver is still scanning to see if the user presses another key,
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Employ reasonable timeout.
Timeout for what? Stop trying to suspend altogether, stop scanning for key changes, or a more "reasonable" poll interval?
Stop trying to suspend for a fraction of a second to see if user wants to press another key.
In other words, try to suspend several times a second until it succeeds.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
or releases the
currently held key.Userspace consumer should wait for the key release and retract "busy" once event is received and handled.
Quoted 6 lines
Quoted 3 lines
No it should not. User-space does not know if the key is coming from a keypad driver that needs to actively scan the matrix while keys are pressed.
OTOH nor does kernel driver know whether system suspend should be blocked while it is scanning.
Yes it does, it cannot deliver wakeup keys if it suspends.
Quoted 2 lines
What should happen in I press
KEY_SUSPEND?
Do we always want to wait till user releases it?
If KEY_SUSPEND is part of the keypad matrix, then yes.
Quoted 39 lines
Quoted 39 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
2. Wait a tiny bit after last application notified you that it finished processing events.
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Quoted 8 lines
Quoted 3 lines
No, the difference is that if a driver needs to prevent suspend for an extended period of time, you don't have user space continuously polling to see if it can suspend.
Why would a driver, on its own, prevent suspend for extended periods of time? I think that the decision should originate from userspace, kernel is here just to serve the requests.
A driver prevents suspend if suspend would prevent it from working. For instance, the gpio keypad matrix code prevents suspend when a key is help down, since it has to activly scan the keypad for changes. Only no-keys-pressed versus one-or-more-keys-pressed can be detected with an interrupt.
Quoted 12 lines
Quoted 8 lines
Quoted 6 lines
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That does not sound right.
Why doesn't it? If a device implements runtime PM it may chose remain in powered-down mode even if system is awake.
Quoted 6 lines
Quoted 2 lines
If the device implements runtime PM it should already be powered-down if it is not in use.
It could have been in use but userspace-initiated suspend accelerated it entering low power state.
So you are suggesting we should repeatedly try to suspend the whole system to accelerate runtime PM powering down devices? Why not power the device down as soon as it is not in use?
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 5 lines · Dmitry Torokhov
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 8 lines
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
2. Wait a tiny bit after last application notified you that it finished processing events.
This is more complicated than necessary. Arve is wrong; my suggested design does not require polling.
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 8 lines
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That's not so easy. The design of the PM core requires that when the system wakes up from suspend (or from an aborted suspend attempt), all devices should go to full-power-on. This is explained in section 6 of Documentation/power/runtime_pm.txt.
The decision over whether to use kernel-space suspend blockers vs. aborting suspends when queues are non-empty comes down to a tradeoff:
Suspend blockers involve a little more code (to create, destroy, enable, and disable them) plus a little extra runtime overhead each time an event occurs. (Some people may object to this extra overhead, although so far nobody in this discussion has done so.)
Suspend blockers eliminate the extra overhead involved in starting suspends that are just going to be aborted.
Suspend blockers offer extra debugging and accountability (the user can find out which subsystems are responsible for keeping the system awake).
Which way you think the tradeoff should go is a subjective decision. I think that kernel suspend blockers are acceptable.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 5 lines · Dmitry Torokhov
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 8 lines
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
2. Wait a tiny bit after last application notified you that it finished processing events.
This is more complicated than necessary. Arve is wrong; my suggested design does not require polling.
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 8 lines
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That's not so easy. The design of the PM core requires that when the system wakes up from suspend (or from an aborted suspend attempt), all devices should go to full-power-on. This is explained in section 6 of Documentation/power/runtime_pm.txt.
The decision over whether to use kernel-space suspend blockers vs. aborting suspends when queues are non-empty comes down to a tradeoff:
Suspend blockers involve a little more code (to create, destroy, enable, and disable them) plus a little extra runtime overhead each time an event occurs. (Some people may object to this extra overhead, although so far nobody in this discussion has done so.)
Suspend blockers eliminate the extra overhead involved in starting suspends that are just going to be aborted.
Suspend blockers offer extra debugging and accountability (the user can find out which subsystems are responsible for keeping the system awake).
Which way you think the tradeoff should go is a subjective decision. I think that kernel suspend blockers are acceptable.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 25 lines · Alan Stern
Quoted 5 lines · Dmitry Torokhov
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 8 lines
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
2. Wait a tiny bit after last application notified you that it finished processing events.
This is more complicated than necessary. Arve is wrong; my suggested design does not require polling.
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
Quoted 3 lines
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
Quoted 26 lines
Quoted 8 lines
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That's not so easy. The design of the PM core requires that when the system wakes up from suspend (or from an aborted suspend attempt), all devices should go to full-power-on. This is explained in section 6 of
Documentation/power/runtime_pm.txt.The decision over whether to use kernel-space suspend blockers vs. aborting suspends when queues are non-empty comes down to a tradeoff:
Suspend blockers involve a little more code (to create, destroy, enable, and disable them) plus a little extra runtime overhead each time an event occurs. (Some people may object to this extra overhead, although so far nobody in this discussion has done so.)
Suspend blockers eliminate the extra overhead involved in starting suspends that are just going to be aborted.
Quoted 6 lines
Suspend blockers offer extra debugging and accountability (the user can find out which subsystems are responsible for keeping the system awake).
Which way you think the tradeoff should go is a subjective decision. I think that kernel suspend blockers are acceptable.
I agree.
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 7 lines
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
And even if it isn't, so what? What's wrong with looping behavior? Especially a loop that's as short as this one and spends almost all of its time sleeping. Think how much harder it would be to write programs if you weren't allowed to use any loops. :-)
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 7 lines
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
And even if it isn't, so what? What's wrong with looping behavior? Especially a loop that's as short as this one and spends almost all of its time sleeping. Think how much harder it would be to write programs if you weren't allowed to use any loops. :-)
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 20 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 7 lines
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
Quoted 5 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Well, yes it is.
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 20 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 7 lines
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
Quoted 5 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Well, yes it is.
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 20 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 7 lines
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
Quoted 6 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Quoted 7 lines
Especially a loop that's as short as this one and spends almost all of its time sleeping. Think how much harder it would be to write programs if you weren't allowed to use any loops. :-)
Alan Stern
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 20 lines · Alan Stern
Quoted 10 lines · Rafael J. Wysocki
Quoted 9 lines
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
Quoted 7 lines
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
Quoted 6 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Quoted 7 lines
Especially a loop that's as short as this one and spends almost all of its time sleeping. Think how much harder it would be to write programs if you weren't allowed to use any loops. :-)
Alan Stern
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 10 lines · Arve Hjønnevåg
Quoted 6 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 10 lines · Arve Hjønnevåg
Quoted 6 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/26 Alan Stern <[email protected]>:
Quoted 18 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan Stern2010/5/26 Alan Stern <[email protected]>:
Quoted 18 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 10 lines · Arve Hjønnevåg
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
Exactly the same as the in-kernel opportunistic suspend implementation.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 10 lines · Arve Hjønnevåg
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
Exactly the same as the in-kernel opportunistic suspend implementation.
Alan Stern
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 21 lines · Arve Hjønnevåg
2010/5/26 Alan Stern <[email protected]>:
Quoted 20 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 2 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 21 lines · Arve Hjønnevåg
2010/5/26 Alan Stern <[email protected]>:
Quoted 20 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 2 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 27 lines · Dmitry Torokhov
Quoted 26 lines · Arve Hjønnevåg
2010/5/26 Alan Stern <[email protected]>:
Quoted 24 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
Quoted 8 lines
Quoted 4 lines
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
I guess Arve meant the case of events that didn't propagate to user space.
Rafael
Quoted 2 lines
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 27 lines · Dmitry Torokhov
Quoted 26 lines · Arve Hjønnevåg
2010/5/26 Alan Stern <[email protected]>:
Quoted 24 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
Quoted 8 lines
Quoted 4 lines
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
I guess Arve meant the case of events that didn't propagate to user space.
Rafael
Quoted 2 lines
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines
2010/5/26 Alan Stern <[email protected]>:
Quoted 24 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
Quoted 8 lines
Quoted 4 lines
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Because the useful work is done in another thread. All the loop does is check if the useful work has completed which most likely will slow down the useful work. Blocking suspend with a suspend blocker until the useful work is done is more efficient.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines
2010/5/26 Alan Stern <[email protected]>:
Quoted 24 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
Quoted 8 lines
Quoted 4 lines
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Because the useful work is done in another thread. All the loop does is check if the useful work has completed which most likely will slow down the useful work. Blocking suspend with a suspend blocker until the useful work is done is more efficient.
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 33 lines · Arve Hjønnevåg
2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 32 lines · Arve Hjønnevåg
Quoted 30 lines
2010/5/26 Alan Stern <[email protected]>:
Quoted 18 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
Quoted 7 lines
Quoted 3 lines
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Because the useful work is done in another thread. All the loop does is check if the useful work has completed which most likely will slow down the useful work.
Or useful work could signal when it is done processing critical section.
Quoted 3 lines
Blocking suspend with a suspend blocker until
the useful work is done is more efficient.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 33 lines · Arve Hjønnevåg
2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 32 lines · Arve Hjønnevåg
Quoted 30 lines
2010/5/26 Alan Stern <[email protected]>:
Quoted 18 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
Quoted 7 lines
Quoted 3 lines
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Because the useful work is done in another thread. All the loop does is check if the useful work has completed which most likely will slow down the useful work.
Or useful work could signal when it is done processing critical section.
Quoted 3 lines
Blocking suspend with a suspend blocker until
the useful work is done is more efficient.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 38 lines · Arve Hjønnevåg
Quoted 37 lines
2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 35 lines · Arve Hjønnevåg
Quoted 21 lines
2010/5/26 Alan Stern <[email protected]>:
Quoted 20 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 2 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Quoted 6 lines
Quoted 3 lines
Because the useful work is done in another thread. All the loop does is check if the useful work has completed which most likely will slow down the useful work.
Or useful work could signal when it is done processing critical section.
That is what suspend_unblock does.
Quoted 7 lines
Quoted 3 lines
Blocking suspend with a suspend blocker until
the useful work is done is more efficient.--
Dmitry
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry Torokhov2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 38 lines · Arve Hjønnevåg
Quoted 37 lines
2010/5/27 Dmitry Torokhov <[email protected]>:
Quoted 35 lines · Arve Hjønnevåg
Quoted 21 lines
2010/5/26 Alan Stern <[email protected]>:
Quoted 20 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 7 lines
I must be missing something. In Arve's patch 1/8, if the system is in opportunistic suspend, and a wakeup event occurs but no suspend blockers get enabled by the handler, what causes the system to go back into suspend after the event is handled? Isn't that a loop of some sort?
Yes it is a loop. I think what you are missing is that it only loops repeatedly if the driver that aborts suspend does not use a suspend blocker.
You mean "the driver that handles the wakeup event". I was asking what happened if suspend succeeded and then a wakeup occurred. But yes, if a suspend blocker is used then its release causes another suspend attempt, with no looping.
Quoted 2 lines
Quoted 1 line
And even if it isn't, so what? What's wrong with looping behavior?
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
It is a significant power drain.
Not in the situation I was discussing.
If you meant it spend most of the time suspended, then I agree. It only wastes power when a driver blocks suspend by returning an error from its suspend hook and we are forced to loop doing no useful work.
If driver refuses to suspend that means there are events that need processing. I fail to see why it would be called "looping doing no useful work".
Quoted 6 lines
Quoted 3 lines
Because the useful work is done in another thread. All the loop does is check if the useful work has completed which most likely will slow down the useful work.
Or useful work could signal when it is done processing critical section.
That is what suspend_unblock does.
Quoted 7 lines
Quoted 3 lines
Blocking suspend with a suspend blocker until
the useful work is done is more efficient.--
Dmitry
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Alan SternQuoted 25 lines · Alan Stern
Quoted 5 lines · Dmitry Torokhov
Quoted 4 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 8 lines
If your userpsace is that stupid - sure. However, you can:
1. Notify the suspend manager process that he rest of your userspace is busy handling keystrokes so that it does not try to suspend while there are events pending.
2. Wait a tiny bit after last application notified you that it finished processing events.
This is more complicated than necessary. Arve is wrong; my suggested design does not require polling.
The reason is simple: When a user process initiates an opportunistic suspend, you make it wait in an interruptible sleep until all the kernel suspend blockers are released. No polling. If another user thread decides in the meantime that it needs to block the suspend, it sends a signal to the power manager process.
Quoted 3 lines
In fact, other threads should signal the power manager process whenever they want to block or unblock suspends. That way the power manager process can spend all its time sleeping, without doing any polling.
I still see an issue here. Namely, if the power manager is in user space and it's signaled to suspend, it has to ask the kernel to do that, presumably by writing something to a sysfs file. Then, if the kernel blocks the suspend, the power manager waits until the block is released. Now, it should go back and check if user space still doesn't block suspend and if so, wait until the block is released and start over. With all suspend blockers in the kernel this looping behavior is avoidable.
Quoted 26 lines
Quoted 8 lines
So basically the difference is that with in-kernel suspend blockers, there is a tiny window where we haven't started the suspend yet but are about to the driver has a chance to prevent entire system from starting sleep.
Without the blocker we may start suspending and will stop midcycle. We may be even better off in the end since we could leave some devices still powered down after aborting system-wide suspend.
That's not so easy. The design of the PM core requires that when the system wakes up from suspend (or from an aborted suspend attempt), all devices should go to full-power-on. This is explained in section 6 of
Documentation/power/runtime_pm.txt.The decision over whether to use kernel-space suspend blockers vs. aborting suspends when queues are non-empty comes down to a tradeoff:
Suspend blockers involve a little more code (to create, destroy, enable, and disable them) plus a little extra runtime overhead each time an event occurs. (Some people may object to this extra overhead, although so far nobody in this discussion has done so.)
Suspend blockers eliminate the extra overhead involved in starting suspends that are just going to be aborted.
Quoted 6 lines
Suspend blockers offer extra debugging and accountability (the user can find out which subsystems are responsible for keeping the system awake).
Which way you think the tradeoff should go is a subjective decision. I think that kernel suspend blockers are acceptable.
I agree.
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 82 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 3 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Then the userspace suspend manager should be a little more clever and should not blindly retry continuously.
It should be more like a governor which makes some simple decisions based on previous events, simple heuristics, uses timeouts etc.,
Kevin
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 82 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 3 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Then the userspace suspend manager should be a little more clever and should not blindly retry continuously.
It should be more like a governor which makes some simple decisions based on previous events, simple heuristics, uses timeouts etc.,
Kevin
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/25 Kevin Hilman <[email protected]>:
Quoted 88 lines
Quoted 82 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 3 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 6 lines
Then the userspace suspend manager should be a little more clever and should not blindly retry continuously.
It should be more like a governor which makes some simple decisions based on previous events, simple heuristics, uses timeouts etc.,
So instead of the kernel suspending as soon as the last driver stops blocking suspend, you want to add heuristics in user-space to guess when suspend will succeed. This would, in my opinion, be a much worse solution.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Kevin Hilman2010/5/25 Kevin Hilman <[email protected]>:
Quoted 88 lines
Quoted 82 lines · Arve Hjønnevåg
2010/5/25 Dmitry Torokhov <[email protected]>:
Quoted 74 lines · Arve Hjønnevåg
Quoted 65 lines
Quoted 53 lines · Dmitry Torokhov
Quoted 48 lines · Alan Stern
Quoted 25 lines · Dmitry Torokhov
Quoted 15 lines
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
I think that could be made to work. And it might remove the need for the userspace suspend-blocker API, which would be an advantage. It could even remove the need for the opportunistic-suspend workqueue -- opportunistic suspends would be initiated by the "suspend manager" process instead of by the kernel.
However you still have the issue of modifying the kernel drivers to disallow opportunistic suspend if their queues are non-empty. Doing that is more or less equivalent to implementing kernel-level suspend blockers. (The suspend blocker approach is slightly more efficient, because it will prevent a suspend from starting if a queue is non-empty, instead of allowing the suspend to start and then aborting it partway through.)
Quoted 3 lines
Maybe I'm missing something here... No doubt someone will point it out if I am.
Quoted 9 lines
Well, from my perspective that would limit changes to the evdev driver (well, limited input core plumbing will be needed) but that is using the current PM infrastructure. The HW driver changes will be limited to what you described "type 2" in your other e-mail.
Also, not suspending while events are in progress) is probably beneficial for platforms other than Android as well. So unless I am missing something this sounds like a win.
Quoted 7 lines
How would this limit the changes you need in the evdev driver? It need to block suspend when there are unprocessed events in some queues. Suspend blockers gives you an api to do this, without it, you check the queues in your suspend hook and abort suspend if they are not empty. Without suspend blockers you have no api to signal that it is OK to suspend again, so you are forcing the thread that tried to suspend to poll until you stop aborting suspend.
Quoted 6 lines
No, you do not need to poll. You just set a timeout (short or long, depending on your needs) and if no userspace task blocked suspend durng that time you attempt to initiate suspend from your manager process. If it succeeds - good, if not that means that more events came your way and you have to do it later.
Quoted 3 lines
How is that not polling? If the user is holding down a key, the keypad driver has to block suspend, and user space will try to suspend again and again and again...
Quoted 6 lines
Then the userspace suspend manager should be a little more clever and should not blindly retry continuously.
It should be more like a governor which makes some simple decisions based on previous events, simple heuristics, uses timeouts etc.,
So instead of the kernel suspending as soon as the last driver stops blocking suspend, you want to add heuristics in user-space to guess when suspend will succeed. This would, in my opinion, be a much worse solution.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 43 lines · Dmitry Torokhov
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
For that to work, you'd have to make the user space suspend manager prevent key-reading processes from emptying the queue before it orders the kernel to put the system to sleep. Otherwise it still is possible that the queue will be emptied right at the moment it writes to /sys/power/state and the scenario described by Alan is going to happen.
Moreover, I don't think it's limited to the input subsystem, because the wakeup events may originate from the network or some other sources and all of them would require similar handling.
The problem here is that user space can't do anything to stop the freezing of tasks without suspend blockers (or something more-or-less equivalent).
Now, you can argue that in theory we can avoid that if tasks are not frozen, but quite frankly that's not a very realistic way to go.
Rafael
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 51 lines · Rafael J. Wysocki
Quoted 43 lines · Dmitry Torokhov
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Quoted 6 lines
For that to work, you'd have to make the user space suspend manager prevent key-reading processes from emptying the queue before it orders the kernel to put the system to sleep. Otherwise it still is possible that the queue will be emptied right at the moment it writes to
/sys/power/stateand the scenario described by Alan is going to happen.
You do exactly the same as what Alan done, but in userspace - poll, post "busy" event to suspend manager, read, process, retract "busy". Basically you still have the suspend blocker, but it is confined to your userspace.
Quoted 3 lines
Moreover, I don't think it's limited to the input subsystem, because the wakeup events may originate from the network or some other sources and all of them would require similar handling.
Yes, all devices (real or virtual), not only input ones, holding the queues have to refuse suspending for this to work.
Quoted 3 lines
The problem here is that user space can't do anything to stop the freezing of tasks without suspend blockers (or something more-or-less equivalent).
Sure it can if suspend is intiated by userspace itself.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 51 lines · Rafael J. Wysocki
Quoted 43 lines · Dmitry Torokhov
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Quoted 6 lines
For that to work, you'd have to make the user space suspend manager prevent key-reading processes from emptying the queue before it orders the kernel to put the system to sleep. Otherwise it still is possible that the queue will be emptied right at the moment it writes to
/sys/power/stateand the scenario described by Alan is going to happen.
You do exactly the same as what Alan done, but in userspace - poll, post "busy" event to suspend manager, read, process, retract "busy". Basically you still have the suspend blocker, but it is confined to your userspace.
Quoted 3 lines
Moreover, I don't think it's limited to the input subsystem, because the wakeup events may originate from the network or some other sources and all of them would require similar handling.
Yes, all devices (real or virtual), not only input ones, holding the queues have to refuse suspending for this to work.
Quoted 3 lines
The problem here is that user space can't do anything to stop the freezing of tasks without suspend blockers (or something more-or-less equivalent).
Sure it can if suspend is intiated by userspace itself.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 59 lines · Dmitry Torokhov
Quoted 51 lines · Rafael J. Wysocki
Quoted 43 lines · Dmitry Torokhov
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Quoted 6 lines
For that to work, you'd have to make the user space suspend manager prevent key-reading processes from emptying the queue before it orders the kernel to put the system to sleep. Otherwise it still is possible that the queue will be emptied right at the moment it writes to
/sys/power/stateand the scenario described by Alan is going to happen.
Quoted 4 lines
You do exactly the same as what Alan done, but in userspace - poll, post "busy" event to suspend manager, read, process, retract "busy". Basically you still have the suspend blocker, but it is confined to your userspace.
OK, now the question is why this is actually better.
Quoted 6 lines
Quoted 3 lines
Moreover, I don't think it's limited to the input subsystem, because the wakeup events may originate from the network or some other sources and all of them would require similar handling.
Yes, all devices (real or virtual), not only input ones, holding the queues have to refuse suspending for this to work.
So, basically, you'd prefer to move the entire complexity to user space. I'm not sure if that's a big win and I'm not sure anyone is actually going to implement it (and some drivers would still have to be modified to participate in this framework). So again, we have a hunch that the goal may be achieved in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Rafael
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 67 lines · Rafael J. Wysocki
Quoted 59 lines · Dmitry Torokhov
Quoted 51 lines · Rafael J. Wysocki
Quoted 43 lines · Dmitry Torokhov
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Quoted 6 lines
For that to work, you'd have to make the user space suspend manager prevent key-reading processes from emptying the queue before it orders the kernel to put the system to sleep. Otherwise it still is possible that the queue will be emptied right at the moment it writes to
/sys/power/stateand the scenario described by Alan is going to happen.Quoted 4 lines
You do exactly the same as what Alan done, but in userspace - poll, post "busy" event to suspend manager, read, process, retract "busy". Basically you still have the suspend blocker, but it is confined to your userspace.
OK, now the question is why this is actually better.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Moreover, I don't think it's limited to the input subsystem, because the wakeup events may originate from the network or some other sources and all of them would require similar handling.
Yes, all devices (real or virtual), not only input ones, holding the queues have to refuse suspending for this to work.
So, basically, you'd prefer to move the entire complexity to user space.
Yes, I want to shift it from the kernel that use used by all platforms into platform-sepcific userspace. Especially since I do not see everyone buying into suspend-blocker model.
Quoted 3 lines
I'm not sure if that's a big win and I'm not sure anyone is actually going to implement it (and some drivers would still have to be modified to participate in this framework).
I think it is much less than sprinkling every input driver out there with suspend blockers.
So again, we have a hunch that the goal may be achieved
Quoted 7 lines
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
Hmm, and this is different form ever other vendor solution how?
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Adding stuff that is not beneficial to anyone but a particular platform? It is uncommon to say the least.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 67 lines · Rafael J. Wysocki
Quoted 59 lines · Dmitry Torokhov
Quoted 51 lines · Rafael J. Wysocki
Quoted 43 lines · Dmitry Torokhov
Quoted 32 lines · Alan Stern
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines
Quoted 2 lines
I don't see a big difference between 2 and 3. You can use suspend blockers to handle either.
You can, but they aren't necessary. If 2 were the only reason for suspend blockers, I would say they shouldn't be merged.
Whereas 3, on the other hand, can _not_ be handled by any existing mechanism. 3 is perhaps the most important reason for using suspend blockers.
Quoted 5 lines
I do not see why 3 has to be implemented using suspend blockers either. If you are concerned that event gets stuck somewhere in the stack make sure that devices in the stack do not suspend while their queue is not empty. This way if you try opportunistic suspend it will keep failing until you drained all important queues.
Here's the scenario:
The system is awake, and the user presses a key. The keyboard driver processes the keystroke and puts it in an input queue. A user process reads it from the event queue, thereby emptying the queue.
At that moment, the system decides to go into opportunistic suspend. Since the input queue is empty, there's nothing to stop it. As the first step, userspace is frozen -- before the process has a chance to do anything with the keystroke it just read. As a result, the system stays asleep until something else wakes it up, even though the keystroke was important and should have prevented it from sleeping.
Suspend blockers protect against this scenario. Here's how:
Quoted 9 lines
The user process doesn't read the input queue directly; instead it does a select or poll. When it sees there is data in the queue, it first acquires a suspend blocker and then reads the data.
Now the system _can't_ go into opportunistic suspend, because a suspend blocker is active. The user process can do whatever it wants with the keystroke. When it is finished, it releases the suspend blocker and loops back to the select/poll call.
Quoted 6 lines
What you describe can be done in userspace though, via a "suspend manager" process. Tasks reading input events will post "busy" events to stop the manager process from sending system into suspend. But this can be confined to Android userspace, leaving the kernel as is (well, kernel needs to be modified to not go into suspend with full queues, but that is using existing kernel APIs).
Quoted 6 lines
For that to work, you'd have to make the user space suspend manager prevent key-reading processes from emptying the queue before it orders the kernel to put the system to sleep. Otherwise it still is possible that the queue will be emptied right at the moment it writes to
/sys/power/stateand the scenario described by Alan is going to happen.Quoted 4 lines
You do exactly the same as what Alan done, but in userspace - poll, post "busy" event to suspend manager, read, process, retract "busy". Basically you still have the suspend blocker, but it is confined to your userspace.
OK, now the question is why this is actually better.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Moreover, I don't think it's limited to the input subsystem, because the wakeup events may originate from the network or some other sources and all of them would require similar handling.
Yes, all devices (real or virtual), not only input ones, holding the queues have to refuse suspending for this to work.
So, basically, you'd prefer to move the entire complexity to user space.
Yes, I want to shift it from the kernel that use used by all platforms into platform-sepcific userspace. Especially since I do not see everyone buying into suspend-blocker model.
Quoted 3 lines
I'm not sure if that's a big win and I'm not sure anyone is actually going to implement it (and some drivers would still have to be modified to participate in this framework).
I think it is much less than sprinkling every input driver out there with suspend blockers.
So again, we have a hunch that the goal may be achieved
Quoted 7 lines
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
Hmm, and this is different form ever other vendor solution how?
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Adding stuff that is not beneficial to anyone but a particular platform? It is uncommon to say the least.
Signature · 1 line
Dmitry
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 11 lines · Dmitry Torokhov
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Adding stuff that is not beneficial to anyone but a particular platform? It is uncommon to say the least.
Yeah, I'd even say we're about to adopt mechanism which will provoke adding drivers with buggy solutions.
Moving that stuff to platform-specific userspace will solve that, more or less.
Also, I'm less than happy about Android vs mainline talks that come into play when out of the technical points. Google is doing a good job but we shouldn't compromise neither the quality nor the principles in order to make them happy. They will not support tons of drivers with custom PM solution by themselves, so it's to mutual benefit if they come with a satisfactory solution.
~Vitaly
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 11 lines · Dmitry Torokhov
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Adding stuff that is not beneficial to anyone but a particular platform? It is uncommon to say the least.
Yeah, I'd even say we're about to adopt mechanism which will provoke adding drivers with buggy solutions.
Moving that stuff to platform-specific userspace will solve that, more or less.
Also, I'm less than happy about Android vs mainline talks that come into play when out of the technical points. Google is doing a good job but we shouldn't compromise neither the quality nor the principles in order to make them happy. They will not support tons of drivers with custom PM solution by themselves, so it's to mutual benefit if they come with a satisfactory solution.
~Vitaly
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 2 lines · Dmitry Torokhov
Quoted 1 line · Rafael J. Wysocki
On Tuesday 25 May 2010, Dmitry Torokhov wrote:
...
Quoted 11 lines
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Adding stuff that is not beneficial to anyone but a particular platform? It is uncommon to say the least.
Well, not quite. We have a number of platform-specific drivers for one example.
Also, In fact I think it would benefit everyone if Android users could run mainline kernels without major modifications on their systems.
Also, I think it would benefit everyone if Android drivers were merged into the mainline.
Moreover, I think this stuff may actually be useful to someone beyond Android, because it's proven working and people can readily play with it. Which is not going to happen if it's not in the mainline.
And I don't believe a user space power manager is going to be implemented in a platform-idependent way, if at all (assuming we reject the Android patches).
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Dmitry TorokhovQuoted 2 lines · Dmitry Torokhov
Quoted 1 line · Rafael J. Wysocki
On Tuesday 25 May 2010, Dmitry Torokhov wrote:
...
Quoted 11 lines
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
Adding stuff that is not beneficial to anyone but a particular platform? It is uncommon to say the least.
Well, not quite. We have a number of platform-specific drivers for one example.
Also, In fact I think it would benefit everyone if Android users could run mainline kernels without major modifications on their systems.
Also, I think it would benefit everyone if Android drivers were merged into the mainline.
Moreover, I think this stuff may actually be useful to someone beyond Android, because it's proven working and people can readily play with it. Which is not going to happen if it's not in the mainline.
And I don't believe a user space power manager is going to be implemented in a platform-idependent way, if at all (assuming we reject the Android patches).
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 1 line · Rafael J. Wysocki
So, basically, you'd prefer to move the entire complexity to user space.
No, just the complexity of the userspace suspend blockers. That was one of the parts of the interface that people objected to, after all.
Quoted 1 line
I'm not sure if that's a big win
It's not a _big_ win, but it is an improvement IMO.
Quoted 3 lines
and I'm not sure anyone is actually going to
implement it (and some drivers would still have to be modified to participate in this framework).
Of course drivers have to be modified. The kernel-layer suspend blockers aren't affected by this proposal, so they still have to be implemented.
Quoted 3 lines
So again, we have a hunch that the goal may be achieved
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).
It's not very different from what has been submitted, and I think there's little doubt that it could be built and used fairly easily. All we're talking about is removing the userspace suspend-blocker API and the opportunistic workqueue, replacing them with an "opportunistic" entry in /sys/power/state, and setting up a userspace power manager process.
Quoted 3 lines
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
The redesign would be pretty small. The kernel changes relative to what they have submitted are minimal, mostly just removing a few of their additions. Furthermore, we've been told that Android _already_ funnels all its userspace suspend-blocker work through a single process. All that would be needed would be to make that process initiate an opportunistic suspend whenever no userspace suspend blockers were active.
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
You don't seem to appreciate how small a change Dmitry has proposed. Almost all of the suspend-blocker work would remain as in the submitted patches. The only difference is that the userspace API and opportunistic-suspend implementation would be simplified, by moving some of the work out of the kernel.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 1 line · Rafael J. Wysocki
So, basically, you'd prefer to move the entire complexity to user space.
No, just the complexity of the userspace suspend blockers. That was one of the parts of the interface that people objected to, after all.
Quoted 1 line
I'm not sure if that's a big win
It's not a _big_ win, but it is an improvement IMO.
Quoted 3 lines
and I'm not sure anyone is actually going to
implement it (and some drivers would still have to be modified to participate in this framework).
Of course drivers have to be modified. The kernel-layer suspend blockers aren't affected by this proposal, so they still have to be implemented.
Quoted 3 lines
So again, we have a hunch that the goal may be achieved
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).
It's not very different from what has been submitted, and I think there's little doubt that it could be built and used fairly easily. All we're talking about is removing the userspace suspend-blocker API and the opportunistic workqueue, replacing them with an "opportunistic" entry in /sys/power/state, and setting up a userspace power manager process.
Quoted 3 lines
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
The redesign would be pretty small. The kernel changes relative to what they have submitted are minimal, mostly just removing a few of their additions. Furthermore, we've been told that Android _already_ funnels all its userspace suspend-blocker work through a single process. All that would be needed would be to make that process initiate an opportunistic suspend whenever no userspace suspend blockers were active.
Quoted 8 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
You don't seem to appreciate how small a change Dmitry has proposed. Almost all of the suspend-blocker work would remain as in the submitted patches. The only difference is that the userspace API and opportunistic-suspend implementation would be simplified, by moving some of the work out of the kernel.
Alan Stern
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 48 lines · Alan Stern
Quoted 1 line · Rafael J. Wysocki
So, basically, you'd prefer to move the entire complexity to user space.
No, just the complexity of the userspace suspend blockers. That was one of the parts of the interface that people objected to, after all.
Quoted 1 line
I'm not sure if that's a big win
It's not a _big_ win, but it is an improvement IMO.
Quoted 3 lines
and I'm not sure anyone is actually going to
implement it (and some drivers would still have to be modified to participate in this framework).Of course drivers have to be modified. The kernel-layer suspend blockers aren't affected by this proposal, so they still have to be implemented.
Quoted 3 lines
So again, we have a hunch that the goal may be achieved
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).It's not very different from what has been submitted, and I think there's little doubt that it could be built and used fairly easily. All we're talking about is removing the userspace suspend-blocker API and the opportunistic workqueue, replacing them with an "opportunistic" entry in
/sys/power/state, and setting up a userspace power manager process.Quoted 3 lines
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
The redesign would be pretty small. The kernel changes relative to what they have submitted are minimal, mostly just removing a few of their additions. Furthermore, we've been told that Android _already_ funnels all its userspace suspend-blocker work through a single process. All that would be needed would be to make that process initiate an opportunistic suspend whenever no userspace suspend blockers were active.
Quoted 6 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
Quoted 8 lines
Quoted 2 lines
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
You don't seem to appreciate how small a change Dmitry has proposed. Almost all of the suspend-blocker work would remain as in the submitted patches. The only difference is that the userspace API and opportunistic-suspend implementation would be simplified, by moving some of the work out of the kernel.
No, I don't really think it's going to be a small change. The problem is that for the Android people changing user space is very hard, so I don't think this realy is an option, given that they would have to implement it themselves, test it, validate it on multiple different hardware platforms etc. and _then_ resubmit the feature without any guarantee that it will be merged.
So, my opinion is that we only have a choice to either take the feature as is now, or reject it altogether and live with the consequeces in each case. And quite frankly I don't feel like I'm in position to make that decision.
Thanks,
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alan Stern
Quoted 1 line · Rafael J. Wysocki
So, basically, you'd prefer to move the entire complexity to user space.
No, just the complexity of the userspace suspend blockers. That was one of the parts of the interface that people objected to, after all.
Quoted 1 line
I'm not sure if that's a big win
It's not a _big_ win, but it is an improvement IMO.
Quoted 3 lines
and I'm not sure anyone is actually going to
implement it (and some drivers would still have to be modified to participate in this framework).Of course drivers have to be modified. The kernel-layer suspend blockers aren't affected by this proposal, so they still have to be implemented.
Quoted 3 lines
So again, we have a hunch that the goal may be achieved
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).It's not very different from what has been submitted, and I think there's little doubt that it could be built and used fairly easily. All we're talking about is removing the userspace suspend-blocker API and the opportunistic workqueue, replacing them with an "opportunistic" entry in
/sys/power/state, and setting up a userspace power manager process.Quoted 3 lines
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
The redesign would be pretty small. The kernel changes relative to what they have submitted are minimal, mostly just removing a few of their additions. Furthermore, we've been told that Android _already_ funnels all its userspace suspend-blocker work through a single process. All that would be needed would be to make that process initiate an opportunistic suspend whenever no userspace suspend blockers were active.
Quoted 6 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
Quoted 8 lines
Quoted 2 lines
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
You don't seem to appreciate how small a change Dmitry has proposed. Almost all of the suspend-blocker work would remain as in the submitted patches. The only difference is that the userspace API and opportunistic-suspend implementation would be simplified, by moving some of the work out of the kernel.
Quoted 6 lines
No, I don't really think it's going to be a small change. The problem is that for the Android people changing user space is very hard, so I don't think this realy is an option, given that they would have to implement it themselves, test it, validate it on multiple different hardware platforms etc. and _then_ resubmit the feature without any guarantee that it will be merged.
The biggest problem here is not that it is hard to change our user-space, but that the proposed change is inferior to what we have now. It forces us to poll until all drivers stop aborting suspend. On one hand we have people telling us that all code that polls is broken and must be fixed (instead of suspending to limit the damage), and on the other hand we have people suggesting we implement opportunistic suspend by polling from user-space until suspend succeeds.
Quoted 4 lines
So, my opinion is that we only have a choice to either take the feature as is now, or reject it altogether and live with the consequeces in each case. And quite frankly I don't feel like I'm in position to make that decision.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alan Stern
Quoted 1 line · Rafael J. Wysocki
So, basically, you'd prefer to move the entire complexity to user space.
No, just the complexity of the userspace suspend blockers. That was one of the parts of the interface that people objected to, after all.
Quoted 1 line
I'm not sure if that's a big win
It's not a _big_ win, but it is an improvement IMO.
Quoted 3 lines
and I'm not sure anyone is actually going to
implement it (and some drivers would still have to be modified to participate in this framework).Of course drivers have to be modified. The kernel-layer suspend blockers aren't affected by this proposal, so they still have to be implemented.
Quoted 3 lines
So again, we have a hunch that the goal may be achieved
in a different way, but at this point we'd rather need a _working_ _solution_ (in the form of code one can build and actually use).It's not very different from what has been submitted, and I think there's little doubt that it could be built and used fairly easily. All we're talking about is removing the userspace suspend-blocker API and the opportunistic workqueue, replacing them with an "opportunistic" entry in
/sys/power/state, and setting up a userspace power manager process.Quoted 3 lines
I don't think it's realistic to expect the Android people to go and redesign their stuff along the lines you've described, because they have a working implementation (in the kernel) that they are satisfied with.
The redesign would be pretty small. The kernel changes relative to what they have submitted are minimal, mostly just removing a few of their additions. Furthermore, we've been told that Android _already_ funnels all its userspace suspend-blocker work through a single process. All that would be needed would be to make that process initiate an opportunistic suspend whenever no userspace suspend blockers were active.
Quoted 6 lines
Now, we can reject their patches, but that's not going to cause any progress to happen, realistically. Quite on the contrary, Android will continue to use wakelocks and Android driver writers will continue to ignore the mainline and the gap between the two kernel lines will only get wider and wider over time.
Quoted 8 lines
Quoted 2 lines
And what really is the drawback if we merge the patches? Quite frankly, I don't see any.
You don't seem to appreciate how small a change Dmitry has proposed. Almost all of the suspend-blocker work would remain as in the submitted patches. The only difference is that the userspace API and opportunistic-suspend implementation would be simplified, by moving some of the work out of the kernel.
Quoted 6 lines
No, I don't really think it's going to be a small change. The problem is that for the Android people changing user space is very hard, so I don't think this realy is an option, given that they would have to implement it themselves, test it, validate it on multiple different hardware platforms etc. and _then_ resubmit the feature without any guarantee that it will be merged.
The biggest problem here is not that it is hard to change our user-space, but that the proposed change is inferior to what we have now. It forces us to poll until all drivers stop aborting suspend. On one hand we have people telling us that all code that polls is broken and must be fixed (instead of suspending to limit the damage), and on the other hand we have people suggesting we implement opportunistic suspend by polling from user-space until suspend succeeds.
Quoted 4 lines
So, my opinion is that we only have a choice to either take the feature as is now, or reject it altogether and live with the consequeces in each case. And quite frankly I don't feel like I'm in position to make that decision.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 7 lines · Arve Hjønnevåg
The biggest problem here is not that it is hard to change our user-space, but that the proposed change is inferior to what we have now. It forces us to poll until all drivers stop aborting suspend. On one hand we have people telling us that all code that polls is broken and must be fixed (instead of suspending to limit the damage), and on the other hand we have people suggesting we implement opportunistic suspend by polling from user-space until suspend succeeds.
No it does _not_. You're really not getting that Dmitry is proposing.
So your proposal is that when we wake userspace, it
opens /dev/suspend_blocker _before_ it consumes whatever event, consumes the event, deals with the event, then closes the suspend_blocker. Then the kernel, upon reaching a 0 suspend_blocker count, will try to suspend again.
What Dmitry proposes is that, the app _before_ it consumes the event, pokes at this suspend manager, it increases a blocker count, then consumes the event (the kernel will _not_ auto-suspend), handles it and then again pokes the suspend manager, this time decreasing the blocker count.
The suspend manager will, upon reaching a 0 block count, suspend the machine. If that fails, it means there's something to do, an app will inc, work, dec its count, and it will try again once it reaches 0 again.
There is no polling what-so-ever in this model.
The only thing is that the kernel will not try to auto-suspend and there is no user-space suspend blocker API.
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 7 lines · Arve Hjønnevåg
The biggest problem here is not that it is hard to change our user-space, but that the proposed change is inferior to what we have now. It forces us to poll until all drivers stop aborting suspend. On one hand we have people telling us that all code that polls is broken and must be fixed (instead of suspending to limit the damage), and on the other hand we have people suggesting we implement opportunistic suspend by polling from user-space until suspend succeeds.
No it does _not_. You're really not getting that Dmitry is proposing.
So your proposal is that when we wake userspace, it
opens /dev/suspend_blocker _before_ it consumes whatever event, consumes the event, deals with the event, then closes the suspend_blocker. Then the kernel, upon reaching a 0 suspend_blocker count, will try to suspend again.
What Dmitry proposes is that, the app _before_ it consumes the event, pokes at this suspend manager, it increases a blocker count, then consumes the event (the kernel will _not_ auto-suspend), handles it and then again pokes the suspend manager, this time decreasing the blocker count.
The suspend manager will, upon reaching a 0 block count, suspend the machine. If that fails, it means there's something to do, an app will inc, work, dec its count, and it will try again once it reaches 0 again.
There is no polling what-so-ever in this model.
The only thing is that the kernel will not try to auto-suspend and there is no user-space suspend blocker API.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 9 lines · Peter Zijlstra
What Dmitry proposes is that, the app _before_ it consumes the event, pokes at this suspend manager, it increases a blocker count, then consumes the event (the kernel will _not_ auto-suspend), handles it and then again pokes the suspend manager, this time decreasing the blocker count.
The suspend manager will, upon reaching a 0 block count, suspend the machine. If that fails, it means there's something to do, an app will inc, work, dec its count, and it will try again once it reaches 0 again.
Alternatively the suspend manager could simply cancel the opportunistic suspend mode on !0, and re-instate it on 0.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
What Dmitry proposes is that, the app _before_ it consumes the event, pokes at this suspend manager, it increases a blocker count, then consumes the event (the kernel will _not_ auto-suspend), handles it and then again pokes the suspend manager, this time decreasing the blocker count.
The suspend manager will, upon reaching a 0 block count, suspend the machine. If that fails, it means there's something to do, an app will inc, work, dec its count, and it will try again once it reaches 0 again.
Alternatively the suspend manager could simply cancel the opportunistic suspend mode on !0, and re-instate it on 0.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
While this approach could be made to work, it's ugly in other ways. After wakeup, userspace has to pause for a while before it can trigger another sleep in order to give all the apps an opportunity to check for wakeup events and block suspend if they wish to. That's additional runtime that doesn't exist in the kernel-mediated case.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraWhile this approach could be made to work, it's ugly in other ways. After wakeup, userspace has to pause for a while before it can trigger another sleep in order to give all the apps an opportunity to check for wakeup events and block suspend if they wish to. That's additional runtime that doesn't exist in the kernel-mediated case.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 1/8] PM: Opportunistic suspend support.
On Wed, 2010-05-26 at 13:49 +0100, Matthew Garrett wrote:
Lack of quoting makes it hard to see what your 'this' refers to. I'll assume its the userspace suspend manager.
Quoted 5 lines
While this approach could be made to work, it's ugly in other ways. After wakeup, userspace has to pause for a while before it can trigger another sleep in order to give all the apps an opportunity to check for wakeup events and block suspend if they wish to. That's additional runtime that doesn't exist in the kernel-mediated case.
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Also, since we did get woken, there clearly is work to do and we should only try suspending again once someone did inform us of completing it.
In both cases, once the event is fully handled, will there be communication of this fact and suspend can be attempted.
I don't see a reason to 'wait' for anything -- except maybe speculate on the avgerage wakeup rate and decide not to suspend quite yet.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Matthew GarrettOn Wed, 2010-05-26 at 13:49 +0100, Matthew Garrett wrote:
Lack of quoting makes it hard to see what your 'this' refers to. I'll assume its the userspace suspend manager.
Quoted 5 lines
While this approach could be made to work, it's ugly in other ways. After wakeup, userspace has to pause for a while before it can trigger another sleep in order to give all the apps an opportunity to check for wakeup events and block suspend if they wish to. That's additional runtime that doesn't exist in the kernel-mediated case.
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Also, since we did get woken, there clearly is work to do and we should only try suspending again once someone did inform us of completing it.
In both cases, once the event is fully handled, will there be communication of this fact and suspend can be attempted.
I don't see a reason to 'wait' for anything -- except maybe speculate on the avgerage wakeup rate and decide not to suspend quite yet.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning -EAGAIN or similar.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning -EAGAIN or similar.
Signature · 1 line
Matthew Garrett | [email protected]
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 10 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.
I still think it would cause a loop-alike behavior between the user space power manager and the kernel PM core to happen, because the power manager will always have to check the user space counter after a failing suspend attempt.
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Matthew GarrettQuoted 7 lines · Matthew Garrett
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 10 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.
I still think it would cause a loop-alike behavior between the user space power manager and the kernel PM core to happen, because the power manager will always have to check the user space counter after a failing suspend attempt.
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Matthew GarrettQuoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.
(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
When there are no more current event indicators, userspace is allowed to request a suspend. Obviously this could fail as an event could happen at any moment, but the same is true when the kernel asks the device to suspend, an interrupt might happen immediately to stop it. But in either case an event will be reported. So when userspace requests a suspend and it fails, it will see events reported and so will wait for them to be handled.
I imagine a sysfs directory with files that appear when events are pending. We could have some separate mechanism for user-space processes to request that the suspend-daemon not suspend. Then it suspends whenever there are no pending requests from user-space or from the kernel.
The advantage of this model of suspend-blockers is that it is a close analogue for something that already exists in hardware so it isn't really creating new concepts, just giving the Linux virtual-machine features that have proved themselves in physical machines.
The cost is that any wake-up event needs to not only be handled, but also explicitly acknowledged by clearing the relevant suspend-blocker (i.e. removing the file from sysfs, or whatever interface was ultimately chosen). I'm hoping that isn't a big cost.
NeilBrown
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Matthew GarrettQuoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.
(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
When there are no more current event indicators, userspace is allowed to request a suspend. Obviously this could fail as an event could happen at any moment, but the same is true when the kernel asks the device to suspend, an interrupt might happen immediately to stop it. But in either case an event will be reported. So when userspace requests a suspend and it fails, it will see events reported and so will wait for them to be handled.
I imagine a sysfs directory with files that appear when events are pending. We could have some separate mechanism for user-space processes to request that the suspend-daemon not suspend. Then it suspends whenever there are no pending requests from user-space or from the kernel.
The advantage of this model of suspend-blockers is that it is a close analogue for something that already exists in hardware so it isn't really creating new concepts, just giving the Linux virtual-machine features that have proved themselves in physical machines.
The cost is that any wake-up event needs to not only be handled, but also explicitly acknowledged by clearing the relevant suspend-blocker (i.e. removing the file from sysfs, or whatever interface was ultimately chosen). I'm hoping that isn't a big cost.
NeilBrown
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 32 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Quoted 6 lines
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
--mgross
Quoted 28 lines
When there are no more current event indicators, userspace is allowed to request a suspend. Obviously this could fail as an event could happen at any moment, but the same is true when the kernel asks the device to suspend, an interrupt might happen immediately to stop it. But in either case an event will be reported. So when userspace requests a suspend and it fails, it will see events reported and so will wait for them to be handled.
I imagine a sysfs directory with files that appear when events are pending. We could have some separate mechanism for user-space processes to request that the suspend-daemon not suspend. Then it suspends whenever there are no pending requests from user-space or from the kernel.
The advantage of this model of suspend-blockers is that it is a close analogue for something that already exists in hardware so it isn't really creating new concepts, just giving the Linux virtual-machine features that have proved themselves in physical machines.
The cost is that any wake-up event needs to not only be handled, but also explicitly acknowledged by clearing the relevant suspend-blocker (i.e. removing the file from sysfs, or whatever interface was ultimately chosen). I'm hoping that isn't a big cost.
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
Signature · 1 line
Arve Hjønnevåg
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to mark grossQuoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
I don't know exactly what Mark has in mind, but I would advocate 1-shot simply because what we currently have (echo mem > /sys/power/state) is 1-shot and I don't believe you need to do more than fix the bugs in that.
Your question of whether to abort or block suspend in central I think - the answer to that question will make or break a possible solution.
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action. Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_prepare had been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).
So the suspend daemon does:
wait for there to be no user-space suspend blocks issue suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issue suspend_abort if needed) issue suspend request
loop
processes that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
I don't know exactly what Mark has in mind, but I would advocate 1-shot simply because what we currently have (echo mem > /sys/power/state) is 1-shot and I don't believe you need to do more than fix the bugs in that.
Your question of whether to abort or block suspend in central I think - the answer to that question will make or break a possible solution.
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action. Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_prepare had been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).
So the suspend daemon does:
wait for there to be no user-space suspend blocks issue suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issue suspend_abort if needed) issue suspend request
loop
processes that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
NeilBrown
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 103 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
I don't know exactly what Mark has in mind, but I would advocate 1-shot simply because what we currently have (echo mem >
/sys/power/state) is 1-shot and I don't believe you need to do more than fix the bugs in that.Your question of whether to abort or block suspend in central I think - the answer to that question will make or break a possible solution.
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action. Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "
suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_preparehad been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).So the suspend daemon does:
wait for there to be no user-space suspend blocks issue
suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issuesuspend_abortif needed) issue suspend request
loopprocesses that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
Quoted 3 lines
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
Well, please have a look at the Alan Stern's proposal here:
http://lkml.org/lkml/2010/5/29/77
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 104 lines · On Sun, 30 May 2010 21:52:14 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 103 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
I don't know exactly what Mark has in mind, but I would advocate 1-shot simply because what we currently have (echo mem >
/sys/power/state) is 1-shot and I don't believe you need to do more than fix the bugs in that.Your question of whether to abort or block suspend in central I think - the answer to that question will make or break a possible solution.
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action. Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "
suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_preparehad been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).So the suspend daemon does:
wait for there to be no user-space suspend blocks issue
suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issuesuspend_abortif needed) issue suspend request
loopprocesses that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
Quoted 7 lines
Quoted 3 lines
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
Well, please have a look at the Alan Stern's proposal here:
http://lkml.org/lkml/2010/5/29/77
Thanks for the reference.
Some of the details are different, but the idea seems almost exactly the same as mine.
The apparent dependence on signals makes me feel a little uncomfortable (interfaces that depend on using signals seem to be easy to use wrongly), but I don't think that is a serious flaw.
Maybe the biggest difference is philosophical. Alan's proposal appears to be adding a new feature. Mine presents as trying to fix an existing feature so that it can be used reliably.
It is easier to argue against a feature than against a bug-fix (??).
Thanks,
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Rafael J. WysockiQuoted 104 lines · On Sun, 30 May 2010 21:52:14 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 103 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
I don't know exactly what Mark has in mind, but I would advocate 1-shot simply because what we currently have (echo mem >
/sys/power/state) is 1-shot and I don't believe you need to do more than fix the bugs in that.Your question of whether to abort or block suspend in central I think - the answer to that question will make or break a possible solution.
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action. Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "
suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_preparehad been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).So the suspend daemon does:
wait for there to be no user-space suspend blocks issue
suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issuesuspend_abortif needed) issue suspend request
loopprocesses that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
Quoted 7 lines
Quoted 3 lines
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
Well, please have a look at the Alan Stern's proposal here:
http://lkml.org/lkml/2010/5/29/77
Thanks for the reference.
Some of the details are different, but the idea seems almost exactly the same as mine.
The apparent dependence on signals makes me feel a little uncomfortable (interfaces that depend on using signals seem to be easy to use wrongly), but I don't think that is a serious flaw.
Maybe the biggest difference is philosophical. Alan's proposal appears to be adding a new feature. Mine presents as trying to fix an existing feature so that it can be used reliably.
It is easier to argue against a feature than against a bug-fix (??).
Thanks,
NeilBrown
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 11 lines · On Mon, 31 May 2010 09:03:29 +1000 Neil Brown <[email protected]> wrote:
Quoted 3 lines
Well, please have a look at the Alan Stern's proposal here:
http://lkml.org/lkml/2010/5/29/77Thanks for the reference.
Some of the details are different, but the idea seems almost exactly the same as mine.
The apparent dependence on signals makes me feel a little uncomfortable (interfaces that depend on using signals seem to be easy to use wrongly), but I don't think that is a serious flaw.
Quoted 4 lines
Maybe the biggest difference is philosophical. Alan's proposal appears to be adding a new feature. Mine presents as trying to fix an existing feature so that it can be used reliably.
It is easier to argue against a feature than against a bug-fix (??).
Addendum...
The use of signals by Alan here got me thinking.. and combining it which what Alan Cox and Thomas Gleixner (and others?) have been saying about detecting idleness led me down an interesting path that I thought I would share.
An absolutely minimal change to allow a user-space initiated auto-suspend to be race-free would be achieved by placing an interruptible wait between
pm_notifier_call_chain(PM_SUSPEND_PREPARE);
and
suspend_freeze_processes();which waits for all kernel threads to have passed through an 'idle' state.
Then any wake event that happened after the PM_SUSPEND_PREPARE would presumably either abort the suspend later, or would cause an immediate wake-up.
Any event that happened before the PM_SUSPEND_PREPARE would have been fully processed by any kernel thread and so would be queued for user-space (or have been discarded).
If we then require any process that handles wakeup events to use the equivalent of fcntl(F_SETOWN) to direct a SIGIO (or other signal) at the process which requests the suspend, then wakeup events won't be lost. They will either send a signal to the suspend-daemon in time to abort the suspend, or will be late enough to either abort the suspend in-kernel, or trigger an immediate wakeup.
Yes: this would require quite a large change of the android code, and the F_SETOWN usage is fairly ugly, but balanced against it actually working and it being minimal, that might be OK.
The hardest part would be waiting for all kernel-threads to pass through idle (or all threads to pass through idle or user-space). We'd need help to make that work, but at least it would be a fairly localised change.
Maybe it is something to keep in mind when other possibilities have proven intractable.
NeilBrown
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Neil BrownQuoted 11 lines · On Mon, 31 May 2010 09:03:29 +1000 Neil Brown <[email protected]> wrote:
Quoted 3 lines
Well, please have a look at the Alan Stern's proposal here:
http://lkml.org/lkml/2010/5/29/77Thanks for the reference.
Some of the details are different, but the idea seems almost exactly the same as mine.
The apparent dependence on signals makes me feel a little uncomfortable (interfaces that depend on using signals seem to be easy to use wrongly), but I don't think that is a serious flaw.
Quoted 4 lines
Maybe the biggest difference is philosophical. Alan's proposal appears to be adding a new feature. Mine presents as trying to fix an existing feature so that it can be used reliably.
It is easier to argue against a feature than against a bug-fix (??).
Addendum...
The use of signals by Alan here got me thinking.. and combining it which what Alan Cox and Thomas Gleixner (and others?) have been saying about detecting idleness led me down an interesting path that I thought I would share.
An absolutely minimal change to allow a user-space initiated auto-suspend to be race-free would be achieved by placing an interruptible wait between
pm_notifier_call_chain(PM_SUSPEND_PREPARE);
and
suspend_freeze_processes();which waits for all kernel threads to have passed through an 'idle' state.
Then any wake event that happened after the PM_SUSPEND_PREPARE would presumably either abort the suspend later, or would cause an immediate wake-up.
Any event that happened before the PM_SUSPEND_PREPARE would have been fully processed by any kernel thread and so would be queued for user-space (or have been discarded).
If we then require any process that handles wakeup events to use the equivalent of fcntl(F_SETOWN) to direct a SIGIO (or other signal) at the process which requests the suspend, then wakeup events won't be lost. They will either send a signal to the suspend-daemon in time to abort the suspend, or will be late enough to either abort the suspend in-kernel, or trigger an immediate wakeup.
Yes: this would require quite a large change of the android code, and the F_SETOWN usage is fairly ugly, but balanced against it actually working and it being minimal, that might be OK.
The hardest part would be waiting for all kernel-threads to pass through idle (or all threads to pass through idle or user-space). We'd need help to make that work, but at least it would be a fairly localised change.
Maybe it is something to keep in mind when other possibilities have proven intractable.
NeilBrown
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Neil BrownQuoted 103 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 38 lines · mark gross
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
Quoted 6 lines
Quoted 1 line
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
I don't know exactly what Mark has in mind, but I would advocate 1-shot simply because what we currently have (echo mem >
/sys/power/state) is 1-shot and I don't believe you need to do more than fix the bugs in that.Your question of whether to abort or block suspend in central I think - the answer to that question will make or break a possible solution.
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action. Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "
suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_preparehad been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).So the suspend daemon does:
wait for there to be no user-space suspend blocks issue
suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issuesuspend_abortif needed) issue suspend request
loopprocesses that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
Quoted 3 lines
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
Well, please have a look at the Alan Stern's proposal here:
http://lkml.org/lkml/2010/5/29/77
Rafael
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Neil BrownQuoted 49 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 44 lines · mark gross
Quoted 32 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Quoted 6 lines
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
Sorry about missing Avr's email, I've been fighting with getting my email forwarding working right.
The problems I want to solve with the one-shot styled interface are:
1) of having to sprinkle suspend blocking sections from isr up to usermode and get them right.
2) provide a platform / architecture independent framework supporting other low power modes.
I've just posted a patch that expresses what I was trying to express. Its hard to take design over email without tossing code back and forth. It's my turn to toss some code.
Quoted 3 lines
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action.
Not if you have sensible event messaging to the user-space processes. I've posted a patch that attempts to add some messaging.
Quoted 24 lines
Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "
suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_preparehad been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).So the suspend daemon does:
wait for there to be no user-space suspend blocks issue
suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issuesuspend_abortif needed) issue suspend request
loop
Quoted 7 lines
processes that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
In my mind I'm thinking of something like:
attempt low power entry (suspend)
if blocked, get -EBUSY back
select on block_file until block is released retry suspend
else // entered low power and exited
read wake_event
do something with event; typically wait a bit and loop.
--mgross
Quoted 6 lines
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
NeilBrown
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 63 lines · mark gross
Quoted 49 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 44 lines · mark gross
Quoted 32 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Quoted 6 lines
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
Quoted 7 lines
Sorry about missing Avr's email, I've been fighting with getting my email forwarding working right.
The problems I want to solve with the one-shot styled interface are:
1) of having to sprinkle suspend blocking sections from isr up to usermode and get them right.
Making the interface one-shot does not change where you need to block suspend.
Quoted 4 lines
2) provide a platform / architecture independent framework supporting other low power modes.
I assume you did not mean that a one-shot interface has any impact on this. What other low power modes are you trying to support. Suspend blocker block suspend regardless of the mode selected (standby/mem). Are there cases where you need to block one but not the other?
Signature · 1 line
Arve Hjønnevåg
Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.
In reply to mark grossQuoted 63 lines · mark gross
Quoted 49 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 44 lines · mark gross
Quoted 32 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Quoted 6 lines
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
Quoted 7 lines
Sorry about missing Avr's email, I've been fighting with getting my email forwarding working right.
The problems I want to solve with the one-shot styled interface are:
1) of having to sprinkle suspend blocking sections from isr up to usermode and get them right.
Making the interface one-shot does not change where you need to block suspend.
Quoted 4 lines
2) provide a platform / architecture independent framework supporting other low power modes.
I assume you did not mean that a one-shot interface has any impact on this. What other low power modes are you trying to support. Suspend blocker block suspend regardless of the mode selected (standby/mem). Are there cases where you need to block one but not the other?
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Neil BrownQuoted 49 lines · Neil Brown
Quoted 46 lines · On Fri, 28 May 2010 21:04:53 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 44 lines · mark gross
Quoted 32 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Quoted 6 lines
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
Quoted 12 lines
Quoted 12 lines
Can you be more specific? If you are talking about only letting drivers abort suspend, not block it, then the main argument against that is that you are forcing user-space to poll until the driver stops aborting suspend (which according to people arguing against us using suspend would make the power-manager a "bad" process). Or are you talking about blocking the request from user-space until all other suspend-blockers have been released and then doing a single suspend cycle before returning. This would not be as bad, but it would force the user-space power manager to be multi-threaded since it now would have way to cancel the request. Either way, what problem are you trying to solve by making it a one-shot request?
Sorry about missing Avr's email, I've been fighting with getting my email forwarding working right.
The problems I want to solve with the one-shot styled interface are:
1) of having to sprinkle suspend blocking sections from isr up to usermode and get them right.
2) provide a platform / architecture independent framework supporting other low power modes.
I've just posted a patch that expresses what I was trying to express. Its hard to take design over email without tossing code back and forth. It's my turn to toss some code.
Quoted 3 lines
Simply aborting the suspend cannot work as you rightly say - the suspend daemon would then spin until other user-space processes get into action.
Not if you have sensible event messaging to the user-space processes. I've posted a patch that attempts to add some messaging.
Quoted 24 lines
Simply blocking while there are any unhandled 'wakeup events' - then aborting if there were any - is how I think it should work. However as it doesn't work that way now I don't think it is safe to make it work that way unconditionally. If we did we could find that existing configurations always block suspend indefinitely with would clearly be a regression.
I think we still need some sort of "
suspend_prepare". This would have two particular effects.
1/ it sets the start time for interpreting the word "were" above. i.e. the
suspend would abort of there were any unhandled wakeup events since the "suspend_prepare" was issued.
2/ It would allow unhandled wakeup events to abort the suspend. If no
suspend_preparehad been issued, then only "new" wakeup events would be allowed to abort the suspend (i.e. the old racy version of suspend).So the suspend daemon does:
wait for there to be no user-space suspend blocks issue
suspend_prepare
check there are still no suspend blocks
if there are, loop (possibly issuesuspend_abortif needed) issue suspend request
loop
Quoted 7 lines
processes that handle wakeup events would
poll for event to be available
request suspend-block
consume event
release suspend-block
loop
In my mind I'm thinking of something like:
attempt low power entry (suspend)
if blocked, get -EBUSY back
select on block_file until block is released retry suspend
else // entered low power and exited
read wake_event
do something with event; typically wait a bit and loop.
--mgross
Quoted 6 lines
(where consuming the event would quite possibly cause some other suspend-block to become active - e.g. it might request that the display be unlocked which would block suspends for a time).
NeilBrown
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Neil BrownQuoted 32 lines · Neil Brown
Quoted 7 lines · On Wed, 26 May 2010 14:20:51 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 4 lines · Peter Zijlstra
I fail to see why. In both cases the woken userspace will contact a central governing task, either the kernel or the userspace suspend manager, and inform it there is work to be done, and please don't suspend now.
Quoted 11 lines
Thinking about this, you're right - we don't have to wait, but that does result in another problem. Imagine we get two wakeup events approximately simultaneously. In the kernel-level universe the kernel knows when both have been handled. In the user-level universe, we may have one task schedule, bump the count, handle the event, drop the count and then we attempt a suspend again because the second event handler hasn't had an opportunity to run yet. We'll then attempt a suspend and immediately bounce back up. That's kind of wasteful, although it'd be somewhat mitigated by checking that right at the top of suspend entry and returning
-EAGAINor similar.(I'm coming a little late to this party, so excuse me if I say something that has already been covered however...)
The above triggers a sequence of thoughts which (When they settled down) look a bit like this.
At the hardware level, there is a thing that we could call a "suspend blocker". It is an interrupt (presumably level-triggered) that causes the processor to come out of suspend, or not to go into it.
Quoted 6 lines
Maybe it makes sense to export a similar thing from the kernel to user-space. When any event happens that would wake the device (and drivers need to know about these already), it would present something to user-space to say that the event happened.
When user-space processes the event, it clears the event indicator.
we did I proposed making the suspend enabling a oneshot type of thing and all sorts of weak arguments came spewing forth. I honestly couldn't tell if I was reading valid input or fanboy BS.
--mgross
Quoted 28 lines
When there are no more current event indicators, userspace is allowed to request a suspend. Obviously this could fail as an event could happen at any moment, but the same is true when the kernel asks the device to suspend, an interrupt might happen immediately to stop it. But in either case an event will be reported. So when userspace requests a suspend and it fails, it will see events reported and so will wait for them to be handled.
I imagine a sysfs directory with files that appear when events are pending. We could have some separate mechanism for user-space processes to request that the suspend-daemon not suspend. Then it suspends whenever there are no pending requests from user-space or from the kernel.
The advantage of this model of suspend-blockers is that it is a close analogue for something that already exists in hardware so it isn't really creating new concepts, just giving the Linux virtual-machine features that have proved themselves in physical machines.
The cost is that any wake-up event needs to not only be handled, but also explicitly acknowledged by clearing the relevant suspend-blocker (i.e. removing the file from sysfs, or whatever interface was ultimately chosen). I'm hoping that isn't a big cost.
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 25 lines · On Wed, 26 May 2010 10:42:22 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 7 lines · Arve Hjønnevåg
The biggest problem here is not that it is hard to change our user-space, but that the proposed change is inferior to what we have now. It forces us to poll until all drivers stop aborting suspend. On one hand we have people telling us that all code that polls is broken and must be fixed (instead of suspending to limit the damage), and on the other hand we have people suggesting we implement opportunistic suspend by polling from user-space until suspend succeeds.
No it does _not_. You're really not getting that Dmitry is proposing.
So your proposal is that when we wake userspace, it
opens/dev/suspend_blocker_before_ it consumes whatever event, consumes the event, deals with the event, then closes thesuspend_blocker. Then the kernel, upon reaching a 0suspend_blockercount, will try to suspend again.What Dmitry proposes is that, the app _before_ it consumes the event, pokes at this suspend manager, it increases a blocker count, then consumes the event (the kernel will _not_ auto-suspend), handles it and then again pokes the suspend manager, this time decreasing the blocker count.
Quoted 8 lines
The suspend manager will, upon reaching a 0 block count, suspend the machine. If that fails, it means there's something to do, an app will inc, work, dec its count, and it will try again once it reaches 0 again.
There is no polling what-so-ever in this model.
The only thing is that the kernel will not try to auto-suspend and there is no user-space suspend blocker API.
There is polling, because the suspend manager in userspace doesn't have the whole picture. i.e. it doesn't know if a suspend will be successfull.
So for aggressive suspending as a powersave-feature you need to poll (i.e. retry upon failure). because you don't want to stay unsuspended.
This discussion really is going in circles. You could all may well be just posting references to postings by now, instead of actually writing mails.
Cheers,
Flo
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 25 lines · On Wed, 26 May 2010 10:42:22 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 7 lines · Arve Hjønnevåg
The biggest problem here is not that it is hard to change our user-space, but that the proposed change is inferior to what we have now. It forces us to poll until all drivers stop aborting suspend. On one hand we have people telling us that all code that polls is broken and must be fixed (instead of suspending to limit the damage), and on the other hand we have people suggesting we implement opportunistic suspend by polling from user-space until suspend succeeds.
No it does _not_. You're really not getting that Dmitry is proposing.
So your proposal is that when we wake userspace, it
opens/dev/suspend_blocker_before_ it consumes whatever event, consumes the event, deals with the event, then closes thesuspend_blocker. Then the kernel, upon reaching a 0suspend_blockercount, will try to suspend again.What Dmitry proposes is that, the app _before_ it consumes the event, pokes at this suspend manager, it increases a blocker count, then consumes the event (the kernel will _not_ auto-suspend), handles it and then again pokes the suspend manager, this time decreasing the blocker count.
Quoted 8 lines
The suspend manager will, upon reaching a 0 block count, suspend the machine. If that fails, it means there's something to do, an app will inc, work, dec its count, and it will try again once it reaches 0 again.
There is no polling what-so-ever in this model.
The only thing is that the kernel will not try to auto-suspend and there is no user-space suspend blocker API.
There is polling, because the suspend manager in userspace doesn't have the whole picture. i.e. it doesn't know if a suspend will be successfull.
So for aggressive suspending as a powersave-feature you need to poll (i.e. retry upon failure). because you don't want to stay unsuspended.
This discussion really is going in circles. You could all may well be just posting references to postings by now, instead of actually writing mails.
Cheers,
Flo
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 5 lines · Florian Mickler
There is polling, because the suspend manager in userspace doesn't have the whole picture. i.e. it doesn't know if a suspend will be successfull.
So for aggressive suspending as a powersave-feature you need to poll (i.e. retry upon failure). because you don't want to stay unsuspended.
Clearly if it fails, there something to be done, right? So whoever does the thing will communicate with the suspend manager that it's going to do and has finished doing its thing, at which point it will try again.
That's event driven, not polled.
Also, if you want you can keep the kernel-side auto-suspend side, and have the suspend manager clear on !0 and re-establish the auto-suspend state on 0.
But you really don't need this device thingy.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Florian MicklerQuoted 5 lines · Florian Mickler
There is polling, because the suspend manager in userspace doesn't have the whole picture. i.e. it doesn't know if a suspend will be successfull.
So for aggressive suspending as a powersave-feature you need to poll (i.e. retry upon failure). because you don't want to stay unsuspended.
Clearly if it fails, there something to be done, right? So whoever does the thing will communicate with the suspend manager that it's going to do and has finished doing its thing, at which point it will try again.
That's event driven, not polled.
Also, if you want you can keep the kernel-side auto-suspend side, and have the suspend manager clear on !0 and re-establish the auto-suspend state on 0.
But you really don't need this device thingy.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 8 lines · Peter Zijlstra
Quoted 5 lines · Florian Mickler
There is polling, because the suspend manager in userspace doesn't have the whole picture. i.e. it doesn't know if a suspend will be successfull.
So for aggressive suspending as a powersave-feature you need to poll (i.e. retry upon failure). because you don't want to stay unsuspended.
Quoted 4 lines
Clearly if it fails, there something to be done, right? So whoever does the thing will communicate with the suspend manager that it's going to do and has finished doing its thing, at which point it will try again.
If you are talking about user-space code here, then that does not work. Not all kernel events that need to block suspend make it to user-space.
Quoted 8 lines
That's event driven, not polled.
Also, if you want you can keep the kernel-side auto-suspend side, and have the suspend manager clear on !0 and re-establish the auto-suspend state on 0.
But you really don't need this device thingy.
I'm not sure what you are proposing that we use instead. Both user-space and kernel code needs to block suspend. If we don't have suspend blockers in the kernel then user-space needs to poll when a driver blocks suspend by returning an error from its suspend hook.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 5 lines · Florian Mickler
There is polling, because the suspend manager in userspace doesn't have the whole picture. i.e. it doesn't know if a suspend will be successfull.
So for aggressive suspending as a powersave-feature you need to poll (i.e. retry upon failure). because you don't want to stay unsuspended.
Quoted 4 lines
Clearly if it fails, there something to be done, right? So whoever does the thing will communicate with the suspend manager that it's going to do and has finished doing its thing, at which point it will try again.
If you are talking about user-space code here, then that does not work. Not all kernel events that need to block suspend make it to user-space.
Quoted 8 lines
That's event driven, not polled.
Also, if you want you can keep the kernel-side auto-suspend side, and have the suspend manager clear on !0 and re-establish the auto-suspend state on 0.
But you really don't need this device thingy.
I'm not sure what you are proposing that we use instead. Both user-space and kernel code needs to block suspend. If we don't have suspend blockers in the kernel then user-space needs to poll when a driver blocks suspend by returning an error from its suspend hook.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 5 lines · Arve Hjønnevåg
I'm not sure what you are proposing that we use instead. Both user-space and kernel code needs to block suspend. If we don't have suspend blockers in the kernel then user-space needs to poll when a driver blocks suspend by returning an error from its suspend hook.
In particular I'm suggesting you ditch the /dev/suspend_block thing.
With a single suspend manager process that manages the suspend state you can achieve the same goal.
When the suspend manager has a !0 busy-task count, it ensures the kernel won't auto-suspend, when it again reaches a 0 busy-task count, it re-instates the auto-suspend feature.
That's pretty much what that device would do too.
Ideally we would not do the auto-suspend thing at all and have runtime-PM improved. Not running apps when they expect to run is like the world turned upside down.
'Evil' apps could always report themselves as blocker anyway.
_______________________________________________
linux-pm mailing list [email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 5 lines · Arve Hjønnevåg
I'm not sure what you are proposing that we use instead. Both user-space and kernel code needs to block suspend. If we don't have suspend blockers in the kernel then user-space needs to poll when a driver blocks suspend by returning an error from its suspend hook.
In particular I'm suggesting you ditch the /dev/suspend_block thing.
With a single suspend manager process that manages the suspend state you can achieve the same goal.
When the suspend manager has a !0 busy-task count, it ensures the kernel won't auto-suspend, when it again reaches a 0 busy-task count, it re-instates the auto-suspend feature.
That's pretty much what that device would do too.
Ideally we would not do the auto-suspend thing at all and have runtime-PM improved. Not running apps when they expect to run is like the world turned upside down.
'Evil' apps could always report themselves as blocker anyway.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 7 lines · Arve Hjønnevåg
Quoted 5 lines
I'm not sure what you are proposing that we use instead. Both user-space and kernel code needs to block suspend. If we don't have suspend blockers in the kernel then user-space needs to poll when a driver blocks suspend by returning an error from its suspend hook.
Quoted 5 lines
In particular I'm suggesting you ditch the
/dev/suspend_blockthing.With a single suspend manager process that manages the suspend state you can achieve the same goal.
Yes we don't need the /dev interface, but it is useful. Without it any program that needs to block suspend has to make a blocking ipc call into the suspend manager process. Android already does this for java code, but system processes written in C block suspend directly with the kernel since they cannot use the java APIs.
Quoted 12 lines
When the suspend manager has a !0 busy-task count, it ensures the kernel won't auto-suspend, when it again reaches a 0 busy-task count, it re-instates the auto-suspend feature.
That's pretty much what that device would do too.
Ideally we would not do the auto-suspend thing at all and have runtime-PM improved. Not running apps when they expect to run is like the world turned upside down.
'Evil' apps could always report themselves as blocker anyway.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter Zijlstra2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 7 lines · Arve Hjønnevåg
Quoted 5 lines
I'm not sure what you are proposing that we use instead. Both user-space and kernel code needs to block suspend. If we don't have suspend blockers in the kernel then user-space needs to poll when a driver blocks suspend by returning an error from its suspend hook.
Quoted 5 lines
In particular I'm suggesting you ditch the
/dev/suspend_blockthing.With a single suspend manager process that manages the suspend state you can achieve the same goal.
Yes we don't need the /dev interface, but it is useful. Without it any program that needs to block suspend has to make a blocking ipc call into the suspend manager process. Android already does this for java code, but system processes written in C block suspend directly with the kernel since they cannot use the java APIs.
Quoted 12 lines
When the suspend manager has a !0 busy-task count, it ensures the kernel won't auto-suspend, when it again reaches a 0 busy-task count, it re-instates the auto-suspend feature.
That's pretty much what that device would do too.
Ideally we would not do the auto-suspend thing at all and have runtime-PM improved. Not running apps when they expect to run is like the world turned upside down.
'Evil' apps could always report themselves as blocker anyway.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 9 lines · Arve Hjønnevåg
Quoted 3 lines
With a single suspend manager process that manages the suspend state you can achieve the same goal.
Yes we don't need the /dev interface, but it is useful. Without it any program that needs to block suspend has to make a blocking ipc call into the suspend manager process. Android already does this for java code, but system processes written in C block suspend directly with the kernel since they cannot use the java APIs.
So provide a C interface to it as well?
Surely you can have the java thing have a unix socket or something a C app can talk to. That shouldn't be hard at all.
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Arve HjønnevågQuoted 9 lines · Arve Hjønnevåg
Quoted 3 lines
With a single suspend manager process that manages the suspend state you can achieve the same goal.
Yes we don't need the /dev interface, but it is useful. Without it any program that needs to block suspend has to make a blocking ipc call into the suspend manager process. Android already does this for java code, but system processes written in C block suspend directly with the kernel since they cannot use the java APIs.
So provide a C interface to it as well?
Surely you can have the java thing have a unix socket or something a C app can talk to. That shouldn't be hard at all.
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 8 lines · Arve Hjønnevåg
Quoted 8 lines
Quoted 2 lines
With a single suspend manager process that manages the suspend state you can achieve the same goal.
Yes we don't need the /dev interface, but it is useful. Without it any program that needs to block suspend has to make a blocking ipc call into the suspend manager process. Android already does this for java code, but system processes written in C block suspend directly with the kernel since they cannot use the java APIs.
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 7 lines
So provide a C interface to it as well?
Surely you can have the java thing have a unix socket or something a C app can talk to. That shouldn't be hard at all.
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
Yup, I don't quite get Arve's argument either. C code can interact with Java code (and vice versa) just fine in userspace.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 8 lines · Arve Hjønnevåg
Quoted 8 lines
Quoted 2 lines
With a single suspend manager process that manages the suspend state you can achieve the same goal.
Yes we don't need the /dev interface, but it is useful. Without it any program that needs to block suspend has to make a blocking ipc call into the suspend manager process. Android already does this for java code, but system processes written in C block suspend directly with the kernel since they cannot use the java APIs.
2010/5/26 Peter Zijlstra <[email protected]>:
Quoted 7 lines
So provide a C interface to it as well?
Surely you can have the java thing have a unix socket or something a C app can talk to. That shouldn't be hard at all.
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
Yup, I don't quite get Arve's argument either. C code can interact with Java code (and vice versa) just fine in userspace.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 2 lines · Pekka Enberg
Yup, I don't quite get Arve's argument either. C code can interact with Java code (and vice versa) just fine in userspace.
This is an incorrect statement. It's possible for java to call C via the JNI, even though there are quite a few gotchas that mean not just *any* C code can do it (been there, tripped over some of them, although they were all ultimately ironed out). It's very difficult for C to call directly into Java without being specially coded because it involves creating and managing a JVM (so in general, arbitrary C code can't do this). The usual way we do C -> Java is process to process via some intermediary like RPC or Corba or SOAP (or even JSON) ... which gets very messy for a mobile device.
Quoted 1 line · Peter Zijlstra
So provide a C interface to it as well?
The way Android is currently coded, all user space suspend blocks are handled in Java code at what's called the Frameworks layer (Frameworks is the Java API for apps) this is also how the suspend permissions are managed and presented to the user. The few C applications which block suspend just manipulate the device directly.
Quoted 5 lines
Surely you can have the java thing have a unix socket or something a C app can talk to. That shouldn't be hard at all.
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Pekka EnbergQuoted 2 lines · Pekka Enberg
Yup, I don't quite get Arve's argument either. C code can interact with Java code (and vice versa) just fine in userspace.
This is an incorrect statement. It's possible for java to call C via the JNI, even though there are quite a few gotchas that mean not just *any* C code can do it (been there, tripped over some of them, although they were all ultimately ironed out). It's very difficult for C to call directly into Java without being specially coded because it involves creating and managing a JVM (so in general, arbitrary C code can't do this). The usual way we do C -> Java is process to process via some intermediary like RPC or Corba or SOAP (or even JSON) ... which gets very messy for a mobile device.
Quoted 1 line · Peter Zijlstra
So provide a C interface to it as well?
The way Android is currently coded, all user space suspend blocks are handled in Java code at what's called the Frameworks layer (Frameworks is the Java API for apps) this is also how the suspend permissions are managed and presented to the user. The few C applications which block suspend just manipulate the device directly.
Quoted 5 lines
Surely you can have the java thing have a unix socket or something a C app can talk to. That shouldn't be hard at all.
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 10 lines · James Bottomley
Quoted 2 lines
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
It wouldn't need to convert the whole Frameworks layer into C, just enough to manage the suspend state.
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
The whole idea of segregating userspace like that, and not letting runnable thing run is very ill considered indeed.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to James BottomleyQuoted 10 lines · James Bottomley
Quoted 2 lines
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
It wouldn't need to convert the whole Frameworks layer into C, just enough to manage the suspend state.
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
The whole idea of segregating userspace like that, and not letting runnable thing run is very ill considered indeed.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 3 lines · Peter Zijlstra
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
It's already been submitted to Linus for 2.6.35, but not on LKML:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025811.html
Kevin
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 3 lines · Peter Zijlstra
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
It's already been submitted to Linus for 2.6.35, but not on LKML:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025811.html
Kevin
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 12 lines · Peter Zijlstra
Quoted 10 lines · James Bottomley
Quoted 2 lines
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
Quoted 2 lines
It wouldn't need to convert the whole Frameworks layer into C, just enough to manage the suspend state.
That's actually what I was saying ... converting the whole frameworks would be impossible. I'm saying the suspend state manager is still a large piece of work.
Quoted 3 lines
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
Well, I suppose that's your prerogative.
Quoted 2 lines
The whole idea of segregating userspace like that, and not letting runnable thing run is very ill considered indeed.
OK, so this is an approach difference. I see it as controlling an application resource problem, which is similar to quotas on filesystems. The opinion divide seems to come down to those who think the application stack has to be fixed before a working device can be released, and those who want to make the devices work now and supply pressure to fix the applications as well.
I fail to see how, in an environment where the whole value of the device is the third party supplied applications that the former view is reasonable. I equally fail to see how the latter is achievable without segregating userspace into trusted and untrusted and taking action to curb the power consumption of untrusted applications.
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 12 lines · Peter Zijlstra
Quoted 10 lines · James Bottomley
Quoted 2 lines
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
Quoted 2 lines
It wouldn't need to convert the whole Frameworks layer into C, just enough to manage the suspend state.
That's actually what I was saying ... converting the whole frameworks would be impossible. I'm saying the suspend state manager is still a large piece of work.
Quoted 3 lines
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
Well, I suppose that's your prerogative.
Quoted 2 lines
The whole idea of segregating userspace like that, and not letting runnable thing run is very ill considered indeed.
OK, so this is an approach difference. I see it as controlling an application resource problem, which is similar to quotas on filesystems. The opinion divide seems to come down to those who think the application stack has to be fixed before a working device can be released, and those who want to make the devices work now and supply pressure to fix the applications as well.
I fail to see how, in an environment where the whole value of the device is the third party supplied applications that the former view is reasonable. I equally fail to see how the latter is achievable without segregating userspace into trusted and untrusted and taking action to curb the power consumption of untrusted applications.
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to James BottomleyQuoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 11 lines · James Bottomley
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Quoted 7 lines
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
The difference is that the limit should be per task. In this model a process that only runs a little still gets suspended.
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to James BottomleyQuoted 11 lines · James Bottomley
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Quoted 7 lines
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
The difference is that the limit should be per task. In this model a process that only runs a little still gets suspended.
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 20 lines · Peter Zijlstra
Quoted 11 lines · James Bottomley
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Quoted 7 lines
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
Quoted 1 line
The difference is that the limit should be per task.
How? You've got two different limits ... one the power the application should be consuming when doing useful work for the user and the other is the idle power. A badly constructed app may only be bad on idle power ... how is the scheduler going to detect this, exactly? And what do we do to applications we've detected are over consuming idle power?
Quoted 2 lines
In this model a
process that only runs a little still gets suspended.
That's why I think it looks like a reasonable solution. For this to work, I agree you have to have all events the user is interested in wake the system up ... but on most embedded platforms, they do.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
OK, so I've got one ... tell me what I should see and I'll try to reproduce.
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 20 lines · Peter Zijlstra
Quoted 11 lines · James Bottomley
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Quoted 7 lines
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
Quoted 1 line
The difference is that the limit should be per task.
How? You've got two different limits ... one the power the application should be consuming when doing useful work for the user and the other is the idle power. A badly constructed app may only be bad on idle power ... how is the scheduler going to detect this, exactly? And what do we do to applications we've detected are over consuming idle power?
Quoted 2 lines
In this model a
process that only runs a little still gets suspended.
That's why I think it looks like a reasonable solution. For this to work, I agree you have to have all events the user is interested in wake the system up ... but on most embedded platforms, they do.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
OK, so I've got one ... tell me what I should see and I'll try to reproduce.
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Hi!
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
Quoted 6 lines
Quoted 3 lines
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
OK, so I've got one ... tell me what I should see and I'll try to reproduce.
Umm... try to boot ordinary distro and see how it copes with opportunistic suspend?
I do have android here, and of course it work well with custom userland. Question is: can common distro be reasonably modified to work with suspend blockers, in a way that's backward compatible?
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: Opportunistic suspend support.
In reply to James BottomleyHi!
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
Quoted 6 lines
Quoted 3 lines
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
OK, so I've got one ... tell me what I should see and I'll try to reproduce.
Umm... try to boot ordinary distro and see how it copes with opportunistic suspend?
I do have android here, and of course it work well with custom userland. Question is: can common distro be reasonably modified to work with suspend blockers, in a way that's backward compatible?
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: Opportunistic suspend support.
Quoted 14 lines · Pavel Machek
Hi!
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
Quoted 5 lines
Quoted 2 lines
OK, so I've got one ... tell me what I should see and I'll try to reproduce.
Umm... try to boot ordinary distro and see how it copes with opportunistic suspend?
That's not really going to help, is it? The issue I was curious are what are the bad things that result from interfering with the regular scheduling of processes ... because undeniably suspend (whether opportunistic or ordinary) does produce this interference.
I could boot debian on an android and have it suspend ... that's still not going to answer my question.
Quoted 3 lines
I do have android here, and of course it work well with custom userland. Question is: can common distro be reasonably modified to work with suspend blockers, in a way that's backward compatible?
You mean how an app could run if it was compiled with suspend blockers but the platform doesn't support it? That's a simple runtime switch in the library surely?
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Pavel MachekQuoted 14 lines · Pavel Machek
Hi!
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
I do not have one, nor have I ever written an application for it (nor will I likely ever do that, since I detest Java), but I would expect an application to run when its runnable.
Quoted 5 lines
Quoted 2 lines
OK, so I've got one ... tell me what I should see and I'll try to reproduce.
Umm... try to boot ordinary distro and see how it copes with opportunistic suspend?
That's not really going to help, is it? The issue I was curious are what are the bad things that result from interfering with the regular scheduling of processes ... because undeniably suspend (whether opportunistic or ordinary) does produce this interference.
I could boot debian on an android and have it suspend ... that's still not going to answer my question.
Quoted 3 lines
I do have android here, and of course it work well with custom userland. Question is: can common distro be reasonably modified to work with suspend blockers, in a way that's backward compatible?
You mean how an app could run if it was compiled with suspend blockers but the platform doesn't support it? That's a simple runtime switch in the library surely?
James
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to James BottomleyQuoted 11 lines · James Bottomley
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Quoted 7 lines
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
Well, generic mechanism would stop processes when they run over something -- not arbitrarily link it to device wakeup.
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
Besides that it is not linux system at all?
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
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: Opportunistic suspend support.
In reply to James BottomleyQuoted 11 lines · James Bottomley
Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · James Bottomley
Given that I'm in the latter category, I think suspend blockers is a reasonable solution to an existing problem. I like Alan's idea of restricting the API into a single user space program so we contain the API contamination ... but realistically that's mostly the current suspend blockers anyway.
There's a _large_ difference between resource limits and these wonky suspend blockers.
Quoted 7 lines
Well, you have policy and then you have implementation ... suspend blockers just looks like an implementation to me. It seems to be reasonably well suited in that regard ... after all, we kill processes that exhaust memory for instance or cut off write privileges to those that go over quota. Preventing power hungry processes from consuming power by not allowing them to run until there's a wakeup event is fairly gentle by those standards.
Well, generic mechanism would stop processes when they run over something -- not arbitrarily link it to device wakeup.
Quoted 7 lines
Quoted 3 lines
The main and most important one being that suspend is a global property and can/will hurt sensible tasks. It puts the whole task model upside down.
OK, so I believe you have an android phone ... it already implements this model ... specifically what are the problems on that platform this causes?
Besides that it is not linux system at all?
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
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: Opportunistic suspend support.
Quoted 1 line · On Wed, 26 May 2010 19:28:24 +0200 Pavel Machek <[email protected]> wrote:
Besides that it is not linux system at all?
I believe the kernel to be a layer between userspace and hardware. What business is it to the kernel if it runs whatever android uses as init process or /bin/bash, sys-v-init or systemd?
There is this thing called choice.
Quoted 5 lines
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
Pavel
I don't think this is a valid concern. Just because current linux/gnu systems don't implement the userspace part of this interface doesn't mean it is useless or broken.
Cheers,
Flo
Signature · 2 lines
Just because I argue an issue, doesn't mean I agree with either side of it.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Pavel MachekQuoted 1 line · On Wed, 26 May 2010 19:28:24 +0200 Pavel Machek <[email protected]> wrote:
Besides that it is not linux system at all?
I believe the kernel to be a layer between userspace and hardware. What business is it to the kernel if it runs whatever android uses as init process or /bin/bash, sys-v-init or systemd?
There is this thing called choice.
Quoted 5 lines
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
Pavel
I don't think this is a valid concern. Just because current linux/gnu systems don't implement the userspace part of this interface doesn't mean it is useless or broken.
Cheers,
Flo
Signature · 2 lines
Just because I argue an issue, doesn't mean I agree with either side of it.
Re: [PATCH 1/8] PM: Opportunistic suspend support.
Quoted 13 lines · Florian Mickler
Quoted 1 line · On Wed, 26 May 2010 19:28:24 +0200 Pavel Machek <[email protected]> wrote:
Besides that it is not linux system at all?
I believe the kernel to be a layer between userspace and hardware. What business is it to the kernel if it runs whatever android uses as init process or
/bin/bash, sys-v-init or systemd?There is this thing called choice.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
PavelI don't think this is a valid concern. Just because current linux/gnu systems don't implement the userspace part of this interface doesn't mean it is useless or broken.
Agreed.
BTW, this is a valid point. We are used to think about Linux as the kernel plus the GNU user space, but that's not how it has to be.
Thanks,
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Florian MicklerQuoted 13 lines · Florian Mickler
Quoted 1 line · On Wed, 26 May 2010 19:28:24 +0200 Pavel Machek <[email protected]> wrote:
Besides that it is not linux system at all?
I believe the kernel to be a layer between userspace and hardware. What business is it to the kernel if it runs whatever android uses as init process or
/bin/bash, sys-v-init or systemd?There is this thing called choice.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
PavelI don't think this is a valid concern. Just because current linux/gnu systems don't implement the userspace part of this interface doesn't mean it is useless or broken.
Agreed.
BTW, this is a valid point. We are used to think about Linux as the kernel plus the GNU user space, but that's not how it has to be.
Thanks,
Rafael
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Florian MicklerQuoted 8 lines · Florian Mickler
Quoted 1 line · On Wed, 26 May 2010 19:28:24 +0200 Pavel Machek <[email protected]> wrote:
Besides that it is not linux system at all?
I believe the kernel to be a layer between userspace and hardware. What business is it to the kernel if it runs whatever android uses as init process or
/bin/bash, sys-v-init or systemd?
The kernel has no business and doesn't care. But precisely that is the reason to clearly separate policy from means. And that separation is not done in a good way by a loosely-defined API but by a (well-defined) kernel-API which allows user-space so implement the policy (whatever it might feel) by using the means (wiht appopriate parameters). So the (kernel-)API should not use policy-defined (read: user-space) semantics/values - plain simply because they will change (in no time). But the kernel must use policy-independent semantics/values - if only the suspend/wakeup-latency or whatever technically makes sense. Perhaps some "will/want to be waken up every 0.1 second" makes sense for periodic jobs.
Quoted 7 lines
There is this thing called choice.
Quoted 3 lines
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
I don't think this is a valid concern. Just because current linux/gnu
A lot of stuff is not (or no longer) implemented because it's - plain simply - a bad idea in the first place.
Other than that: Linux/GNU-systems come from the server and desktop world where power is not an important part. And laptop producers obviously didn't care enough ...
And you do realize that in the non-embedded (and non-Apple) world the user-space is not controlled by one entity in any way.
So forcing "good apps" vs "bad apps" doesn't workout - except you have direct feedback like "powertop" which makes it easy for everyone (especially the users) to rate the apps.
So the kernel actually must have means to do that. If user-space defines the semantics of the API, the kernel can't do that because user-space is always right.
Quoted 2 lines
systems don't implement the userspace part of this interface doesn't mean it is useless or broken.
Just because Android designed and/or implements it doesn't mean it's not broken (in the medium to long run).
So what?
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Florian MicklerQuoted 8 lines · Florian Mickler
Quoted 1 line · On Wed, 26 May 2010 19:28:24 +0200 Pavel Machek <[email protected]> wrote:
Besides that it is not linux system at all?
I believe the kernel to be a layer between userspace and hardware. What business is it to the kernel if it runs whatever android uses as init process or
/bin/bash, sys-v-init or systemd?
The kernel has no business and doesn't care. But precisely that is the reason to clearly separate policy from means. And that separation is not done in a good way by a loosely-defined API but by a (well-defined) kernel-API which allows user-space so implement the policy (whatever it might feel) by using the means (wiht appopriate parameters). So the (kernel-)API should not use policy-defined (read: user-space) semantics/values - plain simply because they will change (in no time). But the kernel must use policy-independent semantics/values - if only the suspend/wakeup-latency or whatever technically makes sense. Perhaps some "will/want to be waken up every 0.1 second" makes sense for periodic jobs.
Quoted 7 lines
There is this thing called choice.
Quoted 3 lines
Yes, with custom userspace it works extremely nicely.
Had anyone even tried running oportunistic suspend on normal desktop?
I don't think this is a valid concern. Just because current linux/gnu
A lot of stuff is not (or no longer) implemented because it's - plain simply - a bad idea in the first place.
Other than that: Linux/GNU-systems come from the server and desktop world where power is not an important part. And laptop producers obviously didn't care enough ...
And you do realize that in the non-embedded (and non-Apple) world the user-space is not controlled by one entity in any way.
So forcing "good apps" vs "bad apps" doesn't workout - except you have direct feedback like "powertop" which makes it easy for everyone (especially the users) to rate the apps.
So the kernel actually must have means to do that. If user-space defines the semantics of the API, the kernel can't do that because user-space is always right.
Quoted 2 lines
systems don't implement the userspace part of this interface doesn't mean it is useless or broken.
Just because Android designed and/or implements it doesn't mean it's not broken (in the medium to long run).
So what?
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Re: [PATCH 1/8] PM: Opportunistic suspend support.
In reply to Peter ZijlstraQuoted 12 lines · Peter Zijlstra
Quoted 10 lines · James Bottomley
Quoted 2 lines
Or make the suspend manager a C proglet and provide a JNI interface, or whatever.
It's a fairly large piece of code to try to rewrite in C, so I don't think that's feasible on a reasonable timescale. Android does have the concept of special sockets that can be used to communicate from less to more privileged processes (it has a very segmented runtime model), so these might be usable ... they have a drawback that they're essentially named pipes, so no multiplexing, but one per suspend influencing C process shouldn't be a huge burden.
Quoted 6 lines
It wouldn't need to convert the whole Frameworks layer into C, just enough to manage the suspend state.
Anyway, I think there's been enough arguments against even the concept of opportunistic/auto-suspend, and I for one will object with a NAK if Rafael send this to Linus.
It was submitted already. I tried to followup with NAK, but can't currently see it in the archive.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html