Skip to contentSkip to conversation

Suspend block api (version 8)

PATCH In review Arve Hjønnevåg 35 participants 1,364 messages May 21, 2010 – Jun 21, 2010 Page 1 of 6

Subsystems (6)
lore
Share & tools
lore
#1 lore raw

PATCH 1/8 PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg

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
new file mode 100644
index 0000000..4bee7bc
@@ -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
index 5e781d8..07023d3 100644
@@ -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
index 5c36ea9..6d11a45 100644
@@ -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
index 4319181..95d8e6d 100644
@@ -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
index 46c5a26..2e9cfd5 100644
@@ -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
index 56e7dbb..9eb3876 100644
@@ -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
#3 lore raw

PATCH 2/8 PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg

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
index dd5806f..e2458f7 100644
@@ -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
index 4bee7bc..93f4c24 100644
@@ -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
index 0b30382..b95a6b2 100644
@@ -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
index 6d11a45..2e665cd 100644
@@ -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
index 95d8e6d..2015594 100644
@@ -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
#5 lore raw

PATCH 3/8 PM: suspend_block: Abort task freezing if a suspend_blocker is active.

In reply to Arve Hjønnevåg

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
index 71ae290..27d26d3 100644
@@ -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
#7 lore raw

PATCH 4/8 PM: suspend_block: Add debugfs file

In reply to Arve Hjønnevåg

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
index cc90b60..6b5eb1d 100644
@@ -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
#9 lore raw

PATCH 5/8 PM: suspend_block: Add suspend_blocker stats

In reply to Arve Hjønnevåg

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
index 8788302..256af15 100755
@@ -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
index 2e665cd..16a2570 100644
@@ -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
index 2e9cfd5..e13c975 100644
@@ -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
index 9eb3876..df694e7 100644
@@ -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
#11 lore raw

PATCH 6/8 PM: Add suspend blocking work.

In reply to Arve Hjønnevåg

Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate suspend_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
index 256af15..bb90b45 100755
@@ -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
#13 lore raw

PATCH 7/8 Input: Block suspend while event queue is not empty.

In reply to Arve Hjønnevåg

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
index 2ee6c7a..bff2247 100644
@@ -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
index 7ed2251..b2d93b4 100644
@@ -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
#16 lore raw

PATCH 7/8 Input: Block suspend while event queue is not empty.

In reply to Arve Hjønnevåg

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
index 2ee6c7a..bff2247 100644
@@ -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
index 7ed2251..b2d93b4 100644
@@ -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
#14 lore raw

PATCH 8/8 power_supply: Block suspend while power supply change notifications are pending

In reply to Arve Hjønnevåg

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
index cce75b4..577a131 100644
@@ -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
index ebd2b8f..f6412c8 100644
@@ -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
#0 lore raw

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]>

#2 lore raw

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
new file mode 100644
index 0000000..4bee7bc
@@ -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
index 5e781d8..07023d3 100644
@@ -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
index 5c36ea9..6d11a45 100644
@@ -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
index 4319181..95d8e6d 100644
@@ -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
index 46c5a26..2e9cfd5 100644
@@ -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
index 56e7dbb..9eb3876 100644
@@ -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
#6 lore raw

PATCH 3/8 PM: suspend_block: Abort task freezing if a suspend_blocker is active.

In reply to Arve Hjønnevåg

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
index 71ae290..27d26d3 100644
@@ -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
#12 lore raw

PATCH 6/8 PM: Add suspend blocking work.

In reply to Arve Hjønnevåg

Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate suspend_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
index 256af15..bb90b45 100755
@@ -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
#10 lore raw

PATCH 5/8 PM: suspend_block: Add suspend_blocker stats

In reply to Arve Hjønnevåg

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
index 8788302..256af15 100755
@@ -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
index 2e665cd..16a2570 100644
@@ -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
index 2e9cfd5..e13c975 100644
@@ -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
index 9eb3876..df694e7 100644
@@ -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
#15 lore raw

PATCH 8/8 power_supply: Block suspend while power supply change notifications are pending

In reply to Arve Hjønnevåg

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
index cce75b4..577a131 100644
@@ -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
index ebd2b8f..f6412c8 100644
@@ -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
#8 lore raw

PATCH 4/8 PM: suspend_block: Add debugfs file

In reply to Arve Hjønnevåg

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
index cc90b60..6b5eb1d 100644
@@ -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
#4 lore raw

PATCH 2/8 PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg

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
index dd5806f..e2458f7 100644
@@ -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
index 4bee7bc..93f4c24 100644
@@ -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
index 0b30382..b95a6b2 100644
@@ -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
index 6d11a45..2e665cd 100644
@@ -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
index 95d8e6d..2015594 100644
@@ -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
#42 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
Quoted 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

#43 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
Quoted 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

#247 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

Thanks,
Rafael

#1363 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

Thanks,
Rafael
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#248 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

Signature · 3 lines
balbi

DefectiveByDesign.org
#249 lore raw
Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Quoted 5 lines
Quoted 1 line

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

I don't think the concerns you're referring to can be solved out. Some people just don't like the whole idea and I don't think there's any way we can improve the patches to make them happy. The only "solution" they would be satisfied with would simply be rejecting the feature altogether, although there are no practically viable alternatives known to me.

OTOH I do think there are quite a few reasons to take the patchset, so I'm going to push it to Linus as I told in one of my replies to Kevin. If Linus decides not to pull it, so be it.

Thanks,
Rafael

#1354 lore raw
In reply to Felipe Balbi
Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Quoted 5 lines
Quoted 1 line

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

I don't think the concerns you're referring to can be solved out. Some people just don't like the whole idea and I don't think there's any way we can improve the patches to make them happy. The only "solution" they would be satisfied with would simply be rejecting the feature altogether, although there are no practically viable alternatives known to me.

OTOH I do think there are quite a few reasons to take the patchset, so I'm going to push it to Linus as I told in one of my replies to Kevin. If Linus decides not to pull it, so be it.

Thanks,
Rafael

#250 lore raw
In reply to Rafael J. Wysocki
Quoted 14 lines · Rafael J. Wysocki
Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Quoted 5 lines
Quoted 1 line

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

Quoted 6 lines

I don't think the concerns you're referring to can be solved out. Some people just don't like the whole idea and I don't think there's any way we can improve the patches to make them happy. The only "solution" they would be satisfied with would simply be rejecting the feature altogether, although there are no practically viable alternatives known to me.

I'm not sure who the "some people" you're referring to are, but I'll assume I'm included in that group.

I don't think this is a fair characterization of the objections, nor do I think "rejecting the feature altogether" is the only satisfactory answer. Speaking for myself, I find the idea of being able to suspend while idle a valid objective, and certainly see the usefulness of it for embedded systems. I'm also an owner and user of an Android phone, so I am certainly not out just to make life difficult for Android.

The primary objection is not the end goal, but rather the implementation. In particular, the problematic redefintion of what it means to be idle, or "not doing work that's immediately useful to the user" to use the phrase from the changelog (where "useful" is still not defined.)

This (re)definition completely bypasses all current idle infrastructure based on timers, scheduler, etc. and makes "usefulness" defined in terms of who holds suspend blockers. This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

Kevin

#1353 lore raw
In reply to Rafael J. Wysocki
Quoted 14 lines · Rafael J. Wysocki
Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Quoted 5 lines
Quoted 1 line

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

Quoted 6 lines

I don't think the concerns you're referring to can be solved out. Some people just don't like the whole idea and I don't think there's any way we can improve the patches to make them happy. The only "solution" they would be satisfied with would simply be rejecting the feature altogether, although there are no practically viable alternatives known to me.

I'm not sure who the "some people" you're referring to are, but I'll assume I'm included in that group.

I don't think this is a fair characterization of the objections, nor do I think "rejecting the feature altogether" is the only satisfactory answer. Speaking for myself, I find the idea of being able to suspend while idle a valid objective, and certainly see the usefulness of it for embedded systems. I'm also an owner and user of an Android phone, so I am certainly not out just to make life difficult for Android.

The primary objection is not the end goal, but rather the implementation. In particular, the problematic redefintion of what it means to be idle, or "not doing work that's immediately useful to the user" to use the phrase from the changelog (where "useful" is still not defined.)

This (re)definition completely bypasses all current idle infrastructure based on timers, scheduler, etc. and makes "usefulness" defined in terms of who holds suspend blockers. This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

Kevin

#251 lore raw
In reply to Kevin Hilman
Quoted 33 lines · Kevin Hilman
Quoted 14 lines · Rafael J. Wysocki
Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Quoted 5 lines
Quoted 1 line

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

Quoted 6 lines

I don't think the concerns you're referring to can be solved out. Some people just don't like the whole idea and I don't think there's any way we can improve the patches to make them happy. The only "solution" they would be satisfied with would simply be rejecting the feature altogether, although there are no practically viable alternatives known to me.

I'm not sure who the "some people" you're referring to are, but I'll assume I'm included in that group.

I don't think this is a fair characterization of the objections, nor do I think "rejecting the feature altogether" is the only satisfactory answer. Speaking for myself, I find the idea of being able to suspend while idle a valid objective, and certainly see the usefulness of it for embedded systems. I'm also an owner and user of an Android phone, so I am certainly not out just to make life difficult for Android.

Quoted 5 lines

The primary objection is not the end goal, but rather the implementation. In particular, the problematic redefintion of what it means to be idle, or "not doing work that's immediately useful to the user" to use the phrase from the changelog (where "useful" is still not defined.)

So, in fact, you don't like the _idea_, because the _idea_ is to use suspend blockers instead of trying to define what "idle" means.

I don't think it's generally possible to define "idle" to match every possible criteria one can imagine, so you're request to do that simply cannot be satisfied.

Quoted 3 lines

This (re)definition completely bypasses all current idle infrastructure based on timers, scheduler, etc. and makes "usefulness" defined in terms of who holds suspend blockers.

That's because the point is not to suspend when the system is "idle", because that would mean "suspend transparently from the applications' point of view", which is what the Android people _don't_ _want_ _to_ _do_, because in that case their battery life would go to the toilet. The idea is to suspend even when the system is not techincally "idle" and you don't like _that_.

Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

As I said before, I don't think there's a way to resolve this so that everyone is happy and in my opinion there are reasons to merge the feature.

Also I don't think we can make any progress discussing it. We've already discussed it for a month or so without any real progress and I don't see how that's going to change now.

