Skip to contentSkip to conversation

Suspend block api (version 6)

PATCH NAK Arve Hjønnevåg 33 participants 699 messages Apr 30, 2010 – May 31, 2010 Page 2 of 4

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

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

In reply to Daniel Walker
Quoted 18 lines · Daniel Walker
Quoted 11 lines · Matthew Garrett
Quoted 9 lines · Daniel Walker
Quoted 4 lines · Matthew Garrett

If your wakeup latencies are sufficiently low and you have fine-grained enough control over your hardware then suspend in idle is a reasonable thing to do - but if you have a userspace app that's spinning then that doesn't solve the issue.

If there's a userspace app spinning then you don't go idle (or that's my assumption anyway). You mean like repeatedly blocking and unblocking right?

Quoted 5 lines

Right, that's the problem. idle-based suspend works fine if your applications let the system go idle, but if your applications are anything other than absolutely perfect in this respect then you consume significant power even if the device is sitting unused in someone's pocket.

Quoted 4 lines

True .. I'd wonder how an OMAP based devices deal with that issue, since they would have that exact problem. According to what Tony is telling us. Actually a bogus userspace can do a lot more than just consume power you could hang the system too.

There's nothing being done on omaps specifically, up to the device user space to deal with that. From the kernel point of view the omaps just run, and if idle enough, the device starts hitting the retention and off modes in idle. But the system keeps on running all the time, no need to suspend really.

I don't think there's a generic solution to the misbehaving apps. I know a lot of work has been done over past five years or so to minimize the timer usage in various apps. But if I installed some app that keeps the system busy, it would drain the battery.

I guess some apps could be just stopped when the screen blanks unless somehow certified for the timer usage or something similar..

Regards,

Tony

#193 lore raw

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

In reply to Daniel Walker
Quoted 6 lines · Daniel Walker
Quoted 4 lines · Tony Lindgren

Oh some SoC devices like omap hit retention or off modes in the idle loop. That brings down the idle consumption of a running system to minimal levels. It's basically the same as suspending the device in every idle loop.

Quoted 8 lines
Quoted 3 lines

The system wakes up every few seconds or so, but that already provides battery life of over ten days or so on an idle system. Of course the wakeup latencies are in milliseconds then.

MSM doesn't have those power states unfortunately .. Your kind of suggesting what I was suggesting in that we should suspend in idle. Your hardware can do it easier tho since your have power states that are equal to suspend.

You might be able to implement suspend-while-idle with cpuidle and a custom idle function on MSM. That is if MSM supports waking to a timer event and some device interrupts. However, if it only wakes to pressing some power button, then you will get missed timers and the system won't behave in a normal way.

Maybe you could still kill -STOP the misbehaving apps, then keep the idle system running until some timer expires, then when no activity, echo mem > /sys/power/state?

Regards,

Tony

#194 lore raw

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

In reply to Daniel Walker
Quoted 6 lines · Daniel Walker
Quoted 4 lines · Tony Lindgren

Oh some SoC devices like omap hit retention or off modes in the idle loop. That brings down the idle consumption of a running system to minimal levels. It's basically the same as suspending the device in every idle loop.

Quoted 8 lines
Quoted 3 lines

The system wakes up every few seconds or so, but that already provides battery life of over ten days or so on an idle system. Of course the wakeup latencies are in milliseconds then.

MSM doesn't have those power states unfortunately .. Your kind of suggesting what I was suggesting in that we should suspend in idle. Your hardware can do it easier tho since your have power states that are equal to suspend.

You might be able to implement suspend-while-idle with cpuidle and a custom idle function on MSM. That is if MSM supports waking to a timer event and some device interrupts. However, if it only wakes to pressing some power button, then you will get missed timers and the system won't behave in a normal way.

Maybe you could still kill -STOP the misbehaving apps, then keep the idle system running until some timer expires, then when no activity, echo mem > /sys/power/state?

Regards,

Tony

#195 lore raw

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

In reply to Tony Lindgren
Quoted 6 lines · Tony Lindgren
Quoted 5 lines · Matthew Garrett
Quoted 2 lines · Tony Lindgren

Or are you suspending constantly, tens of times per minute even if there's no user activity?

Quoted 6 lines
Quoted 2 lines

In this case you'd be repeatedly trying to suspend until the modem driver stopped blocking it. It's pretty much a waste.

But then the userspace knows you're getting data from the modem, and it can kick some inactivity timer that determines when to try to suspend next.

Thank you for thinking.

--mgross

Quoted 6 lines

Why would you need to constantly try to suspend in that case?

Regards,

Tony

#196 lore raw

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

In reply to Tony Lindgren
Quoted 6 lines · Tony Lindgren
Quoted 5 lines · Matthew Garrett
Quoted 2 lines · Tony Lindgren

Or are you suspending constantly, tens of times per minute even if there's no user activity?

Quoted 6 lines
Quoted 2 lines

In this case you'd be repeatedly trying to suspend until the modem driver stopped blocking it. It's pretty much a waste.

But then the userspace knows you're getting data from the modem, and it can kick some inactivity timer that determines when to try to suspend next.

Thank you for thinking.

--mgross

Quoted 6 lines

Why would you need to constantly try to suspend in that case?

Regards,

Tony

#197 lore raw

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

In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Tony Lindgren

Or are you suspending constantly, tens of times per minute even if there's no user activity?

In this case you'd be repeatedly trying to suspend until the modem driver stopped blocking it. It's pretty much a waste.

lets not go off in the weeds for the wrong things now. The answer to the retry is at most one time. The first time would be blocked, then the suspend enable would need to re-enabled under user mode control that would, buy that time, know it has to ack to the modem to stop rejecting the suspend attempt.

duh.

--mgross

#198 lore raw

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

In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Tony Lindgren

Or are you suspending constantly, tens of times per minute even if there's no user activity?

In this case you'd be repeatedly trying to suspend until the modem driver stopped blocking it. It's pretty much a waste.

lets not go off in the weeds for the wrong things now. The answer to the retry is at most one time. The first time would be blocked, then the suspend enable would need to re-enabled under user mode control that would, buy that time, know it has to ack to the modem to stop rejecting the suspend attempt.

duh.

--mgross

#199 lore raw

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

Quoted 10 lines · mgross
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Tony Lindgren

Or are you suspending constantly, tens of times per minute even if there's no user activity?

In this case you'd be repeatedly trying to suspend until the modem driver stopped blocking it. It's pretty much a waste.

Quoted 6 lines

lets not go off in the weeds for the wrong things now.  The answer to the retry is at most one time.  The first time would be blocked, then the suspend enable would need to re-enabled under user mode control that would, buy that time, know it has to ack to the modem to stop rejecting the suspend attempt.

This is incorrect in the general case. User-space has no way of knowing which driver blocked suspend or when it will stop blocking suspend.

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

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

In reply to mgross
Quoted 10 lines · mgross
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Tony Lindgren

Or are you suspending constantly, tens of times per minute even if there's no user activity?

In this case you'd be repeatedly trying to suspend until the modem driver stopped blocking it. It's pretty much a waste.

Quoted 6 lines

lets not go off in the weeds for the wrong things now.  The answer to the retry is at most one time.  The first time would be blocked, then the suspend enable would need to re-enabled under user mode control that would, buy that time, know it has to ack to the modem to stop rejecting the suspend attempt.

This is incorrect in the general case. User-space has no way of knowing which driver blocked suspend or when it will stop blocking suspend.

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

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

In reply to mark gross

2010/5/3 mark gross <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 16 lines

Documentation/power/opportunistic-suspend.txt line 22

Quoted 5 lines
Documentation/power/opportunistic-suspend.txt new file +5 -0
+When the policy is "opportunisic", there is a special value, "on", that can be
+written to /sys/power/state. This will block the automatic sleep request, as if
+a suspend blocker was used by a device driver. This way the opportunistic
+suspend may be blocked by user space whithout switching back to the "forced"
+mode.

You know things would be so much easier if the policy was a one-shot styled thing.  i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior.  That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out.  I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend.  but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.

Quoted 4 lines

Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode.  That would remove my issue with the design.

Making it one shot does not change where kernel code needs to block suspend, but it does force user space to poll trying to suspend while suspend is blocked by a driver.

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

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

In reply to mark gross

2010/5/3 mark gross <[email protected]>:

Quoted 1 line · Arve Hjønnevåg

...

Quoted 16 lines

Documentation/power/opportunistic-suspend.txt line 22

Quoted 5 lines
Documentation/power/opportunistic-suspend.txt new file +5 -0
+When the policy is "opportunisic", there is a special value, "on", that can be
+written to /sys/power/state. This will block the automatic sleep request, as if
+a suspend blocker was used by a device driver. This way the opportunistic
+suspend may be blocked by user space whithout switching back to the "forced"
+mode.

You know things would be so much easier if the policy was a one-shot styled thing.  i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior.  That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out.  I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend.  but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.

Quoted 4 lines

Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode.  That would remove my issue with the design.

Making it one shot does not change where kernel code needs to block suspend, but it does force user space to poll trying to suspend while suspend is blocked by a driver.

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

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

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

---
 Documentation/power/opportunistic-suspend.txt |  119 +++++++++++
 include/linux/suspend_blocker.h               |   64 ++++++
 kernel/power/Kconfig                          |   16 ++
 kernel/power/Makefile                         |    1 +
 kernel/power/main.c                           |   92 ++++++++-
 kernel/power/power.h                          |    9 +
 kernel/power/suspend.c                        |    4 +-
 kernel/power/suspend_blocker.c                |  261 +++++++++++++++++++++++++
 8 files changed, 559 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/power/opportunistic-suspend.txt
 create mode 100755 include/linux/suspend_blocker.h
 create mode 100644 kernel/power/suspend_blocker.c
Documentation/power/opportunistic-suspend.txt new file +12 -0
new file mode 100644
index 0000000..3d060e8
@@ -0,0 +1,119 @@
+Opportunistic Suspend
+=====================
+
+Opportunistic suspend is a feature allowing the system to be suspended (ie. put
+into one of the available sleep states) automatically whenever it is regarded
+as idle.  The suspend blockers framework described below is used to determine
+when that happens.
+
+The /sys/power/policy sysfs attribute is used to switch the system between the
+opportunistic and "forced" suspend behavior, where in the latter case the
+system is only suspended if a specific value, corresponding to one of the
+available system sleep states, is written into /sys/power/state.  However, in

Documentation/power/opportunistic-suspend.txt line 22

Quoted 10 lines
Documentation/power/opportunistic-suspend.txt new file +10 -0
+the former, opportunistic, case the system is put into the sleep state
+corresponding to the value written to /sys/power/state whenever there are no
+active suspend blockers. The default policy is "forced". Also, suspend blockers
+do not affect sleep states entered from idle.
+
+When the policy is "opportunisic", there is a special value, "on", that can be
+written to /sys/power/state. This will block the automatic sleep request, as if
+a suspend blocker was used by a device driver. This way the opportunistic
+suspend may be blocked by user space whithout switching back to the "forced"
+mode.

You know things would be so much easier if the policy was a one-shot styled thing. i.e. when enabled it does what it does, but upon resume the policy must be re-enabled by user mode to get the opportunistic behavior. That way we don't need to grab the suspend blocker from the wake up irq handler all the way up to user mode as the example below calls out. I suppose doing this would put a burden on the user mode code to keep track of if it has no pending blockers registered after a wake up from the suspend. but that seems nicer to me than sprinkling overlapping blocker critical sections from the mettle up to user mode.

Please consider making the policy a one shot API that needs to be re-enabled after resume by user mode. That would remove my issue with the design.

--mgross

Quoted 700 lines
Documentation/power/opportunistic-suspend.txt new file +97 -0
+
+A suspend blocker is an object used to inform the PM subsystem when the system
+can or cannot be suspended in the "opportunistic" mode (the "forced" mode
+ignores suspend blockers).  To use it, a device driver creates a struct
+suspend_blocker that must be initialized with suspend_blocker_init(). Before
+freeing the suspend_blocker structure or its name, suspend_blocker_destroy()
+must be called on it.
+
+A suspend blocker is activated using suspend_block(), which prevents the PM
+subsystem from putting the system into the requested sleep state in the
+"opportunistic" mode until the suspend blocker is deactivated with
+suspend_unblock(). Multiple suspend blockers may be active simultaneously, and
+the system will not suspend as long as at least one of them is active.
+
+If opportunistic suspend is already in progress when suspend_block() is called,
+it will abort the suspend, unless suspend_ops->enter has already been
+executed. If suspend is aborted this way, the system is usually not fully
+operational at that point. The suspend callbacks of some drivers may still be
+running and it usually takes time to restore the system to the fully operational
+state.
+
+Here's an example showing how a cell phone or other embedded system can handle
+keystrokes (or other input events) in the presence of suspend blockers. Use
+set_irq_wake or a platform specific api to make sure the keypad interrupt wakes
+up the cpu. Once the keypad driver has resumed, the sequence of events can look
+like this:
+
+- The Keypad driver gets an interrupt. It then calls suspend_block on the
+  keypad-scan suspend_blocker and starts scanning the keypad matrix.
+- The keypad-scan code detects a key change and reports it to the input-event
+  driver.
+- The input-event driver sees the key change, enqueues an event, and calls
+  suspend_block on the input-event-queue suspend_blocker.
+- The keypad-scan code detects that no keys are held and calls suspend_unblock
+  on the keypad-scan suspend_blocker.
+- The user-space input-event thread returns from select/poll, calls
+  suspend_block on the process-input-events suspend_blocker and then calls read
+  on the input-event device.
+- The input-event driver dequeues the key-event and, since the queue is now
+  empty, it calls suspend_unblock on the input-event-queue suspend_blocker.
+- The user-space input-event thread returns from read. If it determines that
+  the key should be ignored, it calls suspend_unblock on the
+  process_input_events suspend_blocker and then calls select or poll. The
+  system will automatically suspend again, since now no suspend blockers are
+  active.
+
+If the key that was pressed instead should preform a simple action (for example,
+adjusting the volume), this action can be performed right before calling
+suspend_unblock on the process_input_events suspend_blocker. However, if the key
+triggers a longer-running action, that action needs its own suspend_blocker and
+suspend_block must be called on that suspend blocker before calling
+suspend_unblock on the process_input_events suspend_blocker.
+
+                 Key pressed   Key released
+                     |             |
+keypad-scan          ++++++++++++++++++
+input-event-queue        +++          +++
+process-input-events       +++          +++
+
+
+Driver API
+==========
+
+A driver can use the suspend block api by adding a suspend_blocker variable to
+its state and calling suspend_blocker_init. For instance:
+struct state {
+	struct suspend_blocker suspend_blocker;
+}
+
+init() {
+	suspend_blocker_init(&state->suspend_blocker, "suspend-blocker-name");
+}
+
+Before freeing the memory, suspend_blocker_destroy must be called:
+
+uninit() {
+	suspend_blocker_destroy(&state->suspend_blocker);
+}
+
+When the driver determines that it needs to run (usually in an interrupt
+handler) it calls suspend_block:
+	suspend_block(&state->suspend_blocker);
+
+When it no longer needs to run it calls suspend_unblock:
+	suspend_unblock(&state->suspend_blocker);
+
+Calling suspend_block when the suspend blocker is active or suspend_unblock when
+it is not active has no effect (i.e., these functions don't nest). This allows
+drivers to update their state and call suspend suspend_block or suspend_unblock
+based on the result.
+For instance:
+
+if (list_empty(&state->pending_work))
+	suspend_unblock(&state->suspend_blocker);
+else
+	suspend_block(&state->suspend_blocker);
+
include/linux/suspend_blocker.h new file +64 -0
new file mode 100755
index 0000000..f9928cc
@@ -0,0 +1,64 @@
+/* include/linux/suspend_blocker.h
+ *
+ * Copyright (C) 2007-2009 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef _LINUX_SUSPEND_BLOCKER_H
+#define _LINUX_SUSPEND_BLOCKER_H
+
+#include <linux/list.h>
+
+/**
+ * struct suspend_blocker - the basic suspend_blocker structure
+ * @link:	List entry for active or inactive list.
+ * @flags:	Tracks initialized and active state.
+ * @name:	Name used for debugging.
+ *
+ * When a suspend_blocker is active it prevents the system from entering
+ * opportunistic suspend.
+ *
+ * The suspend_blocker structure must be initialized by suspend_blocker_init()
+ */
+
+struct suspend_blocker {
+#ifdef CONFIG_OPPORTUNISTIC_SUSPEND
+	struct list_head    link;
+	int                 flags;
+	const char         *name;
+#endif
+};
+
+#ifdef CONFIG_OPPORTUNISTIC_SUSPEND
+
+void suspend_blocker_init(struct suspend_blocker *blocker, const char *name);
+void suspend_blocker_destroy(struct suspend_blocker *blocker);
+void suspend_block(struct suspend_blocker *blocker);
+void suspend_unblock(struct suspend_blocker *blocker);
+bool suspend_blocker_is_active(struct suspend_blocker *blocker);
+bool suspend_is_blocked(void);
+
+#else
+
+static inline void suspend_blocker_init(struct suspend_blocker *blocker,
+					const char *name) {}
+static inline void suspend_blocker_destroy(struct suspend_blocker *blocker) {}
+static inline void suspend_block(struct suspend_blocker *blocker) {}
+static inline void suspend_unblock(struct suspend_blocker *blocker) {}
+static inline bool suspend_blocker_is_active(struct suspend_blocker *bl)
+								{ return 0; }
+static inline bool suspend_is_blocked(void) { return 0; }
+
+#endif
+
+#endif
+
kernel/power/Kconfig +16 -0
index 5c36ea9..55a06a1 100644
@@ -130,6 +130,22 @@ config SUSPEND_FREEZER
 
 	  Turning OFF this setting is NOT recommended! If in doubt, say Y.
 
+config OPPORTUNISTIC_SUSPEND
+	bool "Suspend blockers"
+	depends on PM_SLEEP
+	select RTC_LIB
+	default n
+	---help---
+	  Opportunistic sleep support.  Allows the system to be put into a sleep
+	  state opportunistically, if it doesn't do any useful work at the
+	  moment. The PM subsystem is switched into this mode of operation by
+	  writing "opportunistic" into /sys/power/policy, while writing
+	  "forced" to this file turns the opportunistic suspend feature off.
+	  In the "opportunistic" mode suspend blockers are used to determine
+	  when to suspend the system and the value written to /sys/power/state
+	  determines the sleep state the system will be put into when there are
+	  no active suspend blockers.
+
 config HIBERNATION_NVS
 	bool
 
kernel/power/Makefile +1 -0
index 4319181..ee5276d 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)	+= suspend_blocker.o
 obj-$(CONFIG_PM_TEST_SUSPEND)	+= suspend_test.o
 obj-$(CONFIG_HIBERNATION)	+= hibernate.o snapshot.o swap.o user.o
 obj-$(CONFIG_HIBERNATION_NVS)	+= hibernate_nvs.o
kernel/power/main.c +86 -6
index b58800b..030ecdc 100644
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/resume-trace.h>
 #include <linux/workqueue.h>
+#include <linux/suspend_blocker.h>
 
 #include "power.h"
 
@@ -20,6 +21,27 @@ DEFINE_MUTEX(pm_mutex);
 unsigned int pm_flags;
 EXPORT_SYMBOL(pm_flags);
 
+struct policy {
+	const char *name;
+	bool (*valid_state)(suspend_state_t state);
+	int (*set_state)(suspend_state_t state);
+};
+static struct policy policies[] = {
+	{
+		.name		= "forced",
+		.valid_state	= valid_state,
+		.set_state	= enter_state,
+	},
+#ifdef CONFIG_OPPORTUNISTIC_SUSPEND
+	{
+		.name		= "opportunistic",
+		.valid_state	= request_suspend_valid_state,
+		.set_state	= request_suspend_state,
+	},
+#endif
+};
+static int policy;
+
 #ifdef CONFIG_PM_SLEEP
 
 /* Routines for PM-transition notifications */
@@ -146,6 +168,12 @@ struct kobject *power_kobj;
  *
  *	store() accepts one of those strings, translates it into the 
  *	proper enumerated value, and initiates a suspend transition.
+ *
+ *	If policy is set to opportunistic, store() does not block until the
+ *	system resumes, and it will try to re-enter the state until another
+ *	state is requested. Suspend blockers are respected and the requested
+ *	state will only be entered when no suspend blockers are active.
+ *	Write "on" to cancel.
  */
 static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
 			  char *buf)
@@ -155,12 +183,13 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
 	int i;
 
 	for (i = 0; i < PM_SUSPEND_MAX; i++) {
-		if (pm_states[i] && valid_state(i))
+		if (pm_states[i] && policies[policy].valid_state(i))
 			s += sprintf(s,"%s ", pm_states[i]);
 	}
 #endif
 #ifdef CONFIG_HIBERNATION
-	s += sprintf(s, "%s\n", "disk");
+	if (!policy)
+		s += sprintf(s, "%s\n", "disk");
 #else
 	if (s != buf)
 		/* convert the last space to a newline */
@@ -173,7 +202,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
 			   const char *buf, size_t n)
 {
 #ifdef CONFIG_SUSPEND
-	suspend_state_t state = PM_SUSPEND_STANDBY;
+	suspend_state_t state = PM_SUSPEND_ON;
 	const char * const *s;
 #endif
 	char *p;
@@ -184,7 +213,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
 	len = p ? p - buf : n;
 
 	/* First, check if we are requested to hibernate */
-	if (len == 4 && !strncmp(buf, "disk", len)) {
+	if (len == 4 && !strncmp(buf, "disk", len) && !policy) {
 		error = hibernate();
   goto Exit;
 	}
@@ -195,7 +224,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
 			break;
 	}
 	if (state < PM_SUSPEND_MAX && *s)
-		error = enter_state(state);
+		error = policies[policy].set_state(state);
 #endif
 
  Exit:
@@ -204,6 +233,55 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
 
 power_attr(state);
 
+/**
+ *	policy - set policy for state
+ */
+
+static ssize_t policy_show(struct kobject *kobj,
+			   struct kobj_attribute *attr, char *buf)
+{
+	char *s = buf;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(policies); i++) {
+		if (i == policy)
+			s += sprintf(s, "[%s] ", policies[i].name);
+		else
+			s += sprintf(s, "%s ", policies[i].name);
+	}
+	if (s != buf)
+		/* convert the last space to a newline */
+		*(s-1) = '\n';
+	return (s - buf);
+}
+
+static ssize_t policy_store(struct kobject *kobj,
+			    struct kobj_attribute *attr,
+			    const char *buf, size_t n)
+{
+	const char *s;
+	char *p;
+	int len;
+	int i;
+
+	p = memchr(buf, '\n', n);
+	len = p ? p - buf : n;
+
+	for (i = 0; i < ARRAY_SIZE(policies); i++) {
+		s = policies[i].name;
+		if (s && len == strlen(s) && !strncmp(buf, s, len)) {
+			mutex_lock(&pm_mutex);
+			policies[policy].set_state(PM_SUSPEND_ON);
+			policy = i;
+			mutex_unlock(&pm_mutex);
+			return n;
+		}
+	}
+	return -EINVAL;
+}
+
+power_attr(policy);
+
 #ifdef CONFIG_PM_TRACE
 int pm_trace_enabled;
 
@@ -231,6 +309,7 @@ power_attr(pm_trace);
 
 static struct attribute * g[] = {
 	&state_attr.attr,
+	&policy_attr.attr,
 #ifdef CONFIG_PM_TRACE
 	&pm_trace_attr.attr,
 #endif
@@ -247,7 +326,7 @@ static struct attribute_group attr_group = {
 	.attrs = g,
 };
 
-#ifdef CONFIG_PM_RUNTIME
+#if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_OPPORTUNISTIC_SUSPEND)
 struct workqueue_struct *pm_wq;
 EXPORT_SYMBOL_GPL(pm_wq);
 
@@ -266,6 +345,7 @@ static int __init pm_init(void)
 	int error = pm_start_workqueue();
 	if (error)
 		return error;
+	suspend_block_init();
 	power_kobj = kobject_create_and_add("power", NULL);
 	if (!power_kobj)
 		return -ENOMEM;
kernel/power/power.h +9 -0
index 46c5a26..67d10fd 100644
@@ -236,3 +236,12 @@ static inline void suspend_thaw_processes(void)
 {
 }
 #endif
+
+/* kernel/power/suspend_block.c */
+extern int request_suspend_state(suspend_state_t state);
+extern bool request_suspend_valid_state(suspend_state_t state);
+#ifdef CONFIG_OPPORTUNISTIC_SUSPEND
+extern void __init suspend_block_init(void);
+#else
+static inline void suspend_block_init(void) {}
+#endif
kernel/power/suspend.c +3 -1
index 56e7dbb..dc42006 100644
@@ -16,10 +16,12 @@
 #include <linux/cpu.h>
 #include <linux/syscalls.h>
 #include <linux/gfp.h>
+#include <linux/suspend_blocker.h>
 
 #include "power.h"
 
 const char *const pm_states[PM_SUSPEND_MAX] = {
+	[PM_SUSPEND_ON]		= "on",
 	[PM_SUSPEND_STANDBY]	= "standby",
 	[PM_SUSPEND_MEM]	= "mem",
 };
@@ -157,7 +159,7 @@ static int suspend_enter(suspend_state_t state)
 
 	error = sysdev_suspend(PMSG_SUSPEND);
 	if (!error) {
-		if (!suspend_test(TEST_CORE))
+		if (!suspend_is_blocked() && !suspend_test(TEST_CORE))
 			error = suspend_ops->enter(state);
 		sysdev_resume();
 	}
kernel/power/suspend_blocker.c new file +261 -0
new file mode 100644
index 0000000..2c58b21
@@ -0,0 +1,261 @@
+/* kernel/power/suspend_blocker.c
+ *
+ * Copyright (C) 2005-2010 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/rtc.h>
+#include <linux/suspend.h>
+#include <linux/suspend_blocker.h>
+#include "power.h"
+
+extern struct workqueue_struct *pm_wq;
+
+enum {
+	DEBUG_EXIT_SUSPEND = 1U << 0,
+	DEBUG_WAKEUP = 1U << 1,
+	DEBUG_USER_STATE = 1U << 2,
+	DEBUG_SUSPEND = 1U << 3,
+	DEBUG_SUSPEND_BLOCKER = 1U << 4,
+};
+static int debug_mask = DEBUG_EXIT_SUSPEND | DEBUG_WAKEUP | DEBUG_USER_STATE;
+module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
+
+#define SB_INITIALIZED            (1U << 8)
+#define SB_ACTIVE                 (1U << 9)
+
+static DEFINE_SPINLOCK(list_lock);
+static DEFINE_SPINLOCK(state_lock);
+static LIST_HEAD(inactive_blockers);
+static LIST_HEAD(active_blockers);
+static int current_event_num;
+struct suspend_blocker main_suspend_blocker;
+static suspend_state_t requested_suspend_state = PM_SUSPEND_MEM;
+static bool enable_suspend_blockers;
+
+#define pr_info_time(fmt, args...) \
+	do { \
+		struct timespec ts; \
+		struct rtc_time tm; \
+		getnstimeofday(&ts); \
+		rtc_time_to_tm(ts.tv_sec, &tm); \
+		pr_info(fmt "(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n" , \
+			args, \
+			tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, \
+			tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); \
+	} while (0);
+
+static void print_active_blockers_locked(void)
+{
+	struct suspend_blocker *blocker;
+
+	list_for_each_entry(blocker, &active_blockers, link)
+		pr_info("active suspend blocker %s\n", blocker->name);
+}
+
+/**
+ * suspend_is_blocked() - Check if suspend should be blocked
+ *
+ * suspend_is_blocked can be used by generic power management code to abort
+ * suspend.
+ *
+ * To preserve backward compatibility suspend_is_blocked returns 0 unless it
+ * is called during suspend initiated from the suspend_block code.
+ */
+bool suspend_is_blocked(void)
+{
+	if (!enable_suspend_blockers)
+		return 0;
+	return !list_empty(&active_blockers);
+}
+
+static void suspend_worker(struct work_struct *work)
+{
+	int ret;
+	int entry_event_num;
+
+	enable_suspend_blockers = true;
+	while (!suspend_is_blocked()) {
+		entry_event_num = current_event_num;
+
+		if (debug_mask & DEBUG_SUSPEND)
+			pr_info("suspend: enter suspend\n");
+
+		ret = pm_suspend(requested_suspend_state);
+
+		if (debug_mask & DEBUG_EXIT_SUSPEND)
+			pr_info_time("suspend: exit suspend, ret = %d ", ret);
+
+		if (current_event_num == entry_event_num)
+			pr_info("suspend: pm_suspend returned with no event\n");
+	}
+	enable_suspend_blockers = false;
+}
+static DECLARE_WORK(suspend_work, suspend_worker);
+
+/**
+ * suspend_blocker_init() - Initialize a suspend blocker
+ * @blocker:	The suspend blocker to initialize.
+ * @name:	The name of the suspend blocker to show in debug messages.
+ *
+ * The suspend blocker struct and name must not be freed before calling
+ * suspend_blocker_destroy.
+ */
+void suspend_blocker_init(struct suspend_blocker *blocker, const char *name)
+{
+	unsigned long irqflags = 0;
+
+	WARN_ON(!name);
+
+	if (debug_mask & DEBUG_SUSPEND_BLOCKER)
+		pr_info("suspend_blocker_init name=%s\n", name);
+
+	blocker->name = name;
+	blocker->flags = SB_INITIALIZED;
+	INIT_LIST_HEAD(&blocker->link);
+
+	spin_lock_irqsave(&list_lock, irqflags);
+	list_add(&blocker->link, &inactive_blockers);
+	spin_unlock_irqrestore(&list_lock, irqflags);
+}
+EXPORT_SYMBOL(suspend_blocker_init);
+
+/**
+ * suspend_blocker_destroy() - Destroy a suspend blocker
+ * @blocker:	The suspend blocker to destroy.
+ */
+void suspend_blocker_destroy(struct suspend_blocker *blocker)
+{
+	unsigned long irqflags;
+	if (WARN_ON(!(blocker->flags & SB_INITIALIZED)))
+		return;
+
+	if (debug_mask & DEBUG_SUSPEND_BLOCKER)
+		pr_info("suspend_blocker_destroy name=%s\n", blocker->name);
+
+	spin_lock_irqsave(&list_lock, irqflags);
+	blocker->flags &= ~SB_INITIALIZED;
+	list_del(&blocker->link);
+	if ((blocker->flags & SB_ACTIVE) && list_empty(&active_blockers))
+		queue_work(pm_wq, &suspend_work);
+	spin_unlock_irqrestore(&list_lock, irqflags);
+}
+EXPORT_SYMBOL(suspend_blocker_destroy);
+
+/**
+ * suspend_block() - Block suspend
+ * @blocker:	The suspend blocker to use
+ *
+ * It is safe to call this function from interrupt context.
+ */
+void suspend_block(struct suspend_blocker *blocker)
+{
+	unsigned long irqflags;
+
+	if (WARN_ON(!(blocker->flags & SB_INITIALIZED)))
+		return;
+
+	spin_lock_irqsave(&list_lock, irqflags);
+
+	if (debug_mask & DEBUG_SUSPEND_BLOCKER)
+		pr_info("suspend_block: %s\n", blocker->name);
+
+	blocker->flags |= SB_ACTIVE;
+	list_move(&blocker->link, &active_blockers);
+	current_event_num++;
+
+	spin_unlock_irqrestore(&list_lock, irqflags);
+}
+EXPORT_SYMBOL(suspend_block);
+
+/**
+ * suspend_unblock() - Unblock suspend
+ * @blocker:	The suspend blocker to unblock.
+ *
+ * If no other suspend blockers block suspend, the system will suspend.
+ *
+ * It is safe to call this function from interrupt context.
+ */
+void suspend_unblock(struct suspend_blocker *blocker)
+{
+	unsigned long irqflags;
+
+	if (WARN_ON(!(blocker->flags & SB_INITIALIZED)))
+		return;
+
+	spin_lock_irqsave(&list_lock, irqflags);
+
+	if (debug_mask & DEBUG_SUSPEND_BLOCKER)
+		pr_info("suspend_unblock: %s\n", blocker->name);
+
+	list_move(&blocker->link, &inactive_blockers);
+
+	if ((blocker->flags & SB_ACTIVE) && list_empty(&active_blockers))
+		queue_work(pm_wq, &suspend_work);
+	blocker->flags &= ~(SB_ACTIVE);
+	if (blocker == &main_suspend_blocker) {
+		if (debug_mask & DEBUG_SUSPEND)
+			print_active_blockers_locked();
+	}
+	spin_unlock_irqrestore(&list_lock, irqflags);
+}
+EXPORT_SYMBOL(suspend_unblock);
+
+/**
+ * suspend_blocker_is_active() - Test if a suspend blocker is blocking suspend
+ * @blocker:	The suspend blocker to check.
+ *
+ * Returns true if the suspend_blocker is currently active.
+ */
+bool suspend_blocker_is_active(struct suspend_blocker *blocker)
+{
+	WARN_ON(!(blocker->flags & SB_INITIALIZED));
+
+	return !!(blocker->flags & SB_ACTIVE);
+}
+EXPORT_SYMBOL(suspend_blocker_is_active);
+
+bool request_suspend_valid_state(suspend_state_t state)
+{
+	return (state == PM_SUSPEND_ON) || valid_state(state);
+}
+
+int request_suspend_state(suspend_state_t state)
+{
+	unsigned long irqflags;
+
+	if (!request_suspend_valid_state(state))
+		return -ENODEV;
+
+	spin_lock_irqsave(&state_lock, irqflags);
+
+	if (debug_mask & DEBUG_USER_STATE)
+		pr_info_time("request_suspend_state: %s (%d->%d) at %lld ",
+			     state != PM_SUSPEND_ON ? "sleep" : "wakeup",
+			     requested_suspend_state, state,
+			     ktime_to_ns(ktime_get()));
+
+	requested_suspend_state = state;
+	if (state == PM_SUSPEND_ON)
+		suspend_block(&main_suspend_blocker);
+	else
+		suspend_unblock(&main_suspend_blocker);
+	spin_unlock_irqrestore(&state_lock, irqflags);
+	return 0;
+}
+
+void __init suspend_block_init(void)
+{
+	suspend_blocker_init(&main_suspend_blocker, "main");
+	suspend_block(&main_suspend_blocker);
+}
Signature · 6 lines
1.6.5.1

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

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

In reply to Arve Hjønnevåg

Hi,

Some comments on the opportunistic suspend portion of this patch.

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.

Quoted 13 lines
---
 Documentation/power/opportunistic-suspend.txt |  119 +++++++++++
 include/linux/suspend_blocker.h               |   64 ++++++
 kernel/power/Kconfig                          |   16 ++
 kernel/power/Makefile                         |    1 +
 kernel/power/main.c                           |   92 ++++++++-
 kernel/power/power.h                          |    9 +
 kernel/power/suspend.c                        |    4 +-
 kernel/power/suspend_blocker.c                |  261 +++++++++++++++++++++++++
 8 files changed, 559 insertions(+), 7 deletions(-)
 create mode 100644 Documentation/power/opportunistic-suspend.txt
 create mode 100755 include/linux/suspend_blocker.h
 create mode 100644 kernel/power/suspend_blocker.c

While reading the patch, it seemed that this opportunistic suspend mechanism is a degenerate case of a system-wide form of CPUIdle. I'll call it "SystemIdle," for lack of a better term. The main difference between this and the CPUIdle design is that this patch's SystemIdle is not integrated with any of the existing Linux mechanisms for limiting idle duration or depth. This is a major problem with the current patch and should prevent it from being merged in its current state. But if some SystemIdle-type code were to be written that did work with the rest of the Linux kernel, it would be very useful.

To take an example from the current Linux-OMAP kernels: right now, the Linux-OMAP code handles system-level idle through CPUIdle.[1] To borrow ACPI terminology, some of the S-states are implemented as C-states. That isn't right, for several reasons:

- There are other constraints on system-level idle modes beyond those that apply to the CPU. To take an OMAP example, on boards that support it, OMAP2+ chips can cut power to the external SoC high-frequency clock oscillator ("HF oscillator").[2] This is the clock that is later used to drive the CPU clock, bus clock, etc., on the SoC, but can also be used to drive other chips on the board, such as external audio codec chips, GPS receivers, etc.) If power is cut to the HF oscillator, it can take several milliseconds to stabilize once power is reapplied. Part of the decision as to whether to cut power to the HF oscillator is a classic idle balancing test between power economy and wakeup latency. But this occurs on a system level - the CPU may not even be involved.

