Skip to contentSkip to conversation

Suspend block api (version 7)

PATCH In review Arve Hjønnevåg 8 participants 101 messages May 14, 2010 – May 27, 2010

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

cover Suspend block api (version 7)

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

--
Arve Hjønnevåg <[email protected]>

#1 lore raw

PATCH 1/8 PM: Add suspend block api.

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

---
 Documentation/power/opportunistic-suspend.txt |  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          |  284 +++++++++++++++++++++++++
 kernel/power/power.h                          |    9 +
 kernel/power/suspend.c                        |    3 +-
 9 files changed, 637 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 +284 -0

284 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
#2 lore raw

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

Add a misc device, "suspend_blocker", that allows user-space processes to block auto suspend. The device has ioctls to create a suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.

---
 Documentation/ioctl/ioctl-number.txt          |    3 +-
 Documentation/power/opportunistic-suspend.txt |   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
#3 lore raw

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

If a suspend_blocker is active, suspend will fail anyway. Since try_to_freeze_tasks can take up to 20 seconds to complete or fail, aborting as soon as someone blocks suspend (e.g. from an interrupt handler) improves the worst case wakeup latency.

On an older kernel where task freezing could fail for processes attached to a debugger, this fixed a problem where the device sometimes hung for 20 seconds before the screen turned on.

---
 kernel/power/process.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
kernel/power/process.c +9 -2
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
#4 lore raw

PATCH 4/8 PM: suspend_block: Add debugfs file

Report active and inactive suspend blockers in
/sys/kernel/debug/suspend_blockers.

---
 kernel/power/opportunistic_suspend.c |   43 +++++++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)
kernel/power/opportunistic_suspend.c +42 -1
index acc1651..c2dad76 100644
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/rtc.h>
 #include <linux/suspend.h>
+#include <linux/debugfs.h>
 
 #include "power.h"
 
@@ -138,7 +139,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().
@@ -282,3 +284,42 @@ void __init opportunistic_suspend_init(void)
 	suspend_blocker_register(&main_suspend_blocker);
 	suspend_block(&main_suspend_blocker);
 }
+
+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
#5 lore raw

PATCH 5/8 PM: suspend_block: Add suspend_blocker stats

Report suspend block stats in /sys/kernel/debug/suspend_blockers.

---
 include/linux/suspend_blocker.h      |   27 +++++-
 kernel/power/Kconfig                 |    8 ++
 kernel/power/opportunistic_suspend.c |  200 +++++++++++++++++++++++++++++++++-
 kernel/power/power.h                 |    5 +
 kernel/power/suspend.c               |    4 +-
 5 files changed, 239 insertions(+), 5 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 +197 -3

268 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
#6 lore raw

PATCH 6/8 PM: Add suspend blocking work.

Allow work to be queued that will block suspend while it is pending or executing. To get the same functionality in the calling code often requires a separate suspend_blocker for pending and executing work, or additional state and locking. This implementation does add additional state and locking, but this can be removed later if we add support for suspend blocking work to the core workqueue code.

---
 include/linux/suspend_blocker.h      |   67 +++++++++++++++++++++
 kernel/power/opportunistic_suspend.c |  109 ++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+), 0 deletions(-)
include/linux/suspend_blocker.h +67 -0
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
#7 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
#8 lore raw

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

Add an ioctl, EVIOCSSUSPENDBLOCK, to enable a suspend_blocker that will block suspend while the event queue is not empty. This allows userspace code to process input events while the device appears to be asleep.

---
 drivers/input/evdev.c |   22 ++++++++++++++++++++++
 include/linux/input.h |    3 +++
 2 files changed, 25 insertions(+), 0 deletions(-)
drivers/input/evdev.c +22 -0
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
#9 lore raw

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

When connecting usb or the charger the device would often go back to sleep before the charge led and screen turned on.

---
 drivers/power/power_supply_core.c |    9 ++++++---
 include/linux/power_supply.h      |    3 ++-
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/power/power_supply_core.c +6 -3
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
#10 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Arve Hjønnevåg

Hello,

some comments on the kernel-level suspend blocker API.

Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Another problem with the suspend-block kernel API is that its primary use-case[1] is to work around the brokenness of patch 1's opportunistic suspend governor. The governor is broken because it intentionally ignores timers and the scheduler. To work around problems caused by this decision, suspend-blocks must be spread throughout the kernel (and userspace) to restore the previous behavior of the system. But if patch 1's opportunistic suspend governor were fixed, most of the need for a suspend blockers would disappear.

[ This E-mail expands on some earlier comments[2] and is also related
to other opportunistic suspend comments[3]. ]

The suspend-block patches require already-working code to be patched to keep it working. This is a backwards approach. Instead, broken code should be patched to fix the brokenness. But the former approach is exactly what the suspend block API is intended to do. Patches 7 and 8 in this series are two clear cases. Patch 7 adds an ioctl to the input subsystem that will cause the system to stay running as long as there is an event in the event queue. Patch 8 adds a suspend-block call to the power_supply code that causes the system to stay running as long as power_supply's changed_work workqueue has work to do. Neither of these patches should be needed, since the default expectation of the mainline Linux kernel is that the system should run when there is work to be done.

This longstanding expectation should be preserved, not broken and then patched around. But since patch 1 violates that expectation, there is no choice but to add patches 7 and 8 -- and ultimately many more patches -- to get a working system. Once the opportunistic suspend governor in patch 1 is introduced and enabled, the kernel will suspend the system immediately, even if the system has work to do. The only way to prevent that is to add suspend-blocks.

Many suspend blocks will be needed throughout the kernel to keep things working. One might think that patches 7 and 8 are the only changes needed to get a working Android-style opportunistic suspend system. It turns out that many more changes are needed. This can be seen by looking at currently shipping Android kernels, such as the current current Android 'msm' kernel tree[4]. Suspend-blocker usage is spread through many drivers and subsystems:

[paul@twilight msm]$ fgrep -r wake_lock . | egrep '(^./drivers|^./arch)' | cut -f1 -d: | sort -u
./arch/arm/mach-msm/htc_battery.c
./arch/arm/mach-msm/pm.c
./arch/arm/mach-msm/qdsp5/adsp.c ./arch/arm/mach-msm/qdsp5/audio_out.c ./arch/arm/mach-msm/smd_qmi.c ./arch/arm/mach-msm/smd_rpcrouter.c ./arch/arm/mach-msm/smd_rpcrouter.h ./arch/arm/mach-msm/smd_rpcrouter_servers.c ./arch/arm/mach-msm/smd_tty.c
./drivers/i2c/chips/mt9t013.c
./drivers/input/evdev.c
./drivers/input/misc/gpio_input.c ./drivers/input/misc/gpio_matrix.c
./drivers/mmc/core/core.c
./drivers/net/msm_rmnet.c
./drivers/rtc/alarm.c
./drivers/serial/msm_serial_hs.c ./drivers/usb/function/mass_storage.c ./drivers/usb/gadget/f_mass_storage.c ./drivers/video/msm/mddi.c
./drivers/video/msm/msm_fb.c

I guess this is something like what kernel developers should eventually expect to see if suspend blockers are merged.

There is a better way to make the system work as expected: these patch 1 shouldn't break general timer and scheduler assumptions. If patch 1's governor is fixed, most of these calls will be unnecessary. The apparent motivation is to prevent "untrusted" userspace processes from preventing the system from entering a low-power state. I agree that this is a problem. But it should be fixed by modifying the specific Linux code that determines when the idle loop is entered and when the next timer wakeup should occur, on a per-process basis. Such targeted changes would ensure that the rest of the kernel would continue to execute as expected.

regards,

- Paul

1. Arve Hjønnevåg E-mail to the linux-pm mailing list, dated Mon, 3 May 2010 17:09:22 -0700:
http://www.spinics.net/lists/linux-pm/msg18432.html

2. Paul Walmsley E-mail to the linux-pm mailing list, dated Wed, 12 May 2010 21:35:30 -0600: http://lkml.org/lkml/2010/5/12/528

3. Paul Walmsley E-mail to the linux-pm mailing list, dated Thu, 13 May 2010 13:01:33 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18592

4. git://android.git.kernel.org/kernel/msm.git - as of commit c7f8bcecb06b937c45dd0e342450a3218b286b8d, "[ARM] msm: defconfig:
Set mmap_min_addr to 32k"

5. http://android.git.kernel.org/?p=kernel/msm.git;a=blob;f=drivers/mmc/core/core.c;h=22f6ddad85c92f34c55035982049bb03b5abfc74;hb=c7f8bcecb06b937c45dd0e342450a3218b286b8d#l721

#11 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Arve Hjønnevåg

Hello,

Another comment on the kernel suspend-blocker API.

Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

	/* give userspace some time to react */
	wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation. The MMC subsystem should have nothing to do with "giving userspace time to react." That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent. What if userspace occasionally needs more than (HZ / 2) to react? If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number. But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

The above code will also waste power. Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time. This is in contrast to an approach that uses the idle loop to enter a system-wide low power state. The moment that the system has no further work to do, it can start saving power.

The problems with the above example are not isolated:

[paul@twilight msm]$ fgrep -r wake_lock_timeout . | egrep '(^./drivers|^./arch)'
./arch/arm/mach-msm/htc_battery.c: wake_lock_timeout(&vbus_wake_lock, HZ / 2);
./arch/arm/mach-msm/smd_tty.c: wake_lock_timeout(&info->wake_lock, HZ / 2);
./arch/arm/mach-msm/smd_qmi.c: wake_lock_timeout(&ctxt->wake_lock, HZ / 2);
./drivers/rtc/alarm.c: wake_lock_timeout(&alarm_wake_lock, 5 * HZ);
./drivers/rtc/alarm.c: wake_lock_timeout(&alarm_rtc_wake_lock, 1 * HZ);
./drivers/rtc/alarm.c: wake_lock_timeout(&alarm_rtc_wake_lock, 2 * HZ);
./drivers/mmc/core/core.c: wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
./drivers/net/msm_rmnet.c: wake_lock_timeout(&p->wake_lock, HZ / 2);
./drivers/video/msm/msm_fb.c: wake_lock_timeout(&msmfb->idle_lock, HZ/4);
./drivers/video/msm/msm_fb.c: wake_lock_timeout(&msmfb->idle_lock, HZ/4);
./drivers/video/msm/msm_fb.c: wake_lock_timeout(&msmfb->idle_lock, HZ);
./drivers/input/evdev.c: wake_lock_timeout(&client->wake_lock, 5 * HZ);
./drivers/serial/msm_serial_hs.c: wake_lock_timeout(&msm_uport->rx.wake_lock, HZ / 2);

It is true that the current patch series does not propose the *_timeout() interface. But that raises the question of what it will be replaced with, in situations where the problem can't simply be pushed to userspace, as it is in Arve's evdev patch 7. Some of these cases seem difficult to handle without some sort of timer-based approach. Timer-based approaches are intrinsically problematic for the reasons mentioned above.