Thanks,
Rafael

#1352 lore raw
In reply to Kevin Hilman
Quoted 33 lines · Kevin Hilman
Quoted 14 lines · Rafael J. Wysocki
Quoted 7 lines · Felipe Balbi
Quoted 6 lines · ext Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Quoted 5 lines
Quoted 1 line

Patches [1-6/8] applied to suspend-2.6/linux-next

funny thing is that even without sorting out the concerns plenty of developers had on the other thread, this series is still taken. What's the point in dicussing/reviewing the patches then ?

Quoted 6 lines

I don't think the concerns you're referring to can be solved out. Some people just don't like the whole idea and I don't think there's any way we can improve the patches to make them happy. The only "solution" they would be satisfied with would simply be rejecting the feature altogether, although there are no practically viable alternatives known to me.

I'm not sure who the "some people" you're referring to are, but I'll assume I'm included in that group.

I don't think this is a fair characterization of the objections, nor do I think "rejecting the feature altogether" is the only satisfactory answer. Speaking for myself, I find the idea of being able to suspend while idle a valid objective, and certainly see the usefulness of it for embedded systems. I'm also an owner and user of an Android phone, so I am certainly not out just to make life difficult for Android.

Quoted 5 lines

The primary objection is not the end goal, but rather the implementation. In particular, the problematic redefintion of what it means to be idle, or "not doing work that's immediately useful to the user" to use the phrase from the changelog (where "useful" is still not defined.)

So, in fact, you don't like the _idea_, because the _idea_ is to use suspend blockers instead of trying to define what "idle" means.

I don't think it's generally possible to define "idle" to match every possible criteria one can imagine, so you're request to do that simply cannot be satisfied.

Quoted 3 lines

This (re)definition completely bypasses all current idle infrastructure based on timers, scheduler, etc. and makes "usefulness" defined in terms of who holds suspend blockers.

That's because the point is not to suspend when the system is "idle", because that would mean "suspend transparently from the applications' point of view", which is what the Android people _don't_ _want_ _to_ _do_, because in that case their battery life would go to the toilet. The idea is to suspend even when the system is not techincally "idle" and you don't like _that_.

Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

As I said before, I don't think there's a way to resolve this so that everyone is happy and in my opinion there are reasons to merge the feature.

Also I don't think we can make any progress discussing it. We've already discussed it for a month or so without any real progress and I don't see how that's going to change now.

Thanks,
Rafael

#44 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern

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
#45 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern

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
#46 lore raw

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

#47 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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

maintainer
#48 lore raw