Consider a low-power audio playback use-case. The CPU may be only rarely involved, but other devices on the SoC may need to be active. For example, if a large number of audio samples are loaded into main memory, the CPU can go into a very deep sleep state while the DMA controller transfers the samples to the audio serial interface device. But the DMA controller and audio serial interface need to run occasionally, so depending on FIFO depths in the system, the HF oscillator clock may need to be kept on, even if the CPU idle level would suggest that it could be disabled.

Additionally, other external chips outside the SoC, may be clocked by that HF oscillator. Continuing the low-power audio playback use-case, the external audio codec chip may also be clocked from the HF oscillator. If the HF oscillator is cut when the SoC is idle, but the audio codec has samples in its buffer, audio playback will be disrupted.

- There should be only one system-level governor. Since all of the production OMAPs so far have been single-CPU systems, we've been able to get away with this. But on multi-CPU systems, there is one CPUIdle governor per CPU. So reusing the CPUIdle governor to do this won't work the same way as it has for us in the past.

So some good SystemIdle-type code would be really useful for us. But a significant part of what "good" means is that such a SystemIdle needs to be driven from the bottom up, rather than from the top down. In other words, both the 'policy' (i.e., the choice of metrics to use to determine the system idle state), and the 'implementation of that policy' (i.e., the way to enter those idle states), should be left up to the underlying chip architecture code that would implement SystemIdle client drivers. (In this regard, it would be even more different than CPUIdle, which hardcodes the policy.)

This way, at least initially, there will be minimal top-down restrictions on what architectures need to do to implement to their chip's power management features. As common features are identified, by individual architectures implementing working code, then the architecture developers can collaborate, and common components can be proposed for merging into the top-level SystemIdle code.

Such a SystemIdle implementation should also work for Android's opportunistic suspend code. Google developers could choose the system metrics that they wish to use to control system idle levels. If they want to ignore timers and the scheduler, that's fine - that design decision can be confined to their policy driver, and the suspend-block code can be activated the moment that some driver sets a PM constraint, rather than doing anything more refined. Similarly, Google can change the way that the policy decisions are implemented. Google could use a driver that does not take any advantage of fine-grained power management aside from CPUIdle. This driver could simply enter full system suspend whenever the policy driver authorizes it to do.

This approach - or some similar approach - should allow Android to do what it needs, while still allowing other, more finely-grained power management approaches to do something different.

regards,

- Paul

#205 lore raw

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

Quoted 1 line · Paul Walmsley

Some comments on the opportunistic suspend portion of this patch.

...

Quoted 3 lines

While reading the patch, it seemed that this opportunistic suspend mechanism is a degenerate case of a system-wide form of CPUIdle. I'll call it "SystemIdle," for lack of a better term.

The footnotes for this E-mail were inadvertently omitted. Sorry about that. They are:

1. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/cpuidle34xx.c;h=3d3d035db9aff62ce522e0080e570cfdbf8e70cc;hb=4462dc02842698f173f518c1f5ce79c0fb89395a#l292

2. OMAP35x Technical Reference Manual Rev. F, section 4.7.5.2 "System Clock Oscillator Control": http://www.ti.com/litv/pdf/spruf98f

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

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version fixes a race in suspend blocking work, has some documentation changes and opportunistic suspend now uses the same workqueue as runtime pm.

Earlier this month, several folks intersted in embedded PM had a BoF as part of the Embedded Linux Conference[1] in San Francisco. Many of us had concerns about wakelocks/suspend-blockers and I wanted to share some of mine here, since I don't know if embedded folks (other than Google) were included in discussions during the LF Collab summmit.

I hope other embedded folks will chime in here as well. My background is in embedded as one of the kernel developers on the TI OMAP SoCs, and I work primarily on PM stuff.

My comments are not about this implementation of suspend blockers in particular, but rather on the potential implications of suspend blockers in general.

Sorry for the lengthy mail, it's broken up in to 3 parts:

- suspend blockers vs. runtime PM
- how to handle PM aware drivers?
- what about dumb or untrusted apps

Suspend blockers vs runtime PM
------------------------------

My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.

Currently in the kernel, we have two main forms of PM

- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)

And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.

The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.

It seems to me the keypad/screen example given in the doc can very easily be solved with runtime PM. The goal of that example is that the keypad not turn on the screen unless a specific key is pressed. That is rather easy to accomplish using runtime PM:

1. system is idle, all devices/drivers runtime suspended (display and keypad drivers are both runtime suspended)
- keypress triggers wakeup ->runtime_resume() of keypad (screen is still runtime suspended)

-  key press trickles up to userspace
-  keypad driver is done, goes idle and is runtime supended
-  userspace decides whether or not to turn on screen based on key
-  if not, goto 1, (display is still runtime suspended)
-  if so, start using display and it will be runtime resumed

I realize this keypad example was only one example usage of suspend blockers, but I suspect the others would be solved similarily using runtime PM.

But anyways, to get back to the main point:

I feel the main problems tackled by _kernel_ suspend blockers (as I understand them) are the same problems already addressed by runtime PM. First and formost, both have the same guiding principle:

Rule #1: Always try for lowest power state, unless X

For runtime PM, X = "activity"
For suspend blockers, X = a held suspend_blocker

In addition, both have the same secondary goals:

- keep device PM independent of other devices (e.g. don't wake up screen just because keypad was pressed)

- wakeups/events can be handled in a device specific way, without affecting other devices or rest of the system, unless desired

So, the goals are the same, but the approaches are different. Runtime PM makes each of the drivers and subsystems do the work, where suspend blockers just forces the issue from on high. IMHO, the more flexible and generic approach of runtime PM is more suited to a general purpose kernel than the one-big-hammer approach currently taken by suspend blockers.

What about PM aware drivers?
----------------------------

All of this brings up a second major concern regarding how to write PM aware drivers.

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 1 line

From my experience with OMAP, we *really* do not want to care about

what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.

What about dumb or untrusted apps?
---------------------------------------

In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)

Again, since suspend blockers were designed, there have been major efforts to track and fix userspace as well as underlying timer issues (deferrable timers, coalescing, timer slack ...) that led to unnecessary wakeups from userspace. Wouldn't it be better to spend our collective efforts in continuing in that direction instead of just hiding the underlying problems by forcing suspend? Fixing the root causes will be better for everyone, not just those using Android.

And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?

Anyways, that's enough rambling for now. I hope that sheds some light on the concerns I have with suspend blockers.

Kevin

[1] http://embeddedlinuxconference.com/elc_2010/index.html

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

This patch series adds a suspend-block api that provides the same functionality as the android wakelock api. This version fixes a race in suspend blocking work, has some documentation changes and opportunistic suspend now uses the same workqueue as runtime pm.

Earlier this month, several folks intersted in embedded PM had a BoF as part of the Embedded Linux Conference[1] in San Francisco. Many of us had concerns about wakelocks/suspend-blockers and I wanted to share some of mine here, since I don't know if embedded folks (other than Google) were included in discussions during the LF Collab summmit.

I hope other embedded folks will chime in here as well. My background is in embedded as one of the kernel developers on the TI OMAP SoCs, and I work primarily on PM stuff.

My comments are not about this implementation of suspend blockers in particular, but rather on the potential implications of suspend blockers in general.

Sorry for the lengthy mail, it's broken up in to 3 parts:

- suspend blockers vs. runtime PM
- how to handle PM aware drivers?
- what about dumb or untrusted apps

Suspend blockers vs runtime PM
------------------------------

My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.

Currently in the kernel, we have two main forms of PM

- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)

And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.

The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.

It seems to me the keypad/screen example given in the doc can very easily be solved with runtime PM. The goal of that example is that the keypad not turn on the screen unless a specific key is pressed. That is rather easy to accomplish using runtime PM:

1. system is idle, all devices/drivers runtime suspended (display and keypad drivers are both runtime suspended)
- keypress triggers wakeup ->runtime_resume() of keypad (screen is still runtime suspended)

-  key press trickles up to userspace
-  keypad driver is done, goes idle and is runtime supended
-  userspace decides whether or not to turn on screen based on key
-  if not, goto 1, (display is still runtime suspended)
-  if so, start using display and it will be runtime resumed

I realize this keypad example was only one example usage of suspend blockers, but I suspect the others would be solved similarily using runtime PM.

But anyways, to get back to the main point:

I feel the main problems tackled by _kernel_ suspend blockers (as I understand them) are the same problems already addressed by runtime PM. First and formost, both have the same guiding principle:

Rule #1: Always try for lowest power state, unless X

For runtime PM, X = "activity"
For suspend blockers, X = a held suspend_blocker

In addition, both have the same secondary goals:

- keep device PM independent of other devices (e.g. don't wake up screen just because keypad was pressed)

- wakeups/events can be handled in a device specific way, without affecting other devices or rest of the system, unless desired

So, the goals are the same, but the approaches are different. Runtime PM makes each of the drivers and subsystems do the work, where suspend blockers just forces the issue from on high. IMHO, the more flexible and generic approach of runtime PM is more suited to a general purpose kernel than the one-big-hammer approach currently taken by suspend blockers.

What about PM aware drivers?
----------------------------

All of this brings up a second major concern regarding how to write PM aware drivers.

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 1 line

From my experience with OMAP, we *really* do not want to care about

what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.

What about dumb or untrusted apps?
---------------------------------------

In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)

Again, since suspend blockers were designed, there have been major efforts to track and fix userspace as well as underlying timer issues (deferrable timers, coalescing, timer slack ...) that led to unnecessary wakeups from userspace. Wouldn't it be better to spend our collective efforts in continuing in that direction instead of just hiding the underlying problems by forcing suspend? Fixing the root causes will be better for everyone, not just those using Android.

And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?

Anyways, that's enough rambling for now. I hope that sheds some light on the concerns I have with suspend blockers.

Kevin

[1] http://embeddedlinuxconference.com/elc_2010/index.html

#208 lore raw
Quoted 9 lines · Kevin Hilman

Suspend blockers vs runtime PM
------------------------------

My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.

There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.

So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.

Quoted 9 lines

Currently in the kernel, we have two main forms of PM

- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)

And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.

I wouldn't describe it like that. Consider dividing PM along a different axis:

- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)

Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.

Quoted 6 lines

The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.

The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.

Quoted 6 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 7 lines

From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.

That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.

Alan Stern

#209 lore raw
In reply to Kevin Hilman
Quoted 9 lines · Kevin Hilman

Suspend blockers vs runtime PM
------------------------------

My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.

There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.

So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.

Quoted 9 lines

Currently in the kernel, we have two main forms of PM

- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)

And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.

I wouldn't describe it like that. Consider dividing PM along a different axis:

- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)

Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.

Quoted 6 lines

The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.

The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.

Quoted 6 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 7 lines

From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.

That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.

Alan Stern

#210 lore raw
Quoted 19 lines · Alan Stern
Quoted 9 lines · Kevin Hilman

Suspend blockers vs runtime PM
------------------------------

My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.

There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.

Quoted 3 lines

So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.

Good point. However, adding CPUidle to runtime PM you indeed achieve a dynamic PM that affects the whole system.

The main difference then comes down to what prevents system-wide low-power state: activity vs. suspend blocker held.

Quoted 13 lines
Quoted 9 lines

Currently in the kernel, we have two main forms of PM

- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)

And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.

I wouldn't describe it like that. Consider dividing PM along a different axis:

Quoted 7 lines

- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)

Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.

Adding CPUidle to runtime PM (dynamic + single), you add 'entire' as well, as CPUidle manages the CPU states.

However, one problem I have with your proposed division is it doesn't seem to match well to the hardware available on modern embedded SoCs, mainly because these are not ACPI devices. The CPU is just another "independent" device whose runtime PM is managed by CPUidle.

IOW, The 'entire system' state is just a function of the CPU state and the state of all the on- and off-chip devices. With CPUidle managing the CPUs, and runtime PM managing the rest of the devices, you have a fully flexible dynamic PM for the entire system.

Quoted 9 lines
Quoted 6 lines

The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.

The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.

True, by iteslf, runtime PM does not shut down CPUs, but in combination with CPUidle the CPU(s) can be shut down based on activity. In a way, you could think of CPUidle as runtime PM for the CPU(s).

Again, the primary difference comes down to: why should I not enter a low-power state? activity (runtime PM + CPUidle) or suspend blocker.

Quoted 14 lines
Quoted 6 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 7 lines

From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.

Quoted 4 lines

That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.

Nor is it clear (to me) what drivers would/should look like that would need to do suspend blockers in addition to runtime PM.

Kevin

#211 lore raw
In reply to Alan Stern
Quoted 19 lines · Alan Stern
Quoted 9 lines · Kevin Hilman

Suspend blockers vs runtime PM
------------------------------

My primary concern is that suspend blockers attempt to address the same problem(s) as runtime PM, but with a very different approach. Suspend blockers use one very large hammer whereas runtime PM hands out many little hammers. Since I believe power management to be a problem of many little nails, I think many little hammers are better suited for the job.

There is a major difference between suspend blockers and runtime PM which was not discussed in your email. Namely: Runtime PM is aimed at suspending individual devices and not the system as a whole (in particular, not CPUs), whereas suspend blockers are aimed at suspending -- or more accurately, blocking suspends -- of the system as a whole and not individual devices.

Quoted 3 lines

So for example, runtime PM cannot be used to put the system into an S3 sleep state. But suspend blockers _are_ used to keep the system from going into S3.

Good point. However, adding CPUidle to runtime PM you indeed achieve a dynamic PM that affects the whole system.

The main difference then comes down to what prevents system-wide low-power state: activity vs. suspend blocker held.

Quoted 13 lines
Quoted 9 lines

Currently in the kernel, we have two main forms of PM

- static PM (system PM, traditional suspend/resume etc.)
- dynamic PM (runtime PM, CPUfreq, CPUidle, etc.)

And with the addition of suspend blockers we have something in between. In my simple world, I think of suspend_blockers as static PM with a retrofit of some basic dynamic capabilities. In my view, a poor man's dynamic PM.

I wouldn't describe it like that. Consider dividing PM along a different axis:

Quoted 7 lines

- entire system (ACPI sleep states, CPUs turned off, etc.)
- single, independent devices (e.g., USB autosuspend)

Then system PM combines static + entire, whereas runtime PM combines dynamic + single. By contrast, suspend blockers are aimed at the dynamic + entire combination. This makes them different from anything already present in the kernel.

Adding CPUidle to runtime PM (dynamic + single), you add 'entire' as well, as CPUidle manages the CPU states.

However, one problem I have with your proposed division is it doesn't seem to match well to the hardware available on modern embedded SoCs, mainly because these are not ACPI devices. The CPU is just another "independent" device whose runtime PM is managed by CPUidle.

IOW, The 'entire system' state is just a function of the CPU state and the state of all the on- and off-chip devices. With CPUidle managing the CPUs, and runtime PM managing the rest of the devices, you have a fully flexible dynamic PM for the entire system.

Quoted 9 lines
Quoted 6 lines

The current design of suspend blockers was (presumably) taken due to major limitations and/or problems in dynamic PM when it was designed. However, since then, some very signifcant improvements in dynamic PM have come along, particularily in the form of runtime PM. What I still feel is missing from this discussion are details about why the issues addressed by suspend blockers cannot be solved with runtime PM.

The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.

True, by iteslf, runtime PM does not shut down CPUs, but in combination with CPUidle the CPU(s) can be shut down based on activity. In a way, you could think of CPUidle as runtime PM for the CPU(s).

Again, the primary difference comes down to: why should I not enter a low-power state? activity (runtime PM + CPUidle) or suspend blocker.

Quoted 14 lines
Quoted 6 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 7 lines

From my experience with OMAP, we *really* do not want to care about what userspace is or isn't capable of, or what suspend-mode the kernel is in. Among other things, the OMAP linux kernel is used in the Nokia N900 (Maemo), the Motorola Droid (Android) and the Palm Pre (webOS). Comments on the future of each SW stack aside, we really want to run the same kernel and drivers across all of those platforms as well as whatever comes next.

Quoted 4 lines

That is indeed a weak point of the proposal. Kernel drivers' use of suspend blockers appears to be somewhat arbitrary and directed by the needs of userspace. It's not at all clear how drivers can use suspend blockers in a way that will work on all systems.

Nor is it clear (to me) what drivers would/should look like that would need to do suspend blockers in addition to runtime PM.

Kevin

#212 lore raw
In reply to Alan Stern

Hello,

Please forgive the delay in commenting - I am just now catching up on these huge E-mail threads;

Quoted 2 lines · Alan Stern

So for example, runtime PM cannot be used to put the system into an S3 sleep state.

This is not quite true. Runtime PM, *in conjunction with CPUIdle,* can put many current embedded Linux systems into not just S3, but actually S5.

This is done right now on OMAP in mainline Linux[1]. (S5 is called "C6" in that codebase, since the CPUIdle governor is used - this is a misnomer.)

This approach allows the system to wake up, or stay running, as requested by the timer subsystem, or the scheduler. No suspend-block-like API is needed.

Several consumer-market Linux devices have already shipped using this mechanism.

Quoted 2 lines

The simplest example is that suspend blockers can be used to control whether or not the CPU shuts down, whereas runtime PM can't.

Runtime PM still needs to be combined with some sort of governor to control not only CPU power states, but also system power states. CPUIdle works pretty well as a system power governor for a single-CPU system, but is admittedly something of a hack[2].

Going forward, some sort of basic, system-wide governor is a cleaner design[3]. But since the "opportunistic suspend" governor proposed in patch 1 ignores timer expiries and the scheduler runqueue, and then hacks around that decision by inserting suspend-block calls into code that would otherwise work normally, it's not a good approach.

- Paul

1. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/cpuidle34xx.c;h=3d3d035db9aff62ce522e0080e570cfdbf8e70cc;hb=4462dc02842698f173f518c1f5ce79c0fb89395a#l292

2. 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

3. ibid.

#213 lore raw
In reply to Kevin Hilman
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

#214 lore raw
In reply to Kevin Hilman
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

#215 lore raw
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 3 lines

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

Thanks,
Rafael

#216 lore raw
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 6 lines
Quoted 3 lines

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 7 lines

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

From the use cases presented, the *usage* of suspend blockers is aimed

at power management of individual devices or subsystems, just like usage of runtime PM.

So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except

- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)

In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Kevin

#217 lore raw
In reply to Rafael J. Wysocki
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 6 lines
Quoted 3 lines

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 7 lines

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

From the use cases presented, the *usage* of suspend blockers is aimed

at power management of individual devices or subsystems, just like usage of runtime PM.

So I still see a large duplication in the usage and the goals of both frameworks. The goal of both is to always enter lowest-power state except

- if there's activity (runtime PM for devices, CPUidle for CPU)
- if there's a suspend blocker (opportunitic suspend)

In addition, it will likely cause duplicate work to be done in drivers. Presumably, PM aware drivers will want to know if the system is in opportunistic mode. For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Kevin

#218 lore raw
Quoted 37 lines · Kevin Hilman
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal.  Given that, which framework should the driver writer target?  Both?  Seems like duplicate effort.  Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running.  If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace.  Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable.  They should only have to think about when the device is (or should be) idle.

Quoted 6 lines
Quoted 3 lines

I fully agree with this.  We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

I _think_ it would be hard at least.  On ACPI-based systems it's not doable at all AFAICS.

Quoted 7 lines

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states?  I think of CPUidle as basically runtime PM for the CPU.  IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system.  What am I missing?

I'm not that familiar with ACPI either, but I think the S-states entered by suspend are much lower power than the C-states entered by idle.

Quoted 10 lines
Quoted 5 lines

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Quoted 4 lines

So I still see a large duplication in the usage and the goals of both frameworks.  The goal of both is to always enter lowest-power state except

Quoted 8 lines

 - if there's activity (runtime PM for devices, CPUidle for CPU)
 - if there's a suspend blocker (opportunitic suspend)

In addition, it will likely cause duplicate work to be done in drivers.  Presumably, PM aware drivers will want to know if the system is in opportunistic mode.  For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

Why? If a device is not in use it should be off regardless of what state the rest of the system is in.

Quoted 7 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Kevin

Signature · 1 line
Arve Hjønnevåg
#219 lore raw
In reply to Kevin Hilman
Quoted 37 lines · Kevin Hilman
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal.  Given that, which framework should the driver writer target?  Both?  Seems like duplicate effort.  Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running.  If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace.  Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable.  They should only have to think about when the device is (or should be) idle.

Quoted 6 lines
Quoted 3 lines

I fully agree with this.  We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

I _think_ it would be hard at least.  On ACPI-based systems it's not doable at all AFAICS.

Quoted 7 lines

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states?  I think of CPUidle as basically runtime PM for the CPU.  IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system.  What am I missing?

I'm not that familiar with ACPI either, but I think the S-states entered by suspend are much lower power than the C-states entered by idle.

Quoted 10 lines
Quoted 5 lines

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Quoted 4 lines

So I still see a large duplication in the usage and the goals of both frameworks.  The goal of both is to always enter lowest-power state except

Quoted 8 lines

 - if there's activity (runtime PM for devices, CPUidle for CPU)
 - if there's a suspend blocker (opportunitic suspend)

In addition, it will likely cause duplicate work to be done in drivers.  Presumably, PM aware drivers will want to know if the system is in opportunistic mode.  For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

Why? If a device is not in use it should be off regardless of what state the rest of the system is in.

Quoted 7 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Kevin

Signature · 1 line
Arve Hjønnevåg
#220 lore raw
Quoted 14 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 6 lines

In addition, it will likely cause duplicate work to be done in drivers.  Presumably, PM aware drivers will want to know if the system is in opportunistic mode.  For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

Why? If a device is not in use it should be off regardless of what state the rest of the system is in.

Quoted 3 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

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

#221 lore raw
In reply to Arve Hjønnevåg
Quoted 14 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 6 lines

In addition, it will likely cause duplicate work to be done in drivers.  Presumably, PM aware drivers will want to know if the system is in opportunistic mode.  For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

Why? If a device is not in use it should be off regardless of what state the rest of the system is in.

Quoted 3 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

Brian

#222 lore raw
Quoted 10 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Quoted 6 lines

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

Quoted 6 lines

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

There's definite work to be done here, yes.

#223 lore raw
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Quoted 8 lines
Quoted 3 lines

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Exactly.

With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Quoted 7 lines
Quoted 6 lines

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

Quoted 7 lines

I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.

Agreed, and because of this, part of my concern is that opportunistic suspend will take the place of doing the "right thing" which (IMHO) would be to improve runtime PM for devices.

Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I think there needs to be more discussion on the indended usage of suspend blockers by drivers/subsystems, especially those PM aware drivers and subsystems already doing runtime PM with constraints etc.

Quoted 8 lines
Quoted 6 lines

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

There's definite work to be done here, yes.

And I've admitted this to be the only compelling reason for opportunistic suspend so far.

But the driver/subsystem implications of opportunistic suspend still need some fleshing out IMO.

Kevin

#224 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Quoted 8 lines
Quoted 3 lines

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Exactly.

With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Quoted 7 lines
Quoted 6 lines

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

Quoted 7 lines

I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.

Agreed, and because of this, part of my concern is that opportunistic suspend will take the place of doing the "right thing" which (IMHO) would be to improve runtime PM for devices.

Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I think there needs to be more discussion on the indended usage of suspend blockers by drivers/subsystems, especially those PM aware drivers and subsystems already doing runtime PM with constraints etc.

Quoted 8 lines
Quoted 6 lines

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

There's definite work to be done here, yes.

And I've admitted this to be the only compelling reason for opportunistic suspend so far.

But the driver/subsystem implications of opportunistic suspend still need some fleshing out IMO.

Kevin

#225 lore raw
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

#226 lore raw
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Quoted 6 lines

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.

However, since Android is a legitimate user of the Linux kernel, I see no reason to reject this feature right away. There are many kernel features that aren't used by all platforms.

Rafael

#227 lore raw
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Quoted 6 lines

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

Quoted 3 lines

At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.

Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.

As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.

IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.

Kevin

#228 lore raw
In reply to Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Quoted 6 lines

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

Quoted 3 lines

At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.

Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.

As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.

IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.

Kevin

#229 lore raw
Quoted 31 lines · Kevin Hilman
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Quoted 6 lines

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

Quoted 3 lines

At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.

Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.

Quoted 7 lines

As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.

IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.

I agree, but "working on towards a world where ..." need not mean "be there from day one" IMO. Also, I guess you'll agree that using the same _binary_ kernel with Android and non-Android user spaces doesn't necessarily make sense (regardless of the fact that Android kernels have hardware-specific board files included), so probably you'll still disable opportunistic suspend building the kernel for non-Android systems (at least for the time being).

It looks like you're thinking the opportunistic suspend somehow is (or can be used as) a replacement for runtime PM, but this is not the case. The reason why it's not the case is that runtime PM works with the assumption that user space is not frozen and it works on individual devices.

OTOH, generally, there is a limit on the amount of energy savings you can achieve with runtime PM alone and something like the opportunistic suspend is necessary to go beyond that limit.

Now, I can easily imagine using suspend blockers and runtime PM in the same driver with the general rule that you'll probably want to call suspend_unblock() whenever the device is suspended with the help of the runtime PM framework. That really depends on the device and the driver in question, though.

Rafael

#230 lore raw
In reply to Kevin Hilman
Quoted 31 lines · Kevin Hilman
Quoted 22 lines · Rafael J. Wysocki
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Quoted 6 lines

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

Quoted 3 lines

At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.

Sure, but there are driver authors and subsystem maintainers who care about optimal PM in "normal" Linux *and* in Android.

Quoted 7 lines

As a PM maintainer for an embedded platform (OMAP) used in both, I certainly care about both, so "disable it if you don't like it" is not really an option.

IMO, driver/subsystem authors should not have to care if the userspace is Android or not. We should be working towards a world where Android is not a special case.

I agree, but "working on towards a world where ..." need not mean "be there from day one" IMO. Also, I guess you'll agree that using the same _binary_ kernel with Android and non-Android user spaces doesn't necessarily make sense (regardless of the fact that Android kernels have hardware-specific board files included), so probably you'll still disable opportunistic suspend building the kernel for non-Android systems (at least for the time being).

It looks like you're thinking the opportunistic suspend somehow is (or can be used as) a replacement for runtime PM, but this is not the case. The reason why it's not the case is that runtime PM works with the assumption that user space is not frozen and it works on individual devices.

OTOH, generally, there is a limit on the amount of energy savings you can achieve with runtime PM alone and something like the opportunistic suspend is necessary to go beyond that limit.

Now, I can easily imagine using suspend blockers and runtime PM in the same driver with the general rule that you'll probably want to call suspend_unblock() whenever the device is suspended with the help of the runtime PM framework. That really depends on the device and the driver in question, though.

Rafael

#231 lore raw
In reply to Mark Brown
Quoted 14 lines · Mark Brown
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Quoted 6 lines

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

At the moment the rule of thumb is: if you don't need the opportunistic suspend, don't use it. It is not going to be enabled by default on anything other than Android right now.

However, since Android is a legitimate user of the Linux kernel, I see no reason to reject this feature right away. There are many kernel features that aren't used by all platforms.

Rafael

#232 lore raw
In reply to Kevin Hilman
Quoted 3 lines · Kevin Hilman

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Well, half the problem I have is that unfortunately it's not a case of doing that period. The prime example I'm familiar with is that for understandable reasons users become irate when you power down the audio CODEC while they're in the middle of a call so if opportunistic PM is in use then the audio subsystem needs some additional help interpreting a suspend request so that it can figure out how to handle it. Similar issues apply to PMICs, though less pressingly for various reasons.

Just to be clear, I do understand and mostly agree with the idea that opportunistic suspend presents a reasonable workaround for our current inability to deliver good power savings with runtime PM methods on many important platforms but I do think that if we're going to make this standard Linux PM functionality then we need to be clearer about how everything is intended to hang together.