- Paul

1. git://android.git.kernel.org/kernel/msm.git - as of commit c7f8bcecb06b937c45dd0e342450a3218b286b8d, "[ARM] msm: defconfig:
Set mmap_min_addr to 32k"

2. http://android.git.kernel.org/?p=kernel/msm.git;a=blob;f=drivers/mmc/core/core.c;h=22f6ddad85c92f34c55035982049bb03b5abfc74;hb=c7f8bcecb06b937c45dd0e342450a3218b286b8d#l721

#12 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 37 lines · Paul Walmsley

Hello,

Another comment on the kernel suspend-blocker API.

Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

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

Re: [PATCH 1/8] PM: Add suspend block api.

Hello Arve,

Quoted 42 lines · Arve Hjønnevåg
Quoted 33 lines · Paul Walmsley
Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Quoted 4 lines

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

Sorry, my E-mail was unclear. Here is my intended point:

The current Android opportunistic suspend governor does not enter full system suspend until all suspend-blocks are released. If the governor were modified to respect the scheduler, then it could enter suspend the moment that the system had no further work to do.

So during part of the (HZ / 2) time interval in the above code, the system is running some kernel or userspace code. But after that work is done, an idle-loop-based opportunistic suspend governor could enter idle during the remaining portion of that (HZ / 2) time interval, while the current governor must keep the system out of suspend.

Of course, to do this, a different method for freezing processes would be needed; one possible approach is described here[1]; others have proposed similar approaches.

regards,

- Paul

1. Paragraphs B4A and B4B of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 18:39:44 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

#14 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 51 lines · Paul Walmsley

Hello Arve,

Quoted 42 lines · Arve Hjønnevåg
Quoted 33 lines · Paul Walmsley
Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Quoted 4 lines

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

Quoted 7 lines

Sorry, my E-mail was unclear.  Here is my intended point:

The current Android opportunistic suspend governor does not enter full system suspend until all suspend-blocks are released.  If the governor were modified to respect the scheduler, then it could enter suspend the moment that the system had no further work to do.

On the hardware that shipped we enter the same power state from idle and suspend, so the only power savings we get from suspend that we don't get in idle is from not respecting the scheduler and timers.

Quoted 6 lines

So during part of the (HZ / 2) time interval in the above code, the system is running some kernel or userspace code.  But after that work is done, an idle-loop-based opportunistic suspend governor could enter idle during the remaining portion of that (HZ / 2) time interval, while the current governor must keep the system out of suspend.

Triggering a full suspend (that disregards normal timers) from idle does not work, since the system may temporarily enter idle while processing the event.

Quoted 4 lines

Of course, to do this, a different method for freezing processes would be needed; one possible approach is described here[1]; others have proposed similar approaches.

If you freeze processes you need something like a suspend blocker to prevent processes from being frozen. By having a process that never gets frozen you could implement this entirely in user space, but you would have to funnel all wakeup events though this process.

Quoted 9 lines

regards,

- Paul

1. Paragraphs B4A and B4B of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 18:39:44 PDT 2010:
  https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

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

Re: [PATCH 1/8] PM: Add suspend block api.

Hello Arve,

Quoted 56 lines · Arve Hjønnevåg
Quoted 47 lines · Paul Walmsley
Quoted 41 lines · Arve Hjønnevåg
Quoted 32 lines · Paul Walmsley
Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Quoted 4 lines

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

Quoted 7 lines

Sorry, my E-mail was unclear.  Here is my intended point:

The current Android opportunistic suspend governor does not enter full system suspend until all suspend-blocks are released.  If the governor were modified to respect the scheduler, then it could enter suspend the moment that the system had no further work to do.

Quoted 3 lines

On the hardware that shipped we enter the same power state from idle and suspend, so the only power savings we get from suspend that we don't get in idle is from not respecting the scheduler and timers.

Other people
say that their hardware XXX. (This is probably likely for anything that supports ACPI.)

Quoted 9 lines
Quoted 6 lines

So during part of the (HZ / 2) time interval in the above code, the system is running some kernel or userspace code.  But after that work is done, an idle-loop-based opportunistic suspend governor could enter idle during the remaining portion of that (HZ / 2) time interval, while the current governor must keep the system out of suspend.

Triggering a full suspend (that disregards normal timers) from idle does not work, since the system may temporarily enter idle while processing the event.

Could you provide an example?

In such a case, how can the kernel guarantee that the system will process the event within (HZ / 2) seconds?

Quoted 6 lines
Quoted 3 lines

Of course, to do this, a different method for freezing processes would be needed; one possible approach is described here[1]; others have proposed similar approaches.

If you freeze processes you need something like a suspend blocker to prevent processes from being frozen.

(It occurs to me that "frozen" is the wrong terminology to use.
Perhaps "paused" would be a better term, along the lines of [1].)

The full set of processes does not need to be paused. For example, if "untrusted" processes are run in a cgroup, and only tasks in that cgroup are put into TASK_INTERRUPTIBLE, then "trusted" processes will not be paused.

Quoted 3 lines

By having a process that never gets frozen you could implement this entirely in user space, but you would have to funnel all wakeup events though this process.

The proposal[2] does require a kernel change. No wakeup funnel process would be needed. The proposal is to put processes into TASK_INTERRUPTIBLE, not TASK_STOPPED (unlike most "freezers").

- Paul

1. Paragraph B4B of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 18:39:44 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

2. ibid.

#16 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 74 lines · Paul Walmsley

Hello Arve,

Quoted 56 lines · Arve Hjønnevåg
Quoted 47 lines · Paul Walmsley
Quoted 41 lines · Arve Hjønnevåg
Quoted 32 lines · Paul Walmsley
Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Quoted 4 lines

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

Quoted 7 lines

Sorry, my E-mail was unclear.  Here is my intended point:

The current Android opportunistic suspend governor does not enter full system suspend until all suspend-blocks are released.  If the governor were modified to respect the scheduler, then it could enter suspend the moment that the system had no further work to do.

Quoted 3 lines

On the hardware that shipped we enter the same power state from idle and suspend, so the only power savings we get from suspend that we don't get in idle is from not respecting the scheduler and timers.

Other people
say that their hardware XXX.  (This is probably likely for anything that supports ACPI.)

Quoted 6 lines
Quoted 6 lines

So during part of the (HZ / 2) time interval in the above code, the system is running some kernel or userspace code.  But after that work is done, an idle-loop-based opportunistic suspend governor could enter idle during the remaining portion of that (HZ / 2) time interval, while the current governor must keep the system out of suspend.

Quoted 5 lines
Quoted 3 lines

Triggering a full suspend (that disregards normal timers) from idle does not work, since the system may temporarily enter idle while processing the event.

Could you provide an example?

The code takes a pagefault. The system is idle while waiting for the dma to finish.

Quoted 4 lines

In such a case, how can the kernel guarantee that the system will process the event within (HZ / 2) seconds?

It can't, but in my opinion if the event did not start processing in 1/2 second it was probably not time critical.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Of course, to do this, a different method for freezing processes would be needed; one possible approach is described here[1]; others have proposed similar approaches.

If you freeze processes you need something like a suspend blocker to prevent processes from being frozen.

Quoted 8 lines

(It occurs to me that "frozen" is the wrong terminology to use. Perhaps "paused" would be a better term, along the lines of [1].)

The full set of processes does not need to be paused.  For example, if "untrusted" processes are run in a cgroup, and only tasks in that cgroup are put into TASK_INTERRUPTIBLE, then "trusted" processes will not be paused.

We want to freeze trusted processes.

Quoted 8 lines
Quoted 3 lines

By having a process that never gets frozen you could implement this entirely in user space, but you would have to funnel all wakeup events though this process.

The proposal[2] does require a kernel change.  No wakeup funnel process would be needed.  The proposal is to put processes into TASK_INTERRUPTIBLE, not TASK_STOPPED (unlike most "freezers").

Why is the method used for pausing the processes relevant? If the process is paused it cannot process the wakeup event. The only way to get the wake event to the process is to funnel it though a process that never is paused.

Quoted 11 lines

- Paul

1. Paragraph B4B of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 18:39:44 PDT 2010:
  https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

2. ibid.

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

Re: [PATCH 1/8] PM: Add suspend block api.

Hi Arve,

Quoted 58 lines · Arve Hjønnevåg
Quoted 57 lines · Paul Walmsley
Quoted 56 lines · Arve Hjønnevåg
Quoted 54 lines · Paul Walmsley
Quoted 41 lines · Arve Hjønnevåg
Quoted 32 lines · Paul Walmsley
Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Quoted 4 lines

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

Sorry, my E-mail was unclear.  Here is my intended point:

The current Android opportunistic suspend governor does not enter full system suspend until all suspend-blocks are released.  If the governor were modified to respect the scheduler, then it could enter suspend the moment that the system had no further work to do.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

On the hardware that shipped we enter the same power state from idle and suspend, so the only power savings we get from suspend that we don't get in idle is from not respecting the scheduler and timers.

Other people
say that their hardware XXX.  (This is probably likely for anything that supports ACPI.)

Heh, looks like this part of my E-mail escaped a little too early.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So during part of the (HZ / 2) time interval in the above code, the system is running some kernel or userspace code.  But after that work is done, an idle-loop-based opportunistic suspend governor could enter idle during the remaining portion of that (HZ / 2) time interval, while the current governor must keep the system out of suspend.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Triggering a full suspend (that disregards normal timers) from idle does not work, since the system may temporarily enter idle while processing the event.

Could you provide an example?

The code takes a pagefault. The system is idle while waiting for the dma to finish.

OK.

Quoted 5 lines
Quoted 2 lines

In such a case, how can the kernel guarantee that the system will process the event within (HZ / 2) seconds?

It can't, but in my opinion if the event did not start processing in 1/2 second it was probably not time critical.

Thanks for the correction regarding the unit of the time interval.

To use the pagefault example, wouldn't that be partially dependent on factors outside the control of the task that handles the input event? (e.g., the time needed to page back in, or other code running on the system.)

Quoted 10 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

Of course, to do this, a different method for freezing processes would be needed; one possible approach is described here[1]; others have proposed similar approaches.

If you freeze processes you need something like a suspend blocker to prevent processes from being frozen.

(It occurs to me that "frozen" is the wrong terminology to use. Perhaps "paused" would be a better term, along the lines of [1].)

Quoted 6 lines
Quoted 4 lines

The full set of processes does not need to be paused.  For example, if "untrusted" processes are run in a cgroup, and only tasks in that cgroup are put into TASK_INTERRUPTIBLE, then "trusted" processes will not be paused.

We want to freeze trusted processes.

By "trusted," I mean processes that are run with a suspend block, as in your example to Tony[1]. Isn't it so that Android has processes that either run entirely under suspend-blocks, or which take suspend-blocks at some point in time during their execution? Wouldn't those processes need to be prevented from a force-pause or force-freeze?