Re: [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
maintainer
#49 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern
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
#50 lore raw

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

#51 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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

maintainer
#52 lore raw

Re: [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
maintainer
#53 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern
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
#54 lore raw

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

#55 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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

maintainer
#56 lore raw

Re: [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
maintainer
#57 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern
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
#58 lore raw

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

#59 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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

#108 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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).

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

#246 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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).

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

maintainer
#109 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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/state and 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
maintainer
#110 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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/state and 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
#111 lore raw

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/state and 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

#245 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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/state and 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

maintainer
#112 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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/state and 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
maintainer
#113 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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/state and 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
#118 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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 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

#119 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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 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

#114 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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

#115 lore raw

Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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

#116 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
Quoted 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

#117 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
Quoted 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

#120 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern
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

#240 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Alan Stern
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

#60 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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.

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
#61 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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.

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
maintainer
#62 lore raw

Re: [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
maintainer
#63 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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
#121 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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
#122 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
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
#64 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov

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
#65 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov

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
maintainer
#66 lore raw

Re: [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
maintainer
#67 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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
#104 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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...

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

#105 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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...

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

#241 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
Quoted 60 lines · Rafael J. Wysocki
Quoted 59 lines · Dmitry Torokhov
Quoted 57 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).

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.

Quoted 6 lines
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.

A couple things come to mind...

1. Fixes problems for *all* kernel users, not just Android.

The kernel changes (refuse to suspend) would be done in a way that would fix problems in the traditional suspend path as well as the opportunistic suspend path, thus benefiting everyone.

2. Keep policy out of the kernel

A userspace suspend manager could implement _policy_ decisions in a platform specific way, rather than having policy hard-coded into the kernel.

Keeping the policy/governor in userspace would also allow various governor techniques to be experimented with (polling/timeout intervals, etc.) without having to patch the kernel.

Kevin

#242 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
Quoted 60 lines · Rafael J. Wysocki
Quoted 59 lines · Dmitry Torokhov
Quoted 57 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).

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.

Quoted 6 lines
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.

A couple things come to mind...

1. Fixes problems for *all* kernel users, not just Android.

The kernel changes (refuse to suspend) would be done in a way that would fix problems in the traditional suspend path as well as the opportunistic suspend path, thus benefiting everyone.

2. Keep policy out of the kernel

A userspace suspend manager could implement _policy_ decisions in a platform specific way, rather than having policy hard-coded into the kernel.

Keeping the policy/governor in userspace would also allow various governor techniques to be experimented with (polling/timeout intervals, etc.) without having to patch the kernel.

Kevin

#68 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov

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
#69 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov

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
maintainer
#70 lore raw

Re: [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
maintainer
#71 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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
#72 lore raw

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
#73 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov

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
#106 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Kevin Hilman

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
#107 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Kevin Hilman

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
maintainer
#74 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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
maintainer
#75 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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
#76 lore raw

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
#77 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov

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
#238 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

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 your position is basically that we're going to merge this stuff because google doesn't want to expend effort into investigating a potential saner solution?

So why don't we simply merge all the crap people throw at us and be done with it.

#123 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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

#243 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

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.

A funny userspace API of questionable use (esp. with the advent of better hardware and better runtime PM support) which we will have to support forever seems like a big enough downside.

#239 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki

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 your position is basically that we're going to merge this stuff because google doesn't want to expend effort into investigating a potential saner solution?

So why don't we simply merge all the crap people throw at us and be done with it.

#244 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

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.

A funny userspace API of questionable use (esp. with the advent of better hardware and better runtime PM support) which we will have to support forever seems like a big enough downside.

#124 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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.

#17 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg
Quoted 11 lines · Arve Hjønnevåg

+To create a suspend blocker from user space, open the suspend_blocker special

Documentation/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

#18 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg
Quoted 11 lines · Arve Hjønnevåg

+To create a suspend blocker from user space, open the suspend_blocker special

Documentation/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.

#1355 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

So you're going to merge this junk?

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#1356 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

So you're going to merge this junk?

#252 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

#1351 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

#125 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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.

#126 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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.

#153 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
Quoted 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 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.

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

#154 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
Quoted 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 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.

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

#155 lore raw

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.

#156 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Florian Mickler
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.

#1357 lore raw
In reply to Peter Zijlstra
Quoted 12 lines · On Wed, 26 May 2010 10:45:33 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

So you're going to merge this junk?

Yes. By now, everyone reading the posts should know all points. Raffael obviously was part of this discussion and came to the decision to merge it.

My take of the discussion:
_IF_ you want to suspend aggressively, I don't see another way.

The thing is, this is a paradigm change. Suspend is not anymore controlled by userspace. In order to let userspace control/work with this scheme, it needs to know when a suspend will be successfull or poll:

1. kernel sees suspend may be possible on his side of things

2. kernel sends a message to userspace that i could be possibly possible to suspend, but it may well be that by the time userspace suspends it is not possible anymore

3. userspace decides to suspend.

<- system suspends... or not ..->

4. userspace retries ... retries ... retries ...

And then you have the whole can of worms and races.

Or you have the suspend-blocker scheme:

1. kernel sees suspend is possible.
2. kernel suspends.
3. bingo.

Cheers,
Flo

#1358 lore raw
In reply to Peter Zijlstra
Quoted 12 lines · On Wed, 26 May 2010 10:45:33 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

So you're going to merge this junk?

Yes. By now, everyone reading the posts should know all points. Raffael obviously was part of this discussion and came to the decision to merge it.

My take of the discussion:
_IF_ you want to suspend aggressively, I don't see another way.

The thing is, this is a paradigm change. Suspend is not anymore controlled by userspace. In order to let userspace control/work with this scheme, it needs to know when a suspend will be successfull or poll:

1. kernel sees suspend may be possible on his side of things

2. kernel sends a message to userspace that i could be possibly possible to suspend, but it may well be that by the time userspace suspends it is not possible anymore

3. userspace decides to suspend.

<- system suspends... or not ..->

4. userspace retries ... retries ... retries ...

And then you have the whole can of worms and races.

Or you have the suspend-blocker scheme:

1. kernel sees suspend is possible.
2. kernel suspends.
3. bingo.

Cheers,
Flo

#253 lore raw
In reply to Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

Signature · 1 line
Arve Hjønnevåg
#254 lore raw
In reply to Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#255 lore raw
Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

Quoted 7 lines
Quoted 3 lines

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#256 lore raw
In reply to Arve Hjønnevåg
Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

Quoted 7 lines
Quoted 3 lines

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#257 lore raw
Quoted 14 lines · Peter Zijlstra
Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

Quoted 6 lines
Quoted 3 lines

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Thanks for your constructive feedback.

Brian

#258 lore raw
In reply to Peter Zijlstra
Quoted 14 lines · Peter Zijlstra
Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

Quoted 6 lines
Quoted 3 lines

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Thanks for your constructive feedback.

Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#157 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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
#1359 lore raw
In reply to Florian Mickler
Quoted 35 lines · Florian Mickler
Quoted 12 lines · On Wed, 26 May 2010 10:45:33 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

So you're going to merge this junk?

Yes. By now, everyone reading the posts should know all points. Raffael obviously was part of this discussion and came to the decision to merge it.

My take of the discussion:
_IF_ you want to suspend aggressively, I don't see another way.

The thing is, this is a paradigm change. Suspend is not anymore controlled by userspace. In order to let userspace control/work with this scheme, it needs to know when a suspend will be successfull or poll:

1. kernel sees suspend may be possible on his side of things

2. kernel sends a message to userspace that i could be possibly possible to suspend, but it may well be that by the time userspace suspends it is not possible anymore

Quoted 7 lines

3. userspace decides to suspend.

<- system suspends... or not ..->

4. userspace retries ... retries ... retries ...

And then you have the whole can of worms and races.

I don't see any races, nor retry loops.

There is always the race of an event arriving whilst in the process of suspending, that is not solved by either the kernel nor user part of suspend-blockers. The only thing is not to loose the event.

You simply have to deal with that, the suspend gets canceled, you do deal with the event, and suspend again. How does making that 'retry' as you call it happen from a kernel thread or from a userspace thread any difference?

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#158 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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
#1360 lore raw
In reply to Florian Mickler
Quoted 35 lines · Florian Mickler
Quoted 12 lines · On Wed, 26 May 2010 10:45:33 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 7 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version adds a delay before suspending again if no suspend blockers were used during the last suspend attempt.

Patches [1-6/8] applied to suspend-2.6/linux-next

So you're going to merge this junk?

Yes. By now, everyone reading the posts should know all points. Raffael obviously was part of this discussion and came to the decision to merge it.

My take of the discussion:
_IF_ you want to suspend aggressively, I don't see another way.

The thing is, this is a paradigm change. Suspend is not anymore controlled by userspace. In order to let userspace control/work with this scheme, it needs to know when a suspend will be successfull or poll:

1. kernel sees suspend may be possible on his side of things

2. kernel sends a message to userspace that i could be possibly possible to suspend, but it may well be that by the time userspace suspends it is not possible anymore

Quoted 7 lines

3. userspace decides to suspend.

<- system suspends... or not ..->

4. userspace retries ... retries ... retries ...

And then you have the whole can of worms and races.

I don't see any races, nor retry loops.

There is always the race of an event arriving whilst in the process of suspending, that is not solved by either the kernel nor user part of suspend-blockers. The only thing is not to loose the event.

You simply have to deal with that, the suspend gets canceled, you do deal with the event, and suspend again. How does making that 'retry' as you call it happen from a kernel thread or from a userspace thread any difference?

#259 lore raw
In reply to Peter Zijlstra
Quoted 14 lines · On Wed, 26 May 2010 11:45:06 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

Quoted 6 lines
Quoted 3 lines

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Hi Peter!

This was already mentioned in one of these threads.

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

So anything relying on (all) userspace solves a different problem.

Cheers,
Flo

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#260 lore raw
In reply to Peter Zijlstra
Quoted 14 lines · On Wed, 26 May 2010 11:45:06 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines · Peter Zijlstra
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

Quoted 6 lines
Quoted 3 lines

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Hi Peter!

This was already mentioned in one of these threads.

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

So anything relying on (all) userspace solves a different problem.

Cheers,
Flo

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1324 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 14 lines · Arve Hjønnevåg
Quoted 13 lines · Peter Zijlstra
Quoted 11 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

Quoted 7 lines
Quoted 3 lines

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

I was not talking about our user-space code. Suspend has to be called by a running thread, so at least one runqueue is not empty.

Signature · 1 line
Arve Hjønnevåg
#1350 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 14 lines · Arve Hjønnevåg
Quoted 13 lines · Peter Zijlstra
Quoted 11 lines · Rafael J. Wysocki
Quoted 6 lines
Quoted 3 lines

This of course will lead to a scattering of suspend blockers into any drivers/subsystems considered "useful", which by looking through current Android kernels is many of them.

That depends on the maintainers of these subsystems, who still have the power to reject requested changes.

So as a scheduler maintainer I'm going to merge a patch that does a suspend_blocker when the runqueue's aren't empty... how about that?

Quoted 7 lines
Quoted 3 lines

I don't know if you are serious, since the all the runqueues are never empty while suspending, this would disable opportunistic suspend altogether.

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

I was not talking about our user-space code. Suspend has to be called by a running thread, so at least one runqueue is not empty.

Signature · 1 line
Arve Hjønnevåg
#159 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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

#160 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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.

#261 lore raw
In reply to Florian Mickler
Quoted 6 lines · Florian Mickler

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

So anything relying on (all) userspace solves a different problem.

So what stops an application from grabbing a suspend blocker?

#264 lore raw
In reply to Florian Mickler
Quoted 6 lines · Florian Mickler

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

So anything relying on (all) userspace solves a different problem.

So what stops an application from grabbing a suspend blocker?

#1325 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

I was not talking about our user-space code. Suspend has to be called by a running thread, so at least one runqueue is not empty.

But why would you need to suspend if the machine is fully idle?

Is it because you're using broken hardware that has lower power consumption in suspend state as in idle?

Couldn't you make the runtime-pm smarter and utilize the suspend states?

#1349 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

I was not talking about our user-space code. Suspend has to be called by a running thread, so at least one runqueue is not empty.

But why would you need to suspend if the machine is fully idle?

Is it because you're using broken hardware that has lower power consumption in suspend state as in idle?

Couldn't you make the runtime-pm smarter and utilize the suspend states?
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#161 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra

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_block thing.

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
#162 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra

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_block thing.

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
#262 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · On Wed, 26 May 2010 12:08:04 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 6 lines · Florian Mickler

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

So anything relying on (all) userspace solves a different problem.

So what stops an application from grabbing a suspend blocker?

Well, I don't own any android devices, but If I read this all correctly, an app can request the permission to grab an suspend blocker at installation time. ("This application is requesting permission to keep the device from sleeping, thus possibly reducing your battery time. Are you shure you want to continue? [Yes,No]")

every app grabbing a suspend blocker is showing
up in a "these programs stop suspend" kind of battery-app and are thus well accounted for. _And the user knows who to blame_.

Maybe this is implemented via fs-permissions? Anyway, I'm shure, that the access control uses a well established method. :)

Cheers,
Flo

#263 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · On Wed, 26 May 2010 12:08:04 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 6 lines · Florian Mickler

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

So anything relying on (all) userspace solves a different problem.

So what stops an application from grabbing a suspend blocker?

Well, I don't own any android devices, but If I read this all correctly, an app can request the permission to grab an suspend blocker at installation time. ("This application is requesting permission to keep the device from sleeping, thus possibly reducing your battery time. Are you shure you want to continue? [Yes,No]")

every app grabbing a suspend blocker is showing
up in a "these programs stop suspend" kind of battery-app and are thus well accounted for. _And the user knows who to blame_.

Maybe this is implemented via fs-permissions? Anyway, I'm shure, that the access control uses a well established method. :)

Cheers,
Flo

#163 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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

#164 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg
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.

#1326 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 7 lines · Arve Hjønnevåg
Quoted 3 lines

I was not talking about our user-space code. Suspend has to be called by a running thread, so at least one runqueue is not empty.

But why would you need to suspend if the machine is fully idle?

I have never seen a system that is fully idle for hours or even minutes.

Quoted 3 lines

Is it because you're using broken hardware that has lower power consumption in suspend state as in idle?

Initially, yes, but for shipping android phones, no.

Quoted 2 lines

Couldn't you make the runtime-pm smarter and utilize the suspend states?

I don't think runtime-pm is relevant here. We don't use suspend to power down devices that are not in use, we use suspend to enter system power states that we cannot enter from idle, and on systems where the same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

Signature · 1 line
Arve Hjønnevåg
#1327 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 7 lines · Arve Hjønnevåg
Quoted 3 lines

I was not talking about our user-space code. Suspend has to be called by a running thread, so at least one runqueue is not empty.

But why would you need to suspend if the machine is fully idle?

I have never seen a system that is fully idle for hours or even minutes.

Quoted 3 lines

Is it because you're using broken hardware that has lower power consumption in suspend state as in idle?

Initially, yes, but for shipping android phones, no.

Quoted 2 lines

Couldn't you make the runtime-pm smarter and utilize the suspend states?

I don't think runtime-pm is relevant here. We don't use suspend to power down devices that are not in use, we use suspend to enter system power states that we cannot enter from idle, and on systems where the same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#165 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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.

#166 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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.

#229 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 5 lines · Arve Hjønnevåg
Quoted 4 lines
Quoted 3 lines

With a single suspend manager process that manages the suspend state you can achieve the same goal.

Quoted 8 lines
Quoted 5 lines

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?

We could, but the result would be that any program that needs to block suspend has to be android specific.

Quoted 6 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.

Signature · 1 line
Arve Hjønnevåg
#230 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 5 lines · Arve Hjønnevåg
Quoted 4 lines
Quoted 3 lines

With a single suspend manager process that manages the suspend state you can achieve the same goal.

Quoted 8 lines
Quoted 5 lines

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?

We could, but the result would be that any program that needs to block suspend has to be android specific.

Quoted 6 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.

Signature · 1 line
Arve Hjønnevåg
#1328 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

#1348 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#231 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg

2010/5/26 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines
Quoted 1 line

So provide a C interface to it as well?

We could, but the result would be that any program that needs to block suspend has to be android specific.

Why? You could put the userspace daemon to tools/suspend-manager, for example?

#232 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg

2010/5/26 Arve Hjønnevåg <[email protected]>:

Quoted 4 lines
Quoted 1 line

So provide a C interface to it as well?

We could, but the result would be that any program that needs to block suspend has to be android specific.

Why? You could put the userspace daemon to tools/suspend-manager, for example?

#1329 lore raw
In reply to Peter Zijlstra
Quoted 10 lines · Peter Zijlstra
Quoted 4 lines · Arve Hjønnevåg

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

As we've stated a number of times in the several weeks of discussion (this time around) of this patchset, we are all in favor of improving runtime pm, finding and resolving issues that prevent idle, and heading toward ever lower power states in idle -- after all, this benefits our battery life in the cases when the system is not suspended as well as moving us closer to a future where the power savings between actively entering suspend and not doing so approach zero. Aggressively entering the lowest possible power state at all times is our goal here.

At the moment, the power savings from opportunistic suspend do directly lead to improved battery life, and there are some advantages to this model in the face of a non-optimal userspace (as we encounter in a world where there are not restrictions on what applications users may install and run).

Brian

#1330 lore raw
In reply to Peter Zijlstra
Quoted 10 lines · Peter Zijlstra
Quoted 4 lines · Arve Hjønnevåg

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

As we've stated a number of times in the several weeks of discussion (this time around) of this patchset, we are all in favor of improving runtime pm, finding and resolving issues that prevent idle, and heading toward ever lower power states in idle -- after all, this benefits our battery life in the cases when the system is not suspended as well as moving us closer to a future where the power savings between actively entering suspend and not doing so approach zero. Aggressively entering the lowest possible power state at all times is our goal here.

At the moment, the power savings from opportunistic suspend do directly lead to improved battery life, and there are some advantages to this model in the face of a non-optimal userspace (as we encounter in a world where there are not restrictions on what applications users may install and run).

Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#1331 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

Signature · 1 line
Arve Hjønnevåg
#1347 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

Signature · 1 line
Arve Hjønnevåg
#19 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Peter Zijlstra

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_blocker special

Documentation/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, the close() be UNBLOCK, and keep the SET_NAME thing if you really care.

That would be very inefficient.

Signature · 1 line
Arve Hjønnevåg
#20 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Peter Zijlstra

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_blocker special

Documentation/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, the close() be UNBLOCK, and keep the SET_NAME thing if you really care.

That would be very inefficient.

Signature · 1 line
Arve Hjønnevåg
#1332 lore raw
In reply to Arve Hjønnevåg
Quoted 12 lines · Arve Hjønnevåg

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

Quoted 5 lines

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

All I'm saying is that merging a stop-gap measure will decrease the urgency and thus the time spend fixing the actual issues while adding the burden of maintaining this stop-gap measure.
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#1333 lore raw
In reply to Arve Hjønnevåg
Quoted 12 lines · Arve Hjønnevåg

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

Quoted 5 lines

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

All I'm saying is that merging a stop-gap measure will decrease the urgency and thus the time spend fixing the actual issues while adding the burden of maintaining this stop-gap measure.
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#21 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg
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_blocker special

Documentation/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, the close() be UNBLOCK, and keep the SET_NAME thing 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

#22 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg
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_blocker special

Documentation/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, the close() be UNBLOCK, and keep the SET_NAME thing 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.

#25 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg
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 17 lines · Arve Hjønnevåg
Quoted 16 lines

+To create a suspend blocker from user space, open the suspend_blocker special

Documentation/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, the close() be UNBLOCK, and keep the SET_NAME thing 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

#26 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Arve Hjønnevåg
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 17 lines · Arve Hjønnevåg
Quoted 16 lines

+To create a suspend blocker from user space, open the suspend_blocker special

Documentation/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, the close() be UNBLOCK, and keep the SET_NAME thing 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

#1334 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 12 lines

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

Quoted 5 lines

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

Quoted 4 lines

All I'm saying is that merging a stop-gap measure will decrease the urgency and thus the time spend fixing the actual issues while adding the burden of maintaining this stop-gap measure.

Fixing the actually issue means fixing all user-space code, and replacing most x86 hardware. I don't think keeping this feature out of the kernel will significantly accelerate this.

Signature · 1 line
Arve Hjønnevåg
#1346 lore raw
In reply to Peter Zijlstra

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 12 lines

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

Quoted 5 lines

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

Quoted 4 lines

All I'm saying is that merging a stop-gap measure will decrease the urgency and thus the time spend fixing the actual issues while adding the burden of maintaining this stop-gap measure.

Fixing the actually issue means fixing all user-space code, and replacing most x86 hardware. I don't think keeping this feature out of the kernel will significantly accelerate this.

Signature · 1 line
Arve Hjønnevåg
#27 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Florian Mickler
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_blocker special

Documentation/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.

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

#28 lore raw

Re: [PATCH 2/8] PM: suspend_block: Add driver to access suspend blockers from user-space

In reply to Florian Mickler
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_blocker special

Documentation/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.

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.

#1335 lore raw
In reply to Arve Hjønnevåg
Quoted 20 lines · Arve Hjønnevåg

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 17 lines

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

Quoted 8 lines
Quoted 4 lines

All I'm saying is that merging a stop-gap measure will decrease the urgency and thus the time spend fixing the actual issues while adding the burden of maintaining this stop-gap measure.

Fixing the actually issue means fixing all user-space code, and replacing most x86 hardware. I don't think keeping this feature out of the kernel will significantly accelerate this.

I don't think x86 is relevant anyway, it doesn't suspend/resume anywhere near fast enough for this to be usable.

My laptop still takes several seconds to suspend (Lenovo T500), and resume (aside from some userspace bustage) takes the same amount of time. That is quick enough for manual suspend, but I'd hate it to try and auto-suspend.

Getting longer idle periods however is something that everybody benefits from. On x86 we're nowhere close to hitting the max idle time of the platform, you get _tons_ of wakeups on current 'desktop' software.

But x86 being a PITA shouldn't stop people from working on this, there's plenty other architectures out there, I remember fixing a NO_HZ bug with davem on sparc64 because his niagra had cores idling for very long times indeed.

So yes, I do think merging this will delay the effort in fixing userspace, simply because all the mobile/embedded folks don't care about it anymore.

#1343 lore raw
In reply to Arve Hjønnevåg
Quoted 20 lines · Arve Hjønnevåg

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 17 lines

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 10 lines · Arve Hjønnevåg
Quoted 5 lines

and on systems where the
same power state can be used from idle and suspend, we use suspend so we can stay in the low power state for minutes to hours instead of milliseconds to seconds.

So don't you think working on making it possible for systems to be idle _that_ long would improve things for everybody? as opposed to this auto-suspend which only improves matters for those that (can) use it?

I'm not preventing anyone from working on improving this. Currently both the kernel and our user-space code polls way too much. I don't think it is reasonable to demand that no one should run any user-space code with periodic timers when we have not even fixed the kernel to not do this.

Quoted 8 lines
Quoted 4 lines

All I'm saying is that merging a stop-gap measure will decrease the urgency and thus the time spend fixing the actual issues while adding the burden of maintaining this stop-gap measure.

Fixing the actually issue means fixing all user-space code, and replacing most x86 hardware. I don't think keeping this feature out of the kernel will significantly accelerate this.

I don't think x86 is relevant anyway, it doesn't suspend/resume anywhere near fast enough for this to be usable.

My laptop still takes several seconds to suspend (Lenovo T500), and resume (aside from some userspace bustage) takes the same amount of time. That is quick enough for manual suspend, but I'd hate it to try and auto-suspend.

Getting longer idle periods however is something that everybody benefits from. On x86 we're nowhere close to hitting the max idle time of the platform, you get _tons_ of wakeups on current 'desktop' software.

But x86 being a PITA shouldn't stop people from working on this, there's plenty other architectures out there, I remember fixing a NO_HZ bug with davem on sparc64 because his niagra had cores idling for very long times indeed.

So yes, I do think merging this will delay the effort in fixing userspace, simply because all the mobile/embedded folks don't care about it anymore.
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#233 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg

2010/5/26 Arve Hjønnevåg <[email protected]>:

Quoted 12 lines

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 11 lines · Arve Hjønnevåg
Quoted 9 lines
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.

Quoted 5 lines
Quoted 2 lines

So provide a C interface to it as well?

We could, but the result would be that any program that needs to block suspend has to be android specific.

Just a suspicion, but... The things you're saying don't make sense to me other than if you're fighting with GPL in userspace here.

~Vitaly

#234 lore raw

Re: [linux-pm] [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Arve Hjønnevåg

2010/5/26 Arve Hjønnevåg <[email protected]>:

Quoted 12 lines

2010/5/26 Peter Zijlstra <[email protected]>:

Quoted 11 lines · Arve Hjønnevåg
Quoted 9 lines
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.

Quoted 5 lines
Quoted 2 lines

So provide a C interface to it as well?

We could, but the result would be that any program that needs to block suspend has to be android specific.

Just a suspicion, but... The things you're saying don't make sense to me other than if you're fighting with GPL in userspace here.

~Vitaly

#265 lore raw
In reply to Florian Mickler
Quoted 11 lines · Florian Mickler
Quoted 2 lines

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Hi Peter!

This was already mentioned in one of these threads.

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

I don't see this as a valid point. Everyone can run a different kernel where nothing will just work. Are you aiming protection against that as well?

~Vitaly

#1323 lore raw
In reply to Florian Mickler
Quoted 11 lines · Florian Mickler
Quoted 2 lines

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Hi Peter!

This was already mentioned in one of these threads.

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

I don't see this as a valid point. Everyone can run a different kernel where nothing will just work. Are you aiming protection against that as well?

~Vitaly

#1344 lore raw
In reply to Arve Hjønnevåg

2010/5/26 Arve Hjønnevåg <[email protected]>:

Quoted 3 lines

Fixing the actually issue means fixing all user-space code, and replacing most x86 hardware. I don't think keeping this feature out of the kernel will significantly accelerate this.

But if this feature gets merged, I bet you'll find another 100 reasons to not fix the actual issue. I wouldn't say so if you haven't provided the irrelevant points already, like "replacing x86 hardware". You're trying to merge the approach which makes the bad way of handing things the easiest way. This shouldn't get in as it is IMO.

~Vitaly

#1345 lore raw
In reply to Arve Hjønnevåg

2010/5/26 Arve Hjønnevåg <[email protected]>:

Quoted 3 lines

Fixing the actually issue means fixing all user-space code, and replacing most x86 hardware. I don't think keeping this feature out of the kernel will significantly accelerate this.

But if this feature gets merged, I bet you'll find another 100 reasons to not fix the actual issue. I wouldn't say so if you haven't provided the irrelevant points already, like "replacing x86 hardware". You're trying to merge the approach which makes the bad way of handing things the easiest way. This shouldn't get in as it is IMO.

~Vitaly

#1361 lore raw
In reply to Peter Zijlstra
Quoted 17 lines · On Wed, 26 May 2010 11:54:37 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 16 lines · Florian Mickler

_IF_ you want to suspend aggressively, I don't see another way.

The thing is, this is a paradigm change. Suspend is not anymore controlled by userspace. In order to let userspace control/work with this scheme, it needs to know when a suspend will be successfull or poll:

1. kernel sees suspend may be possible on his side of things

2. kernel sends a message to userspace that i could be possibly possible to suspend, but it may well be that by the time userspace suspends it is not possible anymore

3. userspace decides to suspend.

Quoted 7 lines
Quoted 5 lines

<- system suspends... or not ..->

4. userspace retries ... retries ... retries ...

And then you have the whole can of worms and races.

I don't see any races, nor retry loops.

What about the worms? :)

I referred to retrying steps 1 through 3 as being the loop.

Quoted 10 lines

There is always the race of an event arriving whilst in the process of suspending, that is not solved by either the kernel nor user part of suspend-blockers. The only thing is not to loose the event.

You simply have to deal with that, the suspend gets canceled, you do deal with the event, and suspend again. How does making that 'retry' as you call it happen from a kernel thread or from a userspace thread any difference?

You have a point there. But what follows?

You either need to let userspace know that the kernel is now able to suspend or you let the kernel know that userspace is now able to suspend.
Else you can not make a well informed suspend-decision and have to guess and retry.

Why not look at blocking and unblocking as these events you want to have? Without wiggle room and retrying.

And not having to route through userspace simplifies the auto-suspend scheme further.

Cheers,
Flo

#1362 lore raw
In reply to Peter Zijlstra
Quoted 17 lines · On Wed, 26 May 2010 11:54:37 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 16 lines · Florian Mickler

_IF_ you want to suspend aggressively, I don't see another way.

The thing is, this is a paradigm change. Suspend is not anymore controlled by userspace. In order to let userspace control/work with this scheme, it needs to know when a suspend will be successfull or poll:

1. kernel sees suspend may be possible on his side of things

2. kernel sends a message to userspace that i could be possibly possible to suspend, but it may well be that by the time userspace suspends it is not possible anymore

3. userspace decides to suspend.

Quoted 7 lines
Quoted 5 lines

<- system suspends... or not ..->

4. userspace retries ... retries ... retries ...

And then you have the whole can of worms and races.

I don't see any races, nor retry loops.

What about the worms? :)

I referred to retrying steps 1 through 3 as being the loop.

Quoted 10 lines

There is always the race of an event arriving whilst in the process of suspending, that is not solved by either the kernel nor user part of suspend-blockers. The only thing is not to loose the event.

You simply have to deal with that, the suspend gets canceled, you do deal with the event, and suspend again. How does making that 'retry' as you call it happen from a kernel thread or from a userspace thread any difference?

You have a point there. But what follows?

You either need to let userspace know that the kernel is now able to suspend or you let the kernel know that userspace is now able to suspend.
Else you can not make a well informed suspend-decision and have to guess and retry.

Why not look at blocking and unblocking as these events you want to have? Without wiggle room and retrying.

And not having to route through userspace simplifies the auto-suspend scheme further.

Cheers,
Flo

#266 lore raw
In reply to Vitaly Wool
Quoted 14 lines · On Wed, 26 May 2010 13:18:51 +0200 Vitaly Wool <[email protected]> wrote:
Quoted 11 lines · Florian Mickler
Quoted 2 lines

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Hi Peter!

This was already mentioned in one of these threads.

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

Quoted 5 lines

I don't see this as a valid point. Everyone can run a different kernel where nothing will just work. Are you aiming protection against that as well?

~Vitaly

This is not "protection". This is functioning properly in a real world scenario. Why would the user change the kernel, if the device would be buggy after that? (Except maybe he is a geek)

Cheers,
Flo

#1322 lore raw
In reply to Vitaly Wool
Quoted 14 lines · On Wed, 26 May 2010 13:18:51 +0200 Vitaly Wool <[email protected]> wrote:
Quoted 11 lines · Florian Mickler
Quoted 2 lines

So why again was this such a great scheme? Go fix your userspace to not not run when not needed.

Hi Peter!

This was already mentioned in one of these threads.

The summary is: The device this kernel is running on dosn't want to (or can) rely on userspace to save power. This is because it is an open system, without an app-store or the like. Everyone can run what he wants.

Quoted 5 lines

I don't see this as a valid point. Everyone can run a different kernel where nothing will just work. Are you aiming protection against that as well?

~Vitaly

This is not "protection". This is functioning properly in a real world scenario. Why would the user change the kernel, if the device would be buggy after that? (Except maybe he is a geek)

Cheers,
Flo

#267 lore raw
In reply to Florian Mickler
Quoted 3 lines · Florian Mickler

This is not "protection". This is functioning properly in a real world scenario. Why would the user change the kernel, if the device would be buggy after that? (Except maybe he is a geek)

Hmm... Why would the user continue to use the program if it slows down his device and sucks the battery as a vampire (Except maybe he's a moron)? ;)

~Vitaly

#268 lore raw
In reply to Florian Mickler
Quoted 3 lines · Florian Mickler

This is not "protection". This is functioning properly in a real world scenario. Why would the user change the kernel, if the device would be buggy after that? (Except maybe he is a geek)

Hmm... Why would the user continue to use the program if it slows down his device and sucks the battery as a vampire (Except maybe he's a moron)? ;)

~Vitaly

#269 lore raw
Quoted 11 lines · On Wed, 26 May 2010 14:01:49 +0200 Vitaly Wool <[email protected]> wrote:
Quoted 3 lines · Florian Mickler

This is not "protection". This is functioning properly in a real world scenario. Why would the user change the kernel, if the device would be buggy after that? (Except maybe he is a geek)

Hmm... Why would the user continue to use the program if it slows down his device and sucks the battery as a vampire (Except maybe he's a moron)? ;)

~Vitaly

Because he is using a robust kernel that provides suspend blockers and is preventing the vampire from sucking power?

Most users don't even grasp the simple concept of different "programs". They just have a device and click here and there and are happy.

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

Cheers,
Flo

#270 lore raw
In reply to Vitaly Wool
Quoted 11 lines · On Wed, 26 May 2010 14:01:49 +0200 Vitaly Wool <[email protected]> wrote:
Quoted 3 lines · Florian Mickler

This is not "protection". This is functioning properly in a real world scenario. Why would the user change the kernel, if the device would be buggy after that? (Except maybe he is a geek)

Hmm... Why would the user continue to use the program if it slows down his device and sucks the battery as a vampire (Except maybe he's a moron)? ;)

~Vitaly

Because he is using a robust kernel that provides suspend blockers and is preventing the vampire from sucking power?

Most users don't even grasp the simple concept of different "programs". They just have a device and click here and there and are happy.

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

Cheers,
Flo

#1336 lore raw
In reply to Peter Zijlstra
Quoted 2 lines

I don't think x86 is relevant anyway, it doesn't suspend/resume anywhere near fast enough for this to be usable.

Yet...

Quoted 4 lines

My laptop still takes several seconds to suspend (Lenovo T500), and resume (aside from some userspace bustage) takes the same amount of time. That is quick enough for manual suspend, but I'd hate it to try and auto-suspend.

This is an area where machines are improving and where the ability to do stuff like autosuspend, the technology like the OLPC screen and so on create an incentive for the BIOS and platform people to improve their bits of it.

Quoted 3 lines

So yes, I do think merging this will delay the effort in fixing userspace, simply because all the mobile/embedded folks don't care about it anymore.

The mobile space probably doesn't care too much about many of the large bloated desktop apps anyway and traditional embedded generally has a very small fixed application set where the optimise both halves of the system together.

Alan

#271 lore raw
In reply to Florian Mickler

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

Signature · 3 lines
balbi

DefectiveByDesign.org
#272 lore raw
In reply to Florian Mickler

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

Signature · 3 lines
balbi

DefectiveByDesign.org
#273 lore raw
Quoted 12 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

Quoted 6 lines

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

Cheers,
Flo

#274 lore raw
In reply to Felipe Balbi
Quoted 12 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

Quoted 6 lines

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

Cheers,
Flo

#275 lore raw

Hi,

Quoted 4 lines · ext Florian Mickler

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

and that's enough to push hacks into the kernel ? I don't think so. Do it like apple and prevent multi-tasking for any non-apple applications :-p

Signature · 3 lines
balbi

DefectiveByDesign.org
#276 lore raw
In reply to Florian Mickler

Hi,

Quoted 4 lines · ext Florian Mickler

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

and that's enough to push hacks into the kernel ? I don't think so. Do it like apple and prevent multi-tasking for any non-apple applications :-p

Signature · 3 lines
balbi

DefectiveByDesign.org
#286 lore raw
In reply to Florian Mickler
Quoted 22 lines · Florian Mickler
Quoted 12 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

Quoted 6 lines

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

Quoted 4 lines

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

Provide the developers and users with tools.

Notify the users that their phone is using power at an unadvised rate due to proglet $foo.

Also, if you can integrate into the development environment and provide developers instant feedback on suckage of their app they can react and fix before letting users run into the issue.

#293 lore raw
In reply to Florian Mickler
Quoted 22 lines · Florian Mickler
Quoted 12 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

Quoted 6 lines

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

Quoted 4 lines

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

Provide the developers and users with tools.

Notify the users that their phone is using power at an unadvised rate due to proglet $foo.

Also, if you can integrate into the development environment and provide developers instant feedback on suckage of their app they can react and fix before letting users run into the issue.

#127 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra

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]
#128 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra

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]
#1337 lore raw
In reply to Alan Cox
Quoted 4 lines · Alan Cox

This is an area where machines are improving and where the ability to do stuff like autosuspend, the technology like the OLPC screen and so on create an incentive for the BIOS and platform people to improve their bits of it.

But do you think its a sensible thing to do? Explicitly not running runnable tasks just sounds wrong. Also, at the extreme end, super fast suspend is basically an efficient idle mode.

Why would the code holding suspend blockers be any more or less important than any other piece of runnable code.

In fact, having runnable but non suspend blocking tasks around will delay the completion of the suspend blocker, so will we start removing those?

This whole thing introduces an artificial segregation of code. My 'cool' code is more important than your 'uncool' code. Without a clear definition of what makes code cool or not.

Quoted 8 lines
Quoted 3 lines

So yes, I do think merging this will delay the effort in fixing userspace, simply because all the mobile/embedded folks don't care about it anymore.

The mobile space probably doesn't care too much about many of the large bloated desktop apps anyway and traditional embedded generally has a very small fixed application set where the optimise both halves of the system together.

Sure, but at least we share the kernel. It was said that the kernel generates too many wakeups (and iwlagn certainly is the top most waker on my laptop). Improvements to the kernel will benefit all, regardless of whatever userspace we run.

#1338 lore raw
In reply to Alan Cox
Quoted 4 lines · Alan Cox

This is an area where machines are improving and where the ability to do stuff like autosuspend, the technology like the OLPC screen and so on create an incentive for the BIOS and platform people to improve their bits of it.

But do you think its a sensible thing to do? Explicitly not running runnable tasks just sounds wrong. Also, at the extreme end, super fast suspend is basically an efficient idle mode.

Why would the code holding suspend blockers be any more or less important than any other piece of runnable code.

In fact, having runnable but non suspend blocking tasks around will delay the completion of the suspend blocker, so will we start removing those?

This whole thing introduces an artificial segregation of code. My 'cool' code is more important than your 'uncool' code. Without a clear definition of what makes code cool or not.

Quoted 8 lines
Quoted 3 lines

So yes, I do think merging this will delay the effort in fixing userspace, simply because all the mobile/embedded folks don't care about it anymore.

The mobile space probably doesn't care too much about many of the large bloated desktop apps anyway and traditional embedded generally has a very small fixed application set where the optimise both halves of the system together.

Sure, but at least we share the kernel. It was said that the kernel generates too many wakeups (and iwlagn certainly is the top most waker on my laptop). Improvements to the kernel will benefit all, regardless of whatever userspace we run.

#277 lore raw
In reply to Felipe Balbi
Quoted 12 lines · On Wed, 26 May 2010 15:35:32 +0300 Felipe Balbi <[email protected]> wrote:

Hi,

Quoted 4 lines · ext Florian Mickler

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

and that's enough to push hacks into the kernel ? I don't think so. Do it like apple and prevent multi-tasking for any non-apple applications :-p

:)

It really comes down to a policy decision by the distribution maker. And I don't think kernel upstream should be the one to force one way or the other. So merging this patch set will allow android to continue their work _on mainline_ while everybody else can continue as before.

All points about the impact on the kernel have already been raised. So you should be happy there.

Nonetheless, I really think the kernel needs to allow for the android way of power saving. It misses out on a big feature and a big user-base if not.

Also I expect there to be synergies between android development and mainline kernel development _only_ if android development can use mainline kernel.

And as for the quality of the "hack": I think you find this ugly, just because you don't like the concept of degrading user space guaranties on timers and stuff.

But look at it this way: Suspend blockers are a way for the kernel to make user space programs accountable for using the resource "power". If a user space program needs the "traditional" guaranties for functioning properly, it needs to take a suspend blocker. But _THEN_ it better be well behaved. This is a kind of contract between userspace and kernelspace.

On the other hand, if I don't need these traditional guaranties on timers and stuff, I don't have to know device specific things about power consumption. I can just use whatever facilities the programming language provides without needing to worry about low level details.

This is a _big_ plus for attracting 3rd party programs. (And of course the thing you don't like).

Cheers,
Flo

#294 lore raw
In reply to Florian Mickler
Quoted 7 lines · Florian Mickler

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

You almost always need to "hack" the mainline software for a production system. So do it here as well. Make sure the hack is well isolated and local. You can even submit it to the mainline, better as a configuration option, _unless_ it is a *framework* that provokes writing code in an ugly and unsafe way.

~Vitaly

#295 lore raw
In reply to Florian Mickler
Quoted 7 lines · Florian Mickler

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

You almost always need to "hack" the mainline software for a production system. So do it here as well. Make sure the hack is well isolated and local. You can even submit it to the mainline, better as a configuration option, _unless_ it is a *framework* that provokes writing code in an ugly and unsafe way.

~Vitaly

#129 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Matthew Garrett

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.

#130 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Matthew Garrett

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.

#287 lore raw
In reply to Peter Zijlstra
Quoted 28 lines · On Wed, 26 May 2010 14:41:29 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 22 lines · Florian Mickler
Quoted 12 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

Quoted 6 lines

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

Quoted 4 lines

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

Quoted 9 lines

Provide the developers and users with tools.

Notify the users that their phone is using power at an unadvised rate due to proglet $foo.

Also, if you can integrate into the development environment and provide developers instant feedback on suckage of their app they can react and fix before letting users run into the issue.

Yeah. And I personally agree with you there. But this is a policy decision that should not prevent android from doing it differently. The kernel can not win if it does not try to integrate any use of it. After all, we are a free comunity and if someone wants to use it their way, why not allow for it? (As long as it does not directly impact other uses)

The best solution wins, but not by decision of some kernel development gatekeepers, but because it is superior. There are no clear markings of the better solution. Time will tell.

Cheers,
Flo

#292 lore raw
In reply to Peter Zijlstra
Quoted 28 lines · On Wed, 26 May 2010 14:41:29 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 22 lines · Florian Mickler
Quoted 12 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

hi,

Quoted 3 lines · ext Florian Mickler

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

Quoted 6 lines

You can install and run anything on the device, and they will work as they should (they will be scheduled and will be processed) but you can't expect the kernel to prevent that application from waking up the CPU every 10 ms simply because someone didn't think straight while writting the app.

Quoted 4 lines

But then someone at the user side has to know what he is doing.

I fear, if you target mass market without central distribution channels, you can not assume that much.

Quoted 9 lines

Provide the developers and users with tools.

Notify the users that their phone is using power at an unadvised rate due to proglet $foo.

Also, if you can integrate into the development environment and provide developers instant feedback on suckage of their app they can react and fix before letting users run into the issue.

Yeah. And I personally agree with you there. But this is a policy decision that should not prevent android from doing it differently. The kernel can not win if it does not try to integrate any use of it. After all, we are a free comunity and if someone wants to use it their way, why not allow for it? (As long as it does not directly impact other uses)

The best solution wins, but not by decision of some kernel development gatekeepers, but because it is superior. There are no clear markings of the better solution. Time will tell.

Cheers,
Flo

#278 lore raw
In reply to Florian Mickler
Quoted 3 lines · Florian Mickler

It really comes down to a policy decision by the distribution maker. And I don't think kernel upstream should be the one to force one way or the other.

That's exactly what we always do. If we were not to do so, the kernel would be a bloated incoherent piece of crap.

Quoted 6 lines

So merging this patch set will allow android to continue
their work _on mainline_ while everybody else can continue as before.

Nonetheless, I really think the kernel needs to allow for the android way of power saving. It misses out on a big feature and a big user-base if not.

I really think we should not do so. Let them help in fixing the real issue instead of creating a new class of userspace that is more important than another.

Quoted 2 lines

But look at it this way: Suspend blockers are a way for the kernel to make user space programs accountable for using the resource "power".

How is userspace without suspend blockers not accountable? We can easily account runtime and in fact have several ways to do so.

#279 lore raw
In reply to Florian Mickler
Quoted 3 lines · Florian Mickler

It really comes down to a policy decision by the distribution maker. And I don't think kernel upstream should be the one to force one way or the other.

That's exactly what we always do. If we were not to do so, the kernel would be a bloated incoherent piece of crap.

Quoted 6 lines

So merging this patch set will allow android to continue
their work _on mainline_ while everybody else can continue as before.

Nonetheless, I really think the kernel needs to allow for the android way of power saving. It misses out on a big feature and a big user-base if not.

I really think we should not do so. Let them help in fixing the real issue instead of creating a new class of userspace that is more important than another.

Quoted 2 lines

But look at it this way: Suspend blockers are a way for the kernel to make user space programs accountable for using the resource "power".

How is userspace without suspend blockers not accountable? We can easily account runtime and in fact have several ways to do so.

#288 lore raw
In reply to Florian Mickler
Quoted 1 line · Florian Mickler

The kernel can not win if it does not try to integrate any use of it.

If we'd integrate every patch that came to lkml, you'd run away screaming.

We most certainly do not want to integrate _any_ use.

#289 lore raw
In reply to Florian Mickler
Quoted 1 line · Florian Mickler

The kernel can not win if it does not try to integrate any use of it.

If we'd integrate every patch that came to lkml, you'd run away screaming.

We most certainly do not want to integrate _any_ use.

#306 lore raw
In reply to Florian Mickler
Quoted 7 lines

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

The problem you have is that this is policy. If I have the device wired to a big screen and I want cows bouncing on it I'll be most upset if instead it suspends. What you are essentially arguing for is for the kernel to disobey the userspace. It's as ridiculous (albeit usually less damaging) as a file system saying "Ooh thats a rude file name, the app can't have meant it, I'll put your document soemwhere else"

The whole API feels wrong to me. It's breaking rule #1 of technology "You cannot solve a social problem with technology". In this case you have a social/economic problem which is crap code. You solve it with an economics solution - creative incentives not to produce crap code like boxes that keep popping up saying "App XYZ is using all your battery" and red-amber-green powermeter scores in app stores.

That said if you want technical mitigation I think it makes more sense if you look at it from a different starting point. The starting point being this: We have idling logic in the kernel and improving this helps everyone. What is needed to improve the existing logic ?

- You don't know which processes should be ignored for the purpose of suspend (except for kernel threads) and there is no way to set this

- You don't know whether a move from a deep idle to a 'suspend' (which is just a really deep idle in truth anyway) might break wakeups requirements because a device has wake dependencies due to hardware design (eg a port that has no electronics to kick the box out of suspend into running). This is a problem we have already. [1]

That maps onto two existing ideas

Sandboxing/Resource Limits: handling apps that can't be trusted. So the phone runs the appstore code via something like

		setpidle(getpid(), something);
		exec()

where 'something' is a value with meaning to both user space and to the existing idling logic in the kernel that basically says to what extent it is permitted to block idling/suspend. That also seems to tie into some of the realtime + idle problems. This I think deals with Kevin Hillman's thoughts on dealing with untrustworthy app code more cleanly and avoids the need for userspace hackery like the blocker API.

And an entirely in kernel API where device drivers can indicate that in their current situation they require that the power level doesn't drop below some limit unless user requested. This is really important because the platform vendor of the phone/pda/tablet whatever effectively owns the kernel - so it's *their* problem, *their* control, *their* hardware and they can make it work as best for the device. Best of all it means its all free software stuff so if the vendor screws up you can still fix your phone.

Implementation-wise it probably ties into setpidle, its simply that a task has a pair of idle values, a dynamic one and a base one, the dynamic one being the base one but updatable temporarily by drivers.

Alan
--

[1] Note I disagree with Kevin here on static/dynamic power management. There are IMHO two types of PM but they are 'user invoked' and 'automatic'. "Static" simply means it's not been made fast enough yet but its just a policy divide dependant on the users 'acceptable' resume time (which for hard RT may just as well rule out some more usual power states)

#280 lore raw
In reply to Florian Mickler
Quoted 3 lines

Nonetheless, I really think the kernel needs to allow for the android way of power saving. It misses out on a big feature and a big user-base if not.

That seems to me to be conflating models of behaviour and implementations.

Quoted 2 lines

This is a _big_ plus for attracting 3rd party programs. (And of course the thing you don't like).

You would do better to concentrate on technical issues that the assignment of malicious intent to other parties.

Alan

#1317 lore raw
In reply to Florian Mickler
Quoted 7 lines

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

The problem you have is that this is policy. If I have the device wired to a big screen and I want cows bouncing on it I'll be most upset if instead it suspends. What you are essentially arguing for is for the kernel to disobey the userspace. It's as ridiculous (albeit usually less damaging) as a file system saying "Ooh thats a rude file name, the app can't have meant it, I'll put your document soemwhere else"

The whole API feels wrong to me. It's breaking rule #1 of technology "You cannot solve a social problem with technology". In this case you have a social/economic problem which is crap code. You solve it with an economics solution - creative incentives not to produce crap code like boxes that keep popping up saying "App XYZ is using all your battery" and red-amber-green powermeter scores in app stores.

That said if you want technical mitigation I think it makes more sense if you look at it from a different starting point. The starting point being this: We have idling logic in the kernel and improving this helps everyone. What is needed to improve the existing logic ?

- You don't know which processes should be ignored for the purpose of suspend (except for kernel threads) and there is no way to set this

- You don't know whether a move from a deep idle to a 'suspend' (which is just a really deep idle in truth anyway) might break wakeups requirements because a device has wake dependencies due to hardware design (eg a port that has no electronics to kick the box out of suspend into running). This is a problem we have already. [1]

That maps onto two existing ideas

Sandboxing/Resource Limits: handling apps that can't be trusted. So the phone runs the appstore code via something like

		setpidle(getpid(), something);
		exec()

where 'something' is a value with meaning to both user space and to the existing idling logic in the kernel that basically says to what extent it is permitted to block idling/suspend. That also seems to tie into some of the realtime + idle problems. This I think deals with Kevin Hillman's thoughts on dealing with untrustworthy app code more cleanly and avoids the need for userspace hackery like the blocker API.

And an entirely in kernel API where device drivers can indicate that in their current situation they require that the power level doesn't drop below some limit unless user requested. This is really important because the platform vendor of the phone/pda/tablet whatever effectively owns the kernel - so it's *their* problem, *their* control, *their* hardware and they can make it work as best for the device. Best of all it means its all free software stuff so if the vendor screws up you can still fix your phone.

Implementation-wise it probably ties into setpidle, its simply that a task has a pair of idle values, a dynamic one and a base one, the dynamic one being the base one but updatable temporarily by drivers.

Alan
--

[1] Note I disagree with Kevin here on static/dynamic power management. There are IMHO two types of PM but they are 'user invoked' and 'automatic'. "Static" simply means it's not been made fast enough yet but its just a policy divide dependant on the users 'acceptable' resume time (which for hard RT may just as well rule out some more usual power states)

#283 lore raw
In reply to Florian Mickler
Quoted 3 lines

Nonetheless, I really think the kernel needs to allow for the android way of power saving. It misses out on a big feature and a big user-base if not.

That seems to me to be conflating models of behaviour and implementations.

Quoted 2 lines

This is a _big_ plus for attracting 3rd party programs. (And of course the thing you don't like).

You would do better to concentrate on technical issues that the assignment of malicious intent to other parties.

Alan

#296 lore raw
In reply to Vitaly Wool
Quoted 10 lines · On Wed, 26 May 2010 14:55:31 +0200 Vitaly Wool <[email protected]> wrote:
Quoted 7 lines · Florian Mickler

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

Quoted 7 lines

You almost always need to "hack" the mainline software for a production system. So do it here as well. Make sure the hack is well isolated and local. You can even submit it to the mainline, better as a configuration option, _unless_ it is a *framework* that provokes writing code in an ugly and unsafe way.

~Vitaly

I don't think that the in-kernel suspend block is a bad idea.

You could probably use the suspend-blockers unconditionally in the suspend framework to indicate if a suspend is possible or not. Regardless of opportunistic suspend or not. This way, you don't have to try-and-fail on a suspend request and thus making suspending potentially more robust or allowing for a "suspend as soon as possible" semantic (which is probably a good idea, if you have to grab your laptop in a hurry to get away).

Cheers,
Flo

#297 lore raw
In reply to Vitaly Wool
Quoted 10 lines · On Wed, 26 May 2010 14:55:31 +0200 Vitaly Wool <[email protected]> wrote:
Quoted 7 lines · Florian Mickler

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

Quoted 7 lines

You almost always need to "hack" the mainline software for a production system. So do it here as well. Make sure the hack is well isolated and local. You can even submit it to the mainline, better as a configuration option, _unless_ it is a *framework* that provokes writing code in an ugly and unsafe way.

~Vitaly

I don't think that the in-kernel suspend block is a bad idea.

You could probably use the suspend-blockers unconditionally in the suspend framework to indicate if a suspend is possible or not. Regardless of opportunistic suspend or not. This way, you don't have to try-and-fail on a suspend request and thus making suspending potentially more robust or allowing for a "suspend as soon as possible" semantic (which is probably a good idea, if you have to grab your laptop in a hurry to get away).

Cheers,
Flo

#131 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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]
#132 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Peter Zijlstra
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]
#290 lore raw
In reply to Peter Zijlstra
Quoted 7 lines · On Wed, 26 May 2010 15:07:27 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 1 line · Florian Mickler

The kernel can not win if it does not try to integrate any use of it.

If we'd integrate every patch that came to lkml, you'd run away screaming.

We most certainly do not want to integrate _any_ use.

We most certainly do want to integrate any use that is not harmful to others.

I don't buy the argument that this is harmful.

Cheers,
Flo

#291 lore raw
In reply to Peter Zijlstra
Quoted 7 lines · On Wed, 26 May 2010 15:07:27 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 1 line · Florian Mickler

The kernel can not win if it does not try to integrate any use of it.

If we'd integrate every patch that came to lkml, you'd run away screaming.

We most certainly do not want to integrate _any_ use.

We most certainly do want to integrate any use that is not harmful to others.

I don't buy the argument that this is harmful.

Cheers,
Flo

#281 lore raw
In reply to Alan Cox
Quoted 7 lines · On Wed, 26 May 2010 14:19:42 +0100 Alan Cox <[email protected]> wrote:
Quoted 2 lines

This is a _big_ plus for attracting 3rd party programs. (And of course the thing you don't like).

You would do better to concentrate on technical issues that the assignment of malicious intent to other parties.

Alan

This was nothing the kind of! He explicitly said this:

Quoted 4 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

And I responded that if the kernel would do this, then that would be a "_big_ plus for attracting 3d party programs".

I had no intent in attacking anyone or putting word's in someones mouth. Sorry if this was unclearly written.

Cheers,
Flo

#282 lore raw
In reply to Alan Cox
Quoted 7 lines · On Wed, 26 May 2010 14:19:42 +0100 Alan Cox <[email protected]> wrote:
Quoted 2 lines

This is a _big_ plus for attracting 3rd party programs. (And of course the thing you don't like).

You would do better to concentrate on technical issues that the assignment of malicious intent to other parties.

Alan

This was nothing the kind of! He explicitly said this:

Quoted 4 lines · On Wed, 26 May 2010 15:29:32 +0300 Felipe Balbi <[email protected]> wrote:

What I find ridiculous is the assumption that kernel should provide good power management even for badly written applications. They should work, of course, but there's no assumption that the kernel should cope with those applications and provide good battery usage on those cases.

And I responded that if the kernel would do this, then that would be a "_big_ plus for attracting 3d party programs".

I had no intent in attacking anyone or putting word's in someones mouth. Sorry if this was unclearly written.

Cheers,
Flo

#307 lore raw
In reply to Alan Cox

Alan,

Quoted 15 lines · Alan Cox
Quoted 7 lines

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

The problem you have is that this is policy. If I have the device wired to a big screen and I want cows bouncing on it I'll be most upset if instead it suspends. What you are essentially arguing for is for the kernel to disobey the userspace. It's as ridiculous (albeit usually less damaging) as a file system saying "Ooh thats a rude file name, the app can't have meant it, I'll put your document soemwhere else"

Quoted 6 lines

The whole API feels wrong to me. It's breaking rule #1 of technology "You cannot solve a social problem with technology". In this case you have a social/economic problem which is crap code. You solve it with an economics solution - creative incentives not to produce crap code like boxes that keep popping up saying "App XYZ is using all your battery" and red-amber-green powermeter scores in app stores.

I completely agree.

We have already proven that the social pressure on crappy applications works. When NOHZ was merged into the kernel we got no effect at all because a big percentage of user space applications just used timers at will and without any thoughts, also it unveiled busy polling and other horrible coding constructs. So what happened ? Arjan created powertop which lets the user analyse the worst offenders in his system. As a result the offending apps got fixed rapidly simply because no maintainer wanted to be on top of the powertop sh*tlist.

In the mobile app space it's basically the same problem. Users can influence the app writers simply by voting and setting up public lists of apps which are crappy or excellent. All it needs is a nice powertop tool for the phone which allows the users to identify the crap on their phones. That provides much more incentive - especially for commercial players - to fix their crappy code.

Adding that sys_try_to_fix_crappy_userspace_code() API to the kernel is just counter productive as it signals to the app provider: Go ahead, keep on coding crap!

That's not a solution, that's just capitulation.

It's absurd that some folks believe that giving up the most efficient tool to apply pressure to crappy app providers is a good idea.

Thanks,

tglx

#308 lore raw
In reply to Alan Cox

Alan,

Quoted 15 lines · Alan Cox
Quoted 7 lines

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

The problem you have is that this is policy. If I have the device wired to a big screen and I want cows bouncing on it I'll be most upset if instead it suspends. What you are essentially arguing for is for the kernel to disobey the userspace. It's as ridiculous (albeit usually less damaging) as a file system saying "Ooh thats a rude file name, the app can't have meant it, I'll put your document soemwhere else"

Quoted 6 lines

The whole API feels wrong to me. It's breaking rule #1 of technology "You cannot solve a social problem with technology". In this case you have a social/economic problem which is crap code. You solve it with an economics solution - creative incentives not to produce crap code like boxes that keep popping up saying "App XYZ is using all your battery" and red-amber-green powermeter scores in app stores.

I completely agree.

We have already proven that the social pressure on crappy applications works. When NOHZ was merged into the kernel we got no effect at all because a big percentage of user space applications just used timers at will and without any thoughts, also it unveiled busy polling and other horrible coding constructs. So what happened ? Arjan created powertop which lets the user analyse the worst offenders in his system. As a result the offending apps got fixed rapidly simply because no maintainer wanted to be on top of the powertop sh*tlist.

In the mobile app space it's basically the same problem. Users can influence the app writers simply by voting and setting up public lists of apps which are crappy or excellent. All it needs is a nice powertop tool for the phone which allows the users to identify the crap on their phones. That provides much more incentive - especially for commercial players - to fix their crappy code.

Adding that sys_try_to_fix_crappy_userspace_code() API to the kernel is just counter productive as it signals to the app provider: Go ahead, keep on coding crap!

That's not a solution, that's just capitulation.

It's absurd that some folks believe that giving up the most efficient tool to apply pressure to crappy app providers is a good idea.

Thanks,

tglx

#78 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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.

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

#79 lore raw

Re: [PATCH 1/8] PM: Opportunistic suspend support.

In reply to Dmitry Torokhov
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.

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

#298 lore raw
In reply to Florian Mickler
Quoted 4 lines · Florian Mickler

I don't think that the in-kernel suspend block is a bad idea.

You could probably use the suspend-blockers unconditionally in the suspend framework to indicate if a suspend is possible or not.

That's not how it works. Drivers aren't supposed to abort unconditional suspend -- not without a really good reason (for example, the device received a wakeup event before it was fully suspended). In short, suspends should be considered to be _always_ possible.

Quoted 5 lines

Regardless of opportunistic suspend or not. This way, you don't have to try-and-fail on a suspend request and thus making suspending potentially more robust or allowing for a "suspend as soon as possible" semantic (which is probably a good idea, if you have to grab your laptop in a hurry to get away).

That's different. Suspend blockers could block (not abort!) regular suspends, just as they do opportunistic suspends.

But why should they? I mean, if userspace wants to initiate a suspend that is capable of being blocked by a kernel suspend blocker, then all it has to do is initiate an opportunistic suspend instead of a normal suspend.

Alan Stern

#299 lore raw
In reply to Florian Mickler
Quoted 4 lines · Florian Mickler

I don't think that the in-kernel suspend block is a bad idea.

You could probably use the suspend-blockers unconditionally in the suspend framework to indicate if a suspend is possible or not.

That's not how it works. Drivers aren't supposed to abort unconditional suspend -- not without a really good reason (for example, the device received a wakeup event before it was fully suspended). In short, suspends should be considered to be _always_ possible.

Quoted 5 lines

Regardless of opportunistic suspend or not. This way, you don't have to try-and-fail on a suspend request and thus making suspending potentially more robust or allowing for a "suspend as soon as possible" semantic (which is probably a good idea, if you have to grab your laptop in a hurry to get away).

That's different. Suspend blockers could block (not abort!) regular suspends, just as they do opportunistic suspends.

But why should they? I mean, if userspace wants to initiate a suspend that is capable of being blocked by a kernel suspend blocker, then all it has to do is initiate an opportunistic suspend instead of a normal suspend.

Alan Stern

#311 lore raw
In reply to Alan Cox
Quoted 15 lines · On Wed, 26 May 2010 14:16:12 +0100 Alan Cox <[email protected]> wrote:
Quoted 7 lines

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

The problem you have is that this is policy. If I have the device wired to a big screen and I want cows bouncing on it I'll be most upset if instead it suspends. What you are essentially arguing for is for the kernel to disobey the userspace. It's as ridiculous (albeit usually less damaging) as a file system saying "Ooh thats a rude file name, the app can't have meant it, I'll put your document soemwhere else"

Quoted 6 lines

The whole API feels wrong to me. It's breaking rule #1 of technology "You cannot solve a social problem with technology". In this case you have a social/economic problem which is crap code. You solve it with an economics solution - creative incentives not to produce crap code like boxes that keep popping up saying "App XYZ is using all your battery" and red-amber-green powermeter scores in app stores.

I'm not saying that your argument is not valid. But why don't you look at suspend blockers as a contract between userspace and kernelspace? An Opt-In to the current guarantees the kernel provides in the non-suspend case.

<<If you want to use the rare resource "power" you have to take a suspend blocker. By this you assert that you are a well written application. If you are not well written, you will get the worst of our red-amber-green powermeter scores we have.>>

On the other hand, applications can say, they don't need that much power and userspace guaranties and not take a suspend blocker.

This is an option which they currently don't have.

I don't think opportunistic suspend is a policy decision by the kernel. it is something new. Something which currently only the android userspace implements / supports. If you don't want to suspend while looking at the bouncing-cow, you have to take a suspend blocker and make yourself a user-visible power-eater, or don't do

echo "opportunistic" > /sys/power/policy

in the first place.

This "optionally being badly written, who cares?" is a new feature the kernel can provide to applications.

That said, your proposed alternative implementation scheme looks like another possible approach.

Quoted 38 lines

That said if you want technical mitigation I think it makes more sense if you look at it from a different starting point. The starting point being this: We have idling logic in the kernel and improving this helps everyone. What is needed to improve the existing logic ?

- You don't know which processes should be ignored for the purpose of suspend (except for kernel threads) and there is no way to set this

- You don't know whether a move from a deep idle to a 'suspend' (which is just a really deep idle in truth anyway) might break wakeups requirements because a device has wake dependencies due to hardware design (eg a port that has no electronics to kick the box out of suspend into running). This is a problem we have already. [1]

That maps onto two existing ideas

Sandboxing/Resource Limits: handling apps that can't be trusted. So the phone runs the appstore code via something like

		setpidle(getpid(), something);
		exec()

where 'something' is a value with meaning to both user space and to the existing idling logic in the kernel that basically says to what extent it is permitted to block idling/suspend. That also seems to tie into some of the realtime + idle problems. This I think deals with Kevin Hillman's thoughts on dealing with untrustworthy app code more cleanly and avoids the need for userspace hackery like the blocker API.

And an entirely in kernel API where device drivers can indicate that in their current situation they require that the power level doesn't drop below some limit unless user requested. This is really important because the platform vendor of the phone/pda/tablet whatever effectively owns the kernel - so it's *their* problem, *their* control, *their* hardware and they can make it work as best for the device. Best of all it means its all free software stuff so if the vendor screws up you can still fix your phone.

Quoted 5 lines

Implementation-wise it probably ties into setpidle, its simply that a task has a pair of idle values, a dynamic one and a base one, the dynamic one being the base one but updatable temporarily by drivers.

Alan

How does this address the loss of wakeup events while using suspend? (For example the 2 issues formulated by Alan Stern in [1])

cheers,
Flo

[1]http://lkml.org/lkml/2010/5/21/458

p.s.:
dmk@schatten /usr/src/linux $ grep -r "setpidle" . dmk@schatten /usr/src/linux $

#354 lore raw
In reply to Alan Cox
Quoted 15 lines · On Wed, 26 May 2010 14:16:12 +0100 Alan Cox <[email protected]> wrote:
Quoted 7 lines

Really, what are you getting at? Do you deny that there are programs, that prevent a device from sleeping? (Just think of the bouncing cows app)

And if you have two kernels, one with which your device is dead after 1 hour and one with which your device is dead after 10 hours. Which would you prefer? I mean really... this is ridiculous.

The problem you have is that this is policy. If I have the device wired to a big screen and I want cows bouncing on it I'll be most upset if instead it suspends. What you are essentially arguing for is for the kernel to disobey the userspace. It's as ridiculous (albeit usually less damaging) as a file system saying "Ooh thats a rude file name, the app can't have meant it, I'll put your document soemwhere else"

Quoted 6 lines

The whole API feels wrong to me. It's breaking rule #1 of technology "You cannot solve a social problem with technology". In this case you have a social/economic problem which is crap code. You solve it with an economics solution - creative incentives not to produce crap code like boxes that keep popping up saying "App XYZ is using all your battery" and red-amber-green powermeter scores in app stores.

I'm not saying that your argument is not valid. But why don't you look at suspend blockers as a contract between userspace and kernelspace? An Opt-In to the current guarantees the kernel provides in the non-suspend case.

<<If you want to use the rare resource "power" you have to take a suspend blocker. By this you assert that you are a well written application. If you are not well written, you will get the worst of our red-amber-green powermeter scores we have.>>

On the other hand, applications can say, they don't need that much power and userspace guaranties and not take a suspend blocker.

This is an option which they currently don't have.

I don't think opportunistic suspend is a policy decision by the kernel. it is something new. Something which currently only the android userspace implements / supports. If you don't want to suspend while looking at the bouncing-cow, you have to take a suspend blocker and make yourself a user-visible power-eater, or don't do

echo "opportunistic" > /sys/power/policy

in the first place.

This "optionally being badly written, who cares?" is a new feature the kernel can provide to applications.

That said, your proposed alternative implementation scheme looks like another possible approach.

Quoted 38 lines

That said if you want technical mitigation I think it makes more sense if you look at it from a different starting point. The starting point being this: We have idling logic in the kernel and improving this helps everyone. What is needed to improve the existing logic ?

- You don't know which processes should be ignored for the purpose of suspend (except for kernel threads) and there is no way to set this

- You don't know whether a move from a deep idle to a 'suspend' (which is just a really deep idle in truth anyway) might break wakeups requirements because a device has wake dependencies due to hardware design (eg a port that has no electronics to kick the box out of suspend into running). This is a problem we have already. [1]

That maps onto two existing ideas

Sandboxing/Resource Limits: handling apps that can't be trusted. So the phone runs the appstore code via something like

		setpidle(getpid(), something);
		exec()

where 'something' is a value with meaning to both user space and to the existing idling logic in the kernel that basically says to what extent it is permitted to block idling/suspend. That also seems to tie into some of the realtime + idle problems. This I think deals with Kevin Hillman's thoughts on dealing with untrustworthy app code more cleanly and avoids the need for userspace hackery like the blocker API.

And an entirely in kernel API where device drivers can indicate that in their current situation they require that the power level doesn't drop below some limit unless user requested. This is really important because the platform vendor of the phone/pda/tablet whatever effectively owns the kernel - so it's *their* problem, *their* control, *their* hardware and they can make it work as best for the device. Best of all it means its all free software stuff so if the vendor screws up you can still fix your phone.

Quoted 5 lines

Implementation-wise it probably ties into setpidle, its simply that a task has a pair of idle values, a dynamic one and a base one, the dynamic one being the base one but updatable temporarily by drivers.

Alan

How does this address the loss of wakeup events while using suspend? (For example the 2 issues formulated by Alan Stern in [1])

cheers,
Flo

[1]http://lkml.org/lkml/2010/5/21/458

p.s.:
dmk@schatten /usr/src/linux $ grep -r "setpidle" . dmk@schatten /usr/src/linux $