#233 lore raw
In reply to Kevin Hilman
Quoted 21 lines · Kevin Hilman
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Quoted 8 lines
Quoted 3 lines

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Exactly.

Quoted 7 lines

With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Guys, please.

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

However, there are situations in which runtime PM is clearly insufficient. The idea behind runtime PM is that subsystems and device drivers will know when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

Quoted 15 lines
Quoted 7 lines
Quoted 6 lines

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

Quoted 7 lines

I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.

Quoted 3 lines

Agreed, and because of this, part of my concern is that opportunistic suspend will take the place of doing the "right thing" which (IMHO) would be to improve runtime PM for devices.

It really can't, at least on some platforms. For example, resuming a PC notebook from suspend to RAM takes more than 1s (with an SSD; rotational disks add more latency here) which is way too much for such a replacement.

Besides, there also is room for runtime PM in the Android framework, because it needs to suspend certain devices without freezing processes, for example.

The freezing of processes is the most important difference to me. Runtime PM works with the assumption that processes are not frozen (hence the name), but arguably energy savings you can get without going behind that point are naturally limited.

Quoted 8 lines
Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I'm not sure. Why _exactly_ would you need that?

Quoted 11 lines

I think there needs to be more discussion on the indended usage of suspend blockers by drivers/subsystems, especially those PM aware drivers and subsystems already doing runtime PM with constraints etc.

Quoted 7 lines
Quoted 6 lines

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

Quoted 7 lines
Quoted 1 line

There's definite work to be done here, yes.

And I've admitted this to be the only compelling reason for opportunistic suspend so far.

But the driver/subsystem implications of opportunistic suspend still need some fleshing out IMO.

At the moment, if you're not on Android, there are none.

Thanks,
Rafael

#234 lore raw
Quoted 32 lines · Rafael J. Wysocki
Quoted 21 lines · Kevin Hilman
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Quoted 8 lines
Quoted 3 lines

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Exactly.

Quoted 7 lines

With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Guys, please.

Quoted 8 lines

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

However, there are situations in which runtime PM is clearly insufficient. The idea behind runtime PM is that subsystems and device drivers will know when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

s/can/can't/; s/reach/go/

Rafael

#235 lore raw
In reply to Rafael J. Wysocki
Quoted 32 lines · Rafael J. Wysocki
Quoted 21 lines · Kevin Hilman
Quoted 8 lines · Mark Brown
Quoted 6 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling. I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

Quoted 8 lines
Quoted 3 lines

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Exactly.

Quoted 7 lines

With runtime PM, there is flexibility in choosing the lowest power state at the device/subsystem level, based on activity, timeouts, bitrate, dependencies, latency/throughput constraints, etc.

With opportunistic suspend, all of this flexibility is gone, and the device/subsystem is told to go into the lowest power, highest latency state, period.

Guys, please.

Quoted 8 lines

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

However, there are situations in which runtime PM is clearly insufficient. The idea behind runtime PM is that subsystems and device drivers will know when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

s/can/can't/; s/reach/go/

Rafael

#236 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman

Mark Brown <[email protected]> writes:

Guys, please.

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.

Quoted 4 lines

when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I'm not sure. Why _exactly_ would you need that?

The use case that causes serious issues with this at the minute in the domains I work is this:

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.

Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

#237 lore raw
Quoted 17 lines · Mark Brown
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman

Mark Brown <[email protected]> writes:

Guys, please.

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.

Quoted 4 lines

when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

Quoted 4 lines

Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.

Evidently, the Android developers had a problem with that. Of course, you can argue that they didn't consider using runtime PM for this purpose, but the real question is how much time it would take to achieve the same level of energy saving using runtime PM without opportunistic suspend.

Quoted 14 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I'm not sure. Why _exactly_ would you need that?

The use case that causes serious issues with this at the minute in the domains I work is this:

Quoted 12 lines

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.

In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.

Quoted 8 lines

Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas.

My understanding is that on Android suspend blockers are used for this purpose.

Quoted 9 lines

I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.

What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).

Rafael

#238 lore raw
Quoted 12 lines · Rafael J. Wysocki
Quoted 5 lines

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Suspend really is a sledgehammer thing.  Either you suspend the whole system or you don't suspend at all.  You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it.  If you want power savings while some parts of the system are active, use runtime PM for that.

Quoted 5 lines

What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).

We actually do use opportunistic suspend for cases like this on Android today. It mostly comes down to a question of latency for return from full suspend. For example:

Some MSM7201 based devices typically resume from power collapse in 3-5ms, but absolute worst case (because the L1 radio services are higher priority than the wake-the-apps-cpu services) is ~90ms. On these devices we hold a suspend_blocker while playing audio. Before discovery of this we went into full suspend while playing audio which worked fine, but in certain network conditions we would drop buffers if we could not wake fast enough.

So, it's somewhat system dependent, but it can be very helpful in a lot of cases.

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

#239 lore raw
In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 5 lines

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Suspend really is a sledgehammer thing.  Either you suspend the whole system or you don't suspend at all.  You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it.  If you want power savings while some parts of the system are active, use runtime PM for that.

Quoted 5 lines

What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).

We actually do use opportunistic suspend for cases like this on Android today. It mostly comes down to a question of latency for return from full suspend. For example:

Some MSM7201 based devices typically resume from power collapse in 3-5ms, but absolute worst case (because the L1 radio services are higher priority than the wake-the-apps-cpu services) is ~90ms. On these devices we hold a suspend_blocker while playing audio. Before discovery of this we went into full suspend while playing audio which worked fine, but in certain network conditions we would drop buffers if we could not wake fast enough.

So, it's somewhat system dependent, but it can be very helpful in a lot of cases.

Brian

#240 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,

In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.

That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.

Honestly I don't think that's a very good solution for actual systems, though. A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.

Quoted 10 lines
Quoted 4 lines

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.

On the one hand that's the answer that works well with the existing Linux design here so great. On the other hand as discussed above that doesn't match so well with user expectations.

Quoted 5 lines

What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).

Remember that even in your full system suspend the system is not actually fully idle - the baseband is still sitting there looking after itself, keeping the phone on the network. The only difference between on call and off call from the point of view of the Linux system is that there is an active audio path which happens to have been set up by the Linux system.

#241 lore raw
Quoted 15 lines · Mark Brown
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,

In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.

That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.

Quoted 7 lines

Honestly I don't think that's a very good solution for actual systems, though.  A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.

Yup. And that's exactly what happens on the platforms we've shipped on so far -- the apps side of the world fully suspends while in a voice call. Some events (prox sensor, buttons, modem sending a state notification) will wake it up, of course.

I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.

The suspend_block system gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).

Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use suspend_block or not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsolete suspend_blockers, awesome, we remove 'em.

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

#242 lore raw
In reply to Mark Brown
Quoted 15 lines · Mark Brown
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,

In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.

That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.

Quoted 7 lines

Honestly I don't think that's a very good solution for actual systems, though.  A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.

Yup. And that's exactly what happens on the platforms we've shipped on so far -- the apps side of the world fully suspends while in a voice call. Some events (prox sensor, buttons, modem sending a state notification) will wake it up, of course.

I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.

The suspend_block system gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).

Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use suspend_block or not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsolete suspend_blockers, awesome, we remove 'em.

Brian

#243 lore raw
Quoted 5 lines · Brian Swetland

I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.

Yup, that'd be good - even with the AP/CP/CODEC SoCs like the MSM devices we really need to get ASoC integration since systems are being built hanging external components such as speaker drivers off the line outputs, and some of those have registers so really do benefit from the sequencing, automated PM and so on that ASoC offers.

There was some work on MSM ASoC support posted last year back but there were a number of review issues with it. Daniel Walker also talked about submitting stuff just before Christmas, quite possibly independently of the other work which looked like a community effort, but I've not seen anything through from that yet.

Quoted 8 lines

The suspend_block system gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).

Quoted 6 lines

Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use suspend_block or not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsolete suspend_blockers, awesome, we remove 'em.

Like I've said a few times here I broadly agree with your goals - they seem to be a reasonable solution to the engineering problems we face presently, even though they're not where we actually want to be. What I do miss from the current proposal is more consideration of how things that do need to ignore the suspend should integrate.

If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.

This hasn't been a pressing issue while the Android code is out of tree since we can just say it's an out of tree patch that has a different design approach to current mainline and it's fairly straightforward for users to introduce suitable system-specific changes. Once it's mainline and part of the standard Linux PM toolkit then obviously subsystems and drivers need to support opportunistic suspend properly in mainline.

#244 lore raw
In reply to Brian Swetland
Quoted 5 lines · Brian Swetland

I haven't spent much time looking at alsa/asoc yet, but it's on my list for 2010 -- I'm hoping to migrate the very simple audio drivers I wrote for the msm platform originally to actually be alsa drivers as part of the general "try to use existing interfaces if they fit" plan we've been working toward.

Yup, that'd be good - even with the AP/CP/CODEC SoCs like the MSM devices we really need to get ASoC integration since systems are being built hanging external components such as speaker drivers off the line outputs, and some of those have registers so really do benefit from the sequencing, automated PM and so on that ASoC offers.

There was some work on MSM ASoC support posted last year back but there were a number of review issues with it. Daniel Walker also talked about submitting stuff just before Christmas, quite possibly independently of the other work which looked like a community effort, but I've not seen anything through from that yet.

Quoted 8 lines

The suspend_block system gets us what we need today (well what we needed three years ago too!) to ship and hit reasonable power targets on a number of platforms. There's been a lot of various handwaving about "android kernel forks" and what have you, but here we are again, trying to work out perhaps the only "new subsystem" type change that our driver code depends on (almost all other contentious stuff is self contained and you can take or leave it).

Quoted 6 lines

Our hope here is to get something out there in the near term so that the various drivers we maintain would "just work" in mainline (your choice of if you use suspend_block or not -- it's designed to be an option) and we can move forward. If in the future runtime power management or other systems completely obsolete suspend_blockers, awesome, we remove 'em.

Like I've said a few times here I broadly agree with your goals - they seem to be a reasonable solution to the engineering problems we face presently, even though they're not where we actually want to be. What I do miss from the current proposal is more consideration of how things that do need to ignore the suspend should integrate.

If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.

This hasn't been a pressing issue while the Android code is out of tree since we can just say it's an out of tree patch that has a different design approach to current mainline and it's fairly straightforward for users to introduce suitable system-specific changes. Once it's mainline and part of the standard Linux PM toolkit then obviously subsystems and drivers need to support opportunistic suspend properly in mainline.

#245 lore raw
Quoted 9 lines · Mark Brown

If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.

We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.

Signature · 1 line
Matthew Garrett | [email protected]
#246 lore raw
In reply to Mark Brown
Quoted 9 lines · Mark Brown

If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.

We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.

Signature · 1 line
Matthew Garrett | [email protected]
#247 lore raw
Quoted 12 lines · Matthew Garrett
Quoted 9 lines · Mark Brown

If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.

Quoted 7 lines

We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.

This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.

Alan Stern

#248 lore raw
In reply to Matthew Garrett
Quoted 12 lines · Matthew Garrett
Quoted 9 lines · Mark Brown

If the conclusion is that we don't have anything generic within the kernel then it'd be good to at least have this explicitly spelled out so that we're clear what everyone thinks is going on here and how things are supposed to work. At the minute it doesn't feel like we've had the discussion so we could end up working at cross purposes. I don't want to end up in the situation where I have to work around the APIs I'm using without the relevant maintainers having sight of that since that not only am I likely to be missing some existing solution to the problem but is also prone to causing problems maintaining the underlying API.

Quoted 7 lines

We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.

This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.

Alan Stern

#249 lore raw
Quoted 8 lines · Alan Stern

This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

Yeah, ok. We probably do need to figure this out.

(Cc:ing Rebecca to see how this got handled on Droid)

The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.

Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?

Signature · 1 line
Matthew Garrett | [email protected]
#250 lore raw
In reply to Alan Stern
Quoted 8 lines · Alan Stern

This particular question could use a little more discussion. I'm interested to know, for example, under what conditions you would or would not want to shut down an autonomous codec while going into system suspend on a cell phone.

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

Yeah, ok. We probably do need to figure this out.

(Cc:ing Rebecca to see how this got handled on Droid)

The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.

Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?

Signature · 1 line
Matthew Garrett | [email protected]
#251 lore raw
Quoted 17 lines · Matthew Garrett
Quoted 3 lines

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

Yeah, ok. We probably do need to figure this out.

(Cc:ing Rebecca to see how this got handled on Droid)

The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.

Quoted 5 lines

Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

Does it know when a call is in progress?

Does Android use forced suspends?

If it does, are they supposed to shut down the codec?

Alan Stern

#252 lore raw
In reply to Matthew Garrett
Quoted 17 lines · Matthew Garrett
Quoted 3 lines

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

Yeah, ok. We probably do need to figure this out.

(Cc:ing Rebecca to see how this got handled on Droid)

The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.

Quoted 5 lines

Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

Does it know when a call is in progress?

Does Android use forced suspends?

If it does, are they supposed to shut down the codec?

Alan Stern

#253 lore raw
Quoted 4 lines · Alan Stern

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

The latter is obviously preferable...

Quoted 1 line

Does it know when a call is in progress?

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Quoted 1 line

Does Android use forced suspends?

No.

Signature · 1 line
Matthew Garrett | [email protected]
#254 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

The latter is obviously preferable...

Quoted 1 line

Does it know when a call is in progress?

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Quoted 1 line

Does Android use forced suspends?

No.

Signature · 1 line
Matthew Garrett | [email protected]
#255 lore raw
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Alan Stern

Does it know when a call is in progress?

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Yes, you can providing we extract a bit more information from the machine drivers and/or userspace - we already do our power management based on paths. The implementation I'd do here is to provide a facility for marking some of the path endpoints as suspend insensitive then on suspend leave those endpoints in their current state, force the other endpoints off temporarily and re-run the standard power checks.

One thing I'll need to have a bit of a think about is if we need to provide the ability to offer control to userspace for the suspend state of path endpoints separately to their runtime state; I suspect the answer is yes.

#256 lore raw
In reply to Matthew Garrett
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Alan Stern

Does it know when a call is in progress?

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Yes, you can providing we extract a bit more information from the machine drivers and/or userspace - we already do our power management based on paths. The implementation I'd do here is to provide a facility for marking some of the path endpoints as suspend insensitive then on suspend leave those endpoints in their current state, force the other endpoints off temporarily and re-run the standard power checks.

One thing I'll need to have a bit of a think about is if we need to provide the ability to offer control to userspace for the suspend state of path endpoints separately to their runtime state; I suspect the answer is yes.

#257 lore raw

Hi Mark,

I confess I've completely lost track of (a) what problem you are trying to solve, and (b) how this might relate to some change that you'd like to see in the suspend block API. Could you do a quick summary and recap? I've gone over the entire thread, and it's still not clear what change you're advocating for in suspend blockers.

Thanks, regards,

- Ted

Quoted 24 lines · Mark Brown
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Alan Stern

Does it know when a call is in progress?

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Yes, you can providing we extract a bit more information from the machine drivers and/or userspace - we already do our power management based on paths. The implementation I'd do here is to provide a facility for marking some of the path endpoints as suspend insensitive then on suspend leave those endpoints in their current state, force the other endpoints off temporarily and re-run the standard power checks.

One thing I'll need to have a bit of a think about is if we need to provide the ability to offer control to userspace for the suspend state of path endpoints separately to their runtime state; I suspect the answer is yes.
--
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/

#258 lore raw
In reply to Mark Brown

Hi Mark,

I confess I've completely lost track of (a) what problem you are trying to solve, and (b) how this might relate to some change that you'd like to see in the suspend block API. Could you do a quick summary and recap? I've gone over the entire thread, and it's still not clear what change you're advocating for in suspend blockers.

Thanks, regards,

- Ted

Quoted 24 lines · Mark Brown
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Alan Stern

Does it know when a call is in progress?

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Yes, you can providing we extract a bit more information from the machine drivers and/or userspace - we already do our power management based on paths. The implementation I'd do here is to provide a facility for marking some of the path endpoints as suspend insensitive then on suspend leave those endpoints in their current state, force the other endpoints off temporarily and re-run the standard power checks.

One thing I'll need to have a bit of a think about is if we need to provide the ability to offer control to userspace for the suspend state of path endpoints separately to their runtime state; I suspect the answer is yes.
--
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/

#259 lore raw
Quoted 5 lines · On Wed, May 05, 2010 at 03:55:34PM -0400, [email protected] wrote:

I confess I've completely lost track of (a) what problem you are trying to solve, and (b) how this might relate to some change that you'd like to see in the suspend block API. Could you do a quick summary and recap? I've gone over the entire thread, and it's still not clear what change you're advocating for in suspend blockers.

The issue isn't suspend blockers, it's the opportunistic suspend stuff that goes along with them. When that is in use the system suspends vastly more aggressively, including in situations where a runtime PM based approach like mainline had been adopting would not suspend since some devices still need to be active, the classic case being keeping the audio subsystem and baseband live when in a phone call. This problem did not appear to have been considered as things stood.

I'm not really advocating a change in what's there. What I'm looking for is some sort of agreement as to how subsystems and drivers that need to not act on suspend requests from the core in these situations should do that. If there is a generic solution it'd probably be an additional mostly orthogonal interface rather than a change to what's being proposed here.

What we look like we're converging on is a subsystem/driver local solution since it doesn't look like a terribly widespread problem. That's totally OK, it's just that as I have said I don't want to go off and do that without the general PM community being aware of it so we avoid anyone running into nasty surprises further down the line.

#260 lore raw
Quoted 23 lines · Mark Brown
Quoted 5 lines · On Wed, May 05, 2010 at 03:55:34PM -0400, [email protected] wrote:

I confess I've completely lost track of (a) what problem you are trying to solve, and (b) how this might relate to some change that you'd like to see in the suspend block API. Could you do a quick summary and recap? I've gone over the entire thread, and it's still not clear what change you're advocating for in suspend blockers.

The issue isn't suspend blockers, it's the opportunistic suspend stuff that goes along with them. When that is in use the system suspends vastly more aggressively, including in situations where a runtime PM based approach like mainline had been adopting would not suspend since some devices still need to be active, the classic case being keeping the audio subsystem and baseband live when in a phone call. This problem did not appear to have been considered as things stood.

I'm not really advocating a change in what's there. What I'm looking for is some sort of agreement as to how subsystems and drivers that need to not act on suspend requests from the core in these situations should do that. If there is a generic solution it'd probably be an additional mostly orthogonal interface rather than a change to what's being proposed here.

Quoted 5 lines

What we look like we're converging on is a subsystem/driver local solution since it doesn't look like a terribly widespread problem. That's totally OK, it's just that as I have said I don't want to go off and do that without the general PM community being aware of it so we avoid anyone running into nasty surprises further down the line.

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Rafael

#261 lore raw
Quoted 4 lines · Rafael J. Wysocki

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Yes, though I think I'd be inclined to treat the problem orthogonally to opportunistic suspend to allow more flexibility in use and since treating it as part of opportunistic suspend would imply that there's some meaningful difference between the end result of that and a manual suspend which AIUI there isn't.

#262 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Yes, though I think I'd be inclined to treat the problem orthogonally to opportunistic suspend to allow more flexibility in use and since treating it as part of opportunistic suspend would imply that there's some meaningful difference between the end result of that and a manual suspend which AIUI there isn't.

#263 lore raw
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rafael J. Wysocki

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Quoted 5 lines

Yes, though I think I'd be inclined to treat the problem orthogonally to opportunistic suspend to allow more flexibility in use and since treating it as part of opportunistic suspend would imply that there's some meaningful difference between the end result of that and a manual suspend which AIUI there isn't.

I'd agree with this. This is one of the reasons I haven't felt opportunistic suspend is a big departure from other work here -- there are always some cases in which drivers will need to keep external resources active even when suspended. Also, as I mentioned earlier, we (Android at least, but hopefully this is non-controversial) would always like drivers to put everything in the lowest possible power state they can get away with. Every little savings adds up.

Brian

#264 lore raw
In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rafael J. Wysocki

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Quoted 5 lines

Yes, though I think I'd be inclined to treat the problem orthogonally to opportunistic suspend to allow more flexibility in use and since treating it as part of opportunistic suspend would imply that there's some meaningful difference between the end result of that and a manual suspend which AIUI there isn't.

I'd agree with this. This is one of the reasons I haven't felt opportunistic suspend is a big departure from other work here -- there are always some cases in which drivers will need to keep external resources active even when suspended. Also, as I mentioned earlier, we (Android at least, but hopefully this is non-controversial) would always like drivers to put everything in the lowest possible power state they can get away with. Every little savings adds up.

Brian

#265 lore raw
In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rafael J. Wysocki

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Quoted 5 lines

Yes, though I think I'd be inclined to treat the problem orthogonally to opportunistic suspend to allow more flexibility in use and since treating it as part of opportunistic suspend would imply that there's some meaningful difference between the end result of that and a manual suspend which AIUI there isn't.

No, there's no such difference.

So, gnerenally, we may need a mechanism to specify which components of the system need to stay powered while the whole system is suspended (in addition to wakeup devices, that is).

That certainly I can agree with.

I'm not sure, however, in what way this is relevant to the $subject patchset.

Rafael

#266 lore raw
Quoted 7 lines · Rafael J. Wysocki

So, gnerenally, we may need a mechanism to specify which components of the system need to stay powered while the whole system is suspended (in addition to wakeup devices, that is).

That certainly I can agree with.

I'm not sure, however, in what way this is relevant to the $subject patchset.

The patch set essentially makes using a full system suspend as the lowest power state for runtime PM part of the standard Linux power management toolkit which means that it's no longer clear as it used to be that suspend is an instruction to cease all activity and go into a minimal power state if the device is not a wake source. In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones. We should therefore have some idea how this and any other affected areas are supposed to work.

As I said in my reply to Ted earlier I think we may actually be converging on not worrying too much about it at the global level and doing subsystem specific things to discover and handle affected cases, at least for the time being. Ideally we'd have something standard to hook into but no subsystems apart from audio have actually been identified as being affected so it's not clear to me that a general solution is going to be worth the effort, if there's no actual users it may just confuse people by adding yet more power managment stuff to learn.

#267 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki

So, gnerenally, we may need a mechanism to specify which components of the system need to stay powered while the whole system is suspended (in addition to wakeup devices, that is).

That certainly I can agree with.

I'm not sure, however, in what way this is relevant to the $subject patchset.

The patch set essentially makes using a full system suspend as the lowest power state for runtime PM part of the standard Linux power management toolkit which means that it's no longer clear as it used to be that suspend is an instruction to cease all activity and go into a minimal power state if the device is not a wake source. In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones. We should therefore have some idea how this and any other affected areas are supposed to work.

As I said in my reply to Ted earlier I think we may actually be converging on not worrying too much about it at the global level and doing subsystem specific things to discover and handle affected cases, at least for the time being. Ideally we'd have something standard to hook into but no subsystems apart from audio have actually been identified as being affected so it's not clear to me that a general solution is going to be worth the effort, if there's no actual users it may just confuse people by adding yet more power managment stuff to learn.

#268 lore raw
Quoted 8 lines · Mark Brown
Quoted 5 lines · Rafael J. Wysocki

So, gnerenally, we may need a mechanism to specify which components of the system need to stay powered while the whole system is suspended (in addition to wakeup devices, that is).

That certainly I can agree with.

Quoted 7 lines
Quoted 1 line

I'm not sure, however, in what way this is relevant to the $subject patchset.

The patch set essentially makes using a full system suspend as the lowest power state for runtime PM part of the standard Linux power management toolkit which means that it's no longer clear as it used to be that suspend is an instruction to cease all activity and go into a minimal power state if the device is not a wake source.

I don't see why, really. This patchset doesn't change the meaning of suspend at all, it only changes the way in which suspend is triggered (if specifically set up that way). Even without the patchset you may implement a power manager in user space that will suspend the system whenever it thinks it's idle.

Quoted 5 lines

In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones.

You said that there's no fundamental difference between manual and opportunistic suspend. It only matters what _you_ are going to use suspend for. I agree that at the moment it's not suitable for aggressive power management in phones because of the audio problem, but that applies to "manual" as well as to "opportunistic" suspend.

You're saying that suspend is not suitable for one particular purpose in its current form, which is entirely correct, but that doesn't imply that the patchset is wrong.

Rafael

#269 lore raw
Quoted 3 lines · Rafael J. Wysocki

set up that way). Even without the patchset you may implement a power manager in user space that will suspend the system whenever it thinks it's idle.

Clearly, but...

Quoted 8 lines · Mark Brown
Quoted 6 lines

In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones.

Quoted 5 lines

You said that there's no fundamental difference between manual and opportunistic suspend. It only matters what _you_ are going to use suspend for. I agree that at the moment it's not suitable for aggressive power management in phones because of the audio problem, but that applies to "manual" as well as to "opportunistic" suspend.

...on the other hand there's exactly one existing application for this, and that's the one that's most likely to run into problems since it's a phone OS and aggressive power management is pretty important for phones.

Merging a feature into mainline makes it much more something which one would expect to play nicely with the rest of the kernel - if it's something that isn't part of the standard kernel or userspaces it's much less surprising that additional changes may be required to produce a well integrated system.

Quoted 3 lines

You're saying that suspend is not suitable for one particular purpose in its current form, which is entirely correct, but that doesn't imply that the patchset is wrong.

As I keep saying I agree that merging this is reasonable given the additional power savings it brings in practical systems today. As I also keep saying I do want to have some understanding about what the story is for dealing with the problems so that people can easily use this feature out of the box.

Like I say, my current impression is that the best approach is for affected subsystems or drivers to implement a custom solution - does that match your understanding and that of the other PM maintainers?

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

set up that way). Even without the patchset you may implement a power manager in user space that will suspend the system whenever it thinks it's idle.

Clearly, but...

Quoted 8 lines · Mark Brown
Quoted 6 lines

In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones.

Quoted 5 lines

You said that there's no fundamental difference between manual and opportunistic suspend. It only matters what _you_ are going to use suspend for. I agree that at the moment it's not suitable for aggressive power management in phones because of the audio problem, but that applies to "manual" as well as to "opportunistic" suspend.

...on the other hand there's exactly one existing application for this, and that's the one that's most likely to run into problems since it's a phone OS and aggressive power management is pretty important for phones.

Merging a feature into mainline makes it much more something which one would expect to play nicely with the rest of the kernel - if it's something that isn't part of the standard kernel or userspaces it's much less surprising that additional changes may be required to produce a well integrated system.

Quoted 3 lines

You're saying that suspend is not suitable for one particular purpose in its current form, which is entirely correct, but that doesn't imply that the patchset is wrong.

As I keep saying I agree that merging this is reasonable given the additional power savings it brings in practical systems today. As I also keep saying I do want to have some understanding about what the story is for dealing with the problems so that people can easily use this feature out of the box.

Like I say, my current impression is that the best approach is for affected subsystems or drivers to implement a custom solution - does that match your understanding and that of the other PM maintainers?

#271 lore raw
Quoted 42 lines · Mark Brown
Quoted 3 lines · Rafael J. Wysocki

set up that way). Even without the patchset you may implement a power manager in user space that will suspend the system whenever it thinks it's idle.

Clearly, but...

Quoted 8 lines · Mark Brown
Quoted 6 lines

In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones.

Quoted 5 lines

You said that there's no fundamental difference between manual and opportunistic suspend. It only matters what _you_ are going to use suspend for. I agree that at the moment it's not suitable for aggressive power management in phones because of the audio problem, but that applies to "manual" as well as to "opportunistic" suspend.

...on the other hand there's exactly one existing application for this, and that's the one that's most likely to run into problems since it's a phone OS and aggressive power management is pretty important for phones.

Merging a feature into mainline makes it much more something which one would expect to play nicely with the rest of the kernel - if it's something that isn't part of the standard kernel or userspaces it's much less surprising that additional changes may be required to produce a well integrated system.

Quoted 3 lines

You're saying that suspend is not suitable for one particular purpose in its current form, which is entirely correct, but that doesn't imply that the patchset is wrong.

As I keep saying I agree that merging this is reasonable given the additional power savings it brings in practical systems today. As I also keep saying I do want to have some understanding about what the story is for dealing with the problems so that people can easily use this feature out of the box.

Quoted 3 lines

Like I say, my current impression is that the best approach is for affected subsystems or drivers to implement a custom solution - does that match your understanding and that of the other PM maintainers?

I agree that this appears to be the best approach for the time being, although I can only speak for myself.

Rafael

#272 lore raw
In reply to Mark Brown
Quoted 42 lines · Mark Brown
Quoted 3 lines · Rafael J. Wysocki

set up that way). Even without the patchset you may implement a power manager in user space that will suspend the system whenever it thinks it's idle.

Clearly, but...

Quoted 8 lines · Mark Brown
Quoted 6 lines

In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones.

Quoted 5 lines

You said that there's no fundamental difference between manual and opportunistic suspend. It only matters what _you_ are going to use suspend for. I agree that at the moment it's not suitable for aggressive power management in phones because of the audio problem, but that applies to "manual" as well as to "opportunistic" suspend.

...on the other hand there's exactly one existing application for this, and that's the one that's most likely to run into problems since it's a phone OS and aggressive power management is pretty important for phones.

Merging a feature into mainline makes it much more something which one would expect to play nicely with the rest of the kernel - if it's something that isn't part of the standard kernel or userspaces it's much less surprising that additional changes may be required to produce a well integrated system.

Quoted 3 lines

You're saying that suspend is not suitable for one particular purpose in its current form, which is entirely correct, but that doesn't imply that the patchset is wrong.

As I keep saying I agree that merging this is reasonable given the additional power savings it brings in practical systems today. As I also keep saying I do want to have some understanding about what the story is for dealing with the problems so that people can easily use this feature out of the box.

Quoted 3 lines

Like I say, my current impression is that the best approach is for affected subsystems or drivers to implement a custom solution - does that match your understanding and that of the other PM maintainers?

I agree that this appears to be the best approach for the time being, although I can only speak for myself.

Rafael

#273 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 5 lines · Rafael J. Wysocki

So, gnerenally, we may need a mechanism to specify which components of the system need to stay powered while the whole system is suspended (in addition to wakeup devices, that is).

That certainly I can agree with.

Quoted 7 lines
Quoted 1 line

I'm not sure, however, in what way this is relevant to the $subject patchset.

The patch set essentially makes using a full system suspend as the lowest power state for runtime PM part of the standard Linux power management toolkit which means that it's no longer clear as it used to be that suspend is an instruction to cease all activity and go into a minimal power state if the device is not a wake source.

I don't see why, really. This patchset doesn't change the meaning of suspend at all, it only changes the way in which suspend is triggered (if specifically set up that way). Even without the patchset you may implement a power manager in user space that will suspend the system whenever it thinks it's idle.

Quoted 5 lines

In the primary existing application this change interoperates very poorly with at least the current audio subsystem since that handles suspend by ceasing all activity and powering as much as it can off, which is sensible for manual only suspends but highly undesirable for opportunistic suspend in phones.

You said that there's no fundamental difference between manual and opportunistic suspend. It only matters what _you_ are going to use suspend for. I agree that at the moment it's not suitable for aggressive power management in phones because of the audio problem, but that applies to "manual" as well as to "opportunistic" suspend.

You're saying that suspend is not suitable for one particular purpose in its current form, which is entirely correct, but that doesn't imply that the patchset is wrong.

Rafael

#274 lore raw
In reply to Mark Brown
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rafael J. Wysocki

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Quoted 5 lines

Yes, though I think I'd be inclined to treat the problem orthogonally to opportunistic suspend to allow more flexibility in use and since treating it as part of opportunistic suspend would imply that there's some meaningful difference between the end result of that and a manual suspend which AIUI there isn't.

No, there's no such difference.

So, gnerenally, we may need a mechanism to specify which components of the system need to stay powered while the whole system is suspended (in addition to wakeup devices, that is).

That certainly I can agree with.

I'm not sure, however, in what way this is relevant to the $subject patchset.

Rafael