Quoted 11 lines
Quoted 8 lines
Quoted 3 lines

By having a process that never gets frozen you could implement this entirely in user space, but you would have to funnel all wakeup events though this process.

The proposal[2] does require a kernel change.  No wakeup funnel process would be needed.  The proposal is to put processes into TASK_INTERRUPTIBLE, not TASK_STOPPED (unlike most "freezers").

Why is the method used for pausing the processes relevant? If the process is paused it cannot process the wakeup event.

Tasks in TASK_INTERRUPTIBLE are woken back up when an event arrives, unlike tasks in TASK_STOPPED, which are stopped until a SIGCONT arrives.

Quoted 2 lines

The only way to get the wake event to the process is to funnel it though a process that never is paused.

- Paul

1. http://lkml.org/lkml/2010/5/7/420

#18 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 95 lines · Paul Walmsley

Hi Arve,

Quoted 58 lines · Arve Hjønnevåg
Quoted 57 lines · Paul Walmsley
Quoted 56 lines · Arve Hjønnevåg
Quoted 54 lines · Paul Walmsley
Quoted 41 lines · Arve Hjønnevåg
Quoted 32 lines · Paul Walmsley
Quoted 7 lines · Arve Hjønnevåg

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Looking at the way that suspend-blocks are used in the current Android 'msm' kernel tree[1], they seem likely to cause layering violations, fragile kernel code with userspace dependencies, and code that consumes power unnecessarily.

For example, in drivers/mmc/core/core.c:721, in mmc_rescan() [2], we find the following code:

       /* give userspace some time to react */ wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);

This is a layering violation.  The MMC subsystem should have nothing to do with "giving userspace time to react."  That is the responsibility of the Linux scheduler.

This code is also intrinsically fragile and use-case dependent.  What if userspace occasionally needs more than (HZ / 2) to react?  If the distributor is lucky enough to catch this before the product ships, then the distributor can patch in a new magic number.  But if the device makes it to the consumer, the result is an unstable device that unpredictably suspends.

Quoted 7 lines

The above code will also waste power.  Even if userspace takes less than (HZ / 2) to react, the system will still be prevented from entering a system-wide low power state for the duration of the remaining time.  This is in contrast to an approach that uses the idle loop to enter a system-wide low power state.  The moment that the system has no further work to do, it can start saving power.

Quoted 4 lines

Yes, preventing suspend for 1/2 second wastes some power, but are you seriously suggesting that it wastes more power then never suspending? Opportunitic suspend does not prevent entering low power modes from idle.

Sorry, my E-mail was unclear.  Here is my intended point:

The current Android opportunistic suspend governor does not enter full system suspend until all suspend-blocks are released.  If the governor were modified to respect the scheduler, then it could enter suspend the moment that the system had no further work to do.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

On the hardware that shipped we enter the same power state from idle and suspend, so the only power savings we get from suspend that we don't get in idle is from not respecting the scheduler and timers.

Other people
say that their hardware XXX.  (This is probably likely for anything that supports ACPI.)

Heh, looks like this part of my E-mail escaped a little too early.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So during part of the (HZ / 2) time interval in the above code, the system is running some kernel or userspace code.  But after that work is done, an idle-loop-based opportunistic suspend governor could enter idle during the remaining portion of that (HZ / 2) time interval, while the current governor must keep the system out of suspend.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Triggering a full suspend (that disregards normal timers) from idle does not work, since the system may temporarily enter idle while processing the event.

Could you provide an example?

The code takes a pagefault. The system is idle while waiting for the dma to finish.

OK.

Quoted 5 lines
Quoted 2 lines

In such a case, how can the kernel guarantee that the system will process the event within (HZ / 2) seconds?

It can't, but in my opinion if the event did not start processing in 1/2 second it was probably not time critical.

Quoted 7 lines

Thanks for the correction regarding the unit of the time interval.

To use the pagefault example, wouldn't that be partially dependent on factors outside the control of the task that handles the input event? (e.g., the time needed to page back in, or other code running on the system.)

Yes (we don't need any timeouts to handle input events though).

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 6 lines
Quoted 3 lines

Of course, to do this, a different method for freezing processes would be needed; one possible approach is described here[1]; others have proposed similar approaches.

If you freeze processes you need something like a suspend blocker to prevent processes from being frozen.

(It occurs to me that "frozen" is the wrong terminology to use. Perhaps "paused" would be a better term, along the lines of [1].)

The full set of processes does not need to be paused.  For example, if "untrusted" processes are run in a cgroup, and only tasks in that cgroup are put into TASK_INTERRUPTIBLE, then "trusted" processes will not be paused.

Quoted 8 lines
Quoted 1 line

We want to freeze trusted processes.

By "trusted," I mean processes that are run with a suspend block, as in your example to Tony[1].  Isn't it so that Android has processes that either run entirely under suspend-blocks, or which take suspend-blocks at some point in time during their execution?  Wouldn't those processes need to be prevented from a force-pause or force-freeze?

We don't freeze processes while any suspend blockers are active.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

By having a process that never gets frozen you could implement this entirely in user space, but you would have to funnel all wakeup events though this process.

The proposal[2] does require a kernel change.  No wakeup funnel process would be needed.  The proposal is to put processes into TASK_INTERRUPTIBLE, not TASK_STOPPED (unlike most "freezers").

Quoted 4 lines
Quoted 2 lines

Why is the method used for pausing the processes relevant? If the process is paused it cannot process the wakeup event.

Tasks in TASK_INTERRUPTIBLE are woken back up when an event arrives,

So you are not actually preventing them from. A task that wakes up 60 times a second will still drain the battery, unless you happened to pause it while it was active.

Quoted 11 lines

unlike tasks in TASK_STOPPED, which are stopped until a SIGCONT arrives.

Quoted 2 lines

The only way to get the wake event to the process is to funnel it though a process that never is paused.

- Paul

1. http://lkml.org/lkml/2010/5/7/420

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

Re: [PATCH 1/8] PM: Add suspend block api.

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

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#20 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

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

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#21 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 11 lines · On Tue, 18 May 2010 15:11:11 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · Arve Hj??nnev??g

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Actually, what would be a better interface?

I wonder why it is not like this:

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

Cheers,
Flo

#22 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Pavel Machek
Quoted 11 lines · On Tue, 18 May 2010 15:11:11 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · Arve Hj??nnev??g

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Actually, what would be a better interface?

I wonder why it is not like this:

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

Cheers,
Flo

#23 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 24 lines · On Thu, 20 May 2010 11:11:11 +0200 Florian Mickler <[email protected]> wrote:
Quoted 11 lines · On Tue, 18 May 2010 15:11:11 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · Arve Hj??nnev??g

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Actually, what would be a better interface?

I wonder why it is not like this:

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

Quoted 6 lines

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

There you have it. One file, one purpose.

Quoted 2 lines

Cheers,
Flo

#24 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Florian Mickler
Quoted 24 lines · On Thu, 20 May 2010 11:11:11 +0200 Florian Mickler <[email protected]> wrote:
Quoted 11 lines · On Tue, 18 May 2010 15:11:11 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · Arve Hj??nnev??g

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Actually, what would be a better interface?

I wonder why it is not like this:

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

Quoted 6 lines

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

There you have it. One file, one purpose.

Quoted 2 lines

Cheers,
Flo

#25 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 15 lines · Florian Mickler
Quoted 12 lines · On Thu, 20 May 2010 11:11:11 +0200 Florian Mickler <[email protected]> wrote:
Quoted 9 lines · On Tue, 18 May 2010 15:11:11 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · Arve Hj??nnev??g

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I still don't like the interface.

Actually, what would be a better interface?

I wonder why it is not like this:

Because I think the "forced" and "opportunistic" suspend "modes" are mutually exclusive in practice and the interface as proposed reflects that quite well.

Quoted 12 lines
Quoted 11 lines

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

Quoted 6 lines

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

There you have it. One file, one purpose.

That's getting messy IMHO.

In addition to that you get a nice race when the user writes "mem" to /sys/power/state and opportunistic suspend happens at the same time. If the latter wins the race, the system will suspend again immediately after being woken up, which probably is not the result you'd like to get.

Thanks,
Rafael

#26 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

Quoted 24 lines · On Fri, 21 May 2010 00:18:43 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

Actually, what would be a better interface?

I wonder why it is not like this:

Because I think the "forced" and "opportunistic" suspend "modes" are mutually exclusive in practice and the interface as proposed reflects that quite well.

Quoted 17 lines
Quoted 11 lines

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

Quoted 8 lines
Quoted 1 line

There you have it. One file, one purpose.

That's getting messy IMHO.

In addition to that you get a nice race when the user writes "mem" to /sys/power/state and opportunistic suspend happens at the same time. If the latter wins the race, the system will suspend again immediately after being woken up, which probably is not the result you'd like to get.

But I don't think there is a problem with that. If the system is 'awake' (suspend blocked) and you hit it with forced 'mem', the system _has_ to suspend. as that is what forced "mem" means. And if opportunistic won the race you would _expect_ the machine to suspend again after the wakeup (and this time for good).

But perhaps this only makes sense if you can specify different wake-events for opportunistic and forced suspend.

This is probably some kind of bikeshed by now. I'm alright with the status quo. For what it's worth (not much): You can add my Reviewed-By.

Cheers,
Flo

#27 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Rafael J. Wysocki
Quoted 24 lines · On Fri, 21 May 2010 00:18:43 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines

Actually, what would be a better interface?

I wonder why it is not like this:

Because I think the "forced" and "opportunistic" suspend "modes" are mutually exclusive in practice and the interface as proposed reflects that quite well.

Quoted 17 lines
Quoted 11 lines

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

Quoted 8 lines
Quoted 1 line

There you have it. One file, one purpose.

That's getting messy IMHO.

In addition to that you get a nice race when the user writes "mem" to /sys/power/state and opportunistic suspend happens at the same time. If the latter wins the race, the system will suspend again immediately after being woken up, which probably is not the result you'd like to get.

But I don't think there is a problem with that. If the system is 'awake' (suspend blocked) and you hit it with forced 'mem', the system _has_ to suspend. as that is what forced "mem" means. And if opportunistic won the race you would _expect_ the machine to suspend again after the wakeup (and this time for good).

But perhaps this only makes sense if you can specify different wake-events for opportunistic and forced suspend.

This is probably some kind of bikeshed by now. I'm alright with the status quo. For what it's worth (not much): You can add my Reviewed-By.

Cheers,
Flo

#28 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Rafael J. Wysocki

Hi!

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Actually, what would be a better interface?

I wonder why it is not like this:

Because I think the "forced" and "opportunistic" suspend "modes" are mutually exclusive in practice and the interface as proposed reflects that quite well.

Why should they be? Forced disk while opportunistic mem is active makes a lot of sense. If code can't support it now, just return -EINVAL, but please don't cripple the interface just because of that.

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

Quoted 7 lines
Quoted 1 line

There you have it. One file, one purpose.

That's getting messy IMHO.

In addition to that you get a nice race when the user writes "mem" to /sys/power/state and opportunistic suspend happens at the same time.

It should not opportunistically suspend when it has work to do (like entering forced suspend).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#29 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Rafael J. Wysocki

Hi!

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

I still don't like the interface.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Actually, what would be a better interface?

I wonder why it is not like this:

Because I think the "forced" and "opportunistic" suspend "modes" are mutually exclusive in practice and the interface as proposed reflects that quite well.

Why should they be? Forced disk while opportunistic mem is active makes a lot of sense. If code can't support it now, just return -EINVAL, but please don't cripple the interface just because of that.

Quoted 17 lines
Quoted 17 lines
Quoted 11 lines

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

Quoted 7 lines
Quoted 1 line

There you have it. One file, one purpose.

That's getting messy IMHO.

In addition to that you get a nice race when the user writes "mem" to /sys/power/state and opportunistic suspend happens at the same time.

It should not opportunistically suspend when it has work to do (like entering forced suspend).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#30 lore raw

Re: [PATCH 1/8] PM: Add suspend block api.

In reply to Florian Mickler
Quoted 15 lines · Florian Mickler
Quoted 12 lines · On Thu, 20 May 2010 11:11:11 +0200 Florian Mickler <[email protected]> wrote:
Quoted 9 lines · On Tue, 18 May 2010 15:11:11 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · Arve Hj??nnev??g

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter

Yeah, one file selects behavior of another file, and to read available states for opportunistic, you have to write to file first.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

I still don't like the interface.

Actually, what would be a better interface?

I wonder why it is not like this:

Because I think the "forced" and "opportunistic" suspend "modes" are mutually exclusive in practice and the interface as proposed reflects that quite well.

Quoted 12 lines
Quoted 11 lines

/sys/power/state
no change, works with and without opportunistic suspend the same. Ignores suspend blockers. Really no change. (From user perspective)

/sys/power/opportunistic
On / Off
While Off the opportunistic suspend is off.
While On, the opportunistic suspend is on and if there are no suspend blockers the system goes to suspend.

Quoted 6 lines

I forgot, of course there needs to be another knob to implement the "on" behaviour in the opportunistic mode

/sys/power/block_opportunistic_suspend

There you have it. One file, one purpose.

That's getting messy IMHO.

In addition to that you get a nice race when the user writes "mem" to /sys/power/state and opportunistic suspend happens at the same time. If the latter wins the race, the system will suspend again immediately after being woken up, which probably is not the result you'd like to get.

Thanks,
Rafael

#31 lore raw
In reply to Arve Hjønnevåg
Quoted 11 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 has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

Rafael

#32 lore raw

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

How about:

PM: Add opportunistic suspend support.

Adds a suspend block api that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Opportunistic suspend is most useful on systems that cannot enter their lowest power state from idle, but it is also useful on systems that enter the same power state from idle and suspend. Periodic timers can cause a significant power drain on these systems, and suspend will stop most of this. Opportunistic suspend can also reduce the harm caused by apps that never go idle.

Quoted 4 lines

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

How about:

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block auto suspend. Opening this device creates a suspend_blocker. ioctls are provided to name this suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.

For example, when select or poll indicates that input event are available, this interface can be used to block suspend before reading those event. This allows the input driver to release its suspend blocker as soon as the event queue is empty.

Signature · 1 line
Arve Hjønnevåg
#33 lore raw
In reply to Rafael J. Wysocki

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

How about:

PM: Add opportunistic suspend support.

Adds a suspend block api that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Opportunistic suspend is most useful on systems that cannot enter their lowest power state from idle, but it is also useful on systems that enter the same power state from idle and suspend. Periodic timers can cause a significant power drain on these systems, and suspend will stop most of this. Opportunistic suspend can also reduce the harm caused by apps that never go idle.

Quoted 4 lines

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

How about:

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block auto suspend. Opening this device creates a suspend_blocker. ioctls are provided to name this suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.

For example, when select or poll indicates that input event are available, this interface can be used to block suspend before reading those event. This allows the input driver to release its suspend blocker as soon as the event queue is empty.

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

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

Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 5 lines

How about:

PM: Add opportunistic suspend support.

Adds a suspend block api

In the future I think it'd be ideal if you were to always use "suspend blocker" (rather than "suspend block").

This work has nothing to do with the block layer yet by the subject I thought it somehow did.

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

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

Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 5 lines

How about:

PM: Add opportunistic suspend support.

Adds a suspend block api

In the future I think it'd be ideal if you were to always use "suspend blocker" (rather than "suspend block").

This work has nothing to do with the block layer yet by the subject I thought it somehow did.

#36 lore raw
In reply to Arve Hjønnevåg
Quoted 23 lines · Arve Hjønnevåg

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

Quoted 22 lines

Adds a suspend block api that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Opportunistic suspend is most useful on systems that cannot enter their lowest power state from idle, but it is also useful on systems that enter the same power state from idle and suspend. Periodic timers can cause a significant power drain on these systems, and suspend will stop most of this. Opportunistic suspend can also reduce the harm caused by apps that never go idle.

Quoted 4 lines

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

Quoted 6 lines

How about:

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block auto suspend.

"automatic suspend" would be better IMO.

Quoted 1 line

Opening this device creates a suspend_blocker.

"suspend blocker that can be used by the opener to prevent automatic suspend from occuring. 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."

Quoted 7 lines

ioctls are provided to name this suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.

For example, when select or poll indicates that input event are available, this interface can be used to block suspend before reading those event. This allows the input driver to release its suspend blocker as soon as the event queue is empty.

I think you should explain in more detail how suspend blockers used by user space make that possible.

Rafael

#37 lore raw
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Arve Hjønnevåg

How about:

Quoted 8 lines
Quoted 1 line

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Yes, this will be helpful.

Quoted 4 lines

Next, "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 useful work, called opportunistic suspend".

Hopefully, a definition of "useful" will be given here, including by what standards on-going work is determined not to be useful.

Kevin

#38 lore raw
In reply to Rafael J. Wysocki
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Arve Hjønnevåg

How about:

Quoted 8 lines
Quoted 1 line

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Yes, this will be helpful.

Quoted 4 lines

Next, "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 useful work, called opportunistic suspend".

Hopefully, a definition of "useful" will be given here, including by what standards on-going work is determined not to be useful.

Kevin

#39 lore raw
In reply to Rafael J. Wysocki

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, 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 useful work is not being done). 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.

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