#275 lore raw
In reply to Mark Brown
Quoted 23 lines · Mark Brown
Quoted 5 lines · On Wed, May 05, 2010 at 03:55:34PM -0400, [email protected] wrote:

I confess I've completely lost track of (a) what problem you are trying to solve, and (b) how this might relate to some change that you'd like to see in the suspend block API. Could you do a quick summary and recap? I've gone over the entire thread, and it's still not clear what change you're advocating for in suspend blockers.

The issue isn't suspend blockers, it's the opportunistic suspend stuff that goes along with them. When that is in use the system suspends vastly more aggressively, including in situations where a runtime PM based approach like mainline had been adopting would not suspend since some devices still need to be active, the classic case being keeping the audio subsystem and baseband live when in a phone call. This problem did not appear to have been considered as things stood.

I'm not really advocating a change in what's there. What I'm looking for is some sort of agreement as to how subsystems and drivers that need to not act on suspend requests from the core in these situations should do that. If there is a generic solution it'd probably be an additional mostly orthogonal interface rather than a change to what's being proposed here.

Quoted 5 lines

What we look like we're converging on is a subsystem/driver local solution since it doesn't look like a terribly widespread problem. That's totally OK, it's just that as I have said I don't want to go off and do that without the general PM community being aware of it so we avoid anyone running into nasty surprises further down the line.

To me, the above may be summarized that in your opinion some components of the system will generally need to stay powered when it's suspended opportunistically, so we need an interface to specify which components they are. Is that correct?

Rafael

#276 lore raw
In reply to Mark Brown
Quoted 10 lines · Mark Brown
Quoted 2 lines · Matthew Garrett

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Yes, you can providing we extract a bit more information from the machine drivers and/or userspace - we already do our power management based on paths. The implementation I'd do here is to provide a facility for marking some of the path endpoints as suspend insensitive then on suspend leave those endpoints in their current state, force the other endpoints off temporarily and re-run the standard power checks.

One thing that's been mentioned before is that some vendors can swap the kernel much more easily than they can swap userspace, with the added constraint that they have little control over the bootloader. So if there's a userspace interface, it may well also be helpful to provide a kernel hook to allow the platform setup code to configure things. But otherwise, I think that'd work for audio - the only question is whether we need it to be more generic.

Signature · 1 line
Matthew Garrett | [email protected]
#277 lore raw
In reply to Mark Brown
Quoted 10 lines · Mark Brown
Quoted 2 lines · Matthew Garrett

Perhaps you could infer that from the audio routing setup? I don't know enough about embedded codecs.

Yes, you can providing we extract a bit more information from the machine drivers and/or userspace - we already do our power management based on paths. The implementation I'd do here is to provide a facility for marking some of the path endpoints as suspend insensitive then on suspend leave those endpoints in their current state, force the other endpoints off temporarily and re-run the standard power checks.

One thing that's been mentioned before is that some vendors can swap the kernel much more easily than they can swap userspace, with the added constraint that they have little control over the bootloader. So if there's a userspace interface, it may well also be helpful to provide a kernel hook to allow the platform setup code to configure things. But otherwise, I think that'd work for audio - the only question is whether we need it to be more generic.

Signature · 1 line
Matthew Garrett | [email protected]
#278 lore raw
Quoted 5 lines · Matthew Garrett

One thing that's been mentioned before is that some vendors can swap the kernel much more easily than they can swap userspace, with the added constraint that they have little control over the bootloader. So if there's a userspace interface, it may well also be helpful to provide a kernel hook to allow the platform setup code to configure things. But

Oh, there's definitely going to be a platform-specific hook to configure things. The platform needs to specify how the devices that make up the audio subsystem are interconnected on the board, and that's done in kernel since it depends on the hardware and can potentially lead to physical damage if done incorrectly.

Quoted 2 lines

otherwise, I think that'd work for audio - the only question is whether we need it to be more generic.

Agreed.

#279 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

One thing that's been mentioned before is that some vendors can swap the kernel much more easily than they can swap userspace, with the added constraint that they have little control over the bootloader. So if there's a userspace interface, it may well also be helpful to provide a kernel hook to allow the platform setup code to configure things. But

Oh, there's definitely going to be a platform-specific hook to configure things. The platform needs to specify how the devices that make up the audio subsystem are interconnected on the board, and that's done in kernel since it depends on the hardware and can potentially lead to physical damage if done incorrectly.

Quoted 2 lines

otherwise, I think that'd work for audio - the only question is whether we need it to be more generic.

Agreed.

#280 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

I think for simplicity and maximum flexibility we should just ignore the reason for suspend here, if I'm adding support for this in the drivers the suspend reason is not going to be terribly useful and it makes the feature more widely useful should people come up with other applications.

Note that we already have advanced runtime PM for embedded audio which will drive modern CODECs into full off state when the device is idle anyway, independently of any suspend or runtime PM that the system does. Older CODECs need their bias levels maintaining but we can ignore the difference there from this point of view.

Quoted 1 line

Does it know when a call is in progress?

Not at present. This is relatively straightforward to add within ASoC, especially for analogue links, if not completely trivial. Digital basebands are a bit more fun but not insurmountable (and need cleaning up anyway, there's some ongoing work which should hit soon).

We currently drive everything into off state when we're told to suspend since it's the right thing to do for most non-phone devices. We'll still need to drive some of the system into an off state (eg, some of the drivers in the CPU) even when this is handled.

Quoted 1 line

Does Android use forced suspends?

Pass, but it's not been an issue users have raised with me - but then we can't tell why the suspend happens and need to handle opportunistic suspend anyway.

Quoted 1 line

If it does, are they supposed to shut down the codec?

I suspect it's a non-issue; if we're not actually using audio then ASoC will drive a modern CODEC into power off anyway as part of its runtime PM. However, I believe some non-Android phone stacks are doing something along that line.

#281 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

I think for simplicity and maximum flexibility we should just ignore the reason for suspend here, if I'm adding support for this in the drivers the suspend reason is not going to be terribly useful and it makes the feature more widely useful should people come up with other applications.

Note that we already have advanced runtime PM for embedded audio which will drive modern CODECs into full off state when the device is idle anyway, independently of any suspend or runtime PM that the system does. Older CODECs need their bias levels maintaining but we can ignore the difference there from this point of view.

Quoted 1 line

Does it know when a call is in progress?

Not at present. This is relatively straightforward to add within ASoC, especially for analogue links, if not completely trivial. Digital basebands are a bit more fun but not insurmountable (and need cleaning up anyway, there's some ongoing work which should hit soon).

We currently drive everything into off state when we're told to suspend since it's the right thing to do for most non-phone devices. We'll still need to drive some of the system into an off state (eg, some of the drivers in the CPU) even when this is handled.

Quoted 1 line

Does Android use forced suspends?

Pass, but it's not been an issue users have raised with me - but then we can't tell why the suspend happens and need to handle opportunistic suspend anyway.

Quoted 1 line

If it does, are they supposed to shut down the codec?

I suspect it's a non-issue; if we're not actually using audio then ASoC will drive a modern CODEC into power off anyway as part of its runtime PM. However, I believe some non-Android phone stacks are doing something along that line.

#282 lore raw
In reply to Alan Stern
Quoted 25 lines · Alan Stern
Quoted 17 lines · Matthew Garrett
Quoted 3 lines

Clearly if there's a call in progress you don't want to shut the codec down.  Are there any other circumstances?  Would they vary according to whether the suspend was forced or opportunistic?

Yeah, ok. We probably do need to figure this out.

(Cc:ing Rebecca to see how this got handled on Droid)

The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.

Quoted 5 lines

Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?

Quoted 6 lines

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

Does it know when a call is in progress?

From my point of view, the codec should be powered up while audio is playing and powered down when it's not -- that's the approach I've taken on MSM, regardless of suspend state. I don't view suspend as something that stops audio playback in progress. Sort of similar to how the modem doesn't power off down when the system is in suspend, etc.

In effect, we have followed a sort of runtime pm model of clocking/powering peripherals at the lowest possible level at all times, which is why I've never viewed suspend_block as somehow competing with runtime pm -- we always want all drivers/peripherals in the lowers power state. Sometimes the lowest power state possible is higher than "full suspend" (for example when we can't meet latency requirements on audio on 7201A) and suspend_blockers cover that case.

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

#283 lore raw
In reply to Alan Stern
Quoted 25 lines · Alan Stern
Quoted 17 lines · Matthew Garrett
Quoted 3 lines

Clearly if there's a call in progress you don't want to shut the codec down.  Are there any other circumstances?  Would they vary according to whether the suspend was forced or opportunistic?

Yeah, ok. We probably do need to figure this out.

(Cc:ing Rebecca to see how this got handled on Droid)

The current state of affairs is that a system suspend request is expected to put the device in as low a power state as possible given the required wakeup events. Runtime power management is expected to put the device in as low a power state as possible given its usage constraints. If opportunistic suspend does the former then it'll tear down devices that may be in use, but we don't have any real way to indicate usage constraints other than the phone app taking a wakelock - and that means leaving userspace running during calls, which seems excessive.

Quoted 5 lines

Mark's right in that the only case I can think of that's really relevant right now is the audio hardware, so the inelegant solution is that this is something that could be provided at the audio level. Is this something we want a generic solution for? If so, what should it look like?

Quoted 8 lines

Should the audio driver be smart enough to know that the codec needs to remain powered up during every opportunistic suspend?

Or only during opportunistic suspends while a call is in progress?

Does it know when a call is in progress?

From my point of view, the codec should be powered up while audio is

playing and powered down when it's not -- that's the approach I've taken on MSM, regardless of suspend state. I don't view suspend as something that stops audio playback in progress. Sort of similar to how the modem doesn't power off down when the system is in suspend, etc.

In effect, we have followed a sort of runtime pm model of clocking/powering peripherals at the lowest possible level at all times, which is why I've never viewed suspend_block as somehow competing with runtime pm -- we always want all drivers/peripherals in the lowers power state. Sometimes the lowest power state possible is higher than "full suspend" (for example when we can't meet latency requirements on audio on 7201A) and suspend_blockers cover that case.

Brian

#284 lore raw
Quoted 2 lines · Brian Swetland

From my point of view, the codec should be powered up while audio is playing and powered down when it's not -- that's the approach I've

This is what we've got already with Linux - we've had rather aggressive runtime PM for embedded audio as standard for years now. It's only very recently that mobile hardware has got to the point where you can actually totally kill the power without introducing problems but it's been getting pretty much as close as possible.

Quoted 4 lines

taken on MSM, regardless of suspend state. I don't view suspend as something that stops audio playback in progress. Sort of similar to how the modem doesn't power off down when the system is in suspend, etc.

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator. In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state. Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

Quoted 4 lines

In effect, we have followed a sort of runtime pm model of clocking/powering peripherals at the lowest possible level at all times, which is why I've never viewed suspend_block as somehow competing with runtime pm -- we always want all drivers/peripherals in

Right, and this will work well on systems like your current devices because the problem hardware is not directly visible to the AP (the actual audio hardware is hidden behind the DSP which functions as autonomously as the modem does) so it's not affected by the Linux suspend process in the first place. It causes confusion when the power for the audio device is managed by Linux since the opportunistic suspend will include suspending the audio device and so the code handling the suspend then has to decide what exactly it's being asked to do.

Quoted 3 lines

the lowers power state. Sometimes the lowest power state possible is higher than "full suspend" (for example when we can't meet latency requirements on audio on 7201A) and suspend_blockers cover that case.

In this situation there's no physical reason why the lower power state is not achievable so blocking the suspend would just waste power, it's just that our way of getting into it is creating some confusion.

#285 lore raw
In reply to Brian Swetland
Quoted 2 lines · Brian Swetland

From my point of view, the codec should be powered up while audio is playing and powered down when it's not -- that's the approach I've

This is what we've got already with Linux - we've had rather aggressive runtime PM for embedded audio as standard for years now. It's only very recently that mobile hardware has got to the point where you can actually totally kill the power without introducing problems but it's been getting pretty much as close as possible.

Quoted 4 lines

taken on MSM, regardless of suspend state. I don't view suspend as something that stops audio playback in progress. Sort of similar to how the modem doesn't power off down when the system is in suspend, etc.

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator. In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state. Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

Quoted 4 lines

In effect, we have followed a sort of runtime pm model of clocking/powering peripherals at the lowest possible level at all times, which is why I've never viewed suspend_block as somehow competing with runtime pm -- we always want all drivers/peripherals in

Right, and this will work well on systems like your current devices because the problem hardware is not directly visible to the AP (the actual audio hardware is hidden behind the DSP which functions as autonomously as the modem does) so it's not affected by the Linux suspend process in the first place. It causes confusion when the power for the audio device is managed by Linux since the opportunistic suspend will include suspending the audio device and so the code handling the suspend then has to decide what exactly it's being asked to do.

Quoted 3 lines

the lowers power state. Sometimes the lowest power state possible is higher than "full suspend" (for example when we can't meet latency requirements on audio on 7201A) and suspend_blockers cover that case.

In this situation there's no physical reason why the lower power state is not achievable so blocking the suspend would just waste power, it's just that our way of getting into it is creating some confusion.

#286 lore raw
Quoted 1 line · Mark Brown

On Wed, May 05, 2010 at 01:56:07PM -0700, Brian Swetland wrote:

...

Quoted 5 lines
Quoted 4 lines

taken on MSM, regardless of suspend state.  I don't view suspend as something that stops audio playback in progress.  Sort of similar to how the modem doesn't power off down when the system is in suspend, etc.

Quoted 9 lines

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator.  In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state.  Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

You can support both in the same driver in some cases (without a switch). If the hardware cannot wake the system when it needs more audio buffers, then the driver needs to block suspend while audio is playing. Since suspend blockers only block opportunistic suspend, the driver can also implement suspend to stop audio playback and it will only be called for forced suspend.

Signature · 1 line
Arve Hjønnevåg
#287 lore raw
In reply to Mark Brown
Quoted 1 line · Mark Brown

On Wed, May 05, 2010 at 01:56:07PM -0700, Brian Swetland wrote:

...

Quoted 5 lines
Quoted 4 lines

taken on MSM, regardless of suspend state.  I don't view suspend as something that stops audio playback in progress.  Sort of similar to how the modem doesn't power off down when the system is in suspend, etc.

Quoted 9 lines

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator.  In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state.  Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

You can support both in the same driver in some cases (without a switch). If the hardware cannot wake the system when it needs more audio buffers, then the driver needs to block suspend while audio is playing. Since suspend blockers only block opportunistic suspend, the driver can also implement suspend to stop audio playback and it will only be called for forced suspend.

Signature · 1 line
Arve Hjønnevåg
#288 lore raw
Quoted 11 lines · Arve Hjønnevåg

On Wed, May 5, 2010 at 4:40 PM, Mark Brown

Quoted 8 lines

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator.  In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state.  Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

Quoted 6 lines

You can support both in the same driver in some cases (without a switch). If the hardware cannot wake the system when it needs more audio buffers, then the driver needs to block suspend while audio is playing. Since suspend blockers only block opportunistic suspend, the driver can also implement suspend to stop audio playback and it will only be called for forced suspend.

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway. It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

#289 lore raw
In reply to Arve Hjønnevåg
Quoted 11 lines · Arve Hjønnevåg

On Wed, May 5, 2010 at 4:40 PM, Mark Brown

Quoted 8 lines

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator.  In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state.  Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

Quoted 6 lines

You can support both in the same driver in some cases (without a switch). If the hardware cannot wake the system when it needs more audio buffers, then the driver needs to block suspend while audio is playing. Since suspend blockers only block opportunistic suspend, the driver can also implement suspend to stop audio playback and it will only be called for forced suspend.

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway. It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

#290 lore raw

2010/5/7 Mark Brown <[email protected]>:

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

On Wed, May 5, 2010 at 4:40 PM, Mark Brown

Quoted 8 lines

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator.  In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state.  Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

Quoted 6 lines

You can support both in the same driver in some cases (without a switch). If the hardware cannot wake the system when it needs more audio buffers, then the driver needs to block suspend while audio is playing. Since suspend blockers only block opportunistic suspend, the driver can also implement suspend to stop audio playback and it will only be called for forced suspend.

Quoted 7 lines

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway.  It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

I was talking about audio from the AP. Why would you ever turn off another core's audio path on suspend?

Signature · 1 line
Arve Hjønnevåg
#291 lore raw
In reply to Mark Brown

2010/5/7 Mark Brown <[email protected]>:

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

On Wed, May 5, 2010 at 4:40 PM, Mark Brown

Quoted 8 lines

This really does depend heavily on system design and the intended function of the suspend on the part of the initiator.  In many systems suspend will remove sufficient power to stop audio running even if it were desired, and there's the idea with existing manually initiated suspends that the system should stop what it's doing and go into a low power, low responsiveness state.  Some systems will initiate a suspend with active audio paths (especially those to or from the AP) which they expect to be stopped.

Quoted 6 lines

You can support both in the same driver in some cases (without a switch). If the hardware cannot wake the system when it needs more audio buffers, then the driver needs to block suspend while audio is playing. Since suspend blockers only block opportunistic suspend, the driver can also implement suspend to stop audio playback and it will only be called for forced suspend.

Quoted 7 lines

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway.  It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

I was talking about audio from the AP. Why would you ever turn off another core's audio path on suspend?

Signature · 1 line
Arve Hjønnevåg
#292 lore raw
Quoted 11 lines · Arve Hjønnevåg

2010/5/7 Mark Brown <[email protected]>:

Quoted 6 lines

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway.  It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

I was talking about audio from the AP. Why would you ever turn off another core's audio path on suspend?

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this. As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

With a runtime PM approach this is trivial - we just turn off anything that isn't in use at the current time. I'll need to extend ASoC to add information about what to do on suspend to the existing power data.

#293 lore raw
In reply to Arve Hjønnevåg
Quoted 11 lines · Arve Hjønnevåg

2010/5/7 Mark Brown <[email protected]>:

Quoted 6 lines

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway.  It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

I was talking about audio from the AP. Why would you ever turn off another core's audio path on suspend?

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this. As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

With a runtime PM approach this is trivial - we just turn off anything that isn't in use at the current time. I'll need to extend ASoC to add information about what to do on suspend to the existing power data.

#294 lore raw
Quoted 10 lines · Mark Brown

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this. As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

This sounds like it may be something unique to your board/product. Or am I missing something?

One of the challenges with PM in the embedded world is that everybody seems to have slightly different assumptions, and hardware that doesn't behave the same way.

More than once this discussion has wandered off into the weeds wrt to whether this patch series is ready to be merged, since there are so many drivers blocked on it....

-- Ted

#295 lore raw
Quoted 2 lines · Theodore Tso

This sounds like it may be something unique to your board/product. Or am I missing something?

I suspect you're missing something here - I'm approaching this as one of the maintainers of the embedded audio subsystem for the kernel. I need to worry about any system running Linux which has an embedded style audio subsystem. The problem might be unique to audio, but I can't say that for certain.

Quoted 3 lines

One of the challenges with PM in the embedded world is that everybody seems to have slightly different assumptions, and hardware that doesn't behave the same way.

This isn't really a problem for audio - we've already got a subsystem which copes well with pretty much all systems and does runtime PM that's equivalent to suspending already, which is half the problem here. If we had less generalisation this would probably not have come up.

Quoted 3 lines

More than once this discussion has wandered off into the weeds wrt to whether this patch series is ready to be merged, since there are so many drivers blocked on it....

Once more, my main objective here has been to make sure that when this is merged we've got a joined up story about how people think this hangs together, which I think we have now. As I say now that we have that understanding I don't see any reason to block merge.

It's unfortunate that I only noticed that this was actually wakelocks very late in the day but I think I can get an implementation which handles paths that ignore suspends done quickly.

#296 lore raw
In reply to Theodore Tso
Quoted 2 lines · Theodore Tso

This sounds like it may be something unique to your board/product. Or am I missing something?

I suspect you're missing something here - I'm approaching this as one of the maintainers of the embedded audio subsystem for the kernel. I need to worry about any system running Linux which has an embedded style audio subsystem. The problem might be unique to audio, but I can't say that for certain.

Quoted 3 lines

One of the challenges with PM in the embedded world is that everybody seems to have slightly different assumptions, and hardware that doesn't behave the same way.

This isn't really a problem for audio - we've already got a subsystem which copes well with pretty much all systems and does runtime PM that's equivalent to suspending already, which is half the problem here. If we had less generalisation this would probably not have come up.

Quoted 3 lines

More than once this discussion has wandered off into the weeds wrt to whether this patch series is ready to be merged, since there are so many drivers blocked on it....

Once more, my main objective here has been to make sure that when this is merged we've got a joined up story about how people think this hangs together, which I think we have now. As I say now that we have that understanding I don't see any reason to block merge.

It's unfortunate that I only noticed that this was actually wakelocks very late in the day but I think I can get an implementation which handles paths that ignore suspends done quickly.

#297 lore raw
Quoted 24 lines · Mark Brown
Quoted 2 lines · Theodore Tso

This sounds like it may be something unique to your board/product.  Or am I missing something?

I suspect you're missing something here - I'm approaching this as one of the maintainers of the embedded audio subsystem for the kernel.  I need to worry about any system running Linux which has an embedded style audio subsystem.  The problem might be unique to audio, but I can't say that for certain.

Quoted 3 lines

One of the challenges with PM in the embedded world is that everybody seems to have slightly different assumptions, and hardware that doesn't behave the same way.

This isn't really a problem for audio - we've already got a subsystem which copes well with pretty much all systems and does runtime PM that's equivalent to suspending already, which is half the problem here.  If we had less generalisation this would probably not have come up.

Quoted 3 lines

More than once this discussion has wandered off into the weeds wrt to whether this patch series is ready to be merged, since there are so many drivers blocked on it....

Quoted 8 lines

Once more, my main objective here has been to make sure that when this is merged we've got a joined up story about how people think this hangs together, which I think we have now.  As I say now that we have that understanding I don't see any reason to block merge.

It's unfortunate that I only noticed that this was actually wakelocks very late in the day but I think I can get an implementation which handles paths that ignore suspends done quickly.

Do you mean an implementation of embedded linux audio or an implementation of suspend blockers "which handles paths that ignore suspends"? I assume you mean the former, but maybe I misunderstand.

We've done a lot of work around multicore SoCs where the baseband generally owns a lot of the audio routing and so on, but we do as general policy not disable audio, codecs, and amps while playback or record is underway. I suppose for environments more like a pc laptop where the expectation is the world stops when you close the lid a different policy would be preferable.

We typically fire up codecs and amps when playback starts (if they were off), and usually set a timer for a couple seconds after playback stops to spin them down (since you tend to have to delay while they're powering up to avoid pops, etc, and if the system just played a short sound there's a reasonable chance it'll follow that with another).

Apologies about the name confusion -- last year when we first started pushing these patches out there was much dislike for the name wakelock and after a lot of back and forth suspend_block ended up as the least hated of the suggested alternatives (I kinda like "wakelock" as a name, but maybe that's just brain rot after dealing with 'em for four years now).

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

#298 lore raw
In reply to Mark Brown
Quoted 24 lines · Mark Brown
Quoted 2 lines · Theodore Tso

This sounds like it may be something unique to your board/product.  Or am I missing something?

I suspect you're missing something here - I'm approaching this as one of the maintainers of the embedded audio subsystem for the kernel.  I need to worry about any system running Linux which has an embedded style audio subsystem.  The problem might be unique to audio, but I can't say that for certain.

Quoted 3 lines

One of the challenges with PM in the embedded world is that everybody seems to have slightly different assumptions, and hardware that doesn't behave the same way.

This isn't really a problem for audio - we've already got a subsystem which copes well with pretty much all systems and does runtime PM that's equivalent to suspending already, which is half the problem here.  If we had less generalisation this would probably not have come up.

Quoted 3 lines

More than once this discussion has wandered off into the weeds wrt to whether this patch series is ready to be merged, since there are so many drivers blocked on it....

Quoted 8 lines

Once more, my main objective here has been to make sure that when this is merged we've got a joined up story about how people think this hangs together, which I think we have now.  As I say now that we have that understanding I don't see any reason to block merge.

It's unfortunate that I only noticed that this was actually wakelocks very late in the day but I think I can get an implementation which handles paths that ignore suspends done quickly.

Do you mean an implementation of embedded linux audio or an implementation of suspend blockers "which handles paths that ignore suspends"? I assume you mean the former, but maybe I misunderstand.

We've done a lot of work around multicore SoCs where the baseband generally owns a lot of the audio routing and so on, but we do as general policy not disable audio, codecs, and amps while playback or record is underway. I suppose for environments more like a pc laptop where the expectation is the world stops when you close the lid a different policy would be preferable.

We typically fire up codecs and amps when playback starts (if they were off), and usually set a timer for a couple seconds after playback stops to spin them down (since you tend to have to delay while they're powering up to avoid pops, etc, and if the system just played a short sound there's a reasonable chance it'll follow that with another).

Apologies about the name confusion -- last year when we first started pushing these patches out there was much dislike for the name wakelock and after a lot of back and forth suspend_block ended up as the least hated of the suggested alternatives (I kinda like "wakelock" as a name, but maybe that's just brain rot after dealing with 'em for four years now).

Brian

#299 lore raw
Quoted 9 lines · Brian Swetland

On Fri, May 7, 2010 at 5:25 AM, Mark Brown

Quoted 3 lines

It's unfortunate that I only noticed that this was actually wakelocks very late in the day but I think I can get an implementation which handles paths that ignore suspends done quickly.

Do you mean an implementation of embedded linux audio or an implementation of suspend blockers "which handles paths that ignore suspends"? I assume you mean the former, but maybe I misunderstand.

I mean that I will extend the embedded audio subsystem that the kernel already has (ASoC, in sound/soc) to support ignoring suspends for some audio paths so that they can be kept up during suspend. This will be primarily intended for use with opportunistic suspend but not specific to it.

I have no intention of touching suspend blockers, except in that some of the drivers I'm responsible for should probably use suspend blockers for similar reasons to the other users you're merging but that's less urgent.

Quoted 2 lines

We've done a lot of work around multicore SoCs where the baseband generally owns a lot of the audio routing and so on,

Multicore isn't really the term here - obviously on something like the OMAP4 or the current nVidia devices you've got a multicore AP but may or may not have an integrated baseband. The distinction is down to how much visibility the AP has of the audio hardware, which is in general orthogonal to how the silicon is split and packaged.

Quoted 3 lines

but we do as
general policy not disable audio, codecs, and amps while playback or record is underway.

Yeah, I know. I have been keeping an eye on the Android stuff, though none of the audio side has been mainlined yet.

Quoted 3 lines

I suppose for environments more like a pc laptop
where the expectation is the world stops when you close the lid a different policy would be preferable.

Yes, quite. It all depends on what the intention of the user is when they do a suspend. Clearly if the suspend was initiated automatically because the system is apparently idle the intention is different to if it was initiated because the user performed some explicit action.

Quoted 5 lines

We typically fire up codecs and amps when playback starts (if they were off), and usually set a timer for a couple seconds after playback stops to spin them down (since you tend to have to delay while they're powering up to avoid pops, etc, and if the system just played a short sound there's a reasonable chance it'll follow that with another).

This is exactly what ASoC does - the two biggest wins it offers are that it allows reuse of the code specific to a given piece of silicon on all boards using that silicon and that it provides automatic runtime power management in the core by keeping track of which audio paths are live.

There is the slight wrinkle that you don't really want to *fully* power down devices that don't have ground referenced outputs since they take a relatively long time to bring their reference level up without audible artifacts in the output.

#300 lore raw
In reply to Brian Swetland
Quoted 9 lines · Brian Swetland

On Fri, May 7, 2010 at 5:25 AM, Mark Brown

Quoted 3 lines

It's unfortunate that I only noticed that this was actually wakelocks very late in the day but I think I can get an implementation which handles paths that ignore suspends done quickly.

Do you mean an implementation of embedded linux audio or an implementation of suspend blockers "which handles paths that ignore suspends"? I assume you mean the former, but maybe I misunderstand.

I mean that I will extend the embedded audio subsystem that the kernel already has (ASoC, in sound/soc) to support ignoring suspends for some audio paths so that they can be kept up during suspend. This will be primarily intended for use with opportunistic suspend but not specific to it.

I have no intention of touching suspend blockers, except in that some of the drivers I'm responsible for should probably use suspend blockers for similar reasons to the other users you're merging but that's less urgent.

Quoted 2 lines

We've done a lot of work around multicore SoCs where the baseband generally owns a lot of the audio routing and so on,

Multicore isn't really the term here - obviously on something like the OMAP4 or the current nVidia devices you've got a multicore AP but may or may not have an integrated baseband. The distinction is down to how much visibility the AP has of the audio hardware, which is in general orthogonal to how the silicon is split and packaged.

Quoted 3 lines

but we do as
general policy not disable audio, codecs, and amps while playback or record is underway.

Yeah, I know. I have been keeping an eye on the Android stuff, though none of the audio side has been mainlined yet.

Quoted 3 lines

I suppose for environments more like a pc laptop
where the expectation is the world stops when you close the lid a different policy would be preferable.

Yes, quite. It all depends on what the intention of the user is when they do a suspend. Clearly if the suspend was initiated automatically because the system is apparently idle the intention is different to if it was initiated because the user performed some explicit action.

Quoted 5 lines

We typically fire up codecs and amps when playback starts (if they were off), and usually set a timer for a couple seconds after playback stops to spin them down (since you tend to have to delay while they're powering up to avoid pops, etc, and if the system just played a short sound there's a reasonable chance it'll follow that with another).

This is exactly what ASoC does - the two biggest wins it offers are that it allows reuse of the code specific to a given piece of silicon on all boards using that silicon and that it provides automatic runtime power management in the core by keeping track of which audio paths are live.

There is the slight wrinkle that you don't really want to *fully* power down devices that don't have ground referenced outputs since they take a relatively long time to bring their reference level up without audible artifacts in the output.

#301 lore raw
Quoted 5 lines · Mark Brown

I mean that I will extend the embedded audio subsystem that the kernel already has (ASoC, in sound/soc) to support ignoring suspends for some audio paths so that they can be kept up during suspend. This will be primarily intended for use with opportunistic suspend but not specific to it.

Just for the record I've now done an implementation of this which should show up in -next when it's rebuilt and 2.6.35. It's not the most thoroughly tested code I've ever written but I'm fairly happy it'll do the right thing, especially for analogue basebands. The functionality needs to be explicitly requested by machine drivers so there should be no impact on systems using suspend in a more standard fashion.

This means that there should be even less of an issue merging this from an audio point of view.

#302 lore raw
In reply to Mark Brown
Quoted 5 lines · Mark Brown

I mean that I will extend the embedded audio subsystem that the kernel already has (ASoC, in sound/soc) to support ignoring suspends for some audio paths so that they can be kept up during suspend. This will be primarily intended for use with opportunistic suspend but not specific to it.

Just for the record I've now done an implementation of this which should show up in -next when it's rebuilt and 2.6.35. It's not the most thoroughly tested code I've ever written but I'm fairly happy it'll do the right thing, especially for analogue basebands. The functionality needs to be explicitly requested by machine drivers so there should be no impact on systems using suspend in a more standard fashion.

This means that there should be even less of an issue merging this from an audio point of view.

#303 lore raw
In reply to Mark Brown

2010/5/7 Mark Brown <[email protected]>:

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

2010/5/7 Mark Brown <[email protected]>:

Quoted 6 lines

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway.  It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

I was talking about audio from the AP. Why would you ever turn off another core's audio path on suspend?

Quoted 6 lines

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this.  As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that

Are you trying to use the same driver on systems that can support audio while suspend and on systems where this is impossible? If audio cannot work while suspended, supporting opportunistic suspend is easy. You block suspend while audio is active.

If the hardware does support some audio paths while suspended, I'll ask again, is there a reason to turn them off on suspend?

Quoted 8 lines

that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

With a runtime PM approach this is trivial - we just turn off anything that isn't in use at the current time.  I'll need to extend ASoC to add information about what to do on suspend to the existing power data.

OK, but is this at all related to opportunistic suspend?

Signature · 1 line
Arve Hjønnevåg
#304 lore raw
In reply to Mark Brown

2010/5/7 Mark Brown <[email protected]>:

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

2010/5/7 Mark Brown <[email protected]>:

Quoted 6 lines

As discussed elsewhere in the thread a suspend blocker is not desirable here - the AP is not doing anything useful on a voice call so blocking the suspend will just waste power unless runtime PM is good enough to mean opportunistic suspend isn't adding anything anyway.  It will avoid the immediate issue with loosing audio but it's not really what we want to happen.

I was talking about audio from the AP. Why would you ever turn off another core's audio path on suspend?

Quoted 6 lines

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this.  As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that

Are you trying to use the same driver on systems that can support audio while suspend and on systems where this is impossible? If audio cannot work while suspended, supporting opportunistic suspend is easy. You block suspend while audio is active.

If the hardware does support some audio paths while suspended, I'll ask again, is there a reason to turn them off on suspend?

Quoted 8 lines

that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

With a runtime PM approach this is trivial - we just turn off anything that isn't in use at the current time.  I'll need to extend ASoC to add information about what to do on suspend to the existing power data.

OK, but is this at all related to opportunistic suspend?

Signature · 1 line
Arve Hjønnevåg
#305 lore raw
Quoted 11 lines · Arve Hjønnevåg

2010/5/7 Mark Brown <[email protected]>:

Quoted 6 lines

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this.  As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that

Are you trying to use the same driver on systems that can support audio while suspend and on systems where this is impossible? If audio

Yes, each chip in the audio subsystem gets its own device driver. All Linux systems using a given CODEC share the device specific driver code (modulo out of tree code, obviously). Further, the power management is mostly abstracted out of the individual device drivers into the embedded audio core so the individual drivers don't really take any decisions about power for themselves.

Quoted 2 lines

cannot work while suspended, supporting opportunistic suspend is easy. You block suspend while audio is active.

Right, but that's not really an interesting case here.

Quoted 2 lines

If the hardware does support some audio paths while suspended, I'll ask again, is there a reason to turn them off on suspend?

As the mail you're replying to says:

Quoted 3 lines
Quoted 3 lines

that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

this all comes down to the intention of the user when they initiated the suspend.

Quoted 5 lines
Quoted 3 lines

With a runtime PM approach this is trivial - we just turn off anything that isn't in use at the current time.  I'll need to extend ASoC to add information about what to do on suspend to the existing power data.

OK, but is this at all related to opportunistic suspend?

Well, opportunistic suspend is essentially blurring the lines between a suspend and runtime PM - it's using suspend as part of the automatic drive down into the lowest possible power state. I'm just saying that in a pure runtime PM model this issue doesn't come up since the suspend semantic is much clearer.

#306 lore raw
In reply to Arve Hjønnevåg
Quoted 11 lines · Arve Hjønnevåg

2010/5/7 Mark Brown <[email protected]>:

Quoted 6 lines

This goes back to the thing about a full system suspend being a sledgehammer which doesn't give enough information about what's going on when it's used like this.  As discussed we need a way to know that the connections involved are able to stay live during suspend (on a large proportion of systems suspend is going to mean that the relevant bits of the board will loose power so need to be shut down) and that

Are you trying to use the same driver on systems that can support audio while suspend and on systems where this is impossible? If audio

Yes, each chip in the audio subsystem gets its own device driver. All Linux systems using a given CODEC share the device specific driver code (modulo out of tree code, obviously). Further, the power management is mostly abstracted out of the individual device drivers into the embedded audio core so the individual drivers don't really take any decisions about power for themselves.

Quoted 2 lines

cannot work while suspended, supporting opportunistic suspend is easy. You block suspend while audio is active.

Right, but that's not really an interesting case here.

Quoted 2 lines

If the hardware does support some audio paths while suspended, I'll ask again, is there a reason to turn them off on suspend?

As the mail you're replying to says:

Quoted 3 lines
Quoted 3 lines

that the intention of the user is that they should do so (this isn't clear in the general system, especially not if the suspend is initiated manually).

this all comes down to the intention of the user when they initiated the suspend.

Quoted 5 lines
Quoted 3 lines

With a runtime PM approach this is trivial - we just turn off anything that isn't in use at the current time.  I'll need to extend ASoC to add information about what to do on suspend to the existing power data.

OK, but is this at all related to opportunistic suspend?

Well, opportunistic suspend is essentially blurring the lines between a suspend and runtime PM - it's using suspend as part of the automatic drive down into the lowest possible power state. I'm just saying that in a pure runtime PM model this issue doesn't come up since the suspend semantic is much clearer.

#307 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

Aside from things where the CODEC is acting as a wake source (for stuff like jack detect) which are obviously already handled it's basically just when you've got an external audio source flowing through the device which is going to continue to function during suspend. Things like FM radios, for example. I'm not aware of non-audio examples that are use case specific and don't just involve utterly ignoring AP suspends.

Quoted 2 lines

In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.

It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.

When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.

#308 lore raw
In reply to Alan Stern
Quoted 3 lines · Alan Stern

Clearly if there's a call in progress you don't want to shut the codec down. Are there any other circumstances? Would they vary according to whether the suspend was forced or opportunistic?

Aside from things where the CODEC is acting as a wake source (for stuff like jack detect) which are obviously already handled it's basically just when you've got an external audio source flowing through the device which is going to continue to function during suspend. Things like FM radios, for example. I'm not aware of non-audio examples that are use case specific and don't just involve utterly ignoring AP suspends.

Quoted 2 lines

In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.

It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.

When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.

#309 lore raw
Quoted 6 lines · Mark Brown
Quoted 2 lines

In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.

It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.

Then the underlying problem should be solved -- hopefully in a nice, system-independent way. But I'm still trying to understand exactly what that underlying problem _is_.

That means understanding when the codec needs to be shut down and when it doesn't, and knowing how much of this information is available to the driver.

Quoted 2 lines

When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

For this reason I don't see how using runtime PM instead of suspend blockers would solve anything.

Alan Stern

#310 lore raw
In reply to Mark Brown
Quoted 6 lines · Mark Brown
Quoted 2 lines

In short, I'm trying to get at how much information drivers _really_ need to have about the reason for a system suspend.

It's not exactly the *reason* that makes the difference, it's more that this aggressive use of suspend makes much more apparent a problem which might exist anyway for this sort of hardware.

Then the underlying problem should be solved -- hopefully in a nice, system-independent way. But I'm still trying to understand exactly what that underlying problem _is_.

That means understanding when the codec needs to be shut down and when it doesn't, and knowing how much of this information is available to the driver.

Quoted 2 lines

When we get runtime PM delviering similar power levels we'll sidestep the problem since we won't need to do a system wide suspend.

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

For this reason I don't see how using runtime PM instead of suspend blockers would solve anything.

Alan Stern

#311 lore raw
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

Signature · 1 line
Matthew Garrett | [email protected]
#312 lore raw
In reply to Alan Stern
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

Signature · 1 line
Matthew Garrett | [email protected]
#313 lore raw
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

Alan Stern

P.S.: What happens if a suspend occurs while a call is in progress, so the codec is left powered up, and then the call ends? Does the system wake up at that point? Or does it stay suspended with the codec still powered, even though it's not needed any more?

#314 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

Alan Stern

P.S.: What happens if a suspend occurs while a call is in progress, so the codec is left powered up, and then the call ends? Does the system wake up at that point? Or does it stay suspended with the codec still powered, even though it's not needed any more?

#315 lore raw
Quoted 4 lines · Alan Stern

P.S.: What happens if a suspend occurs while a call is in progress, so the codec is left powered up, and then the call ends? Does the system wake up at that point? Or does it stay suspended with the codec still powered, even though it's not needed any more?

Call end will be a system wake event in pretty much all systems, userspace will want to do some work when the call goes away anyway. Anyone who doesn't do that will see the CODEC stay powered, hopefully the baseband will send it a nice mute signal instead of popping.

#316 lore raw
In reply to Alan Stern
Quoted 4 lines · Alan Stern

P.S.: What happens if a suspend occurs while a call is in progress, so the codec is left powered up, and then the call ends? Does the system wake up at that point? Or does it stay suspended with the codec still powered, even though it's not needed any more?

Call end will be a system wake event in pretty much all systems, userspace will want to do some work when the call goes away anyway. Anyone who doesn't do that will see the CODEC stay powered, hopefully the baseband will send it a nice mute signal instead of popping.

#317 lore raw
In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

Quoted 6 lines

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

We'd need a separate control, I think. The problem is, though, that the Android user space, for example, doesn't use the sysfs attributes of devices, so this control wouldn't be particularly useful for it.

Quoted 4 lines

P.S.: What happens if a suspend occurs while a call is in progress, so the codec is left powered up, and then the call ends? Does the system wake up at that point? Or does it stay suspended with the codec still powered, even though it's not needed any more?

I guess you end up telling the user that the call ended, so the system wakes up. That's only a guess, though.

Rafael

#318 lore raw
In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

Quoted 6 lines

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

We'd need a separate control, I think. The problem is, though, that the Android user space, for example, doesn't use the sysfs attributes of devices, so this control wouldn't be particularly useful for it.

Quoted 4 lines

P.S.: What happens if a suspend occurs while a call is in progress, so the codec is left powered up, and then the call ends? Does the system wake up at that point? Or does it stay suspended with the codec still powered, even though it's not needed any more?

I guess you end up telling the user that the call ended, so the system wakes up. That's only a guess, though.

Rafael

#319 lore raw
In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

Quoted 6 lines

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

I guess what we're talking about here is a set of per-device constraints that could be used by both [opportunistic|system] suspend and runtime PM. For lack of a better term, per-device PM QoS (as compared to the current system-wide PM QoS.)

For example, if userspace (or some other device) has communicated that it has a constraint on the audio HW, then both the suspend path and the runtime PM path could check those constraints before making a decision on how to act. Hopefully the phone app would set a constraint and the cow-noise app would not. :)

On OMAP, we keep track of per-device constraints (currently latency and throughput) in order to make proper run-time PM decicions in the kernel, but we are realizing that we need a way for userspace to communicate these constraints as well, so that userspace can make power vs. performance policy decisions instead of the kernel.

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

Kevin

#320 lore raw
In reply to Alan Stern
Quoted 23 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

Quoted 6 lines

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

I guess what we're talking about here is a set of per-device constraints that could be used by both [opportunistic|system] suspend and runtime PM. For lack of a better term, per-device PM QoS (as compared to the current system-wide PM QoS.)

For example, if userspace (or some other device) has communicated that it has a constraint on the audio HW, then both the suspend path and the runtime PM path could check those constraints before making a decision on how to act. Hopefully the phone app would set a constraint and the cow-noise app would not. :)

On OMAP, we keep track of per-device constraints (currently latency and throughput) in order to make proper run-time PM decicions in the kernel, but we are realizing that we need a way for userspace to communicate these constraints as well, so that userspace can make power vs. performance policy decisions instead of the kernel.

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

Kevin

#321 lore raw
Quoted 49 lines · Kevin Hilman
Quoted 23 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

Quoted 6 lines

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

I guess what we're talking about here is a set of per-device constraints that could be used by both [opportunistic|system] suspend and runtime PM. For lack of a better term, per-device PM QoS (as compared to the current system-wide PM QoS.)

For example, if userspace (or some other device) has communicated that it has a constraint on the audio HW, then both the suspend path and the runtime PM path could check those constraints before making a decision on how to act. Hopefully the phone app would set a constraint and the cow-noise app would not. :)

On OMAP, we keep track of per-device constraints (currently latency and throughput) in order to make proper run-time PM decicions in the kernel, but we are realizing that we need a way for userspace to communicate these constraints as well, so that userspace can make power vs. performance policy decisions instead of the kernel.

Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

That sounds reasonable although it may be a challenge to find a set of universal constraints common to all devices.

Rafael

#322 lore raw
In reply to Kevin Hilman
Quoted 49 lines · Kevin Hilman
Quoted 23 lines · Alan Stern
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

One the face of it, a runtime-PM solution would dictate that the codec's driver ought to turn off the codec whenever the driver thinks it isn't being used. Ergo, if the driver didn't know when a call was in progress, it would use runtime PM to turn off the codec during a call.

Quoted 7 lines

Well, part of the problem is that right now most of our beliefs about imposed constraints tend to be based on what userspace is doing - "Don't power down the audio codec when userspace has it open", for instance. But that goes away with opportunistic suspend. In most cases you don't want the audio codec to stay awake just because userspace was using it to make bouncing cow noises, especially if you've just frozen userspace. So the problem becomes more complicated than it would otherwise be.

It sounds like the problem can be stated simply enough: At the moment, nobody knows when the codec should be powered down! Userspace might have some idea, but even if its ideas are right it has no way of communicating them to the kernel.

Quoted 6 lines

The power/control sysfs attribute was intended for just that purpose, although it was aimed at runtime PM rather than system PM. Nevertheless, it or something like it could be used. Of course, there would still remain the issue of userspace telling the kernel not to power down the codec while making bouncing cow noises -- but at this point it's not really a kernel problem any more.

I guess what we're talking about here is a set of per-device constraints that could be used by both [opportunistic|system] suspend and runtime PM. For lack of a better term, per-device PM QoS (as compared to the current system-wide PM QoS.)

For example, if userspace (or some other device) has communicated that it has a constraint on the audio HW, then both the suspend path and the runtime PM path could check those constraints before making a decision on how to act. Hopefully the phone app would set a constraint and the cow-noise app would not. :)

On OMAP, we keep track of per-device constraints (currently latency and throughput) in order to make proper run-time PM decicions in the kernel, but we are realizing that we need a way for userspace to communicate these constraints as well, so that userspace can make power vs. performance policy decisions instead of the kernel.

Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

That sounds reasonable although it may be a challenge to find a set of universal constraints common to all devices.

Rafael

#323 lore raw
In reply to Kevin Hilman
Quoted 18 lines · Kevin Hilman

I guess what we're talking about here is a set of per-device constraints that could be used by both [opportunistic|system] suspend and runtime PM.  For lack of a better term, per-device PM QoS (as compared to the current system-wide PM QoS.)

For example, if userspace (or some other device) has communicated that it has a constraint on the audio HW, then both the suspend path and the runtime PM path could check those constraints before making a decision on how to act.  Hopefully the phone app would set a constraint and the cow-noise app would not.  :)

On OMAP, we keep track of per-device constraints (currently latency and throughput) in order to make proper run-time PM decicions in the kernel, but we are realizing that we need a way for userspace to communicate these constraints as well, so that userspace can make power vs. performance policy decisions instead of the kernel.

Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

The constraint stuff is definitely something I'd love to talk about in detail. It's a problem that I think is common to every SoC I've worked with. Having a general solution for this problem (of specifying and observing various constraints for clock, power, qos, etc) kernel-wide would seem like a big win.

Might be worth kicking some design ideas around and getting a bunch of the interested parties together at some of the upcoming linux conference things this fall on the east coast?

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

#324 lore raw
In reply to Kevin Hilman
Quoted 18 lines · Kevin Hilman

I guess what we're talking about here is a set of per-device constraints that could be used by both [opportunistic|system] suspend and runtime PM.  For lack of a better term, per-device PM QoS (as compared to the current system-wide PM QoS.)

For example, if userspace (or some other device) has communicated that it has a constraint on the audio HW, then both the suspend path and the runtime PM path could check those constraints before making a decision on how to act.  Hopefully the phone app would set a constraint and the cow-noise app would not.  :)

On OMAP, we keep track of per-device constraints (currently latency and throughput) in order to make proper run-time PM decicions in the kernel, but we are realizing that we need a way for userspace to communicate these constraints as well, so that userspace can make power vs. performance policy decisions instead of the kernel.

Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

The constraint stuff is definitely something I'd love to talk about in detail. It's a problem that I think is common to every SoC I've worked with. Having a general solution for this problem (of specifying and observing various constraints for clock, power, qos, etc) kernel-wide would seem like a big win.

Might be worth kicking some design ideas around and getting a bunch of the interested parties together at some of the upcoming linux conference things this fall on the east coast?

Brian

#325 lore raw
Quoted 13 lines · Brian Swetland
Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

The constraint stuff is definitely something I'd love to talk about in detail. It's a problem that I think is common to every SoC I've worked with. Having a general solution for this problem (of specifying and observing various constraints for clock, power, qos, etc) kernel-wide would seem like a big win.

Quoted 3 lines

Might be worth kicking some design ideas around and getting a bunch of the interested parties together at some of the upcoming linux conference things this fall on the east coast?

The Linux Power-Management Summit is scheduled for August 9, at the start of the LinuxCon meeting in Boston. This would make an excellent topic for discussion.

Alan Stern

#326 lore raw
In reply to Brian Swetland
Quoted 13 lines · Brian Swetland
Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

The constraint stuff is definitely something I'd love to talk about in detail. It's a problem that I think is common to every SoC I've worked with. Having a general solution for this problem (of specifying and observing various constraints for clock, power, qos, etc) kernel-wide would seem like a big win.

Quoted 3 lines

Might be worth kicking some design ideas around and getting a bunch of the interested parties together at some of the upcoming linux conference things this fall on the east coast?

The Linux Power-Management Summit is scheduled for August 9, at the start of the LinuxCon meeting in Boston. This would make an excellent topic for discussion.

Alan Stern

#327 lore raw
Quoted 15 lines · Alan Stern
Quoted 13 lines · Brian Swetland
Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

The constraint stuff is definitely something I'd love to talk about in detail. It's a problem that I think is common to every SoC I've worked with. Having a general solution for this problem (of specifying and observing various constraints for clock, power, qos, etc) kernel-wide would seem like a big win.

Quoted 7 lines
Quoted 3 lines

Might be worth kicking some design ideas around and getting a bunch of the interested parties together at some of the upcoming linux conference things this fall on the east coast?

The Linux Power-Management Summit is scheduled for August 9, at the start of the LinuxCon meeting in Boston. This would make an excellent topic for discussion.

Agreed.

Rafael

#328 lore raw
In reply to Alan Stern
Quoted 15 lines · Alan Stern
Quoted 13 lines · Brian Swetland
Quoted 6 lines

Probably generalizing these into the LDM is the direction to go so userspace can set constraints on a per-device (or per-class?) basis:

/sys/devices/.../power/constraint/throughput
/sys/devices/.../power/constraint/wakeup_latency
/sys/devices/.../power/constraint/... ?

The constraint stuff is definitely something I'd love to talk about in detail. It's a problem that I think is common to every SoC I've worked with. Having a general solution for this problem (of specifying and observing various constraints for clock, power, qos, etc) kernel-wide would seem like a big win.

Quoted 7 lines
Quoted 3 lines

Might be worth kicking some design ideas around and getting a bunch of the interested parties together at some of the upcoming linux conference things this fall on the east coast?

The Linux Power-Management Summit is scheduled for August 9, at the start of the LinuxCon meeting in Boston. This would make an excellent topic for discussion.

Agreed.

Rafael

#329 lore raw
In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett

We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.

Right, the big issue for me is that there's likely to be some form of userspace API visible for controlling this. I think I can keep it mostly in-kernel for audio (by providing new APIs to mark some inputs and outputs as being live during suspend) but need to check.

#330 lore raw
In reply to Matthew Garrett
Quoted 7 lines · Matthew Garrett

We seem to have ended up managing most of our PM infrastructure iteratively. If the concern is more about best practices than intrinsic incompatibilities, I'd lean towards us being better off merging this now and then working things out over the next few releases as we get a better understanding of the implications. The main thing that we have to get right in the short term is the userspace API - everything else is easier to fix up as we go along.

Right, the big issue for me is that there's likely to be some form of userspace API visible for controlling this. I think I can keep it mostly in-kernel for audio (by providing new APIs to mark some inputs and outputs as being live during suspend) but need to check.

#331 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Mark Brown

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC,

In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.

That is not actually what Android systems are doing, and if it is what's supposed to happen then I'd really expect to see a patch to ASoC as part of this series which shows how this is supposed to be integrated - it's the sort of thing I'd expect to see some kernel space management for.

Honestly I don't think that's a very good solution for actual systems, though. A part of the reasoning behind designing systems in this way is allowing the AP to go into the lowest possible power state while on a voice call so it doesn't seem at all unreasonable for the system integrator to expect that the AP will be driven into the standard low power state the system uses for it during a call and in a system using opportunistic suspend that's suspend mode.

Quoted 10 lines
Quoted 4 lines

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.

On the one hand that's the answer that works well with the existing Linux design here so great. On the other hand as discussed above that doesn't match so well with user expectations.

Quoted 5 lines

What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).