Quoted 41 lines
Quoted 22 lines

Adds a suspend block api that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Opportunistic suspend is most useful on systems that cannot enter their lowest power state from idle, but it is also useful on systems that enter the same power state from idle and suspend. Periodic timers can cause a significant power drain on these systems, and suspend will stop most of this. Opportunistic suspend can also reduce the harm caused by apps that never go idle.

Quoted 4 lines

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

Quoted 6 lines

How about:

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block auto suspend.

"automatic suspend" would be better IMO.

Quoted 1 line

Opening this device creates a suspend_blocker.

"suspend blocker that can be used by the opener to prevent automatic suspend from occuring.  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."

Quoted 3 lines

ioctls are provided to name this suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.

Quoted 8 lines
Quoted 4 lines

For example, when select or poll indicates that input event are available, this interface can be used to block suspend before reading those event. This allows the input driver to release its suspend blocker as soon as the event queue is empty.

I think you should explain in more detail how suspend blockers used by user space make that possible.

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block automatic suspend.

Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring. There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name. Closing the device special file causes the suspend blocker to be destroyed.

For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.

By careful use of suspend blockers in drivers and user space system code, one can arrange for the system to stay awake for extremely short periods of time in reaction to events, rapidly returning to a fully suspended state.

Signature · 1 line
Arve Hjønnevåg
#40 lore raw
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Kevin

#41 lore raw
In reply to Arve Hjønnevåg
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Kevin

#42 lore raw
In reply to Arve Hjønnevåg
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Kevin

#43 lore raw
Quoted 12 lines · Kevin Hilman
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 3 lines

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

That one is really easy.: because some (the majority of?) architectures don't even implement it.

Quoted 12 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

Quoted 3 lines

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Probably "useful" is not the right word here. I guess it's more like "work that can be deferred without visible impact on functionality".

Rafael

#44 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Kevin Hilman
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 6 lines
Quoted 3 lines

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

That one is really easy.: because some (the majority of?) architectures don't even implement it.

OK, then this problem will still in traditional suspend even after this series, so calling it out as a the problem to be solved but not fixing it doesn't seem right.

This problem needs an independent fix, namely implementing check_wakeup_irqs().

That being said, what exactly is there for architectures to implement for check_wakeup_irqs()? IIUC, this all handled by genirq as long as deferred disable (now the default) is used?

I suspect the platforms that Android currently cares about already have this functionality. At least OMAP does already.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

Quoted 6 lines
Quoted 3 lines

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Probably "useful" is not the right word here. I guess it's more like "work that can be deferred without visible impact on functionality".

OK, then a definition of "visible impact on functionality" should be provided and the critera for determining that.

I know this sounds like splitting hairs, but what I'm getting at is that this series implements a brand new method for making decisions about when the system is idle. That fact should be clearly stated and the criteria for making this decision should be clearly described.

Kevin

#45 lore raw
In reply to Rafael J. Wysocki
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Kevin Hilman
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 6 lines
Quoted 3 lines

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

That one is really easy.: because some (the majority of?) architectures don't even implement it.

OK, then this problem will still in traditional suspend even after this series, so calling it out as a the problem to be solved but not fixing it doesn't seem right.

This problem needs an independent fix, namely implementing check_wakeup_irqs().

That being said, what exactly is there for architectures to implement for check_wakeup_irqs()? IIUC, this all handled by genirq as long as deferred disable (now the default) is used?

I suspect the platforms that Android currently cares about already have this functionality. At least OMAP does already.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

Quoted 6 lines
Quoted 3 lines

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Probably "useful" is not the right word here. I guess it's more like "work that can be deferred without visible impact on functionality".

OK, then a definition of "visible impact on functionality" should be provided and the critera for determining that.

I know this sounds like splitting hairs, but what I'm getting at is that this series implements a brand new method for making decisions about when the system is idle. That fact should be clearly stated and the criteria for making this decision should be clearly described.

Kevin

#46 lore raw
Quoted 22 lines · Kevin Hilman
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Kevin Hilman
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 6 lines
Quoted 3 lines

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

That one is really easy.: because some (the majority of?) architectures don't even implement it.

Quoted 6 lines

OK, then this problem will still in traditional suspend even after this series, so calling it out as a the problem to be solved but not fixing it doesn't seem right.

This problem needs an independent fix, namely implementing check_wakeup_irqs().

No, it is not. There's nothing like wake-up interrupts on (ACPI-based) x86 PCs.

Quoted 3 lines

That being said, what exactly is there for architectures to implement for check_wakeup_irqs()? IIUC, this all handled by genirq as long as deferred disable (now the default) is used?

No. Wakeup IRQs cause the system to wake up from sleep states. On a PC the only interrupts that can do that are PCIe root port PME interrupts, but they are not really "device" interrupts (ie. they come from a source that is different from a device signaling wakeup).

Quoted 2 lines

I suspect the platforms that Android currently cares about already have this functionality. At least OMAP does already.

ISTR there is an x86 Android port, so not all of them. Although that really doesn't matter.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Quoted 7 lines
Quoted 2 lines

Probably "useful" is not the right word here. I guess it's more like "work that can be deferred without visible impact on functionality".

OK, then a definition of "visible impact on functionality" should be provided and the critera for determining that.

I know this sounds like splitting hairs,

Yes, it does.

Quoted 2 lines

but what I'm getting at is that this series implements a brand new method for making decisions about when the system is idle.

Since we are splitting hairs, I'd be rather cautious about the word "idle". It would be safer to say "when the system is not doing anything the user really cares about at the moment and therefore it may be suspended".

That actually is the whole point of the patch series.

Quoted 2 lines

That fact should be clearly stated and the criteria for making this decision should be clearly described.

Well, suspend blockers are the tool to define the criteria.

Thanks,
Rafael

#47 lore raw
In reply to Kevin Hilman
Quoted 22 lines · Kevin Hilman
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Kevin Hilman
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 6 lines
Quoted 3 lines

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

That one is really easy.: because some (the majority of?) architectures don't even implement it.

Quoted 6 lines

OK, then this problem will still in traditional suspend even after this series, so calling it out as a the problem to be solved but not fixing it doesn't seem right.

This problem needs an independent fix, namely implementing check_wakeup_irqs().

No, it is not. There's nothing like wake-up interrupts on (ACPI-based) x86 PCs.

Quoted 3 lines

That being said, what exactly is there for architectures to implement for check_wakeup_irqs()? IIUC, this all handled by genirq as long as deferred disable (now the default) is used?

No. Wakeup IRQs cause the system to wake up from sleep states. On a PC the only interrupts that can do that are PCIe root port PME interrupts, but they are not really "device" interrupts (ie. they come from a source that is different from a device signaling wakeup).

Quoted 2 lines

I suspect the platforms that Android currently cares about already have this functionality. At least OMAP does already.

ISTR there is an x86 Android port, so not all of them. Although that really doesn't matter.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Quoted 7 lines
Quoted 2 lines

Probably "useful" is not the right word here. I guess it's more like "work that can be deferred without visible impact on functionality".

OK, then a definition of "visible impact on functionality" should be provided and the critera for determining that.

I know this sounds like splitting hairs,

Yes, it does.

Quoted 2 lines

but what I'm getting at is that this series implements a brand new method for making decisions about when the system is idle.

Since we are splitting hairs, I'd be rather cautious about the word "idle". It would be safer to say "when the system is not doing anything the user really cares about at the moment and therefore it may be suspended".

That actually is the whole point of the patch series.

Quoted 2 lines

That fact should be clearly stated and the criteria for making this decision should be clearly described.

Well, suspend blockers are the tool to define the criteria.

Thanks,
Rafael

#48 lore raw
In reply to Kevin Hilman
Quoted 12 lines · Kevin Hilman
Quoted 9 lines · Arve Hjønnevåg

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, because low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 3 lines

I think the problems with wakeups in the current suspend path need to be described in more detail. In particular, why check_wakeup_irqs() is not enough etc.

That one is really easy.: because some (the majority of?) architectures don't even implement it.

Quoted 12 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

Quoted 3 lines

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Probably "useful" is not the right word here. I guess it's more like "work that can be deferred without visible impact on functionality".

Rafael

#49 lore raw
In reply to Kevin Hilman

2010/5/18 Kevin Hilman <[email protected]>:

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

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, because low power states can only safely be entered from idle.  Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 4 lines

I think the problems with wakeups in the current suspend path need to be described in more detail.  In particular, why check_wakeup_irqs() is not enough etc.

check_wakeup_irqs only handles interrupts that occurred after the interrupt was masked during suspend. If the interrupt occurred before it was masked, it will not be pending when check_wakeup_irqs is called.

Quoted 18 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Kevin

Signature · 1 line
Arve Hjønnevåg
#50 lore raw
In reply to Kevin Hilman

2010/5/18 Kevin Hilman <[email protected]>:

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

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, because low power states can only safely be entered from idle.  Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 4 lines

I think the problems with wakeups in the current suspend path need to be described in more detail.  In particular, why check_wakeup_irqs() is not enough etc.

check_wakeup_irqs only handles interrupts that occurred after the interrupt was masked during suspend. If the interrupt occurred before it was masked, it will not be pending when check_wakeup_irqs is called.

Quoted 18 lines
Quoted 11 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

A definition of "useful work" here would provide clarity and would also help clarify by what criteria other on-going work is determined to be not useful.

Kevin

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

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

Quoted 6 lines

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, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings. I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible. Is that correct?

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here. I'd say "not suitable" instead and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

Quoted 8 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism

Just "introduce" without "we" works too.

Quoted 3 lines

by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

I think we can address the Kevin's comment about "useful" and say "whenever it's only doing work that can be done later without noticeable effect on functionality".

Quoted 3 lines

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 useful work is not being done). Add an

Perhaps remove the part in parens entirely.

Quoted 9 lines

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.

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

...

Quoted 19 lines

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block automatic suspend.

Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring. There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name. Closing the device special file causes the suspend blocker to be destroyed.

For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.

Quoted 4 lines

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.

That's fine by me.

Thanks,
Rafael

#52 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 47 lines · Arve Hjønnevåg
Quoted 46 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 44 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

Quoted 9 lines
Quoted 6 lines

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, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

Quoted 6 lines

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings.  I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible.  Is that correct?

Yes, is this not what the next paragraph explains?

Quoted 5 lines
Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here.  I'd say "not suitable" instead

I don't think it is too strong, but I can change it.

Quoted 3 lines

and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

When I say wakeup events I mean events that do both. Is there another term for this, or should I just add: "since wakeup events (events that wake the CPU from idle and the system from suspend)..."

Quoted 67 lines
Quoted 9 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism

Just "introduce" without "we" works too.

Quoted 3 lines

by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

I think we can address the Kevin's comment about "useful" and say "whenever it's only doing work that can be done later without noticeable effect on functionality".

Quoted 3 lines

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 useful work is not being done). Add an

Perhaps remove the part in parens entirely.

Quoted 9 lines

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.

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

...

Quoted 19 lines

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block automatic suspend.

Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring.  There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name.  Closing the device special file causes the suspend blocker to be destroyed.

For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.

Quoted 4 lines

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.

That's fine by me.

Thanks,
Rafael

Signature · 1 line
Arve Hjønnevåg
#53 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 47 lines · Arve Hjønnevåg
Quoted 46 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 44 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

Quoted 9 lines
Quoted 6 lines

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, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

Quoted 6 lines

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings.  I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible.  Is that correct?

Yes, is this not what the next paragraph explains?

Quoted 5 lines
Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here.  I'd say "not suitable" instead

I don't think it is too strong, but I can change it.

Quoted 3 lines

and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

When I say wakeup events I mean events that do both. Is there another term for this, or should I just add: "since wakeup events (events that wake the CPU from idle and the system from suspend)..."

Quoted 67 lines
Quoted 9 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism

Just "introduce" without "we" works too.

Quoted 3 lines

by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

I think we can address the Kevin's comment about "useful" and say "whenever it's only doing work that can be done later without noticeable effect on functionality".

Quoted 3 lines

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 useful work is not being done). Add an

Perhaps remove the part in parens entirely.

Quoted 9 lines

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.

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

...

Quoted 19 lines

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block automatic suspend.

Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring.  There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name.  Closing the device special file causes the suspend blocker to be destroyed.

For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.

Quoted 4 lines

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.

That's fine by me.

Thanks,
Rafael

Signature · 1 line
Arve Hjønnevåg
#54 lore raw
Quoted 50 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

Quoted 7 lines
Quoted 6 lines

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings. I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible. Is that correct?

Yes, is this not what the next paragraph explains?

Well, it doesn't explain that. It explains why idle + runtime PM is generally insufficient and is using that as an argument (at least in my view).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here. I'd say "not suitable" instead

I don't think it is too strong, but I can change it.

Quoted 7 lines
Quoted 3 lines

and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

When I say wakeup events I mean events that do both. Is there another term for this, or should I just add: "since wakeup events (events that wake the CPU from idle and the system from suspend)..."

Yes, that would clarify things IMO.

Thanks,
Rafael

#55 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 56 lines · Arve Hjønnevåg
Quoted 55 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 54 lines · Arve Hjønnevåg
Quoted 52 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

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, because low power states can only safely be entered from idle.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 38 lines
Quoted 8 lines
Quoted 7 lines

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings.  I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible.  Is that correct?

Yes, is this not what the next paragraph explains?

Well, it doesn't explain that.  It explains why idle + runtime PM is generally insufficient and is using that as an argument (at least in my view).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here.  I'd say "not suitable" instead

I don't think it is too strong, but I can change it.

Quoted 7 lines
Quoted 3 lines

and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

When I say wakeup events I mean events that do both. Is there another term for this, or should I just add: "since wakeup events (events that wake the CPU from idle and the system from suspend)..."

Yes, that would clarify things IMO.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#56 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 56 lines · Arve Hjønnevåg
Quoted 55 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 54 lines · Arve Hjønnevåg
Quoted 52 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

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, because low power states can only safely be entered from idle.

Quoted 8 lines
Quoted 3 lines
Quoted 2 lines

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 38 lines
Quoted 8 lines
Quoted 7 lines

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings.  I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible.  Is that correct?

Yes, is this not what the next paragraph explains?

Well, it doesn't explain that.  It explains why idle + runtime PM is generally insufficient and is using that as an argument (at least in my view).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here.  I'd say "not suitable" instead

I don't think it is too strong, but I can change it.

Quoted 7 lines
Quoted 3 lines

and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

When I say wakeup events I mean events that do both. Is there another term for this, or should I just add: "since wakeup events (events that wake the CPU from idle and the system from suspend)..."

Yes, that would clarify things IMO.

Thanks,
Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Signature · 1 line
Arve Hjønnevåg
#57 lore raw
Quoted 61 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 58 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 47 lines · Arve Hjønnevåg
Quoted 46 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 44 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

Quoted 9 lines
Quoted 6 lines

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, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

Quoted 8 lines
Quoted 4 lines

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

Quoted 10 lines
Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

Quoted 2 lines

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Sorry, I'm confused now. Isn't that why you do that on Android?

AFACS, your hardware is capable of doing that, isn't it?

Rafael

#58 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

Quoted 5 lines
Quoted 2 lines

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Sorry, I'm confused now.  Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 2 lines

AFACS, your hardware is capable of doing that, isn't it?