Remember that even in your full system suspend the system is not actually fully idle - the baseband is still sitting there looking after itself, keeping the phone on the network. The only difference between on call and off call from the point of view of the Linux system is that there is an active audio path which happens to have been set up by the Linux system.

#332 lore raw
In reply to Mark Brown
Quoted 17 lines · Mark Brown
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman

Mark Brown <[email protected]> writes:

Guys, please.

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.

Quoted 4 lines

when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

Quoted 4 lines

Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.

Evidently, the Android developers had a problem with that. Of course, you can argue that they didn't consider using runtime PM for this purpose, but the real question is how much time it would take to achieve the same level of energy saving using runtime PM without opportunistic suspend.

Quoted 14 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I'm not sure. Why _exactly_ would you need that?

The use case that causes serious issues with this at the minute in the domains I work is this:

Quoted 12 lines

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.

In that case someone (either a driver or, most likely, user space) will need to keep a suspend blocker active.

Quoted 8 lines

Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas.

My understanding is that on Android suspend blockers are used for this purpose.

Quoted 9 lines

I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Suspend really is a sledgehammer thing. Either you suspend the whole system or you don't suspend at all. You can prevent opportunistic suspend from happening using suspend blockers (that's what they are for), but that's pretty much everything you can do about it. If you want power savings while some parts of the system are active, use runtime PM for that.

What I'd use opportunistic suspend for is not the saving of energy when there's a call in progress, because in that case some parts of the system need to be active, but to save energy when the device is completely idle, ie. the user interface is not used, music is not played "in the background" etc. (my phone is in such a state 90% of the time at least).

Rafael

#333 lore raw
In reply to Mark Brown
Quoted 13 lines · Mark Brown

Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.

Quoted 4 lines

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Android must already include some solution to this problem. Why not use that solution more generally?

Alan Stern

#334 lore raw
In reply to Mark Brown
Quoted 13 lines · Mark Brown

Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.

Quoted 4 lines

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Android must already include some solution to this problem. Why not use that solution more generally?

Alan Stern

#335 lore raw
Quoted 9 lines · Alan Stern
Quoted 4 lines · Mark Brown

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Android must already include some solution to this problem. Why not use that solution more generally?

Not so much; at least for audio it's being handled with platform specific bodges as far as I've seen so far. If there had been a standard way of doing this I'd have expected to see it in this patch series. The Google systems all use Qualcomm chipsets which aren't affected by this since the audio CODEC is hidden from Linux and none of the audio actually uses ALSA at all in the BSPs I looked at.

It's entirely possible I'm missing something here, everything I know has come from either talking to users or trawling code on the internet.

#336 lore raw
In reply to Alan Stern
Quoted 9 lines · Alan Stern
Quoted 4 lines · Mark Brown

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

Android must already include some solution to this problem. Why not use that solution more generally?

Not so much; at least for audio it's being handled with platform specific bodges as far as I've seen so far. If there had been a standard way of doing this I'd have expected to see it in this patch series. The Google systems all use Qualcomm chipsets which aren't affected by this since the audio CODEC is hidden from Linux and none of the audio actually uses ALSA at all in the BSPs I looked at.

It's entirely possible I'm missing something here, everything I know has come from either talking to users or trawling code on the internet.

#337 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Kevin Hilman

Mark Brown <[email protected]> writes:

Guys, please.

The opportunistic suspend feature is _not_ to replace runtime PM by any means!

Certainly in my case and I think Kevin's I agree with the need for the bodge at the minute if we can get a clearer idea of how it's supposed to work.

Quoted 4 lines

when to put devices into low power states and save energy this way. Still, even if all subsystems do that 100% efficiently, there may be more savings possible by putting the entire system into a sleep state (like on ACPI-based PCs) and we can reach there by runtime PM alone.

Right, this is likely to be a win for PCs - for embedded systems we rarely have other software to interoperate with so if you can make the hardware do it then it's unlikely there would be any fundamental issue with Linux doing it at runtime.

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

I agree.

I'm not sure. Why _exactly_ would you need that?

The use case that causes serious issues with this at the minute in the domains I work is this:

On a mobile phone when the system is in a voice call the data flow for the call is entirely handled outside the CPU (normally referred to as Applications Processor or AP here) by the baseband and audio CODEC, which are either integrated or directly connected by analogue or digital audio links on the board. If the user has the phone to their ear and is talking away with the screen blanked then the AP is just waiting for input, will appear idle and so trigger an opportunistic suspend. If the audio CODEC is managed by Linux (as is standard) then running through the suspend process will as things stand cause the audio subsystem to be suspended. Since in the normal course of affairs suspend means power down that's what will happen, but this is clearly highly undesirable in this situation.

Now, the solution here if we're going to use opportunistic suspend like this is to provide some method for the audio subsystem to figure out that the system doesn't actually want it to suspend when it gets told do do so. Like I say ideally we'd provide some standard interface in the PM subsystem for userspace to communicate this to subsystems and drivers so that we've got a joined up story when people run into issues in cases like this, though obviously if this goes in then we'll have to put in something subsystem or driver specific for affected areas. I know what I'd implement generically for audio, but I've held back since the option is fairly messy when not used in conjunction with a deliberate choice to use opportunistic suspend and I was expecting a standard mechanism to slot into to provide control for userspace.

In other words, the issue is that we run into situations where we need an element of suspend control to go along with the opportunistic suspend in order to allow some elements to be kept running - since suspend blocking is taken suspend suppression seems like a reasonable term.

#338 lore raw
In reply to Brian Swetland
Quoted 10 lines · Brian Swetland
Quoted 5 lines · Arve Hjønnevåg

On Mon, May 3, 2010 at 4:37 PM, Kevin Hilman

Quoted 3 lines

This last point is especially troubling.  I don't find it a comforting path to go down if the drivers have to start caring about which PM policy is currently in use.

I'll echo Arve here -- all drivers should seek to be in the lowest power state possible at all times. We've never suggested that suspend_block is a substitute for that.

Looking at this from a subsystem/driver author point of view the problem I'm faced with is that as a result of using system suspend much more aggressively the subsystem and driver layers are getting conflicting instructions about what the lowest power state possible is.

Quoted 6 lines

Suspend blockers give us some flexibility on systems where runtime pm will not get us all the way there. If you can meet your power needs without needing suspend blockers, awesome, you don't need them on that platform. The patchset Arve sent out makes this feature an off-by-default kernel configuration option that compiles out to no-ops when disabled.

I think a big part of this for me is that this approach changes the intended use of the system-wide suspend a bit, complicating it a bit further than it already is. We end up doing a suspend (which in the normal course of affairs means that the driver should shut everything down) partly as a substitute for runtime PM on the core system devices and partly because our runtime PM isn't doing as well as it should on the individual devices.

I'd be a lot more comfortable with this if it came with a mechanism for communicating the intended effect of a suspend on a per-device level so that the drivers have a clear way of figuring out what to do when the system suspends. If there isn't one we can add subsystem or driver specific hooks, of course, but it'd be better to address this at the system level.

Quoted 6 lines

In our experience, periodic timers and polling, both userspace side and kernelside make suspend blockers a win even on platforms like OMAP which have pretty flexible hardware power management. Going to low power states in idle results in higher average power consumption than going to the same states in full suspend, at least on Android devices shipping today.

There's definite work to be done here, yes.

#339 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg
Quoted 2 lines · Kevin Hilman

"Rafael J. Wysocki" <[email protected]> writes:

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

Quoted 7 lines
Quoted 4 lines

From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

OK, but my point was that their *usage* is at the level of inidividual devices and subsystems, just like runtime PM. Hence, duplicate work.

Quoted 7 lines
Quoted 7 lines

So I still see a large duplication in the usage and the goals of both frameworks.  The goal of both is to always enter lowest-power state except

 - if there's activity (runtime PM for devices, CPUidle for CPU)
 - if there's a suspend blocker (opportunitic suspend)

Quoted 8 lines
Quoted 5 lines

In addition, it will likely cause duplicate work to be done in drivers.  Presumably, PM aware drivers will want to know if the system is in opportunistic mode.  For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

Why? If a device is not in use it should be off regardless of what state the rest of the system is in.

Not necessarily.

If a device is not in use, what power state it goes into depends on many device/subsystem specific things. For example, recent activity (timeouts), whether it will be busy soon (pending transfers), latency/throughput constraints, dependency on other devices, or any other device/subsystem specific reason.

All of these can be handled with runtime PM. None of which are taken into consideration with opportunistic suspend.

Kevin

#340 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · Arve Hjønnevåg
Quoted 2 lines · Kevin Hilman

"Rafael J. Wysocki" <[email protected]> writes:

[...]

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

Quoted 7 lines
Quoted 4 lines

From the use cases presented, the *usage* of suspend blockers is aimed at power management of individual devices or subsystems, just like usage of runtime PM.

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

OK, but my point was that their *usage* is at the level of inidividual devices and subsystems, just like runtime PM. Hence, duplicate work.

Quoted 7 lines
Quoted 7 lines

So I still see a large duplication in the usage and the goals of both frameworks.  The goal of both is to always enter lowest-power state except

 - if there's activity (runtime PM for devices, CPUidle for CPU)
 - if there's a suspend blocker (opportunitic suspend)

Quoted 8 lines
Quoted 5 lines

In addition, it will likely cause duplicate work to be done in drivers.  Presumably, PM aware drivers will want to know if the system is in opportunistic mode.  For example, for many drivers, doing runtime PM may not be worth the effort if the system is in opportunistic mode.

Why? If a device is not in use it should be off regardless of what state the rest of the system is in.

Not necessarily.

If a device is not in use, what power state it goes into depends on many device/subsystem specific things. For example, recent activity (timeouts), whether it will be busy soon (pending transfers), latency/throughput constraints, dependency on other devices, or any other device/subsystem specific reason.

All of these can be handled with runtime PM. None of which are taken into consideration with opportunistic suspend.

Kevin

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

Hello,

Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Standard Linux systems don't need these, because the scheduler just keeps the system running as long as there is work to be done.

Suspend-blocks are only needed because patch 1's opportunistic suspend governor tries to suspend the system even when the scheduler indicates that there is work to be done. That decision requires all kinds of hacks throughout the codebase [1][2].

- Paul

1. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:27:56 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18658

2. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:13:50 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18657

#342 lore raw
Quoted 10 lines · Paul Walmsley

Hello,

Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do. Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

Quoted 3 lines

because the scheduler just keeps
the system running as long as there is work to be done.

That is only true if you never use suspend.

Quoted 18 lines

Suspend-blocks are only needed because patch 1's opportunistic suspend governor tries to suspend the system even when the scheduler indicates that there is work to be done.  That decision requires all kinds of hacks throughout the codebase [1][2].

- Paul

1. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:27:56 -0600:
  http://permalink.gmane.org/gmane.linux.power-management.general/18658

2. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:13:50 -0600:
  http://permalink.gmane.org/gmane.linux.power-management.general/18657

Signature · 1 line
Arve Hjønnevåg
#343 lore raw
Quoted 10 lines · Arve Hjønnevåg
Quoted 9 lines · Paul Walmsley

Hello,

Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Quoted 5 lines
Quoted 1 line

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do. Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

The primary client for opportunistic suspend and suspend blockers appears to be embedded systems. These systems are typically capable of powering the CPU down and up again with low latency, and they typically have very aggressive runtime PM support capable of powering down each device when it's not in active use. Given this ability, it does seem that opportunistic suspend and suspend blockers might be unnecessary.

I'd like to explore this avenue a little farther. In particular, what is the issue involving loss of wakeup events? Can you describe this in more detail?

Quoted 5 lines
Quoted 3 lines

because the scheduler just keeps
the system running as long as there is work to be done.

That is only true if you never use suspend.

Why would you want to use system suspend if runtime PM can do everything you need?

Sure, I can see that an ACPI-based system needs something more. But that's not the real issue here.

Alan Stern