The current hardware, yes, the hardware we started with, no.

Signature · 1 line
Arve Hjønnevåg
#59 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle. Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

Quoted 5 lines
Quoted 2 lines

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Sorry, I'm confused now.  Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 2 lines

AFACS, your hardware is capable of doing that, isn't it?

The current hardware, yes, the hardware we started with, no.

Signature · 1 line
Arve Hjønnevåg
#60 lore raw
Quoted 67 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system. Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost. This additional mechanism is suspend blockers.

Is this correct?

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now. Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Rafael

#61 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 91 lines · Arve Hjønnevåg
Quoted 67 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 8 lines

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Memory should also be in a low power state, but yes, everything should be in the lowest power possible state for as long as possible.

Quoted 11 lines

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system.  Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

Quoted 5 lines

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost.  This additional mechanism is suspend blockers.

Is this correct?

Yes.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now.  Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 7 lines

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Does this work for you:

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, because the system must always respond to certain events. Suspend, in its current form, cannot be used on these platforms, 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 wake up the system 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 have 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 useful work, 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.

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

Signature · 1 line
Arve Hjønnevåg
#62 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 91 lines · Arve Hjønnevåg
Quoted 67 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8].  I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 8 lines

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Memory should also be in a low power state, but yes, everything should be in the lowest power possible state for as long as possible.

Quoted 11 lines

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system.  Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

Quoted 5 lines

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost.  This additional mechanism is suspend blockers.

Is this correct?

Yes.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now.  Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 7 lines

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Does this work for you:

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, because the system must always respond to certain events. Suspend, in its current form, cannot be used on these platforms, 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 wake up the system 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 have 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 useful work, 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.

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

Signature · 1 line
Arve Hjønnevåg
#63 lore raw
Quoted 152 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 91 lines · Arve Hjønnevåg
Quoted 67 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same
functionality as the android wakelock api. This version has some
changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added
for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an
optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though
there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 8 lines

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Memory should also be in a low power state, but yes, everything should be in the lowest power possible state for as long as possible.

Quoted 11 lines

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system. Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

Quoted 5 lines

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost. This additional mechanism is suspend blockers.

Is this correct?

Yes.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now. Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 7 lines

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Quoted 1 line

Does this work for you:

Well, almost.

Quoted 5 lines

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,

I'd finish the first sentence here.

Quoted 3 lines

because the system must always respond to certain events. Suspend, in its current form, cannot be used on these platforms,

This doesn't seem to be correct. Surely you can suspend these systems, but you can't address the problem at hand using suspend as is.

I'd say (in the second sentence) "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 ..."

Quoted 3 lines

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 wake up

"... wakes up ..." I guess.

Quoted 13 lines

the system 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 have to be suspended as a whole to achieve the maximum energy savings.

Quoted 5 lines

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 useful work, called opportunistic suspend.

I'd say "... whenever it's not doing work that's immediately useful to the user, called ..." or something like this.

The rest is fine by me.

Rafael

#64 lore raw

2010/5/19 Rafael J. Wysocki <[email protected]>:

Quoted 209 lines · Arve Hjønnevåg
Quoted 152 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 91 lines · Arve Hjønnevåg
Quoted 67 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 21 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 has some
changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added
  for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an
  optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though
there were a few cosmetic changes.

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for
patch [1/8].  I think it should explain (in a few words) what the purpose of
the feature is and what problems it solves that generally a combination of
runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you
think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 8 lines

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Memory should also be in a low power state, but yes, everything should be in the lowest power possible state for as long as possible.

Quoted 11 lines

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system.  Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

Quoted 5 lines

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost.  This additional mechanism is suspend blockers.

Is this correct?

Yes.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now.  Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 7 lines

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Quoted 1 line

Does this work for you:

Well, almost.

Quoted 5 lines

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,

I'd finish the first sentence here.

Quoted 3 lines

because the system must always respond to certain events. Suspend, in its current form, cannot be used on these platforms,

This doesn't seem to be correct.  Surely you can suspend these systems, but you can't address the problem at hand using suspend as is.

I'd say (in the second sentence) "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 ..."

Quoted 3 lines

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 wake up

"... wakes up ..." I guess.

Quoted 13 lines

the system 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 have to be suspended as a whole to achieve the maximum energy savings.

Quoted 5 lines

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 useful work, called opportunistic suspend.

Quoted 5 lines

I'd say "... whenever it's not doing work that's immediately useful to the user, called  ..." or something like this.

The rest is fine by me.

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.

Signature · 1 line
Arve Hjønnevåg
#65 lore raw
In reply to Rafael J. Wysocki

2010/5/19 Rafael J. Wysocki <[email protected]>:

Quoted 209 lines · Arve Hjønnevåg
Quoted 152 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 91 lines · Arve Hjønnevåg
Quoted 67 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 21 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 has some
changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added
  for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an
  optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though
there were a few cosmetic changes.

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for
patch [1/8].  I think it should explain (in a few words) what the purpose of
the feature is and what problems it solves that generally a combination of
runtime PM and cpuidle is not suitable for in your opinion.  IOW, why you
think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation.  Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done).  Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 8 lines

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Memory should also be in a low power state, but yes, everything should be in the lowest power possible state for as long as possible.

Quoted 11 lines

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system.  Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

Quoted 5 lines

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost.  This additional mechanism is suspend blockers.

Is this correct?

Yes.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle.  This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling.  It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now.  Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 7 lines

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Quoted 1 line

Does this work for you:

Well, almost.

Quoted 5 lines

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,

I'd finish the first sentence here.

Quoted 3 lines

because the system must always respond to certain events. Suspend, in its current form, cannot be used on these platforms,

This doesn't seem to be correct.  Surely you can suspend these systems, but you can't address the problem at hand using suspend as is.

I'd say (in the second sentence) "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 ..."

Quoted 3 lines

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 wake up

"... wakes up ..." I guess.

Quoted 13 lines

the system 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 have to be suspended as a whole to achieve the maximum energy savings.

Quoted 5 lines

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 useful work, called opportunistic suspend.

Quoted 5 lines

I'd say "... whenever it's not doing work that's immediately useful to the user, called  ..." or something like this.

The rest is fine by me.

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.

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

On Wednesday 19 May 2010, Arve Hjønnevåg wrote:
...

Quoted 45 lines

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.

Quoted 5 lines

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.

That looks good to me.

Thanks,
Rafael

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

On Wednesday 19 May 2010, Arve Hjønnevåg wrote:
...

Quoted 45 lines

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.

Quoted 5 lines

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.

That looks good to me.

Thanks,
Rafael

#68 lore raw
In reply to Arve Hjønnevåg
Quoted 152 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 91 lines · Arve Hjønnevåg
Quoted 67 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same
functionality as the android wakelock api. This version has some
changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added
for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an
optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though
there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Quoted 8 lines

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Memory should also be in a low power state, but yes, everything should be in the lowest power possible state for as long as possible.

Quoted 11 lines

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system. Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

Quoted 5 lines

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost. This additional mechanism is suspend blockers.

Is this correct?

Yes.

Quoted 21 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now. Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Quoted 7 lines

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Quoted 1 line

Does this work for you:

Well, almost.

Quoted 5 lines

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,

I'd finish the first sentence here.

Quoted 3 lines

because the system must always respond to certain events. Suspend, in its current form, cannot be used on these platforms,

This doesn't seem to be correct. Surely you can suspend these systems, but you can't address the problem at hand using suspend as is.

I'd say (in the second sentence) "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 ..."

Quoted 3 lines

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 wake up

"... wakes up ..." I guess.

Quoted 13 lines

the system 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 have to be suspended as a whole to achieve the maximum energy savings.

Quoted 5 lines

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 useful work, called opportunistic suspend.

I'd say "... whenever it's not doing work that's immediately useful to the user, called ..." or something like this.

The rest is fine by me.

Rafael

#69 lore raw
In reply to Arve Hjønnevåg
Quoted 67 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 66 lines · Arve Hjønnevåg
Quoted 65 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 64 lines · Arve Hjønnevåg
Quoted 50 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

OK. Is this clearer:

Not really.

Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because some wakeup events must work at all times which means that low power states can only safely be entered from idle.

It's not clear what you mean by "some wakeup events must work at all times" and what "safely" means.

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

Well, I _guess_ I know what you're trying to say, but I'm not sure if that's the core of the problem the patchset is supposed to address.

The problem, as I see it, is really two-fold.

First, to save as much energy as reasonably possible you need to put everything except for memory (ie. I/O devices and CPUs) into low-power states and let that stay in these low-power states for as long as reasonably possible, right?

Second, you need the system to _always_ respond to some _specific_ events regardless of its current state, correct?

Now, at present, we can put I/O devices and the CPU into low-power states at the same time in two ways: (1) by using runtime PM and cpuidle and (2) by suspending the system. Unfortunately, none of these approaches is ideal, because (1) is vulnerable to periodic timers and polling apps (and CPU-bound apps) and (2) doesn't guarantee that all events you care about will be responded to.

The proposed solution is to use suspend with an additional mechanism that will prevent the events that have to be responded to from being lost. This additional mechanism is suspend blockers.

Is this correct?

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Quoted 6 lines
Quoted 2 lines

Sorry, I'm confused now. Isn't that why you do that on Android?

Yes, but it is not the only reason to use opportunistic support. It is way more important to have opportunistic suspend support if the hardware can enter lower power states from suspend than idle.

Sure, but you can add something like "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 have to be suspended as a whole to achieve the maximum energy savings".

Rafael

#70 lore raw
In reply to Arve Hjønnevåg
Quoted 61 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 60 lines · Arve Hjønnevåg
Quoted 58 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 47 lines · Arve Hjønnevåg
Quoted 46 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 44 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

Quoted 9 lines
Quoted 6 lines

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, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

Quoted 8 lines
Quoted 4 lines

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

I don't think that makes my statement false. If you can only safely enter low power states from idle, but some low power states cannot be entered from idle, then it follows that you cannot safely enter those low power states.

Define "safely", then.

Quoted 10 lines
Quoted 9 lines

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

Quoted 2 lines

This only explain why we still want to use suspend on systems that can enter the same power states from idle and suspend.

Sorry, I'm confused now. Isn't that why you do that on Android?

AFACS, your hardware is capable of doing that, isn't it?

Rafael

#71 lore raw
In reply to Arve Hjønnevåg
Quoted 50 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 49 lines · Arve Hjønnevåg
Quoted 48 lines

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

PM: Opportunistic suspend support.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I think either.

The statement is not true for system low-power states (or sleep states), because generally (ie. on many platforms) they aren't entered from idle. Suspend is for entering them.

So, there is a difference and the explanation can go like this: "... to achieve maximum energy savings one has to put all I/O devices and the CPU into low-power states, but the CPU can only be put into a low-power state from idle. This, in turn, means that the CPU leaves the low-power state on interrupts triggered by periodic timers and user space processes that use polling. It turns out, however, that many of these events causing the CPU to leave the low-power state aren't essential for the desired system functionality and from the power management point of view it would be better if they didn't occur".

Quoted 7 lines
Quoted 6 lines

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings. I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible. Is that correct?

Yes, is this not what the next paragraph explains?

Well, it doesn't explain that. It explains why idle + runtime PM is generally insufficient and is using that as an argument (at least in my view).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here. I'd say "not suitable" instead

I don't think it is too strong, but I can change it.

Quoted 7 lines
Quoted 3 lines

and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

When I say wakeup events I mean events that do both. Is there another term for this, or should I just add: "since wakeup events (events that wake the CPU from idle and the system from suspend)..."

Yes, that would clarify things IMO.

Thanks,
Rafael

#72 lore raw
In reply to Arve Hjønnevåg
Quoted 46 lines · Arve Hjønnevåg

2010/5/17 Rafael J. Wysocki <[email protected]>:

Quoted 35 lines · Arve Hjønnevåg
Quoted 23 lines

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Quoted 9 lines

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

Quoted 6 lines

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, because low power states can only safely be entered from idle.

Do you mean CPU low-power states or system low-power states here?

I'd add more details here, because it may not be completely clear to the (interested) reader why entering these states only from idle affects the possibility to achieve maximum energy savings. I _guess_ you mean that using idle is not sufficient, because there are so many wakeups on the systems in question that more savings are still possible. Is that correct?

Quoted 3 lines

Suspend, in its current form, cannot be used, since wakeup events that occur right after initiating suspend will not be processed until another possibly unrelated event wake up the system again.

I think the word "cannot" is too strong here. I'd say "not suitable" instead and I'd say what kind of wakeup events I meant more precisely (there are events that wake up a CPU from idle and events that wake up the system from suspend).

Quoted 8 lines

On some systems idle combined with runtime PM can enter the same power state as suspend, but periodic wakeups increase the average power consumption. Suspending the system also reduces the harm caused by apps that never go idle. On other systems suspend can enter a much lower power state than idle.

To allow Android and similar platforms to save more energy than they currently can save using the mainline kernel, we introduce a mechanism

Just "introduce" without "we" works too.

Quoted 3 lines

by which the system is automatically suspended (i.e. put into a system-wide sleep state) whenever it's not doing useful work, called opportunistic suspend.

I think we can address the Kevin's comment about "useful" and say "whenever it's only doing work that can be done later without noticeable effect on functionality".

Quoted 3 lines

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 useful work is not being done). Add an

Perhaps remove the part in parens entirely.

Quoted 9 lines

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.

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

...

Quoted 19 lines

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block automatic suspend.

Opening this device creates a suspend blocker that can be used by the opener to prevent automatic suspend from occurring. There are ioctls provided for blocking and unblocking suspend and for giving the suspend blocker a meaningful name. Closing the device special file causes the suspend blocker to be destroyed.

For example, when select or poll indicates that input event are available, this interface can be used by user space to block suspend before it reads those events. This allows the input driver to release its suspend blocker as soon as the event queue is empty. If user space could not use a suspend blocker here the input driver would need to delay the release of its suspend blocker until it knows (or assumes) that user space has finished processing the events.

Quoted 4 lines

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.

That's fine by me.

Thanks,
Rafael

#73 lore raw
In reply to Arve Hjønnevåg
Quoted 23 lines · Arve Hjønnevåg

2010/5/14 Rafael J. Wysocki <[email protected]>:

Quoted 13 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Quoted 8 lines

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

Quoted 3 lines

How about:

PM: Add opportunistic suspend support.

"PM: Opportunistic suspend support" would be sufficient IMO.

Now, I'd start with the motivation. Like "Power management features present in the current mainline kernel are insufficient to get maximum possible energy savings on some platforms, such as Android, because ..." (here go explanations why this is the case in your opinion).

Next, "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 useful work, 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 useful work is not being done). Add an API that ..."

Quoted 22 lines

Adds a suspend block api that drivers can use to block opportunistic suspend. This is needed to avoid losing wakeup events that occur right after suspend is initiated.

Adds /sys/power/policy that selects the behaviour of /sys/power/state. After setting the policy to opportunistic, writes to /sys/power/state become non-blocking requests that specify which suspend state to enter when no suspend blockers are active. A special state, "on", stops the process by activating the "main" suspend blocker.

Opportunistic suspend is most useful on systems that cannot enter their lowest power state from idle, but it is also useful on systems that enter the same power state from idle and suspend. Periodic timers can cause a significant power drain on these systems, and suspend will stop most of this. Opportunistic suspend can also reduce the harm caused by apps that never go idle.

Quoted 4 lines

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

Quoted 6 lines

How about:

PM: suspend_block: Add driver to access suspend blockers from user-space

Add a misc device, "suspend_blocker", that allows user-space processes to block auto suspend.

"automatic suspend" would be better IMO.

Quoted 1 line

Opening this device creates a suspend_blocker.

"suspend blocker that can be used by the opener to prevent automatic suspend from occuring. 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."

Quoted 7 lines

ioctls are provided to name this suspend_blocker, and to block and unblock suspend. To delete the suspend_blocker, close the device.

For example, when select or poll indicates that input event are available, this interface can be used to block suspend before reading those event. This allows the input driver to release its suspend blocker as soon as the event queue is empty.

I think you should explain in more detail how suspend blockers used by user space make that possible.

Rafael

#74 lore raw
In reply to Arve Hjønnevåg
Quoted 11 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 has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

Thanks for the patches, I think they are in a pretty good shape now.

That said, I'd like the changelogs to be a bit more descriptive, at least for patch [1/8]. I think it should explain (in a few words) what the purpose of the feature is and what problems it solves that generally a combination of runtime PM and cpuidle is not suitable for in your opinion. IOW, why you think we need that feature.

The changelog of patch [2/8] appears to be outdated, that needs to be fixed. Also, it would be nice to explain in the changelog what the interface is needed for (in terms of the problems that it helps to handle).

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

#75 lore raw
In reply to Arve Hjønnevåg
Quoted 11 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 has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

I have one more comment, sorry for that.

Namely, if /sys/power/policy is set to "opportunistic" and "mem" is written into /sys/power/state and there are no suspend blockers present except for the main blocker (and the blockers used only for statistics), the system won't be able to go out of an infinit suspend-resume loop (or at least it seems so from reading the code).

I think we should prevent that from happening somehow.

Thanks,
Rafael

#76 lore raw

2010/5/16 Rafael J. Wysocki <[email protected]>:

Quoted 15 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

I have one more comment, sorry for that.

Quoted 8 lines

Namely, if /sys/power/policy is set to "opportunistic" and "mem" is written into /sys/power/state and there are no suspend blockers present except for the main blocker (and the blockers used only for statistics), the system won't be able to go out of an infinit suspend-resume loop (or at least it seems so from reading the code).

I think we should prevent that from happening somehow.

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Signature · 1 line
Arve Hjønnevåg
#77 lore raw
In reply to Rafael J. Wysocki

2010/5/16 Rafael J. Wysocki <[email protected]>:

Quoted 15 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

I have one more comment, sorry for that.

Quoted 8 lines

Namely, if /sys/power/policy is set to "opportunistic" and "mem" is written into /sys/power/state and there are no suspend blockers present except for the main blocker (and the blockers used only for statistics), the system won't be able to go out of an infinit suspend-resume loop (or at least it seems so from reading the code).

I think we should prevent that from happening somehow.

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Signature · 1 line
Arve Hjønnevåg
#78 lore raw
Quoted 22 lines · Arve Hjønnevåg

2010/5/16 Rafael J. Wysocki <[email protected]>:

Quoted 21 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

I have one more comment, sorry for that.

Namely, if /sys/power/policy is set to "opportunistic" and "mem" is written into /sys/power/state and there are no suspend blockers present except for the main blocker (and the blockers used only for statistics), the system won't be able to go out of an infinit suspend-resume loop (or at least it seems so from reading the code).

Quoted 6 lines
Quoted 2 lines

I think we should prevent that from happening somehow.

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Well, the scenario I have in mind is the following. Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this? I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

Rafael

#79 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following.  Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this?  I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

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

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

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following.  Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this?  I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

Brian

#81 lore raw
Quoted 16 lines · Brian Swetland
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following. Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this? I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

Quoted 7 lines

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

I agree, but I think it's necessary. We shouldn't add interfaces that hurt users if not used with care.

Thanks,
Rafael

#82 lore raw
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Brian Swetland
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following.  Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this?  I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

Quoted 7 lines
Quoted 3 lines

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

I agree, but I think it's necessary.  We shouldn't add interfaces that hurt users if not used with care.

I'm not sure this can be "fixed". The user asked that the system to suspend whenever possible, which is what it is doing. I don't think disabling opportunistic suspend if no suspend blockers have been registered will work. As soon as we register a suspend blocker we are back in the same situation.

Signature · 1 line
Arve Hjønnevåg
#83 lore raw
In reply to Rafael J. Wysocki
Quoted 21 lines · Rafael J. Wysocki
Quoted 20 lines · Brian Swetland
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following.  Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this?  I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

Quoted 7 lines
Quoted 3 lines

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

I agree, but I think it's necessary.  We shouldn't add interfaces that hurt users if not used with care.

I'm not sure this can be "fixed". The user asked that the system to suspend whenever possible, which is what it is doing. I don't think disabling opportunistic suspend if no suspend blockers have been registered will work. As soon as we register a suspend blocker we are back in the same situation.

Signature · 1 line
Arve Hjønnevåg
#84 lore raw
Quoted 26 lines · Arve Hjønnevåg
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Brian Swetland
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following. Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this? I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

Quoted 5 lines
Quoted 3 lines

I agree, but I think it's necessary. We shouldn't add interfaces that hurt users if not used with care.

I'm not sure this can be "fixed".

Yes, it can, but perhaps a workaround would be sufficient (see below).

Quoted 4 lines

The user asked that the system to suspend whenever possible, which is what it is doing. I don't think disabling opportunistic suspend if no suspend blockers have been registered will work. As soon as we register a suspend blocker we are back in the same situation.

Not really, because the new suspend blocker is not added by the _framework_ _itself_.

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

Thanks,
Rafael

#85 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 33 lines · Arve Hjønnevåg
Quoted 26 lines · Rafael J. Wysocki
Quoted 25 lines · Brian Swetland
Quoted 23 lines · Rafael J. Wysocki
Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following.  Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this?  I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

Quoted 5 lines
Quoted 3 lines

I agree, but I think it's necessary.  We shouldn't add interfaces that hurt users if not used with care.

I'm not sure this can be "fixed".

Quoted 9 lines

Yes, it can, but perhaps a workaround would be sufficient (see below).

Quoted 4 lines

The user asked that the system to suspend whenever possible, which is what it is doing. I don't think disabling opportunistic suspend if no suspend blockers have been registered will work. As soon as we register a suspend blocker we are back in the same situation.