#344 lore raw
Quoted 18 lines · Alan Stern
Quoted 10 lines · Arve Hjønnevåg
Quoted 9 lines · Paul Walmsley

Hello,

Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Quoted 5 lines
Quoted 1 line

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do. Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

Quoted 7 lines

The primary client for opportunistic suspend and suspend blockers appears to be embedded systems.  These systems are typically capable of powering the CPU down and up again with low latency, and they typically have very aggressive runtime PM support capable of powering down each device when it's not in active use.  Given this ability, it does seem that opportunistic suspend and suspend blockers might be unnecessary.

With the current kernel and user-space code we run, we get significantly better battery life on the msm plaform using suspend compared to entering the same power state from idle. On some devices it takes only five wakeup events per second to cut the best case battery life in half.

Quoted 4 lines

I'd like to explore this avenue a little farther.  In particular, what is the issue involving loss of wakeup events?  Can you describe this in more detail?

On the desktop systems I have used I only wake the up the system by pressing a button/key or with an rtc alarm. Losing a button or key wakeup event is not usually a problem on a desktop since the user will press it again. Losing an alarm however could be a problem and this can be avoided by using opportunistic suspend and suspend blockers.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

because the scheduler just keeps
the system running as long as there is work to be done.

That is only true if you never use suspend.

Why would you want to use system suspend if runtime PM can do everything you need?

Because it stops threads that wakeup every second to check if they have work to do (this includes standard kernel threads), and it prevents bad apps that never go idle from completely destroying our battery life.

Quoted 3 lines

Sure, I can see that an ACPI-based system needs something more.  But that's not the real issue here.

The system we started with entered a much lower power state from suspend than idle so we needed wakelocks to get more than 24 hours battery life. We kept wakelocks when we moved to the msm platform since it reduces our power consumption.

Signature · 1 line
Arve Hjønnevåg
#345 lore raw
Quoted 10 lines · Arve Hjønnevåg
Quoted 4 lines

I'd like to explore this avenue a little farther.  In particular, what is the issue involving loss of wakeup events?  Can you describe this in more detail?

On the desktop systems I have used I only wake the up the system by pressing a button/key or with an rtc alarm. Losing a button or key wakeup event is not usually a problem on a desktop since the user will press it again. Losing an alarm however could be a problem and this can be avoided by using opportunistic suspend and suspend blockers.

How can runtime PM combined with CPUidle cause an alarm to be lost?

Quoted 7 lines
Quoted 3 lines

Why would you want to use system suspend if runtime PM can do everything you need?

Because it stops threads that wakeup every second to check if they have work to do (this includes standard kernel threads), and it prevents bad apps that never go idle from completely destroying our battery life.

Ah, the ill-behaved apps problem. I think everybody agrees that they are hard to deal with.

The kernel-threads problem might better be addressed by fixing those threads than by adding a new API.

Quoted 8 lines
Quoted 3 lines

Sure, I can see that an ACPI-based system needs something more.  But that's not the real issue here.

The system we started with entered a much lower power state from suspend than idle so we needed wakelocks to get more than 24 hours battery life. We kept wakelocks when we moved to the msm platform since it reduces our power consumption.

Is it generally true among embedded systems nowadays that idle is capable of reaching essentially the same power states as suspend?

Alan Stern

#346 lore raw
Quoted 7 lines · Alan Stern
Quoted 5 lines · Arve Hjønnevåg
Quoted 4 lines

I'd like to explore this avenue a little farther.  In particular, what is the issue involving loss of wakeup events?  Can you describe this in more detail?

Quoted 8 lines
Quoted 5 lines

On the desktop systems I have used I only wake the up the system by pressing a button/key or with an rtc alarm. Losing a button or key wakeup event is not usually a problem on a desktop since the user will press it again. Losing an alarm however could be a problem and this can be avoided by using opportunistic suspend and suspend blockers.

How can runtime PM combined with CPUidle cause an alarm to be lost?

It doesn't. My desktop systems only gets to a low power state (<3W) from suspend.

Quoted 18 lines
Quoted 7 lines
Quoted 3 lines

Why would you want to use system suspend if runtime PM can do everything you need?

Because it stops threads that wakeup every second to check if they have work to do (this includes standard kernel threads), and it prevents bad apps that never go idle from completely destroying our battery life.

Ah, the ill-behaved apps problem.  I think everybody agrees that they are hard to deal with.

The kernel-threads problem might better be addressed by fixing those threads than by adding a new API.

Quoted 4 lines
Quoted 3 lines

Sure, I can see that an ACPI-based system needs something more.  But that's not the real issue here.

Quoted 7 lines
Quoted 4 lines

The system we started with entered a much lower power state from suspend than idle so we needed wakelocks to get more than 24 hours battery life. We kept wakelocks when we moved to the msm platform since it reduces our power consumption.

Is it generally true among embedded systems nowadays that idle is capable of reaching essentially the same power states as suspend?

Embedded system in general, no, but all the recent SOCs I've seen that target phones do.

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

Hello Arve,

Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines · Paul Walmsley
Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Quoted 5 lines
Quoted 1 line

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do. Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

Sorry, I don't follow. What causes wakeup events to be lost? Is it the current opportunistic suspend governor? On OMAP Linux systems, as far as I know, we don't lose any wakeup events.

Quoted 4 lines
Quoted 2 lines

because the scheduler just keeps the system running as long as there is work to be done.

That is only true if you never use suspend.

If, instead of the current Android opportunistic suspend governor, the system entered suspend from pm_idle(), wouldn't that keep the system running as long as there is work to done?

As far as I can see, it's the current Android opportunistic suspend governor design in patch 1 that causes the system to enter suspend even when there is work to be done, since it will try to suspend even when the system is out of the idle loop.

- Paul

#348 lore raw
Quoted 14 lines · Paul Walmsley

Hello Arve,

Quoted 10 lines · Arve Hjønnevåg
Quoted 8 lines · Paul Walmsley
Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Standard Linux systems don't need these,

Quoted 8 lines
Quoted 3 lines

If you don't want to lose wakeup events they do.  Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

Sorry, I don't follow.  What causes wakeup events to be lost?  Is it the current opportunistic suspend governor?  On OMAP Linux systems, as far as I know, we don't lose any wakeup events.

Have you used suspend?

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

because the scheduler just keeps the system running as long as there is work to be done.

That is only true if you never use suspend.

If, instead of the current Android opportunistic suspend governor, the system entered suspend from pm_idle(), wouldn't that keep the system running as long as there is work to done?

How do you know if the work being done while suspending is work that is needed to suspend or work that should abort suspend? When should the system wake up?

Quoted 5 lines

As far as I can see, it's the current Android opportunistic suspend governor design in patch 1 that causes the system to enter suspend even when there is work to be done, since it will try to suspend even when the system is out of the idle loop.

It does not matter how you enter suspend. Without opportunistic suspend, once you tell the kernel that you want to suspend, you cannot abort. If a wakeup event occurs at this point, it will probably not be processed until the system wakes up for another wakeup event.

Signature · 1 line
Arve Hjønnevåg
#349 lore raw
Quoted 5 lines · Arve Hjønnevåg

It does not matter how you enter suspend. Without opportunistic suspend, once you tell the kernel that you want to suspend, you cannot abort. If a wakeup event occurs at this point, it will probably not be processed until the system wakes up for another wakeup event.

Since it seems to be at the very core of the argument, how long time does it take to suspend your system? Is it something that could be improved upon?

Henrik

#350 lore raw
Quoted 9 lines · Henrik Rydberg
Quoted 5 lines · Arve Hjønnevåg

It does not matter how you enter suspend. Without opportunistic suspend, once you tell the kernel that you want to suspend, you cannot abort. If a wakeup event occurs at this point, it will probably not be processed until the system wakes up for another wakeup event.

Since it seems to be at the very core of the argument, how long time does it take to suspend your system? Is it something that could be improved upon?

It's not a matter of time. It's a matter of lost keystrokes and such.

Rafael

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

Hello Arve,

I regret the delay in responding.

Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · Paul Walmsley
Quoted 12 lines · Arve Hjønnevåg
Quoted 7 lines · Paul Walmsley
Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do.  Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

Quoted 5 lines
Quoted 4 lines

Sorry, I don't follow.  What causes wakeup events to be lost?  Is it the current opportunistic suspend governor?  On OMAP Linux systems, as far as I know, we don't lose any wakeup events.

Have you used suspend?

I see. You are referring to wakeup event loss/delay caused by the full system suspend process (e.g., kernel/power/suspend.c:enter_state() onwards[1]), correct? This message addresses this at the end of the mail.

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

because the scheduler just keeps the system running as long as there is work to be done.

That is only true if you never use suspend.

If, instead of the current Android opportunistic suspend governor, the system entered suspend from pm_idle(), wouldn't that keep the system running as long as there is work to done?

How do you know if the work being done while suspending is work that is needed to suspend or work that should abort suspend?

Consider a suspending system in which all "untrusted" processes have been placed into TASK_INTERRUPTIBLE state and have had their timers disabled.[2] The only remaining work to do on the system is work that needs to be done as part of the suspend process, or work that is part of a "trusted" process or the kernel. If the suspend needs to be aborted due to the arrival of an event, this can be handled as part of the standard suspend process (described below).

Quoted 1 line

When should the system wake up?

I suspect that I am misunderstanding your question, but the system should wake up the same way it does now: when a wakeup interrupt arrives (either from the next scheduled timer expiration, or from some external device).

Quoted 7 lines
Quoted 4 lines

As far as I can see, it's the current Android opportunistic suspend governor design in patch 1 that causes the system to enter suspend even when there is work to be done, since it will try to suspend even when the system is out of the idle loop.

It does not matter how you enter suspend. Without opportunistic suspend, once you tell the kernel that you want to suspend, you cannot abort.

Any driver should be able to abort suspend by returning an error from its struct device_driver/struct dev_pm_ops suspend function. Consider this partial callgraph for full system suspend, from [3], [4]:

kernel/power/suspend.c: enter_state() ->
kernel/power/suspend.c: suspend_devices_and_enter() ->

drivers/base/power/main.c:     dpm_suspend_start() ->
drivers/base/power/main.c:      dpm_suspend() ->
drivers/base/power/main.c:       device_suspend() ->
drivers/base/power/main.c:        __device_suspend() ->
drivers/base/power/main.c:         pm_op() ->
drivers/base/power/main.c:          ops->suspend()

If ops->suspend() returns an error, it's ultimately passed back to suspend_devices_and_enter(), which aborts the suspend[5].

In this context, the main change that should be necessary is for driver/subsystem suspend functions to return an error when there are events pending. For example, as an alternative to the Android series' evdev.c patch[6], the evdev.c suspend function could return an error such as -EBUSY if events are currently queued (example below).

Aborting suspend in the event of driver activity seems like the right thing to do in a system that attempts to enter full system suspend while idle. But it is not the current expected Linux behavior, which also seems useful. Any abort-suspend-if-busy behavior should be configurable. One way would be to add a sysfs file for each driver/subsystem: perhaps something like 'abort_suspend_if_busy'. The default value would be zero to preserve the current behavior. Systems that wish to use opportunistic suspend could write a one to some or all of those files.

An untested, purely illustrative example, based on evdev.c, is at the end of this message. It's not meant to be functional; it's just meant to demonstrate the basic idea in code form.

...

Like suspend-blockers, adding abort_suspend_if_busy support would require changes throughout many drivers and subsystems. However, unlike suspend-blockers, the above abort_suspend_if_busy approach would not introduce any new APIs[7], nor would it change the default suspend behavior of the system.

As an aside, it seems that Android shouldn't currently need this if it's possible to pause "untrusted" processes and timers[8], since current shipping Android hardware can enter the same system low power state both with and without full system suspend[9]. But this could be useful for non-Android systems that still wish to use an idle-loop based, opportunistic full system suspend.

regards,

- Paul

1. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/power/suspend.c;h=56e7dbb8b996db295b4fc7cdf1b5f11a0409cb0c;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l258

2. Section B4 of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 19:39:44 CDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

3. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/power/suspend.c;h=56e7dbb8b996db295b4fc7cdf1b5f11a0409cb0c;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l258

4. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/base/power/main.c;h=941fcb87e52a12765df2aaa2e2ab21267693af9f;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l1062

5. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/power/suspend.c;h=56e7dbb8b996db295b4fc7cdf1b5f11a0409cb0c;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l207

6. Arve Hjønnevåg E-mail to the linux-pm mailing list, dated Fri May 21 15:46:54 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025747.html

7. Paul Walmsley E-mail to the linux-pm mailing list, dated Thu May 13 23:13:50 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025524.html

8. 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

9. Arve Hjønnevåg E-mail to the linux-pm mailing list, dated Mon, May 17 20:06:33 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025668.html

--------------------------------------------------------------------------------------

evdev.c abort_suspend_if_idle experiment:

---
 drivers/input/evdev.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 1 deletions(-)
drivers/input/evdev.c +63 -1
index 2ee6c7a..23eaad1 100644
@@ -20,8 +20,16 @@
 #include <linux/input.h>
 #include <linux/major.h>
 #include <linux/device.h>
+#include <linux/pm.h>
 #include "input-compat.h"
 
+/*
+ * abort_suspend_if_busy: set to 1 to prevent suspend as long as there
+ * is an event in the queue; set to 0 to allow suspend at any time.
+ * XXX Intended to be read from sysfs or the input subsystem.
+ */
+static int abort_suspend_if_busy;
+
 struct evdev {
 	int exist;
 	int open;
@@ -118,6 +126,36 @@ static int evdev_flush(struct file *file, fl_owner_t id)
 	return retval;
 }
 
+static int evdev_suspend(struct device *dev)
+{
+	struct evdev *evdev = container_of(dev, struct evdev, dev);
+	struct evdev_client *client;
+	int ret = 0;
+
+	if (!abort_suspend_if_busy)
+		return 0;
+
+	rcu_read_lock();
+
+	client = rcu_dereference(evdev->grab);
+	if (client) {
+		if (client->head != client->tail)
+			ret = -EBUSY;
+	} else {
+		list_for_each_entry_rcu(client, &evdev->client_list, node) {
+			if (client->head != client->tail) {
+				ret = -EBUSY;
+				break;
+			}
+		}
+	}
+
+	rcu_read_unlock();
+
+	return ret;
+}
+
+
 static void evdev_free(struct device *dev)
 {
 	struct evdev *evdev = container_of(dev, struct evdev, dev);
@@ -787,6 +825,21 @@ static void evdev_cleanup(struct evdev *evdev)
 	}
 }
 
+static const struct dev_pm_ops evdev_pm_ops = {
+	.suspend	= &evdev_suspend,
+};
+
+static char *evdev_devnode(struct device *dev, mode_t *mode)
+{
+	return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev));
+}
+
+static struct class evdev_class = {
+	.name		= "evdev",
+	.devnode	= evdev_devnode,
+	.pm		= &evdev_pm_ops,
+};
+
 /*
  * Create new evdev device. Note that input core serializes calls
  * to connect and disconnect so we don't need to lock evdev_table here.
@@ -826,7 +879,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
 	evdev->handle.private = evdev;
 
 	evdev->dev.devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor);
-	evdev->dev.class = &input_class;
+	evdev->dev.class = &evdev_class;
 	evdev->dev.parent = &dev->dev;
 	evdev->dev.release = evdev_free;
 	device_initialize(&evdev->dev);
@@ -883,12 +936,21 @@ static struct input_handler evdev_handler = {
 
 static int __init evdev_init(void)
 {
+	int err;
+
+	err = class_register(&input_class);
+	if (err) {
+		printk(KERN_ERR "evdev: unable to register evdev class\n");
+		return err;
+	}
+
 	return input_register_handler(&evdev_handler);
 }
 
 static void __exit evdev_exit(void)
 {
 	input_unregister_handler(&evdev_handler);
+	class_unregister(&evdev_class);
 }
 
 module_init(evdev_init);
Signature · 1 line
1.7.1.GIT
#352 lore raw
Quoted 43 lines · Paul Walmsley

Hello Arve,

I regret the delay in responding.

Quoted 15 lines · Arve Hjønnevåg
Quoted 14 lines · Paul Walmsley
Quoted 12 lines · Arve Hjønnevåg
Quoted 7 lines · Paul Walmsley
Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do.  Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

Quoted 5 lines
Quoted 4 lines

Sorry, I don't follow.  What causes wakeup events to be lost?  Is it the current opportunistic suspend governor?  On OMAP Linux systems, as far as I know, we don't lose any wakeup events.

Have you used suspend?

I see.  You are referring to wakeup event loss/delay caused by the full system suspend process (e.g., kernel/power/suspend.c:enter_state() onwards[1]), correct?  This message addresses this at the end of the mail.

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

because the scheduler just keeps the system running as long as there is work to be done.

That is only true if you never use suspend.

If, instead of the current Android opportunistic suspend governor, the system entered suspend from pm_idle(), wouldn't that keep the system running as long as there is work to done?

How do you know if the work being done while suspending is work that is needed to suspend or work that should abort suspend?

Quoted 8 lines

Consider a suspending system in which all "untrusted" processes have been placed into TASK_INTERRUPTIBLE state and have had their timers disabled.[2] The only remaining work to do on the system is work that needs to be done as part of the suspend process, or work that is part of a "trusted" process or the kernel.  If the suspend needs to be aborted due to the arrival of an event, this can be handled as part of the standard suspend process (described below).

That means modifying all kernel code that would use suspend blockers to abort suspend by returning an error from suspend instead. How is this better than using suspend blockers?

Quoted 6 lines
Quoted 1 line

When should the system wake up?

I suspect that I am misunderstanding your question, but the system should wake up the same way it does now: when a wakeup interrupt arrives (either from the next scheduled timer expiration, or from some external device).

That is not how the system wakes up from suspend now. The monotonic clock stops, and timers are ignored.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

As far as I can see, it's the current Android opportunistic suspend governor design in patch 1 that causes the system to enter suspend even when there is work to be done, since it will try to suspend even when the system is out of the idle loop.

It does not matter how you enter suspend. Without opportunistic suspend, once you tell the kernel that you want to suspend, you cannot abort.

Any driver should be able to abort suspend by returning an error from its struct device_driver/struct dev_pm_ops suspend function.  Consider this

Yes a driver can abort, but the user space code that initiated suspend cannot.

Quoted 29 lines

partial callgraph for full system suspend, from [3], [4]:

  kernel/power/suspend.c:   enter_state() -> kernel/power/suspend.c:    suspend_devices_and_enter() -> drivers/base/power/main.c:     dpm_suspend_start() -> drivers/base/power/main.c:      dpm_suspend() -> drivers/base/power/main.c:       device_suspend() -> drivers/base/power/main.c:        __device_suspend() -> drivers/base/power/main.c:         pm_op() -> drivers/base/power/main.c:          ops->suspend()

If ops->suspend() returns an error, it's ultimately passed back to suspend_devices_and_enter(), which aborts the suspend[5].

In this context, the main change that should be necessary is for driver/subsystem suspend functions to return an error when there are events pending.  For example, as an alternative to the Android series' evdev.c patch[6], the evdev.c suspend function could return an error such as -EBUSY if events are currently queued (example below).

Aborting suspend in the event of driver activity seems like the right thing to do in a system that attempts to enter full system suspend while idle.  But it is not the current expected Linux behavior, which also seems useful.  Any abort-suspend-if-busy behavior should be configurable.  One way would be to add a sysfs file for each driver/subsystem: perhaps something like 'abort_suspend_if_busy'.  The default value would be zero to preserve the current behavior.  Systems that wish to use opportunistic suspend could write a one to some or all of those files.

Quoted 4 lines

An untested, purely illustrative example, based on evdev.c, is at the end of this message.  It's not meant to be functional; it's just meant to demonstrate the basic idea in code form.

Do you think this is simpler than using a suspend blocker?

Quoted 8 lines

...

Like suspend-blockers, adding abort_suspend_if_busy support would require changes throughout many drivers and subsystems.  However, unlike suspend-blockers, the above abort_suspend_if_busy approach would not introduce any new APIs[7], nor would it change the default suspend behavior of the system.

Opportunistic suspend does not change the default behaviour either. Your proposal requires that all the drivers that would block suspend using a suspend blocker, now block suspend without the help of the suspend blocker api.

Quoted 2 lines

As an aside, it seems that Android shouldn't currently need this if it's possible to pause "untrusted" processes and timers[8], since current

Your proposal to "pause"processes by putting them in TASK_INTERRUPTIBLE state and stop their timers does not work. It is effectivly the same ase freezing them, since if you "paused" it while it was busy, a wakeup event cannot unpause it.

Quoted 162 lines

shipping Android hardware can enter the same system low power state both with and without full system suspend[9].  But this could be useful for non-Android systems that still wish to use an idle-loop based, opportunistic full system suspend.

regards,

- Paul

1. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/power/suspend.c;h=56e7dbb8b996db295b4fc7cdf1b5f11a0409cb0c;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l258

2. Section B4 of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 19:39:44 CDT 2010:
  https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

3. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/power/suspend.c;h=56e7dbb8b996db295b4fc7cdf1b5f11a0409cb0c;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l258

4. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/base/power/main.c;h=941fcb87e52a12765df2aaa2e2ab21267693af9f;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l1062

5. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/power/suspend.c;h=56e7dbb8b996db295b4fc7cdf1b5f11a0409cb0c;hb=7e125f7b9cbfce4101191b8076d606c517a73066#l207

6. Arve Hjønnevåg E-mail to the linux-pm mailing list, dated Fri May 21 15:46:54 PDT 2010:
  https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025747.html

7. Paul Walmsley E-mail to the linux-pm mailing list, dated Thu May 13 23:13:50 PDT 2010:
  https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025524.html

8. 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

9. Arve Hjønnevåg E-mail to the linux-pm mailing list, dated Mon, May 17 20:06:33 PDT 2010:
  https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025668.html

--------------------------------------------------------------------------------------

evdev.c abort_suspend_if_idle experiment:

---
 drivers/input/evdev.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++-

 1 files changed, 63 insertions(+), 1 deletions(-)
drivers/input/evdev.c +63 -2
index 2ee6c7a..23eaad1 100644
@@ -20,8 +20,16 @@
  #include <linux/input.h>
  #include <linux/major.h>
  #include <linux/device.h>
+#include <linux/pm.h>
  #include "input-compat.h"
 
+/*
+ * abort_suspend_if_busy: set to 1 to prevent suspend as long as there
+ * is an event in the queue; set to 0 to allow suspend at any time.
+ * XXX Intended to be read from sysfs or the input subsystem.
+ */
+static int abort_suspend_if_busy;
+
  struct evdev {
        int exist;
        int open;
@@ -118,6 +126,36 @@ static int evdev_flush(struct file *file, fl_owner_t id)
        return retval;
  }
 
+static int evdev_suspend(struct device *dev)
+{
+       struct evdev *evdev = container_of(dev, struct evdev, dev);
+       struct evdev_client *client;
+       int ret = 0;
+
+       if (!abort_suspend_if_busy)
+               return 0;
+
+       rcu_read_lock();
+
+       client = rcu_dereference(evdev->grab);
+       if (client) {
+               if (client->head != client->tail)
+                       ret = -EBUSY;
+       } else {
+               list_for_each_entry_rcu(client, &evdev->client_list, node) {
+                       if (client->head != client->tail) {
+                               ret = -EBUSY;
+                               break;
+                       }
+               }
+       }
+
+       rcu_read_unlock();
+
+       return ret;
+}
+
+
  static void evdev_free(struct device *dev)
  {
        struct evdev *evdev = container_of(dev, struct evdev, dev);
@@ -787,6 +825,21 @@ static void evdev_cleanup(struct evdev *evdev)
        }
  }
 