Not really, because the new suspend blocker is not added by the _framework_ _itself_.

I'm not sure what you mean by this. If we add a workaround that is disabled when the first suspend blocker is registered, then we cannot add any suspend blockers without disabling the workaround (for instance the power supply framework patch later in this patch set).

Quoted 4 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Signature · 1 line
Arve Hjønnevåg
#86 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 33 lines · Arve Hjønnevåg
Quoted 26 lines · Rafael J. Wysocki
Quoted 25 lines · Brian Swetland
Quoted 23 lines · Rafael J. Wysocki
Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following.  Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this?  I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

Quoted 5 lines
Quoted 3 lines

I agree, but I think it's necessary.  We shouldn't add interfaces that hurt users if not used with care.

I'm not sure this can be "fixed".

Quoted 9 lines

Yes, it can, but perhaps a workaround would be sufficient (see below).

Quoted 4 lines

The user asked that the system to suspend whenever possible, which is what it is doing. I don't think disabling opportunistic suspend if no suspend blockers have been registered will work. As soon as we register a suspend blocker we are back in the same situation.

Not really, because the new suspend blocker is not added by the _framework_ _itself_.

I'm not sure what you mean by this. If we add a workaround that is disabled when the first suspend blocker is registered, then we cannot add any suspend blockers without disabling the workaround (for instance the power supply framework patch later in this patch set).

Quoted 4 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Signature · 1 line
Arve Hjønnevåg
#87 lore raw
Quoted 7 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 6 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

Quoted 7 lines

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

But the user can still manually write to /sys/power/state. :-)

Rafael

#88 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 6 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

Quoted 7 lines

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

I'm not convinced adding a configurable delay here is necessary. Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

Signature · 1 line
Arve Hjønnevåg
#89 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 6 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

Quoted 7 lines

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

I'm not convinced adding a configurable delay here is necessary. Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

Signature · 1 line
Arve Hjønnevåg
#90 lore raw
Quoted 24 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 13 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 5 lines
Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

Yes, but that should allow the user to avoid rebooting the system if he does the "wrong thing".

Quoted 1 line

I'm not convinced adding a configurable delay here is necessary.

No, it's not, but it would be useful in some cases IMO. Pretty much the same way your debug features are useful.

Quoted 6 lines

Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

The point is, if there's a delay, it may be too aggressive for some users and too conservative for some other users, so it makes sense to provide a means to adjust it to the user's needs.

Rafael

#91 lore raw

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 46 lines · Arve Hjønnevåg
Quoted 24 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 13 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 5 lines
Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

Yes, but that should allow the user to avoid rebooting the system if he does the "wrong thing".

Quoted 1 line

I'm not convinced adding a configurable delay here is necessary.

No, it's not, but it would be useful in some cases IMO.  Pretty much the same way your debug features are useful.

Quoted 6 lines

Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

Quoted 4 lines

The point is, if there's a delay, it may be too aggressive for some users and too conservative for some other users, so it makes sense to provide a means to adjust it to the user's needs.

My point is that the delay will not be used at all if the driver uses a suspend blocker (like it should). Why add a configuration option for opportunistic suspend that only works when the driver does not support opportunistic suspend.

Signature · 1 line
Arve Hjønnevåg
#92 lore raw
In reply to Rafael J. Wysocki

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 46 lines · Arve Hjønnevåg
Quoted 24 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 13 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 5 lines
Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

Yes, but that should allow the user to avoid rebooting the system if he does the "wrong thing".

Quoted 1 line

I'm not convinced adding a configurable delay here is necessary.

No, it's not, but it would be useful in some cases IMO.  Pretty much the same way your debug features are useful.

Quoted 6 lines

Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

Quoted 4 lines

The point is, if there's a delay, it may be too aggressive for some users and too conservative for some other users, so it makes sense to provide a means to adjust it to the user's needs.

My point is that the delay will not be used at all if the driver uses a suspend blocker (like it should). Why add a configuration option for opportunistic suspend that only works when the driver does not support opportunistic suspend.

Signature · 1 line
Arve Hjønnevåg
#93 lore raw
Quoted 52 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 46 lines · Arve Hjønnevåg
Quoted 24 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 13 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 5 lines
Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

Yes, but that should allow the user to avoid rebooting the system if he does the "wrong thing".

Quoted 1 line

I'm not convinced adding a configurable delay here is necessary.

No, it's not, but it would be useful in some cases IMO. Pretty much the same way your debug features are useful.

Quoted 6 lines

Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

Quoted 4 lines

The point is, if there's a delay, it may be too aggressive for some users and too conservative for some other users, so it makes sense to provide a means to adjust it to the user's needs.

Quoted 4 lines

My point is that the delay will not be used at all if the driver uses a suspend blocker (like it should). Why add a configuration option for opportunistic suspend that only works when the driver does not support opportunistic suspend.

Because on many systems there are no such drivers (yet, at least).

Rafael

#94 lore raw
In reply to Arve Hjønnevåg
Quoted 52 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 46 lines · Arve Hjønnevåg
Quoted 24 lines

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 13 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 5 lines
Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

Yes, but that should allow the user to avoid rebooting the system if he does the "wrong thing".

Quoted 1 line

I'm not convinced adding a configurable delay here is necessary.

No, it's not, but it would be useful in some cases IMO. Pretty much the same way your debug features are useful.

Quoted 6 lines

Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

Quoted 4 lines

The point is, if there's a delay, it may be too aggressive for some users and too conservative for some other users, so it makes sense to provide a means to adjust it to the user's needs.

Quoted 4 lines

My point is that the delay will not be used at all if the driver uses a suspend blocker (like it should). Why add a configuration option for opportunistic suspend that only works when the driver does not support opportunistic suspend.

Because on many systems there are no such drivers (yet, at least).

Rafael

#95 lore raw
In reply to Arve Hjønnevåg
Quoted 24 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

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

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 13 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

Quoted 5 lines
Quoted 2 lines

But the user can still manually write to /sys/power/state. :-)

Does adding or removing a delay change this? It seems in only changes how quickly the user can finish that write.

Yes, but that should allow the user to avoid rebooting the system if he does the "wrong thing".

Quoted 1 line

I'm not convinced adding a configurable delay here is necessary.

No, it's not, but it would be useful in some cases IMO. Pretty much the same way your debug features are useful.

Quoted 6 lines

Once the driver that enabled the wakeup event has been updated to block suspend until this event gets to user space, then this delay will never be triggered. The kernel cannot tell the difference between a user enabling opportunistic suspend but not wanting it and opportunistic suspend aware user space code deciding that this wakeup event should be ignored.

The point is, if there's a delay, it may be too aggressive for some users and too conservative for some other users, so it makes sense to provide a means to adjust it to the user's needs.

Rafael

#96 lore raw
In reply to Arve Hjønnevåg
Quoted 7 lines · Arve Hjønnevåg

2010/5/18 Rafael J. Wysocki <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Brian Swetland
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line

...

Quoted 6 lines
Quoted 5 lines

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

Quoted 7 lines

I can add a delay (and the timeout support code does add a delay as an optimization) to the unknown wakeup case, but this does not fix the problem of a user turning on opportunistic suspend with a user space framework that does not use suspend blockers. If the kernel uses suspend blockers to make sure the wakeup event makes it to user space, but user space does not block suspend, then the system will suspend before the event is processed.

But the user can still manually write to /sys/power/state. :-)

Rafael

#97 lore raw
In reply to Arve Hjønnevåg
Quoted 26 lines · Arve Hjønnevåg
Quoted 25 lines · Rafael J. Wysocki
Quoted 23 lines · Brian Swetland
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following. Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this? I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

Quoted 5 lines
Quoted 3 lines

I agree, but I think it's necessary. We shouldn't add interfaces that hurt users if not used with care.

I'm not sure this can be "fixed".

Yes, it can, but perhaps a workaround would be sufficient (see below).

Quoted 4 lines

The user asked that the system to suspend whenever possible, which is what it is doing. I don't think disabling opportunistic suspend if no suspend blockers have been registered will work. As soon as we register a suspend blocker we are back in the same situation.

Not really, because the new suspend blocker is not added by the _framework_ _itself_.

Now, to make it more "user-friendly", we can simply use queue_delayed_work() with a reasonable delay instead of queue_work() to queue the suspend work (the delay may be configurable via sysfs).

Thanks,
Rafael

#98 lore raw
In reply to Brian Swetland
Quoted 16 lines · Brian Swetland
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Arve Hjønnevåg

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Quoted 8 lines

Well, the scenario I have in mind is the following. Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this? I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

Quoted 7 lines

I guess we could set a flag when a suspend blocker is registered and refuse to enter opportunistic mode if no blockers have ever been registered.

It does seem like extra effort to go through to handle a "don't do that" type scenario (entering into opportunistic suspend without anything that will prevent it).

I agree, but I think it's necessary. We shouldn't add interfaces that hurt users if not used with care.

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

#99 lore raw
In reply to Arve Hjønnevåg
Quoted 22 lines · Arve Hjønnevåg

2010/5/16 Rafael J. Wysocki <[email protected]>:

Quoted 21 lines · Arve Hjønnevåg
Quoted 11 lines

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

I have one more comment, sorry for that.

Namely, if /sys/power/policy is set to "opportunistic" and "mem" is written into /sys/power/state and there are no suspend blockers present except for the main blocker (and the blockers used only for statistics), the system won't be able to go out of an infinit suspend-resume loop (or at least it seems so from reading the code).

Quoted 6 lines
Quoted 2 lines

I think we should prevent that from happening somehow.

It should get out of that loop as soon as someone blocks suspend. If someone is constantly aborting suspend without using a suspend blocker it will be very inefficient, but it should still work.

Well, the scenario I have in mind is the following. Someone wants to check the feature and simply writes "opportunistic" to /sys/power/policy and "mem" to /sys/power/state without any drivers or apps that use suspend blockers.

How in that case is the system supposed to break out of the suspend-resume loop resulting from this? I don't see right now, because the main blocker is inactive, there are no other blockers that can be activated and it is next to impossible to write to /sys/power/state again.

Rafael

#100 lore raw
In reply to Arve Hjønnevåg
Quoted 11 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 has some changes from, or requested by, Rafael. The most notable changes are:
- DEFINE_SUSPEND_BLOCKER and suspend_blocker_register have been added for statically allocated suspend blockers.
- suspend_blocker_destroy is now called suspend_blocker_unregister
- The user space mandatory _INIT ioctl has been replaced with an optional _SET_NAME ioctl.

I kept the ack and reviewed by tags on two of the patches even though there were a few cosmetic changes.

I have one more comment, sorry for that.

Namely, if /sys/power/policy is set to "opportunistic" and "mem" is written into /sys/power/state and there are no suspend blockers present except for the main blocker (and the blockers used only for statistics), the system won't be able to go out of an infinit suspend-resume loop (or at least it seems so from reading the code).

I think we should prevent that from happening somehow.

Thanks,
Rafael

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