+static const struct dev_pm_ops evdev_pm_ops = {
+       .suspend        = &evdev_suspend,
+};
+
+static char *evdev_devnode(struct device *dev, mode_t *mode)
+{
+       return kasprintf(GFP_KERNEL, "input/%s", dev_name(dev));
+}
+
+static struct class evdev_class = {
+       .name           = "evdev",
+       .devnode        = evdev_devnode,
+       .pm             = &evdev_pm_ops,
+};
+
  /*
  * Create new evdev device. Note that input core serializes calls
  * to connect and disconnect so we don't need to lock evdev_table here.
@@ -826,7 +879,7 @@ static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
        evdev->handle.private = evdev;
 
        evdev->dev.devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor);
-       evdev->dev.class = &input_class;
+       evdev->dev.class = &evdev_class;
        evdev->dev.parent = &dev->dev;
        evdev->dev.release = evdev_free;
        device_initialize(&evdev->dev);
@@ -883,12 +936,21 @@ static struct input_handler evdev_handler = {
 
  static int __init evdev_init(void)
  {
+       int err;
+
+       err = class_register(&input_class);
+       if (err) {
+               printk(KERN_ERR "evdev: unable to register evdev class\n");
+               return err;
+       }
+
        return input_register_handler(&evdev_handler);
  }
 
  static void __exit evdev_exit(void)
  {
        input_unregister_handler(&evdev_handler);
+       class_unregister(&evdev_class);
  }
 
  module_init(evdev_init);
--

1.7.1.GIT

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

[Arve wrote]

Quoted 15 lines · Paul Walmsley
Quoted 5 lines · Arve Hjønnevåg
Quoted 3 lines

How do you know if the work being done while suspending is work that is needed to suspend or work that should abort suspend?

Quoted 8 lines

Consider a suspending system in which all "untrusted" processes have been placed into TASK_INTERRUPTIBLE state and have had their timers disabled.[2] The only remaining work to do on the system is work that needs to be done as part of the suspend process, or work that is part of a
"trusted" process or the kernel.  If the suspend needs to be aborted due to the arrival of an event, this can be handled as part of the standard suspend process (described below).

Quoted 3 lines

That means modifying all kernel code that would use suspend blockers to abort suspend by returning an error from suspend instead. How is this better than using suspend blockers?

It will mean that the same API is used for blocking suspend in regular suspend/resume, runtime PM runtime_suspend/runtime_resume and now also suspend blockers, right? So only one code path for drivers that want to support both, no?

That'll be a bit more elegant for drivers that want to support both runtime PM and suspend blockers I believe.

Overall as a driver writer I'm quite confused at this point, if I have a driver X, how is that code going to look if it is going to support both runtime PM *and* suspend blockers? I don't say it has to support both mechanisms in parallell, I'm even fine with putting it in #ifdef:s, but how will the source code look? A real-world example on a simple driver out of the Motorola Droid git or so would help a lot.

It's quite relevant since e.g. all OMAP drivers will need this modification to be used with Android-like systems, and at ST-Ericsson we will need both runtime PM and suspend blockers for our drivers as well. It will as a consequence affect the drivers for all ARM reference boards since we use the drivers for ARM PrimeCells. etc...

Now if this mechanism is going in, my main interest is that there is some clearly cut way and design pattern for supporting both runtime PM and suspend blocks.

Yours,
Linus Walleij

#354 lore raw
Quoted 15 lines · Linus WALLEIJ

Overall as a driver writer I'm quite confused at this point, if I have a driver X, how is that code going to look if it is going to support both runtime PM *and* suspend blockers? I don't say it has to support both mechanisms in parallell, I'm even fine with putting it in #ifdef:s, but how will the source code look? A real-world example on a simple driver out of the Motorola Droid git or so would help a lot.

It's quite relevant since e.g. all OMAP drivers will need this modification to be used with Android-like systems, and at ST-Ericsson we will need both runtime PM and suspend blockers for our drivers as well. It will as a consequence affect the drivers for all ARM reference boards since we use the drivers for ARM PrimeCells. etc...

Quoted 3 lines

Now if this mechanism is going in, my main interest is that there is some clearly cut way and design pattern for supporting both runtime PM and suspend blocks.

It's not difficult. You just have to decide what situations should block opportunistic suspend. For example, let's say that opportunistic suspend should be blocked when your event queue is non-empty.

Then in the routine that adds new events to the queue, while still holding the spinlock that protects your queue, you enable your suspend blocker. Likewise, in the routine that takes events off the queue and sends them to userspace, while holding the spinlock you test whether the queue has become empty; if it has you disable your suspend blocker.

That's all. No other changes are needed (except to create and destroy the suspend blocker, of course). No other interaction with suspend, resume, or runtime PM.

Alan Stern

#355 lore raw

[Alan Stern]

Quoted 16 lines · Linus WALLEIJ

(...)

Quoted 3 lines

Now if this mechanism is going in, my main interest is that there is some clearly cut way and design pattern for supporting both runtime PM and suspend blocks.

It's not difficult. You just have to decide what situations should block opportunistic suspend. For example, let's say that opportunistic suspend should be blocked when your event queue is non-empty.

Then in the routine that adds new events to the queue, while still holding the spinlock that protects your queue, you enable your suspend blocker. Likewise, in the routine that takes events off the queue and sends them to userspace, while holding the spinlock you test whether the queue has become empty; if it has you disable your suspend blocker.

Quoted 3 lines

That's all. No other changes are needed (except to create and destroy the suspend blocker, of course). No other interaction with suspend, resume, or runtime PM.

OK I understand it will be rather OK to do this. For example I have drivers/spi/amba-pl022.c which is quite clearly taking elements off a queue and transmitting them.

Currently, as we do not have suspend blockers, we try to stop the queue in suspend() and if that fails we return something negative so that the suspend() is blocked by the negative return code.

Maybe the behaviour for an SPI bus should rather be to return -EBUSY as long as there are events in the queue. I don't quite know frankly.

(We haven't added runtime PM yet, it will likely be the same thing.)

With suspend blockers we take a suspend blocker when we add elements to the queue and release it when the queue is empty.

But with suspend blockers the need for suspend() to check if the queue can be stopped or return -EBUSY if there are elements in it is not necessary: suspend() simply won't be called since a suspend blocker is taken. There is no way for suspend() to stop a running queue like we do today if using suspend blockers.

This means that driver writers only targeting configurations where suspend blockers are used will probably not care about handling suspend() calls by trying to stop the queue or checking if there are things in it, because there will never be anything there.

So while it is easy for me to have the driver work under both suspend blockers and runtime PM or common suspend(), the two configurations actually have different semantics of the suspend() call: in the suspend blockers case you don't need to check anything, just suspend, and in the runtime PM case you have to check that you can actually suspend.

Is this analysis correct?

If yes then OK, it's not totally elegant but if that is where we have to go, I can live with it. There will likely be people who implement for only one or the other semantic behaviour, but we have worse things to cope with already.

Yours,
Linus Walleij

#356 lore raw
Quoted 4 lines · On Thu, 27 May 2010 09:46:51 +0200 Linus WALLEIJ…

If yes then OK, it's not totally elegant but if that is where we have to go, I can live with it. There will likely be people who implement for only one or the other semantic behaviour, but we have worse things to cope with already.

Alan Cox suggested, that this kind of explicit requirement definition might be necessary for all drivers anyway in the long run.

That way, the semantic differences between those two cases would vanish.

Cheers,
Flo

#357 lore raw
In reply to Linus WALLEIJ
Quoted 52 lines · Linus WALLEIJ

[Alan Stern]

Quoted 16 lines · Linus WALLEIJ

(...)

Quoted 3 lines

Now if this mechanism is going in, my main interest is that there is some clearly cut way and design pattern for supporting both runtime PM and suspend blocks.

It's not difficult.  You just have to decide what situations should block opportunistic suspend.  For example, let's say that opportunistic suspend should be blocked when your event queue is non-empty.

Then in the routine that adds new events to the queue, while still holding the spinlock that protects your queue, you enable your suspend blocker.  Likewise, in the routine that takes events off the queue and sends them to userspace, while holding the spinlock you test whether the queue has become empty; if it has you disable your suspend blocker.

Quoted 3 lines

That's all.  No other changes are needed (except to create and destroy the suspend blocker, of course).  No other interaction with suspend, resume, or runtime PM.

OK I understand it will be rather OK to do this. For example I have drivers/spi/amba-pl022.c which is quite clearly taking elements off a queue and transmitting them.

Currently, as we do not have suspend blockers, we try to stop the queue in suspend() and if that fails we return something negative so that the suspend() is blocked by the negative return code.

Maybe the behaviour for an SPI bus should rather be to return -EBUSY as long as there are events in the queue. I don't quite know frankly.

(We haven't added runtime PM yet, it will likely be the same thing.)

With suspend blockers we take a suspend blocker when we add elements to the queue and release it when the queue is empty.

But with suspend blockers the need for suspend() to check if the queue can be stopped or return -EBUSY if there are elements in it is not necessary: suspend() simply won't be called since a suspend blocker is taken. There is no way for suspend() to stop a running queue like we do today if using suspend blockers.

This means that driver writers only targeting configurations where suspend blockers are used will probably not care about handling suspend() calls by trying to stop the queue or checking if there are things in it, because there will never be anything there.

Quoted 9 lines

So while it is easy for me to have the driver work under both suspend blockers and runtime PM or common suspend(), the two configurations actually have different semantics of the suspend() call: in the suspend blockers case you don't need to check anything, just suspend, and in  the runtime PM case you have to check that you can actually suspend.

Is this analysis correct?

Mostly, yes. With the current suspend blocker implementation, if you only start blocking suspend from a user-space thread, or a freezable kernel thread, then your suspend hook will never be called while you block suspend unless you use forced suspend. If you for instance start blocking suspend in response to an interrupt on the other hand, there is no guarantee that drivers you depend on have not already been suspended or that they will not suspend after you block suspend, so you may have to implement a suspend hook to manually abort suspend even when using suspend blockers. You can add a check if your suspend blocker is active within your critical section in your suspend hook. Our alarm driver does this.

Quoted 5 lines

If yes then OK, it's not totally elegant but if that is where we have to go, I can live with it. There will likely be people who implement for only one or the other semantic behaviour, but we have worse things to cope with already.

Yes, but you can support both forced suspend and opportunistic suspend in the same driver. Supporting both is harder if the suspend blocker api is not in the mainline kernel.

Signature · 1 line
Arve Hjønnevåg
#358 lore raw
In reply to Linus WALLEIJ
Quoted 7 lines · Linus WALLEIJ

OK I understand it will be rather OK to do this. For example I have drivers/spi/amba-pl022.c which is quite clearly taking elements off a queue and transmitting them.

Currently, as we do not have suspend blockers, we try to stop the queue in suspend() and if that fails we return something negative so that the suspend() is blocked by the negative return code.

How can it fail? Even if the queue can't be stopped immediately, can't the suspend routine block for a few milliseconds until the queue can be stopped?

Quoted 3 lines

Maybe the behaviour for an SPI bus should rather be to return -EBUSY as long as there are events in the queue. I don't quite know frankly.

No. It should stop the queue.

Think of it this way: Somebody has just closed the lid of their laptop and thrown the computer into a backpack. You don't want the machine to fail to suspend merely because an SPI queue wasn't empty.

Quoted 2 lines

(We haven't added runtime PM yet, it will likely be the same thing.)

Runtime PM is very different. It is supposed to take effect only when the device is idle. So failing if the queue is non-empty makes sense.

Quoted 7 lines

With suspend blockers we take a suspend blocker when we add elements to the queue and release it when the queue is empty.

But with suspend blockers the need for suspend() to check if the queue can be stopped or return -EBUSY if there are elements in it is not necessary: suspend() simply won't be called since a suspend blocker is taken.

No, that's completely wrong. The user can tell the computer to suspend at any time, whether or not any suspend blockers are enabled. Think of the laptop-in-the-backpack case.

Quoted 3 lines

There is no way for
suspend() to stop a running queue like we do today if using suspend blockers.

I don't know what you mean by this, but it doesn't sound right.

Quoted 5 lines

This means that driver writers only targeting configurations where suspend blockers are used will probably not care about handling suspend() calls by trying to stop the queue or checking if there are things in it, because there will never be anything there.

You also have to handle races. What happens if your suspend routine is called, and at that moment an interrupt occurs, causing the driver to add an entry to the queue?

You're trying to over-simplify this, probably because you're not thinking about it in the right way. To put it bluntly, suspend blockers should not affect with your suspend/resume routines at all.

Quoted 6 lines

So while it is easy for me to have the driver work under both suspend blockers and runtime PM or common suspend(), the two configurations actually have different semantics of the suspend() call: in the suspend blockers case you don't need to check anything, just suspend, and in the runtime PM case you have to check that you can actually suspend.

The suspend-blockers case is exactly the same as the normal suspend case. The runtime PM case does require extra checking.

Quoted 1 line

Is this analysis correct?

No, it's mostly wrong.

Alan Stern

#359 lore raw

[Alan]

Quoted 18 lines · Linus WALLEIJ
Quoted 8 lines

OK I understand it will be rather OK to do this. For example I have drivers/spi/amba-pl022.c which is quite clearly taking elements off a queue and transmitting them.

Currently, as we do not have suspend blockers, we try to stop the queue in suspend() and if that fails we return something negative so that the suspend() is blocked by the negative return code.

How can it fail? Even if the queue can't be stopped immediately, can't the suspend routine block for a few milliseconds until the queue can be stopped?

Quoted 3 lines

Maybe the behaviour for an SPI bus should rather be to return -EBUSY as long as there are events in the queue. I don't quite know frankly.

Quoted 5 lines

No. It should stop the queue.

Think of it this way: Somebody has just closed the lid of their laptop and thrown the computer into a backpack. You don't want the machine to fail to suspend merely because an SPI queue wasn't empty.

Not quite! On the other end of that SPI link is our power regulators. (I'm not making this up, they are really there.) The events in the queue may be the register writes that actually put the system to low-power sleep.

But the apropriate action may likely be to wait for this queue to become empty before returning 0 from suspend().

Yours,
Linus Walleij

#360 lore raw
In reply to Paul Walmsley
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines · Arve Hjønnevåg
Quoted 2 lines

No, suspend blockers are mostly used to

ensure wakeup events are not

Quoted 1 line
Quoted 1 line
Quoted 1 line

ignored, and to ensure tasks triggered by

these wakeup events

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

complete.

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do.

Standard Linux systems

Quoted 1 line

support suspend, but since they usually don't have a

lot of wakeup

Quoted 1 line

events you don't run into a lot of problems.

Yes and no... stick a bunch of USB hubs and devices on the system, and you may have a lot of wake events. Keyboard, mouse, network adapter, and so on.

Way back when I made USB remote wakeup work, ISTR running
into a version of the issue you're raising. Briefly, the wake event could be queued in hardware, but there were also various unavoidable races .... with ambiguity about just when particular events should be recognized. If the system entered sleep before the wake event(s) triggered, or the relevant devices suspended first, then things were clear; otherwise, not. On first blush, I'd expect every hardware wake mechanism would have the same issues; the fact that USB wakes are mediated via khubd is not a huge difference.

maintainer
#361 lore raw
In reply to Arve Hjønnevåg
Quoted 10 lines · Arve Hjønnevåg
Quoted 9 lines · Paul Walmsley

Hello,

Quoted 3 lines · Arve Hjønnevåg

No, suspend blockers are mostly used to ensure wakeup events are not ignored, and to ensure tasks triggered by these wakeup events complete.

Quoted 6 lines
Quoted 1 line

Standard Linux systems don't need these,

If you don't want to lose wakeup events they do. Standard Linux systems support suspend, but since they usually don't have a lot of wakeup events you don't run into a lot of problems.

What I do not quite understand is how exactly suspend blocks save us from missing wakeup events. Consider case when all events have been processed and system starts entering the sleep: we are in a half-sleep, half awake state, with some devices already put to sleep and some just now being processed. If user presses a key while physical input device is being suspended, what will happen? Do you expect interrupt routine abort suspend process? Initiate resume if suspend of the device has completed?

Also, let's say device is suspended and is configured as a wakeup source while the rest of the system is still awake... If I press a key I do not think that it will necessarily abort suspend process. Or will it?

BTW, If you are concerned about events that already "left" physical device but has not reached userspace yet - maybe instead of suspend blockers we should make sure that all drivers throughout the chain implement suspend/resume and refuse suspending if their queues are not empty. In input land that would mean extending suspend routine in input_dev and adding one to evdev.

Thanks.

Signature · 1 line
Dmitry
#362 lore raw
Quoted 8 lines · Dmitry Torokhov

What I do not quite understand is how exactly suspend blocks save us from missing wakeup events. Consider case when all events have been processed and system starts entering the sleep: we are in a half-sleep, half awake state, with some devices already put to sleep and some just now being processed. If user presses a key while physical input device is being suspended, what will happen? Do you expect interrupt routine abort suspend process? Initiate resume if suspend of the device has completed?

This depends on several factors, such as how the input device drivers are written and how the hardware works, as well as the details of the timing. Here are a few possibilities:

The keypress is not handled but stays in the hardware as a wakeup event. The system goes through its entire suspend procedure, and then the pending wakeup event immediately cases it to wake up. Then the keypress gets handled normally.

Or the keypress is treated as a normal IRQ and handled by the hardware. The input subsystem puts the keystroke on the event queue (all done while in_interrupt), where it languishes because userspace is frozen and can't read it. The system goes to sleep and stays that way until something else wakes it up. (This is a type-3 failure as described in my earlier email.)

Or the keypress is handled normally and the input subsystem interprets it as a runtime resume request, telling the PM core to queue a resume call. But the PM core's runtime workqueue thread has already been frozen, and so the event remains on the work queue until the system wakes up on its own. (This is a type-2 failure.)

Or we fix the PM core, so that when the resume call is added to the workqueue it realizes the suspend-in-progress needs to be aborted. The system goes back to a fully-awake state and the keystroke is handled normally.

Quoted 3 lines

Also, let's say device is suspended and is configured as a wakeup source while the rest of the system is still awake... If I press a key I do not think that it will necessarily abort suspend process. Or will it?

Since the keyboard is a wakeup device, it certainly should abort the suspend. Or at least it should wake the system up as soon as the system finishes going to sleep. At the moment, though, I'm not sure that it does behave either way.

Quoted 6 lines

BTW, If you are concerned about events that already "left" physical device but has not reached userspace yet - maybe instead of suspend blockers we should make sure that all drivers throughout the chain implement suspend/resume and refuse suspending if their queues are not empty. In input land that would mean extending suspend routine in input_dev and adding one to evdev.

That's not the only problem. We also have to consider events that have reached userspace but not yet been fully processed. The user thread handling the event needs some way to prevent the system from suspending until it is all done.

Alan Stern

maintainer
#363 lore raw
Quoted 9 lines · Alan Stern
Quoted 6 lines · Dmitry Torokhov

BTW, If you are concerned about events that already "left" physical device but has not reached userspace yet - maybe instead of suspend blockers we should make sure that all drivers throughout the chain implement suspend/resume and refuse suspending if their queues are not empty. In input land that would mean extending suspend routine in input_dev and adding one to evdev.

Quoted 5 lines

That's not the only problem. We also have to consider events that have reached userspace but not yet been fully processed. The user thread handling the event needs some way to prevent the system from suspending until it is all done.

It is a problem if kernel initiated suspend transition on its own. I believe that it is userspace responsibility to initiate sustend (and make sure that needs of userspace, including processing of certain events, are served beforehand).

Signature · 1 line
Dmitry
#364 lore raw
Quoted 16 lines · Dmitry Torokhov
Quoted 9 lines · Alan Stern
Quoted 6 lines · Dmitry Torokhov

BTW, If you are concerned about events that already "left" physical device but has not reached userspace yet - maybe instead of suspend blockers we should make sure that all drivers throughout the chain implement suspend/resume and refuse suspending if their queues are not empty.  In input land that would mean extending suspend routine in input_dev and adding one to evdev.

Quoted 5 lines

That's not the only problem.  We also have to consider events that have reached userspace but not yet been fully processed.  The user thread handling the event needs some way to prevent the system from suspending until it is all done.

Quoted 4 lines

It is a problem if kernel initiated suspend transition on its own. I believe that it is userspace responsibility to initiate sustend (and make sure that needs of userspace, including processing of certain events, are served beforehand).

That only works if a single user-space thread initiates suspend and consumes all wakeup events (or if the user-space code that initiates suspend implements suspend blockers), and even then the kernel would still need to block suspend in same places as it does if the kernel initiates suspend. If a wakeup event happens right after user-space initiates suspend, that suspend must be aborted. By only initiating suspend from user-space, you force this to be a polling operation.

Signature · 1 line
Arve Hjønnevåg
maintainer
#365 lore raw
Quoted 18 lines · Arve Hjønnevåg
Quoted 16 lines · Dmitry Torokhov
Quoted 14 lines · Alan Stern
Quoted 6 lines · Dmitry Torokhov

BTW, If you are concerned about events that already "left" physical device but has not reached userspace yet - maybe instead of suspend blockers we should make sure that all drivers throughout the chain implement suspend/resume and refuse suspending if their queues are not empty.  In input land that would mean extending suspend routine in input_dev and adding one to evdev.

That's not the only problem.  We also have to consider events that have reached userspace but not yet been fully processed.  The user thread handling the event needs some way to prevent the system from suspending until it is all done.

Quoted 6 lines
Quoted 4 lines

It is a problem if kernel initiated suspend transition on its own. I believe that it is userspace responsibility to initiate sustend (and make sure that needs of userspace, including processing of certain events, are served beforehand).

That only works if a single user-space thread initiates suspend

Yes, there should be a single entity controlling suspend.

Quoted 3 lines

and
consumes all wakeup events (or if the user-space code that initiates suspend implements suspend blockers),

Yes.

Quoted 4 lines

and even then the kernel would
still need to block suspend in same places as it does if the kernel initiates suspend. If a wakeup event happens right after user-space initiates suspend, that suspend must be aborted.

This is true regardless of whether we use suspend blockers or not. If, after initiating suspend, we detect wake up event that event shoudl be acted upon and suspend should be ignored.

Quoted 3 lines

By only initiating
suspend from user-space, you force this to be a polling operation.

I am not sure what you mean by this.

Signature · 1 line
Dmitry
#366 lore raw
In reply to Kevin Hilman
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Signature · 1 line
Matthew Garrett | [email protected]
#367 lore raw
In reply to Kevin Hilman
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Signature · 1 line
Matthew Garrett | [email protected]
#368 lore raw
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

Alan Stern

#369 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

Alan Stern

#370 lore raw
Quoted 16 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Quoted 5 lines

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

In an embedded system I'd expect that these other system devices would fall naturally out through the management of the CPUs and devices - for example, the drivers for the individual devices could use the regulator API to manage their supplies and runtime PM is being used to manage CPU core stuff - or could at least readily be handled in a similar fashion.

This isn't to say that we're there yet from an implementation point of view, of course.

#371 lore raw
In reply to Alan Stern
Quoted 16 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Quoted 5 lines

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

In an embedded system I'd expect that these other system devices would fall naturally out through the management of the CPUs and devices - for example, the drivers for the individual devices could use the regulator API to manage their supplies and runtime PM is being used to manage CPU core stuff - or could at least readily be handled in a similar fashion.

This isn't to say that we're there yet from an implementation point of view, of course.

#372 lore raw
In reply to Alan Stern
Quoted 17 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Quoted 5 lines

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

I consider all of those things devices.

On non-ACPI systems where the kernel has to manage all of the above directly, we have drivers for all of them using runtime PM as well as the regulator framework for dynamic PM power supplies.

Kevin

#373 lore raw
In reply to Alan Stern
Quoted 17 lines · Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

Quoted 5 lines

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

I consider all of those things devices.

On non-ACPI systems where the kernel has to manage all of the above directly, we have drivers for all of them using runtime PM as well as the regulator framework for dynamic PM power supplies.

Kevin

#374 lore raw
In reply to Alan Stern
Quoted 5 lines · Alan Stern

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

Somewhat true - machines with C1E support will put the RAM into self refresh when the cpu is idle, but you're right that there are various components that we simply don't have control over in the desktop world at present.

Signature · 1 line
Matthew Garrett | [email protected]
#375 lore raw
In reply to Alan Stern
Quoted 5 lines · Alan Stern

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

Somewhat true - machines with C1E support will put the RAM into self refresh when the cpu is idle, but you're right that there are various components that we simply don't have control over in the desktop world at present.

Signature · 1 line
Matthew Garrett | [email protected]
#376 lore raw
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

Another thing that Kevin is missing: There is more to the system than the devices and the CPU.  For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on.  Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

Quoted 4 lines

Somewhat true - machines with C1E support will put the RAM into self refresh when the cpu is idle, but you're right that there are various components that we simply don't have control over in the desktop world at present.

As a contrast, at least on some embedded SoCs without firmware limitations the low level sleep code for Runtime PM / CPU Idle is shared with system wide suspend. So the RAM is put into self refresh regardless of entering a half-deep CPU Idle state or entering suspend-to-memory.

I've heard that newer SH-Mobile ARM hardware monitors the memory bus activity behind the scenes and can put the system RAM into self refresh automatically. On older parts we had to manage that from CPU idle context.

/ magnus

#377 lore raw
In reply to Matthew Garrett
Quoted 8 lines · Matthew Garrett
Quoted 5 lines · Alan Stern

Another thing that Kevin is missing: There is more to the system than the devices and the CPU.  For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on.  Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

Quoted 4 lines

Somewhat true - machines with C1E support will put the RAM into self refresh when the cpu is idle, but you're right that there are various components that we simply don't have control over in the desktop world at present.

As a contrast, at least on some embedded SoCs without firmware limitations the low level sleep code for Runtime PM / CPU Idle is shared with system wide suspend. So the RAM is put into self refresh regardless of entering a half-deep CPU Idle state or entering suspend-to-memory.

I've heard that newer SH-Mobile ARM hardware monitors the memory bus activity behind the scenes and can put the system RAM into self refresh automatically. On older parts we had to manage that from CPU idle context.

/ magnus

#378 lore raw
In reply to Alan Stern

Hello,

Quoted 5 lines · Alan Stern

Another thing that Kevin is missing: There is more to the system than the devices and the CPU. For example: RAM, an embedded controller (on modern desktop/laptop systems), a power supply, and so on. Dynamic PM for the CPU and the devices won't power-down these things, but system PM will.

No. A dynamic PM-based kernel can, and in the case of the mainline Linux code running on OMAP, does, power down RAM[1] and the power supply[2].

Since the CPU is already powered off when it is time for this to happen, so this is done under autonomous hardware control. We currently use CPUIdle[3] to choose whether to program the SoC hardware to enable this autonomous power control before it goes off, depending on the required wakeup latency for timers and PM constraints.

- Paul

1. (technically, put the RAM into self-refresh mode):
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/sleep34xx.S/sleep34xx.S;h=d522cd70bf53485d0a3af2453845777e3a89edd7;hb=4fc4c3ce0dc1096cbd0daa3fe8f6905cbec2b87e#l204

2. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/sleep34xx.S/sleep34xx.S;h=d522cd70bf53485d0a3af2453845777e3a89edd7;hb=4fc4c3ce0dc1096cbd0daa3fe8f6905cbec2b87e#l204

3. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/cpuidle34xx.c;h=3d3d035db9aff62ce522e0080e570cfdbf8e70cc;hb=4462dc02842698f173f518c1f5ce79c0fb89395a#l292

#379 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

OK, that's a major difference with embedded SoCs where the kernel must directly manage the power state of all devices using runtime PM.

So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.

Kevin

#380 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

Quoted 5 lines

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend. The number of wakeup events available to us on a given machine is usually small and the wakeup latency large, so it's not terribly practical to do this transparently on most hardware.

OK, that's a major difference with embedded SoCs where the kernel must directly manage the power state of all devices using runtime PM.

So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.

Kevin

#381 lore raw
Quoted 2 lines · Kevin Hilman

So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.

I'd say it does for most devices, but the power savings may not be as great as they would be with fine-grained control over power rails.

Signature · 1 line
Matthew Garrett | [email protected]
#382 lore raw
In reply to Kevin Hilman
Quoted 2 lines · Kevin Hilman

So basically, on ACPI systems, runtime PM doesn't get you any power savings for most devices.

I'd say it does for most devices, but the power savings may not be as great as they would be with fine-grained control over power rails.

Signature · 1 line
Matthew Garrett | [email protected]
#383 lore raw
In reply to Matthew Garrett

Hello,

Quoted 11 lines · Matthew Garrett
Quoted 6 lines · Kevin Hilman

Please forgive the ignorance of ACPI (in embedded, we thankfully live in magical world without ACPI) but doesn't that already happen with CPUidle and C-states? I think of CPUidle as basically runtime PM for the CPU. IOW, runtime PM manages the devices, CPUidle manages the CPU (via C-states), resulting in dynaimc PM for the entire system. What am I missing?

ACPI doesn't provide any functionality for cutting power to most devices other than shifting into full system suspend.

ACPI may not, but the vast majority of ACPI systems are paired with PCI buses, or buses that emulate PCI buses; and PCI devices can implement device power control through the PCI Power Management capability. On my 2-year old ThinkPad, 13 of the 24 devices do, according to lspci.

Many Linux device drivers already use PCI D-states to support a rudimentary form of runtime PM:

[paul@twilight current]$ fgrep -r pci_set_power_state drivers/ | cut -d:
-f1 | sort -u
drivers/ata/ata_piix.c
drivers/ata/libata-core.c
drivers/ata/pata_macio.c
drivers/block/cciss.c
drivers/char/agp/amd64-agp.c
drivers/char/agp/amd-k7-agp.c
drivers/char/agp/ati-agp.c
drivers/char/agp/nvidia-agp.c
drivers/char/agp/sis-agp.c
drivers/char/agp/via-agp.c
drivers/firewire/ohci.c
drivers/gpio/bt8xxgpio.c
drivers/gpu/drm/i915/i915_dma.c drivers/gpu/drm/i915/i915_drv.c drivers/gpu/drm/nouveau/nouveau_drv.c drivers/gpu/drm/radeon/radeon_device.c drivers/gpu/drm/vmwgfx/vmwgfx_drv.c drivers/i2c/busses/i2c-i801.c
drivers/ide/delkin_cb.c
drivers/ide/sc1200.c
drivers/ide/setup-pci.c
drivers/ieee1394/ohci1394.c drivers/media/video/bt8xx/bttv-driver.c drivers/media/video/cx88/cx88-mpeg.c drivers/media/video/cx88/cx88-video.c drivers/media/video/saa7134/saa7134-core.c drivers/memstick/host/jmb38x_ms.c drivers/message/fusion/mptbase.c
drivers/misc/cb710/core.c
drivers/misc/tifm_7xx1.c
drivers/mmc/host/sdhci-pci.c
drivers/mmc/host/via-sdmmc.c
drivers/net/3c59x.c
drivers/net/8139cp.c
drivers/net/8139too.c
drivers/net/amd8111e.c
drivers/net/atl1c/atl1c_main.c drivers/net/atl1e/atl1e_main.c
drivers/net/atlx/atl1.c
drivers/net/atlx/atl2.c
drivers/net/benet/be_main.c
drivers/net/e1000/e1000_main.c
drivers/net/e1000e/netdev.c
drivers/net/e100.c
drivers/net/forcedeth.c
drivers/net/igb/igb_main.c
drivers/net/irda/vlsi_ir.c
drivers/net/ixgbe/ixgbe_main.c
drivers/net/jme.c
drivers/net/ksz884x.c
drivers/net/myri10ge/myri10ge.c
drivers/net/ne2k-pci.c
drivers/net/netxen/netxen_nic_main.c drivers/net/pci-skeleton.c
drivers/net/pcnet32.c
drivers/net/qlcnic/qlcnic_main.c drivers/net/qlge/qlge_main.c
drivers/net/r8169.c
drivers/net/sc92031.c
drivers/net/sfc/efx.c
drivers/net/sis900.c
drivers/net/skge.c
drivers/net/sky2.c
drivers/net/smsc9420.c
drivers/net/starfire.c
drivers/net/tc35815.c
drivers/net/tg3.c
drivers/net/tulip/dmfe.c
drivers/net/tulip/tulip_core.c
drivers/net/tulip/uli526x.c
drivers/net/typhoon.c
drivers/net/via-rhine.c
drivers/net/via-velocity.c
drivers/net/vmxnet3/vmxnet3_drv.c drivers/net/wireless/adm8211.c
drivers/net/wireless/airo.c drivers/net/wireless/ath/ath9k/pci.c drivers/net/wireless/hostap/hostap_pci.c drivers/net/wireless/ipw2x00/ipw2100.c drivers/net/wireless/ipw2x00/ipw2200.c drivers/net/wireless/iwlwifi/iwl-core.c drivers/net/wireless/orinoco/orinoco_pci.h drivers/net/wireless/p54/p54pci.c drivers/net/wireless/prism54/islpci_hotplug.c drivers/net/wireless/rt2x00/rt2x00pci.c drivers/net/wireless/rtl818x/rtl8180_dev.c drivers/parport/parport_serial.c
drivers/pci/pci-acpi.c
drivers/pci/pci.c
drivers/pci/pci-driver.c
drivers/pcmcia/yenta_socket.c
drivers/scsi/3w-9xxx.c
drivers/scsi/3w-sas.c
drivers/scsi/aic7xxx/aic79xx_osm_pci.c drivers/scsi/aic7xxx/aic7xxx_osm_pci.c drivers/scsi/aic7xxx/aic7xxx_pci.c
drivers/scsi/hpsa.c
drivers/scsi/lpfc/lpfc_init.c drivers/scsi/megaraid/megaraid_sas.c drivers/scsi/mpt2sas/mpt2sas_scsih.c
drivers/scsi/nsp32.c
drivers/scsi/pm8001/pm8001_init.c
drivers/scsi/pmcraid.c
drivers/serial/8250_pci.c
drivers/serial/serial_txx9.c
drivers/spi/dw_spi_pci.c
drivers/ssb/pcihost_wrapper.c drivers/staging/crystalhd/crystalhd_lnx.c drivers/staging/rt2860/pci_main_dev.c drivers/staging/rtl8187se/r8180_core.c drivers/staging/rtl8192e/r8192_pm.c drivers/staging/sm7xx/smtcfb.c drivers/staging/vt6655/device_main.c drivers/usb/gadget/langwell_udc.c
drivers/video/arkfb.c
drivers/video/aty/aty128fb.c
drivers/video/aty/atyfb_base.c
drivers/video/aty/radeon_pm.c
drivers/video/i810/i810_main.c
drivers/video/nvidia/nvidia.c
drivers/video/s3fb.c
drivers/video/savage/savagefb_driver.c drivers/video/vt8623fb.c
drivers/virtio/virtio_pci.c

- Paul

#384 lore raw
In reply to Rafael J. Wysocki

Hi,

Quoted 6 lines · Rafael J. Wysocki

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

Runtime PM is also aimed at system power management as a whole. The difference is that it approaches the problem from the bottom up (i.e., the activity level of the actual hardware devices) rather than from the top down (i.e., "echo mem > /sys/power/state").

In bottom-up approaches, like runtime PM, system-level power management becomes a very small fraction of the total power management problem. It is only possible to power down that small fraction once all devices, and the clock and power domains/islands that contain those devices, become idle. ("Devices" here is used in a hardware sense, and thus includes the CPU.)

A bottom-up approach like runtime PM allows parts of the system can be powered off when they are not in use. This is important on systems that have more levels of power management hierarchy than just "device" and "system," as is the case on modern SoCs like Renesas SH-Mobile, Intel Moorestown[1], and TI OMAP[2]. These chips group devices into sets of multiple power domains/islands, which can be controlled independently.

Once the devices, including the CPU, are idle, the system idle loop can be entered to determine what power level the system should be programmed to enter. At this point, system-level power management only controls a small fraction, maybe 1% or 2%, of the chipset that is not associated with any devices; along with any board-level resources that the chipset depends on to function that are power-controllable, such as the system high-frequency clock oscillator[3].

No heavyweight process of iterating through the device tree to suspend them is needed at this point, as with a top-down power management approach like Android opportunistic suspend, since the system already knows that the devices are idle.

Of course, to determine what system-level power state to enter, there needs to be some sort of governor to handle these system-level power decisions. On mainline Linux OMAP, we use the CPUIdle governor to do this[4]. This is not the cleanest possible choice[5], but works pretty well in the absence of a system-level governor.

The Linux OMAP CPUIdle code considers the next timer expiration and any PM constraints[6]. Based on the required wakeup latency and constraints, the PM code[7][8] programs the power-controllable parts of the system to enter one of several power states. The CPU then enters WFI (wait-for-interrupt, like x86 HLT), and the SoC power management controller implements the system power transition, now that all on-chip devices are idle.

All of this is already implemented in mainline Linux code[9]. Devices based on this code have already shipped from multiple vendors[10][11][12][13]. These devices have small batteries and long use-times, which attests to the performance of this approach.

Since this approach does not "echo mem > /sys/power/state", it honors the existing Linux timer and scheduler subsystems, and so this is all possible without systemic modification of the kernel code tree or device drivers, in contrast to the current Android proposal under consideration.

- Paul

1. Jacob Pan's presentation at ELC 2010, "Porting the Linux Kernel to x86 MID Platforms":
http://elinux.org/images/e/ee/Jacob-Pan-x86MID-elc2010.pdf

2. OMAP35x Technical Reference Manual Rev. F, Figure 4-16 "Device Power Domains": http://www.ti.com/litv/pdf/spruf98f

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. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/cpuidle34xx.c;h=3d3d035db9aff62ce522e0080e570cfdbf8e70cc;hb=4462dc02842698f173f518c1f5ce79c0fb89395a#l292

5. 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

6. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/plat-omap/include/plat/omap-pm.h;h=3ee41d7114929d771cadbb9f02191fd16c5b5abe;hb=4fc4c3ce0dc1096cbd0daa3fe8f6905cbec2b87e

7. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/pm24xx.c;h=374299ea7aded92999b5e54439e43f017806ce4d;hb=4fc4c3ce0dc1096cbd0daa3fe8f6905cbec2b87e

8. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/mach-omap2/pm34xx.c;h=ea0000bc5358e196df58e88da3f54dd71f0a4706;hb=4fc4c3ce0dc1096cbd0daa3fe8f6905cbec2b87e

9. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree;f=arch/arm/mach-omap2;hb=4fc4c3ce0dc1096cbd0daa3fe8f6905cbec2b87e

10. http://en.wikipedia.org/wiki/Palm_Pre

11. http://en.wikipedia.org/wiki/N800

12. http://en.wikipedia.org/wiki/N810

13. http://en.wikipedia.org/wiki/N900

#385 lore raw
In reply to Mark Brown
Quoted 27 lines · Mark Brown
Quoted 7 lines · Kevin Hilman

At least from the kernel perspective, both suspend blockers and runtime PM have the same goal. Given that, which framework should the driver writer target? Both? Seems like duplicate effort. Using suspend blockers assumes the system is in opportunitstic suspend mode and (at least in the keypad example given) assumes a suspend-blocker aware userspace (Android.) Without both, targeted power savings will not be acheived.

The other concern here is that for many mobile systems the actual semantic intended by "suspend" as it's currently used is more runtime PM like than full suspend - the classic example of this is that when suspending while on a call in a phone you don't want to suspend the modem or audio CODEC, you want to leave them running. If you use a full system suspend then the drivers for affected components have to play guessing games (or add currently non-standard knobs for apps to twiddle) to decide if the system intends them to actually implement the suspend or not but with runtime PM it all falls out very naturally without any effort on the part of the driver.

Quoted 5 lines

To me, runtime PM is a generic and flexible approach that can be used with any userspace. Driver writers should not have to care whether the system is in "opportunistic" mode or about whether userspace is suspend blocker capable. They should only have to think about when the device is (or should be) idle.

Quoted 3 lines

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

I _think_ it would be hard at least. On ACPI-based systems it's not doable at all AFAICS.

However, the real question is whether or not the opportunistic suspend feature is worth adding to the kernel as such and I think it is.

To me, it doesn't duplicate the runtime PM framework which is aimed at the power management of individual devices rather than the system as a whole.

Thanks,
Rafael

#386 lore raw
In reply to Mark Brown

Hello,

Quoted 3 lines · Mark Brown

I fully agree with this. We do need to ensure that a runtime PM based system can suspend the CPU core and RAM as well as system suspend can but that seems doable.

It is already possible on OMAP-based systems running mainline Linux[1].

Consumer-market Linux devices that do this have been available since at least 2007[2].

Intel is pursing a similar approach with Moorestown[3], since "echo mem > /sys/power/state" is much more inflexible than an idle-loop-based system "suspend."

Going forward, ACPI-style centralized power management is dead. Like "echo mem > /sys/power/state", ACPI PM is too inflexible for most use-cases, and so wastes power because the system must be kept in a higher-power state than necessary. Even Intel is abandoning ACPI[4].

- Paul

1. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri May 14 10:22:05 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025530.html

2. http://en.wikipedia.org/wiki/Nokia_N800

3. German Monroy's presentation at ELC 2010, "Wake-ups Effect on Idle Power for Intel's Moorestown MID and Smartphone Platform":
http://elinux.org/images/0/07/Effect_of_wakeups_on_Moorestown_power.pdf

4. Jacob Pan's presentation at ELC 2010, "Porting the Linux Kernel to x86 MID Platforms": http://elinux.org/images/e/ee/Jacob-Pan-x86MID-elc2010.pdf

#387 lore raw
In reply to Kevin Hilman
Quoted 5 lines · Kevin Hilman

In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)

I'd say that this is certainly the main issue, though the remaining periodic timers in the kernel are also inconvenient.

Quoted 5 lines

And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?

I considered this. The problem is that not all of your wakeup events pass through trusted code. Assume we've used a freezer cgroup and the applications are now frozen. One of them is blocking on a network socket. A packet arrives and triggers a wakeup of the hardware. How do we unfreeze the userspace app?

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace. The use-cases that Google have provided are valid and they have an implementation that addresses them, and while we're unable to provide an alternative that provides the same level of functionality I think we're in a poor position to prevent this from going in.

Signature · 1 line
Matthew Garrett | [email protected]
#388 lore raw
In reply to Kevin Hilman
Quoted 5 lines · Kevin Hilman

In my view, the truly significant difference between suspend blockers and runtime PM is what happens to userspace. So far, to me the only compelling argument for suspend blockers is the goal of forcibly shutting down userspace and thus forcing the system into idle (although drivers could still reject a suspend request.)

I'd say that this is certainly the main issue, though the remaining periodic timers in the kernel are also inconvenient.

Quoted 5 lines

And if untrusted userspace apps remain as the major problem, maybe we should aim for a solution directly targetting that problem. I'm just shooting from the hip now, but maybe containing (cgroups?) untrusted processes together into a set that could be frozen/idled so that runtime PM would be more effective would be a workable solution?

I considered this. The problem is that not all of your wakeup events pass through trusted code. Assume we've used a freezer cgroup and the applications are now frozen. One of them is blocking on a network socket. A packet arrives and triggers a wakeup of the hardware. How do we unfreeze the userspace app?

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace. The use-cases that Google have provided are valid and they have an implementation that addresses them, and while we're unable to provide an alternative that provides the same level of functionality I think we're in a poor position to prevent this from going in.

Signature · 1 line
Matthew Garrett | [email protected]
#389 lore raw

Hello,

Quoted 3 lines · Matthew Garrett

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace.

The problem of how to start and stop (some) userspace is not specifically system power management-related, nor top-down, /sys/power/state-suspend related. PM is just one potential user.

It's hard to see how the Android opportunistic suspend approach would be useful for the other use-cases (e.g., checkpoint/restart). On the other hand, it's easier to see how something like freezer cgroups could be useful for system power management and checkpoint/restart.

And the Android opportunistic suspend patches have design problems - they definitely do not come for free, as noted in [1][2][3] (among others' comments).

- Paul

1. 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

2. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:13:50 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18657

3. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:27:56 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18658

#390 lore raw
Quoted 8 lines · Paul Walmsley

Hello,

Quoted 3 lines · Matthew Garrett

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace.

Quoted 8 lines

The problem of how to start and stop (some) userspace is not specifically system power management-related, nor top-down, /sys/power/state-suspend related. PM is just one potential user.

It's hard to see how the Android opportunistic suspend approach would be useful for the other use-cases (e.g., checkpoint/restart). On the other hand, it's easier to see how something like freezer cgroups could be useful for system power management and checkpoint/restart.

And difficult to see how to implement something using freezer cgroups that actually works in this case. Look, I don't want to sound like I have a one-track mind or anything, but all of these arguments would be significantly more compelling if someone would actually provide a concrete implementation proposal that deals with the set of use-cases that Google's implementation does and which doesn't make anyone cry. Otherwise the immeasurably most likely outcome is that this code gets merged and we get to live with it.

Signature · 1 line
Matthew Garrett | [email protected]
#391 lore raw
Quoted 18 lines · Matthew Garrett
Quoted 8 lines · Paul Walmsley

Hello,

Quoted 3 lines · Matthew Garrett

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace.

Quoted 8 lines

The problem of how to start and stop (some) userspace is not specifically system power management-related, nor top-down, /sys/power/state-suspend related. PM is just one potential user.

It's hard to see how the Android opportunistic suspend approach would be useful for the other use-cases (e.g., checkpoint/restart). On the other hand, it's easier to see how something like freezer cgroups could be useful for system power management and checkpoint/restart.

Quoted 6 lines

And difficult to see how to implement something using freezer cgroups that actually works in this case. Look, I don't want to sound like I have a one-track mind or anything, but all of these arguments would be significantly more compelling if someone would actually provide a concrete implementation proposal that deals with the set of use-cases that Google's implementation does and which doesn't make anyone cry.

That might be possible if this "set of use-cases" was available someplace. At least I haven't seen it, and would expect it to be in the docs included with patch 1.

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

Yes, "excruciatingly bad" apps can kill PM on these systems since anyone can write apps, but the same is true on an opporunistic-suspend based system since any app could hold a suspend blocker whenever it wants.

Kevin

[1] https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025415.html
[2] https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025532.html

#392 lore raw
Quoted 38 lines · Kevin Hilman
Quoted 18 lines · Matthew Garrett
Quoted 8 lines · Paul Walmsley

Hello,

Quoted 3 lines · Matthew Garrett

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace.

Quoted 8 lines

The problem of how to start and stop (some) userspace is not specifically system power management-related, nor top-down, /sys/power/state-suspend related.  PM is just one potential user.

It's hard to see how the Android opportunistic suspend approach would be useful for the other use-cases (e.g., checkpoint/restart).  On the other hand, it's easier to see how something like freezer cgroups could be useful for system power management and checkpoint/restart.

Quoted 6 lines

And difficult to see how to implement something using freezer cgroups that actually works in this case. Look, I don't want to sound like I have a one-track mind or anything, but all of these arguments would be significantly more compelling if someone would actually provide a concrete implementation proposal that deals with the set of use-cases that Google's implementation does and which doesn't make anyone cry.

That might be possible if this "set of use-cases" was available someplace.  At least I haven't seen it, and would expect it to be in the docs included with patch 1.

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

Quoted 5 lines

Yes, "excruciatingly bad" apps can kill PM on these systems since anyone can write apps, but the same is true on an opporunistic-suspend based system since any app could hold a suspend blocker whenever it wants.

No, apps need permission to block suspend.

Signature · 1 line
Arve Hjønnevåg
#393 lore raw
Quoted 40 lines · Arve Hjønnevåg
Quoted 38 lines · Kevin Hilman
Quoted 18 lines · Matthew Garrett
Quoted 8 lines · Paul Walmsley

Hello,

Quoted 3 lines · Matthew Garrett

I agree that the runtime scenario is a far more appealing one from an aesthetic standpoint, but so far we don't have a very compelling argument for dealing with the starting and stopping of userspace.

Quoted 8 lines

The problem of how to start and stop (some) userspace is not specifically system power management-related, nor top-down, /sys/power/state-suspend related. PM is just one potential user.

It's hard to see how the Android opportunistic suspend approach would be useful for the other use-cases (e.g., checkpoint/restart). On the other hand, it's easier to see how something like freezer cgroups could be useful for system power management and checkpoint/restart.

Quoted 6 lines

And difficult to see how to implement something using freezer cgroups that actually works in this case. Look, I don't want to sound like I have a one-track mind or anything, but all of these arguments would be significantly more compelling if someone would actually provide a concrete implementation proposal that deals with the set of use-cases that Google's implementation does and which doesn't make anyone cry.

That might be possible if this "set of use-cases" was available someplace. At least I haven't seen it, and would expect it to be in the docs included with patch 1.

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

Quoted 7 lines
Quoted 5 lines

Yes, "excruciatingly bad" apps can kill PM on these systems since anyone can write apps, but the same is true on an opporunistic-suspend based system since any app could hold a suspend blocker whenever it wants.

No, apps need permission to block suspend.

Are you referring to the fact the permissions of the special device file or something different?

Rafael

#394 lore raw
Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines
Quoted 5 lines

Yes, "excruciatingly bad" apps can kill PM on these systems since anyone can write apps, but the same is true on an opporunistic-suspend based system since any app could hold a suspend blocker whenever it wants.

No, apps need permission to block suspend.

Are you referring to the fact the permissions of the special device file or something different?

The special device file will have filesystem permissions that limit access to system services.

Arbitrary userspace apps do not have direct access to the device -- they use a service (provided by binder rpc), and the app must declare its intent (and the user accept this on install) in order to use that service. The service keeps track of usage stats so if a user experiences poor battery life they can look at the battery usage thing and see which apps are keeping the device awake, etc.

Brian

#395 lore raw
Quoted 12 lines · Brian Swetland
Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines
Quoted 5 lines

Yes, "excruciatingly bad" apps can kill PM on these systems since anyone can write apps, but the same is true on an opporunistic-suspend based system since any app could hold a suspend blocker whenever it wants.

No, apps need permission to block suspend.

Are you referring to the fact the permissions of the special device file or something different?

Quoted 7 lines

The special device file will have filesystem permissions that limit access to system services.

Arbitrary userspace apps do not have direct access to the device -- they use a service (provided by binder rpc), and the app must declare its intent (and the user accept this on install) in order to use that service.

On Android, right?

Quoted 3 lines

The service keeps track of usage stats so if a user experiences poor battery life they can look at the battery usage thing and see which apps are keeping the device awake, etc.

That sounds like it should go into a doc or at least into the changelog of patch [2/8] IMnsHO.

The thing you said about timers in one of the previous messages should be documented too, BTW, because it's one of the motivation factors for this work.

In general, I think the motivation is not explained sufficienty in the patches' changelogs and that's one of the reasons why people have so many doubts about the feature's usefulness.

Thanks,
Rafael

#396 lore raw
Quoted 10 lines · Rafael J. Wysocki
Quoted 7 lines · Brian Swetland

The special device file will have filesystem permissions that limit access to system services.

Arbitrary userspace apps do not have direct access to the device -- they use a service (provided by binder rpc), and the app must declare its intent (and the user accept this on install) in order to use that service.

On Android, right?

Yup -- other userspace environments may choose different ways to grant/deny access. At the bottom we gate it by having a group that processes which may access the device are part of (with the device node being 0660, etc).

Quoted 7 lines
Quoted 3 lines

The service keeps track of usage stats so if a user experiences poor battery life they can look at the battery usage thing and see which apps are keeping the device awake, etc.

That sounds like it should go into a doc or at least into the changelog of patch [2/8] IMnsHO.

Quoted 7 lines

The thing you said about timers in one of the previous messages should be documented too, BTW, because it's one of the motivation factors for this work.

In general, I think the motivation is not explained sufficienty in the patches' changelogs and that's one of the reasons why people have so many doubts about the feature's usefulness.

Seems reasonable -- I know Arve's working on making these a bit more verbose for you.

Brian

#397 lore raw
In reply to Kevin Hilman
Quoted 6 lines · Kevin Hilman

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

The examples cited where the things like the Palm Pre, and the Nokia N770/800/810 series. #1, what works on one embedded chipset/architecture might not work on another, and #2, the battery lifetime on the N770 and N800 (both of which I have) is **appalling** **bad**.

I really don't understand why people are so opposed to merging code that works well for a very large set of devices and products. Just because *you* don't need it is not a sufficiently good reason to argue for it not be merged. If you don't want to use it, then don't CONFIG it in.

- Ted

#398 lore raw
Quoted 14 lines · On Saturday 15 May 2010, [email protected] wrote:
Quoted 6 lines · Kevin Hilman

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

The examples cited where the things like the Palm Pre, and the Nokia N770/800/810 series. #1, what works on one embedded chipset/architecture might not work on another, and #2, the battery lifetime on the N770 and N800 (both of which I have) is **appalling** **bad**.

Quoted 5 lines

I really don't understand why people are so opposed to merging code that works well for a very large set of devices and products. Just because *you* don't need it is not a sufficiently good reason to argue for it not be merged. If you don't want to use it, then don't CONFIG it in.

Violently agreed.

And really, the only semi-technical argument against the opportunistic suspend feature I've seen so far in this thread is that it _may_ _be_ possible to achieve the same goal in a different way. If I don't see anything more serious than that, I will take the patchset and push it to Linus (patches [1-6/8] from version 7 to be precise, as soon as the changelogs are improved as requested).

Thanks,
Rafael

#399 lore raw
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · On Saturday 15 May 2010, [email protected] wrote:

The examples cited where the things like the Palm Pre, and the Nokia N770/800/810 series. #1, what works on one embedded chipset/architecture might not work on another, and #2, the battery

Pretty much all of the architectures going after this sort of market seem to be taking very similar design decisions here. The high degree of integration on the SoCs kind of forces it since you're always going to end up with at least some things on the CPU sitting around idle so something needs to be done to drive their runtime power cost down. However, this does all require software support and the level of implementation of that you see does vary.

Quoted 2 lines
Quoted 2 lines

lifetime on the N770 and N800 (both of which I have) is **appalling** **bad**.

Hrm. I've got those devices as well and I don't recall the battery life being particularly awful when they weren't actively being used which is the interesting case there. It's been a while but ISTR they compared well enough with the smartphones of their generation. YMMV, of course.

I guess the other direction to look at this from is that Android devices seem to have battery lifetimes that are comparable to other smartphones, including Linux based ones, rather than remarkably better than them. There's a reasonable number out there that I've seen, using a range of approaches including both pure runtime PM and also normal suspends initiated from userspace with varying degrees of control over the customisation end users can do on their system.

Wakelocks aren't totally going out on a limb in their use of suspend, general systems in this area aren't actually relying purely on runtime PM yet. Where wakelocks do stand out from the other solutions I have seen is that they push the management of the decision to suspend into the kernel.

I think it's probably most accurate to say that the thing that what wakelocks are designed to deliver is to make the system more forgiving of power inefficient application code (providing it doesn't just request permission to burn the battery, of course). I can't think of any actual implementations I have seen which do anything special to deal with them. The argument there would I guess be that the impact on battery life provides a fairly strong incentive to the application developers to not do silly things. There's a fairly clear tradeoff there, and neither approach is going to be universally right.

Quoted 6 lines

And really, the only semi-technical argument against the opportunistic suspend feature I've seen so far in this thread is that it _may_ _be_ possible to achieve the same goal in a different way. If I don't see anything more serious than that, I will take the patchset and push it to Linus (patches [1-6/8] from version 7 to be precise, as soon as the changelogs are improved as requested).

Well, the other concerns that *might* be considered technical are the requirement for driver modifications to take wakelocks (personally I'm fairly OK with that - it's not especially pretty but they seem trivial enough so meh) and the userspace ABI that's being created to manage suspend blocking (which I've not even looked at).

Like I say, I don't personally object to merging the code at this point - I mostly wanted to provide a broader view on the approaches people are using here.

#400 lore raw
In reply to Rafael J. Wysocki

Hello Rafael,

Quoted 6 lines · Rafael J. Wysocki

And really, the only semi-technical argument against the opportunistic suspend feature I've seen so far in this thread is that it _may_ _be_ possible to achieve the same goal in a different way. If I don't see anything more serious than that, I will take the patchset and push it to Linus (patches [1-6/8] from version 7 to be precise, as soon as the changelogs are improved as requested).

The Android opportunistic suspend series still has problems, even if opportunistic suspend mode is not enabled. These problems can be fixed, but it's too late to fix them for this merge window. There shouldn't be a rush to merge these patches, given the current amount of discussion.

Details:

A. The series still has problems, even if the opportunistic suspend
mode is not enabled:

1. Many suspend_block() calls will need to be added throughout the kernel and drivers[1], beyond just those in the current patch series. Android systems will not work without these calls. The primary stated goal of adding suspend-block calls is not to add a new feature, but to restore an approximation of the original, expected behavior of the kernel timer and scheduler
subsystems: to keep running as long as there is work to be done. This approach -- requiring patching of the kernel to restore expected behavior -- is inferior to an approach that preserves the timer and scheduler subsystems' behavior and only patches areas where the kernel doesn't have enough information to make the right decision[2].

2. suspend_block() calls will be difficult for driver and subsystem maintainers to test. This is because the calls contain hidden dependencies to specific Android userspace setups and unrelated kernel code[3].

B. These problems can be fixed:

1. Patch 1's opportunistic suspend governor can be converted into an "opportunistic system low power governor." In other words, when the governor decides to put the system into a low-power state, the way to do it should be up to the architecture, system integrator, or user -- not only "queue_work(pm_wq, &suspend_work);"

2. The opportunistic system low power governor can then be extended to handle multiple system low-power states ("S-states" in ACPI terms)[4], rather than just one low-power state; similar to the way that CPUIdle selects C-states.

3. The system low power governor can then be entered before the last active CPU in the system enters WFI/HLT (i.e., immediately before CPUIdle calls state->enter() [5]). At this point, the governor would respect timers and the scheduler, and most suspend-block calls can be removed from the kernel.

4. The process-freezing behavior of the opportunistic suspend patches can be implemented by improving the Linux timer and scheduler subsystems. If freezer cgroups won't do, then based on a quick glance last week, here might be some reasonable approaches for emulating the Android behavior:

A. To prevent untrusted process timers from waking the system,
the processes can be run in a cgroup that calls del_timer_sync() on all process timers upon receipt of some trigger. When the system returns from the system low-power state and some trigger event happens, add_timer() can be called to add all the cgroup's timers back.

B. To prevent untrusted processes from hogging CPUs, the
processes can be run in a cgroup that puts all threads in TASK_RUNNING processes into TASK_INTERRUPTIBLE state and calls schedule() [6], upon receipt of some trigger. This should allow processes to be awakened by an external system event, e.g., network packet received. When the system returns from the system low-power state and some trigger event happens, those process threads can be placed back into TASK_RUNNING state and rescheduled.

The trigger events could be as simple as writing '1' or '0' into some cgroup or sysfs control file.

5. At this point there would likely be a few remaining suspend-block users that use suspend_block() as an ersatz PM constraint API. These should be replaced by a declarative PM constraint API a la [7] or [8]. Architectures and system integrators must be allowed to control how these PM constraints are implemented, because different chipsets, boards, and use-cases may have different power management feature implementations.

Fixing the above issues should remove any need to add a suspend-block API. It should handle the process-freezing use case. Android can still enter full system suspend in their system idle governor, but it should no longer need to. Since this approach will honor "trusted" timers and processes, it won't break code that relies on longstanding kernel scheduling assumptions.

C. There shouldn't be a rush to merge the existing Android series:

1. The lack of suspend-block support should not prevent existing drivers from being upstreamed without suspend-block calls. Non-Android users will be using the drivers without suspend-blocks, so the drivers will need to work without suspend-blocks anyway. Until a fixed version of the series is submitted, Android can just carry the suspend-block patches in their own tree: the suspend-block patch rebase load from one Linux kernel release to the next should be light. Many of the code sites where suspend-block calls are currently present in Android's MSM kernel[9] are unlikely to change, so git should be able to merge those automatically.

2. Once these patches are merged, it will be difficult to remove the suspend-block approach from the kernel[10]. It touches a lot of kernel code. And the power management constraint that it specifies is so general ("block system suspend"), that, for the subset of suspend_block() use-cases that actually implement a driver PM constraint, it will be difficult to figure out what these constraints were originally intended to be.

3. There is no imminent danger if these patches are not merged. These are not security patches, or patches that fix some existing code that could damage hardware. There is no liability motivation to fast-track these patches, particularly given the current high level of discussion.

Some of the features that these opportunistic suspend patches implement are desirable, such as process freezing and a system low power governor independent from CPUIdle. However, there are significant problems with the way that these opportunistic suspend patches are designed, since they break existing kernel semantics and then touch lots of other code to work around the breakage.

The right approach should be to implement these features in a way that does not require patching all over the kernel, does not break existing timer and scheduler behavior, and will not impact bottom-up power management approaches.

regards,

- Paul

1. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:27:56 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18658

2. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/plat-omap/include/plat/omap-pm.h;h=3ee41d7114929d771cadbb9f02191fd16c5b5abe;hb=ba2e1c5f25a99dec3873745031ad23ce3fd79bff

3. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:27:56 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18658

4. 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

5. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=drivers/cpuidle/cpuidle.c;h=12fdd3987a36c2b09ab65b9d598f276e51fbf5b7;hb=ba2e1c5f25a99dec3873745031ad23ce3fd79bff#l88

6. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/signal.c;h=dbd7fe073c558dbc57080e7d0d9344b2cf47b2dd;hb=ba2e1c5f25a99dec3873745031ad23ce3fd79bff#l2696

7. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=arch/arm/plat-omap/include/plat/omap-pm.h;h=3ee41d7114929d771cadbb9f02191fd16c5b5abe;hb=ba2e1c5f25a99dec3873745031ad23ce3fd79bff

8. http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=kernel/pm_qos_params.c;h=3db49b9ca374ded32bf224f266e904a8006e61a8;hb=ba2e1c5f25a99dec3873745031ad23ce3fd79bff

9. Paul Walmsley E-mail to the linux-pm mailing list, dated Fri, 14 May 2010 00:13:50 -0600:
http://permalink.gmane.org/gmane.linux.power-management.general/18657

10. 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
#401 lore raw
Quoted 6 lines · Paul Walmsley

A. To prevent untrusted process timers from waking the system,
the processes can be run in a cgroup that calls del_timer_sync() on all process timers upon receipt of some trigger. When the system returns from the system low-power state and some trigger event happens, add_timer() can be called to add all the cgroup's timers back.

This doesn't work, for the reasons previously discussed.

Signature · 1 line
Matthew Garrett | [email protected]
#402 lore raw

Hi Matthew,

Quoted 10 lines · Matthew Garrett
Quoted 6 lines · Paul Walmsley

A. To prevent untrusted process timers from waking the system,
the processes can be run in a cgroup that calls del_timer_sync() on all process timers upon receipt of some trigger. When the system returns from the system low-power state and some trigger event happens, add_timer() can be called to add all the cgroup's timers back.

This doesn't work, for the reasons previously discussed.

Could you please elaborate, or provide a link to an E-mail in the archives that would explain why?

thanks,

- Paul

#403 lore raw
Quoted 2 lines · Paul Walmsley

Could you please elaborate, or provide a link to an E-mail in the archives that would explain why?

What would otherwise be a wakeup event may be delivered between you deciding to stop tasks and you actually stopping tasks. How do you know to restart tasks at that point?

Signature · 1 line
Matthew Garrett | [email protected]
#404 lore raw

Hello Matthew,

Quoted 8 lines · Matthew Garrett
Quoted 2 lines · Paul Walmsley

Could you please elaborate, or provide a link to an E-mail in the archives that would explain why?

What would otherwise be a wakeup event may be delivered between you deciding to stop tasks and you actually stopping tasks. How do you know to restart tasks at that point?

The original message you sent[1] quoted this part[2] of the proposal:

----
A. To prevent untrusted process timers from waking the system,
the processes can be run in a cgroup that calls del_timer_sync() on all process timers upon receipt of some trigger. When the system returns from the system low-power state and some trigger event happens, add_timer() can be called to add all the cgroup's timers back.
----

That isn't intended to address the task restarting problem. The task restarting problem is intended to be addressed by this part[3]:

----
B. To prevent untrusted processes from hogging CPUs, the
processes can be run in a cgroup that puts all threads in TASK_RUNNING processes into TASK_INTERRUPTIBLE state and calls schedule() [6], upon receipt of some trigger. This should allow processes to be awakened by an external system event, e.g., network packet received. When the system returns from the system low-power state and some trigger event happens, those process threads can be placed back into TASK_RUNNING state and rescheduled.
----

It sounds like Android doesn't even need to use full system suspend if some proposal like (A) and (B) are implemented[4]. In that case, all the code that deals with races in full system suspend (like suspend blockers) can be dropped.

- Paul

1. Matthew Garrett E-mail to the linux-pm mailing list, dated Tue May 18 02:55:19 +0100
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025664.html

2. Paragraph B4A of Paul Walmsley E-mail to the linux-pm mailing list, dated Mon May 17 19:39:44 CDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025663.html

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

4. Arve Hjønnevåg E-mail to the linux-pm mailing list, dated Mon, May 17 20:06:33 PDT 2010:
https://lists.linux-foundation.org/pipermail/linux-pm/2010-May/025668.html

#405 lore raw

Hi,

just wanted to clarify one point:

Quoted 2 lines · Paul Walmsley

In that case, all the code that deals with races in full system suspend (like suspend blockers) can be dropped.

Not necessarily dropped entirely - just considered separately, apart from the contexts of "getting Android device drivers upstream" and "pausing processes/timers before entering a system low-power state".

- Paul

#406 lore raw
In reply to Paul Walmsley
Quoted 9 lines · Paul Walmsley

B. To prevent untrusted processes from hogging CPUs, the
processes can be run in a cgroup that puts all threads in TASK_RUNNING processes into TASK_INTERRUPTIBLE state and calls schedule() [6], upon receipt of some trigger. This should allow processes to be awakened by an external system event, e.g., network packet received. When the system returns from the system low-power state and some trigger event happens, those process threads can be placed back into TASK_RUNNING state and rescheduled.

I don't think that works. If I have an app that would generally complete some work and then call select(), you'll instead stop it in the middle of that work. If that app is the one that should process the wakeup event then it'll never be delivered because you've never got back to select().

Signature · 1 line
Matthew Garrett | [email protected]
#407 lore raw
In reply to [email protected]
Quoted 8 lines · On Sat, May 15, 2010 at 8:15 AM, <[email protected]> wrote:
Quoted 6 lines · Kevin Hilman

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

Quoted 5 lines

The examples cited where the things like the Palm Pre, and the Nokia N770/800/810 series.  #1, what works on one embedded chipset/architecture might not work on another, and #2, the battery lifetime on the N770 and N800 (both of which I have) is **appalling** **bad**.

Really? My experience is sort of the opposite.

My 3 year old Maemo-based Nokia N800 survived about a week idle. My half-year old HTC HT-03A with Android 1.6 survives a day or three, but not much more. Fortunately the japanese cellphone provider Docomo bundled it with two batteries, haha. =)

The Nexus One only came with one battery, but from my perspective it's as good as N800 or maybe even better.

In the end, I don't think it's a question of Maemo vs Android here or wakelock vs Runtime PM. I'm sure both would do just fine with enough optimizations.

/ magnus

#408 lore raw
In reply to [email protected]
Quoted 11 lines · [email protected] writes:
Quoted 6 lines · Kevin Hilman

Another likely reason that that there hasn't been an alternate proposal (at least from some of us that are raising concerns) is because we already have a working solution to dynamic, system-wide PM that is 1) already in mainline and 2) shipping on consumer devices with very strict power budgets (as already pointed out in detail by Paul[2].)

The examples cited where the things like the Palm Pre, and the Nokia N770/800/810 series. #1, what works on one embedded chipset/architecture might not work on another,

In my experience with embedded SoCs they are all remarkably similar in power management capabilities and control.

Quoted 2 lines

and #2, the battery lifetime on the N770 and N800 (both of which I have) is **appalling** **bad**.

Appalling bad compared to what?

What's probably more interesting in terms of rough comparisons is comparing similar devices with and without opportunistic suspend. The Nokia n900 (maemo) and the Moto Droid (android) use the same SoC (TI OMAP3) and roughly the same kernel (2.6.2[89], although both are heavily patched from mainline.)

The n900 *never* suspends. It only uses dynamic PM + CPUidle. The droid uses opportunistic suspend (as well as dynamic PM + CPUidle)

I don't know of any more objective comparison of the two, but as a user of both devices I can say that the active usage is basically the same (around a day) and the idle use is similar as well, even though the Droid has a slightly bigger battery (1400 mAh vs. 1320 mAh.) My own usage suggests the n900 is a bit better in idle time, but I have not done any measuring or objective tests. I'm guessing the difference is probably because the Droid does not use the deepest off-mode power states either in idle or suspend (IIRC) where the n900 does. I suspect that if both were using off-mode and had the same battery, these differences would go away.

While this is not really a scientific comparison, it at least gives a rough idea. If using opportunistic suspend was adding noticably better battery life, I think this would be a different discussion.

Quoted 5 lines

I really don't understand why people are so opposed to merging code that works well for a very large set of devices and products. Just because *you* don't need it is not a sufficiently good reason to argue for it not be merged. If you don't want to use it, then don't CONFIG it in.

At least for OMAP, I don't consider "config it out" a viable option.

We would like one kernel (in particular one PM core) to be usable for a broad range of devices: maemo/meego, Android, webOS, Archos, and whatever else we haven't seen yet. Having to config in/out something as important as core PM functionality has other consequences. It makes PM-aware driver and subsystem writers (and maintainers) to have to develop and validate against two different types of PM functionality.

As co-maintainer of the PM subsystem for an architecture (OMAP) where people *really* care about power, I don't consider that a viable or scalable option.

Kevin

#409 lore raw
Quoted 25 lines · Kevin Hilman
Quoted 2 lines

and #2, the battery lifetime on the N770 and N800 (both of which I have) is **appalling** **bad**.

Appalling bad compared to what?

What's probably more interesting in terms of rough comparisons is comparing similar devices with and without opportunistic suspend.  The Nokia n900 (maemo) and the Moto Droid (android) use the same SoC (TI OMAP3) and roughly the same kernel (2.6.2[89], although both are heavily patched from mainline.)

The n900 *never* suspends.  It only uses dynamic PM + CPUidle. The droid uses opportunistic suspend (as well as dynamic PM + CPUidle)

I don't know of any more objective comparison of the two, but as a user of both devices I can say that the active usage is basically the same (around a day) and the idle use is similar as well, even though the Droid has a slightly bigger battery (1400 mAh vs. 1320 mAh.)  My own usage suggests the n900 is a bit better in idle time, but I have not done any measuring or objective tests.  I'm guessing the difference is probably because the Droid does not use the deepest off-mode power states either in idle or suspend (IIRC) where the n900 does.  I suspect that if both were using off-mode and had the same battery, these differences would go away.

Quoted 3 lines

While this is not really a scientific comparison, it at least gives a rough idea.  If using opportunistic suspend was adding noticably better battery life, I think this would be a different discussion.

Exactly. The point is, opportunistic suspend doesn't in fact add any value compared to dynamic PM + CPUIdle. It only produces some false impression that one can handle power management right without using dynamic PM. And this false impression is the cause for many really ugly designs (like, for instance, 15 minutes touchscreen inactivity delay before forcibly shutting down the wireless, as it's done in stock Android framework).

Thanks,
Vitaly

#410 lore raw
Quoted 7 lines · Vitaly Wool

Exactly. The point is, opportunistic suspend doesn't in fact add any value compared to dynamic PM + CPUIdle. It only produces some false impression that one can handle power management right without using dynamic PM. And this false impression is the cause for many really ugly designs (like, for instance, 15 minutes touchscreen inactivity delay before forcibly shutting down the wireless, as it's done in stock Android framework).

Run this (or equivalent code) on an N900 and on an Android. Measure the screen-off power draw on both.

int main() {
	int i;
	while (1)
		i++;
	return 0;
}
Signature · 1 line
Matthew Garrett | [email protected]
#411 lore raw
Quoted 7 lines · Matthew Garrett
int main() {
	int i;
	while (1)
		i++;
	return 0;
}

We already know it's really rare on an embedded system you would get this bad of an app. However, if you assume that you might have this 1 in a million app, couldn't we just have a watch dog that identifies and kills it. It would also let the user know what happened of course. Killing the app seems pretty reasonable to me.

Daniel