Attempted summary of suspend-blockers LKML thread
Subsystems (4)
Quoted 4 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3. You could try stopping processes by using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
Sure, you could do someting amazing complicated using cgroups, and user space processes that have to wake up the CPU every 30 seconds to see if it's safe to suspend the system --- but why not just use the system which is being used by 200,000 new phones every day? It's simple and it works. And unlike Maemo, untrustworthy applications don't end up chewing up your battery lifetime.
- Ted
Quoted 4 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3. You could try stopping processes by using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
Sure, you could do someting amazing complicated using cgroups, and user space processes that have to wake up the CPU every 30 seconds to see if it's safe to suspend the system --- but why not just use the system which is being used by 200,000 new phones every day? It's simple and it works. And unlike Maemo, untrustworthy applications don't end up chewing up your battery lifetime.
- Ted
Quoted 20 lines · Ted Ts'o
Quoted 3 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Quoted 4 lines
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3.
Exactly the same happens on Android.
Install one bad application, a request for PM permissions is made, you click Yes. There's no difference at all.
Quoted 7 lines
You could try stopping processes by
using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
No. You are assuming that PM permissions will be magically set appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
2) Install a good application that is not requesting PM permissions (or is denied them)
Imagine this application requires expensive initialization, but afterwards it only needs to send a small packet each minute to a server. If this application forgets to request PM permission (or is denied them), then it might miss the 1 minute mark, and would have to re-initialize when a trusted app starts some work.
In this case suspend blockers cause more battery drain (and the application to behave poorly).
There's only one case when suspend blockers might actually help:
a) The application is badly written (most probably a UI app drawing when it shouldn't, which incidentally is not a problem in Android since it's not multi-tasking)
b) The application is either not requesting, or denied PM permissions
c) The application is not affected too badly if it's not running all the time (piggy-backing on trusted apps is ok)
For that it's much better to have a different strategy: all applications are trusted, bad applications must be manually tagged. Also, instead of having each and every user figure out which are the bad apps, such information is more pertinent in the app store, where users could vote when an app is bad PM-use or not; crowd-sourcing the problem.
But guess what; once you have an app store system that can detect when an application is badly written, why would you expose the users to such bad apps?
In Maemo, 3rd party applications have to go trough a community review (maemo.org extras testing) before they go into the main repository, and this way bad applications (functionality or PM-wise) don't make it to the general public.
Also, on mobile phones in general there are 3 kinds of applications.
1) desktop widgets: by far the ones with the most danger of drawing the battery
2) foreground UI apps: also have some danger, but only on multi-tasking systems (not Android)
3) background services: usually don't do unnecessary work
Suspend blockers are mostly useful for 1), but desktop widgets are platform-specific, so they are written for embedded anyway, and if you are writing for embedded, there's no point in relying on suspend-blockers; just write it PM optimized.
Signature · 5 lines
Felipe Contreras _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 20 lines · Ted Ts'o
Quoted 3 lines · On Fri, Aug 06, 2010 at 06:00:34PM -0700, [email protected] wrote:
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Most other devices use a lot more power at idle; in some cases it's because the hardware just isn't as power optimized (why bother, when you have 94,000 mWh of power at your disposal with a 6 cell laptop battery, as opposed to the 800-1000 mWh that you might have on a cell phone battery). In other cases, it's because the kernel and the low-level software stack (never mind the applications) are waking up the CPU too darned often --- in other words, idle simply isn't idle enough.
So you may want to consider whether part of the problem is that general purpose Linux systems need a radical redesign to get power utilization down to those sorts of levels --- where the CPU might only be waking up once every half-hour or so, and then only do actual useful work.
Quoted 4 lines
Can you get there by assuming that every single application is competently written? In an idle approach, you have to. That way lies Maemo, where installing just one bad application will cut your battery life time by a factor of 2-3.
Exactly the same happens on Android.
Install one bad application, a request for PM permissions is made, you click Yes. There's no difference at all.
Quoted 7 lines
You could try stopping processes by
using kill -STOP, but this at that point, you've moved into Android strategy of "suspend". And the only question is what is the most efficient way to allow the system to run when there is true work that needs to be done, and how to avoid deadlocks by stopping processes that might be holding user space locks --- and to administer when and how to suspend the processes.
No. You are assuming that PM permissions will be magically set appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
2) Install a good application that is not requesting PM permissions (or is denied them)
Imagine this application requires expensive initialization, but afterwards it only needs to send a small packet each minute to a server. If this application forgets to request PM permission (or is denied them), then it might miss the 1 minute mark, and would have to re-initialize when a trusted app starts some work.
In this case suspend blockers cause more battery drain (and the application to behave poorly).
There's only one case when suspend blockers might actually help:
a) The application is badly written (most probably a UI app drawing when it shouldn't, which incidentally is not a problem in Android since it's not multi-tasking)
b) The application is either not requesting, or denied PM permissions
c) The application is not affected too badly if it's not running all the time (piggy-backing on trusted apps is ok)
For that it's much better to have a different strategy: all applications are trusted, bad applications must be manually tagged. Also, instead of having each and every user figure out which are the bad apps, such information is more pertinent in the app store, where users could vote when an app is bad PM-use or not; crowd-sourcing the problem.
But guess what; once you have an app store system that can detect when an application is badly written, why would you expose the users to such bad apps?
In Maemo, 3rd party applications have to go trough a community review (maemo.org extras testing) before they go into the main repository, and this way bad applications (functionality or PM-wise) don't make it to the general public.
Also, on mobile phones in general there are 3 kinds of applications.
1) desktop widgets: by far the ones with the most danger of drawing the battery
2) foreground UI apps: also have some danger, but only on multi-tasking systems (not Android)
3) background services: usually don't do unnecessary work
Suspend blockers are mostly useful for 1), but desktop widgets are platform-specific, so they are written for embedded anyway, and if you are writing for embedded, there's no point in relying on suspend-blockers; just write it PM optimized.
Signature · 1 line
Felipe Contreras
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident. The various failure modes that exist in a non-wakelock world can be triggered in a wide variety of ways by accident. A sufficiently reductionist viewpoint will equate the two situations, but in the real world they're clearly different.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident. The various failure modes that exist in a non-wakelock world can be triggered in a wide variety of ways by accident. A sufficiently reductionist viewpoint will equate the two situations, but in the real world they're clearly different.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 11 lines · Matthew Garrett
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
Signature · 1 line
Felipe Contreras
Quoted 11 lines · Matthew Garrett
Quoted 5 lines · Felipe Contreras
appropriately; that's not the case.
1) Install a bad application that requests PM permissions and is granted those
In this case you've gained nothing with user-space suspend blockers.
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
Signature · 1 line
Felipe Contreras
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
No, that's not the typical case.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
No, that's not the typical case.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
That would be exceptionally unusual. A more common case is that the application will take a wakelock while performing some specific long running task which needs no user intervention such as downloading a file or displaying constantly update status that the user is not expected to respond to. There's no need for applications to take wakelocks while the user is directly interacting with them since the system will be kept awake as a result of the user interaction, the wakelocks are used to override the default suspend that occurs when the user is not interacting with the device.
Quoted 7 lines · Mark Brown
Quoted 5 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
Quoted 6 lines
Quoted 4 lines
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
That would be exceptionally unusual. A more common case is that the application will take a wakelock while performing some specific long running task which needs no user intervention such as downloading a file or displaying constantly update status that the user is not expected to respond to. There's no need for applications to take wakelocks while the user is directly interacting with them since the system will be kept awake as a result of the user interaction, the wakelocks are used to override the default suspend that occurs when the user is not interacting with the device.
Fair enough, but if that the case, if suspend blockers are to be used in desktop software, everything would need extensive modifications just to work. I remember somebody said that was not the case, I thought it was because the lock could be held the whole time the application is running.
Signature · 1 line
Felipe Contreras
Quoted 7 lines · Mark Brown
Quoted 5 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
Quoted 6 lines
Quoted 4 lines
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
That would be exceptionally unusual. A more common case is that the application will take a wakelock while performing some specific long running task which needs no user intervention such as downloading a file or displaying constantly update status that the user is not expected to respond to. There's no need for applications to take wakelocks while the user is directly interacting with them since the system will be kept awake as a result of the user interaction, the wakelocks are used to override the default suspend that occurs when the user is not interacting with the device.
Fair enough, but if that the case, if suspend blockers are to be used in desktop software, everything would need extensive modifications just to work. I remember somebody said that was not the case, I thought it was because the lock could be held the whole time the application is running.
Signature · 1 line
Felipe Contreras
Quoted 9 lines · Felipe Contreras
Quoted 3 lines · Matthew Garrett
It's clearly possible for a pathological Android application to destroy the power management policy. But to do that, the author would have to explicitly take a wakelock. That's difficult to do by accident.
The writer can take a wakelock the whole time the application is running (isn't that the typical case?), because perhaps the author realizes that way the application works correctly, or he copy-pasted it from somewhere else.
That would be exceptionally unusual. A more common case is that the application will take a wakelock while performing some specific long running task which needs no user intervention such as downloading a file or displaying constantly update status that the user is not expected to respond to. There's no need for applications to take wakelocks while the user is directly interacting with them since the system will be kept awake as a result of the user interaction, the wakelocks are used to override the default suspend that occurs when the user is not interacting with the device.
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications". Technically that boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
Thanks,
Rafael
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications". Technically that boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
Thanks,
Rafael
Quoted 11 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 5 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
Quoted 6 lines
Quoted 3 lines
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
David Lang
Quoted 11 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 5 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
Quoted 6 lines
Quoted 3 lines
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
David Lang
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call schedule() sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable() being analogous to acquiring a suspend blocker, and preempt_enable() being analogous to releasing a suspend blocker).
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
We already covered the differences between suspend and idle, now didn't we? ;-)
Thanx, Paul
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call schedule() sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable() being analogous to acquiring a suspend blocker, and preempt_enable() being analogous to releasing a suspend blocker).
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
We already covered the differences between suspend and idle, now didn't we? ;-)
Thanx, Paul
Quoted 40 lines · Paul E. McKenney
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.
Quoted 5 lines
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
the issue isn't avoiding the memory useage, the issue is avoiding the special API requirement that make the userspace code no longer be portable.
note that there are a lot of battery powered embedded devices out there that work just fine without wakelocks. They are able to use the existing idle/sleep and suspend options to get good battery life.
The key difference is that Android allows other programs to be loaded on the system, and the current idle/sleep/suspend triggers can't tell the difference between the important software and the other software.
Quoted 7 lines
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call
schedule()sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable()being analogous to acquiring a suspend blocker, andpreempt_enable()being analogous to releasing a suspend blocker).
Quoted 7 lines
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
for one thing, there was never any thought that any code that would have to have preempt written would ever run anywhere else other than inside the linux kernel.
If you had proposed that userspace be allowed to do preempt_enable/disable calls, it would have been a very different discussion.
In the case of real-time applications, we require that things that are given real-time priority be carefully coded to behave well, and that if they depend on things that are not given real-time priority they may not behave as expected. Priority Inheritance is a way to avoid complete system lockup in many cases, but it would still be possible for a badly written real-time app to kill the system if it does something like go into a busy-loop waiting for a file to be created by a non-real-time process.
wakelocks are like implementing real-time by allowing userspace to issue preempt_disable() calls to tell the scheduler not to take the CPU away from them until they make a preempt_enable() call.
In addition wakelocks cannot replace the need to write efficient code. all that wakelocks do is to prevent the system from doing a suspend, you still want to have the code written to not do unneccessary wakeups that would prevent you from using the low-power modes other than suspend. On the other hand, it _is_ possible for the idle/sleep states to be extended to also cover suspend.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 8 lines
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
I want the kernel to be explicitly told that this application is important (or alternativly that these other applications are not). I suggested cgroups as a possible way to do this, but anything that could tell the kernel what processes to care about and what ones to not care about would work. My initial thought had actually been to do something like echo the pid of important processes into a /proc or /sys file, but I was under the impression that there were a lot of processes that would get this state and therefore a more general tool like cgroups (which as I understand it automatically puts children of a process into the same cgroup as the parent) seemed moreuseful
Quoted 10 lines
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 6 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.
Quoted 8 lines
Quoted 3 lines
well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
I agree tha the power down and restart needs to be planned, but it's not like you are going to wake up the drive (or the audio hardware0 without waking up the CPU first.
even with idle sleep modes and drive spin-down there is no provision for the drive to be restarted if the CPU is asleep, you first have something happen that wakes up the CPU and it then wakes up the drive. This same approach should work for other things.
Quoted 9 lines
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
We already covered the differences between suspend and idle, now didn't we? ;-)
we did, however at the time suspend was to stop everything, now we are finding that Android has multiple flavors of suspend, one of which stops everything, the others leave some things running.
David Lang
Quoted 48 lines · On Sat, Aug 07, 2010 at 01:17:48PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.Quoted 5 lines
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Quoted 8 lines
the issue isn't avoiding the memory useage, the issue is avoiding the special API requirement that make the userspace code no longer be portable.
note that there are a lot of battery powered embedded devices out there that work just fine without wakelocks. They are able to use the existing idle/sleep and suspend options to get good battery life.
There certainly are such devices, but their power-optimized software is highly non-portable, so I fail to see how this example can possibly support your position. In addition, there are quite a few non-portable Linux extensions to the user-mode API, so your point would not carry in any case.
Quoted 4 lines
The key difference is that Android allows other programs to be loaded on the system, and the current idle/sleep/suspend triggers can't tell the difference between the important software and the other software.
But the suspend blockers can, to the Android guys' point. And something needs to tell the difference. It is not helpful for you to try to hide from this issue.
Quoted 15 lines
Quoted 7 lines
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call
schedule()sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable()being analogous to acquiring a suspend blocker, andpreempt_enable()being analogous to releasing a suspend blocker).Quoted 7 lines
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 3 lines
for one thing, there was never any thought that any code that would have to have preempt written would ever run anywhere else other than inside the linux kernel.
Portability is for the common-case power-oblivious applications. Even on Android, the power-oblivious applications do not need to use suspend blockers. Suspend blockers are instead used by PM-driving and power-optimized applications. And as you yourself pointed out in an earlier email, the PM-driving and power-optimized applications are in the minority. Furthermore, the suspend-blocker approach allows the bulk of the code in a PM-driving application to be written in a power-oblivious manner, greatly easing its implementation while still providing power-efficient operation.
So again, your point does not carry.
Quoted 3 lines
If you had proposed that userspace be allowed to do preempt_enable/disable calls, it would have been a very different discussion.
There have been proposals that userspace be allowed to disable preemption, and the proposals indeed did not get far. However, the Linux user-kernel API -was- extended to accommodate the underlying need, namely with futexes. And futexes provide an excellent example of a non-portable extension to the Linux user-kernel API.
So, sorry, but again, your point does not carry.
Quoted 4 lines
In the case of real-time applications, we require that things that are given real-time priority be carefully coded to behave well, and that if they depend on things that are not given real-time priority they may not behave as expected.
And therefore real-world applications often are designed to minimize the amount of code that needs real-time privileges, exactly because real-time code is harder to develop than is non-realtime code. In addition, a number of Linux-specific facilities have been used to mitigate the effects of bad behavior by real-time applications.
A similar effect is making itself felt in the power-efficiency arena -- apps minimize the amount of code that must obey the PM-driving rules. Android suspend blockers are one mechanism to carry this minimization further.
Easing development of code is something you would do well to take more seriously.
Quoted 5 lines
Priority Inheritance is a way to
avoid complete system lockup in many cases, but it would still be possible for a badly written real-time app to kill the system if it does something like go into a busy-loop waiting for a file to be created by a non-real-time process.
Just as it is possible for a badly-designed PM-driving app to kill the battery. And this is exactly why most apps are power-oblivious, and further why Android allows PM-driving apps that are not currently holding suspend blockers to be written in a power-oblivious manner. Doing this reduces the opportunity for even PM-driving apps to kill the battery.
Quoted 3 lines
wakelocks are like implementing real-time by allowing userspace to issue
preempt_disable()calls to tell the scheduler not to take the CPU away from them until they make apreempt_enable()call.
Not so. Suspend blockers are actually less dangerous than a thread raising its priority to a real-time level, let alone than the ability to disable preemption at user level.
Quoted 5 lines
In addition wakelocks cannot replace the need to write efficient code. all that wakelocks do is to prevent the system from doing a suspend, you still want to have the code written to not do unneccessary wakeups that would prevent you from using the low-power modes other than suspend.
If you had said "wakelocks cannot -completely- replace the need to write efficient code", I might agree with you. Just as I would agree that a compiler cannot -completely- replace the need to write assembly from time to time. This is no more an argument against suspend blockers (or something like them) than the occasional need to write assembly is an argument against compilers.
Quoted 2 lines
On the other hand, it _is_ possible for
the idle/sleep states to be extended to also cover suspend.
Nice try, but please take a look at any of the prior discussion of how idle and suspend differ, and then feel free to try again.
Quoted 29 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 8 lines
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
Quoted 11 lines
I want the kernel to be explicitly told that this application is important (or alternativly that these other applications are not). I suggested cgroups as a possible way to do this, but anything that could tell the kernel what processes to care about and what ones to not care about would work. My initial thought had actually been to do something like echo the pid of important processes into a /proc or /sys file, but I was under the impression that there were a lot of processes that would get this state and therefore a more general tool like cgroups (which as I understand it automatically puts children of a process into the same cgroup as the parent) seemed moreuseful
Again, the Android guys just use a different mechanism. So, as I said in my earlier email, that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Please keep in mind that the Android guys really do have code that works in production, which, despite real and perceived imperfections, carries serious weight. Rafael and Alan have some code that meets some but apparently not all of the Android guys' requirements. You have some serious work to do if you want to catch up to them.
I am sorry, but until you actually have something credible running, I have to place much more weight on Arve's, Brian's, Rafael's, and Alan's opinions than on yours.
Quoted 14 lines
Quoted 14 lines
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
Quoted 8 lines
Quoted 4 lines
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
I agree tha the power down and restart needs to be planned, but it's not like you are going to wake up the drive (or the audio hardware0 without waking up the CPU first.
On servers, desktops, and laptops, agreed. In contrast, the embedded guys have facilities that allows hardware to activate without the CPU being active at the time. So there is a difference.
Quoted 4 lines
even with idle sleep modes and drive spin-down there is no provision for the drive to be restarted if the CPU is asleep, you first have something happen that wakes up the CPU and it then wakes up the drive. This same approach should work for other things.
It will indeed work, but it can be quite energy inefficient, given the capabilities of embedded hardware.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
Quoted 6 lines
Quoted 2 lines
We already covered the differences between suspend and idle, now didn't we? ;-)
we did, however at the time suspend was to stop everything, now we are finding that Android has multiple flavors of suspend, one of which stops everything, the others leave some things running.
Suspend never has stopped the time-of-day clock, so Android's approach is nothing new. Besides, in the embedded world, the ability to leave other types of hardware running during a suspend long predates Android. It might well be new to you, but it is not at all new.
Thanx, Paul
Quoted 48 lines · On Sat, Aug 07, 2010 at 01:17:48PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 17 lines · On Sat, Aug 07, 2010 at 03:00:48AM -0700, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 4 lines · On Saturday, August 07, 2010, [email protected] wrote:
Quoted 2 lines · Mark Brown
Quoted 1 line · On Fri, Aug 06, 2010 at 04:35:59PM -0700, [email protected] wrote:
On Fri, 6 Aug 2010, Paul E. McKenney wrote:
...
Quoted 8 lines
What we want to have happen in an ideal world is
when the storage isn't needed (between reads) the storage should shutdown to as low a power state as possible.
when the CPU isn't needed (between decoding bursts) the CPU and as much of the system as possible (potentially including some banks of RAM) should shutdown to as low a power state as possible.
Quoted 7 lines
Quoted 2 lines
Unfortunately, the criteria for "not being needed" are not really straightforward and one of the wakelocks' roles is to work around this issue.
if you can ignore the activity caused by the other "unimportant" processes in the system, why is this much different then just the one process running, in which case standard power management sleeps work pretty well.
But isn't the whole point of wakelocks to permit developers to easily and efficiently identify which processes are "unimportant" at a given point in time, thereby allowing them to be ignored?
I understand your position -- you believe that PM-driving applications should be written to remain idle any time that they aren't doing something "important". This is a reasonable position to take, but it is also reasonable to justify your position. Exactly -why- is this better? Here is my evaluation:
o You might not need suspend blockers. This is not totally clear,
and won't be until you actually build a system based on your design.Quoted 5 lines
o You will be requiring that developers of PM-driving applications
deal with more code that must be very carefully coded and validated. This requirement forces the expenditure of lots of people time to save a very small amount of very inexpensive memory (that occupied by the suspend-blocker code).
Quoted 8 lines
the issue isn't avoiding the memory useage, the issue is avoiding the special API requirement that make the userspace code no longer be portable.
note that there are a lot of battery powered embedded devices out there that work just fine without wakelocks. They are able to use the existing idle/sleep and suspend options to get good battery life.
There certainly are such devices, but their power-optimized software is highly non-portable, so I fail to see how this example can possibly support your position. In addition, there are quite a few non-portable Linux extensions to the user-mode API, so your point would not carry in any case.
Quoted 4 lines
The key difference is that Android allows other programs to be loaded on the system, and the current idle/sleep/suspend triggers can't tell the difference between the important software and the other software.
But the suspend blockers can, to the Android guys' point. And something needs to tell the difference. It is not helpful for you to try to hide from this issue.
Quoted 15 lines
Quoted 7 lines
Keep in mind that there was a similar decision in the -rt kernel. One choice was similar to your proposal: all code paths must call
schedule()sufficiently frequently. The other choice was to allow almost all code paths to be preempted, which resembles suspend blockers (preempt_disable()being analogous to acquiring a suspend blocker, andpreempt_enable()being analogous to releasing a suspend blocker).Quoted 7 lines
Then as now, there was much debate. The choice then was preemption. One big reason was that the choice of preemption reduced the amount of real-time-aware code from the entire kernel to only that part of the kernel that disabled preemption, which turned out to greatly simplify the job of meeting aggressive scheduling-latency goals. This experience does add some serious precedent against your position. So, what do you believe is different in the energy-efficiency case?
Quoted 3 lines
for one thing, there was never any thought that any code that would have to have preempt written would ever run anywhere else other than inside the linux kernel.
Portability is for the common-case power-oblivious applications. Even on Android, the power-oblivious applications do not need to use suspend blockers. Suspend blockers are instead used by PM-driving and power-optimized applications. And as you yourself pointed out in an earlier email, the PM-driving and power-optimized applications are in the minority. Furthermore, the suspend-blocker approach allows the bulk of the code in a PM-driving application to be written in a power-oblivious manner, greatly easing its implementation while still providing power-efficient operation.
So again, your point does not carry.
Quoted 3 lines
If you had proposed that userspace be allowed to do preempt_enable/disable calls, it would have been a very different discussion.
There have been proposals that userspace be allowed to disable preemption, and the proposals indeed did not get far. However, the Linux user-kernel API -was- extended to accommodate the underlying need, namely with futexes. And futexes provide an excellent example of a non-portable extension to the Linux user-kernel API.
So, sorry, but again, your point does not carry.
Quoted 4 lines
In the case of real-time applications, we require that things that are given real-time priority be carefully coded to behave well, and that if they depend on things that are not given real-time priority they may not behave as expected.
And therefore real-world applications often are designed to minimize the amount of code that needs real-time privileges, exactly because real-time code is harder to develop than is non-realtime code. In addition, a number of Linux-specific facilities have been used to mitigate the effects of bad behavior by real-time applications.
A similar effect is making itself felt in the power-efficiency arena -- apps minimize the amount of code that must obey the PM-driving rules. Android suspend blockers are one mechanism to carry this minimization further.
Easing development of code is something you would do well to take more seriously.
Quoted 5 lines
Priority Inheritance is a way to
avoid complete system lockup in many cases, but it would still be possible for a badly written real-time app to kill the system if it does something like go into a busy-loop waiting for a file to be created by a non-real-time process.
Just as it is possible for a badly-designed PM-driving app to kill the battery. And this is exactly why most apps are power-oblivious, and further why Android allows PM-driving apps that are not currently holding suspend blockers to be written in a power-oblivious manner. Doing this reduces the opportunity for even PM-driving apps to kill the battery.
Quoted 3 lines
wakelocks are like implementing real-time by allowing userspace to issue
preempt_disable()calls to tell the scheduler not to take the CPU away from them until they make apreempt_enable()call.
Not so. Suspend blockers are actually less dangerous than a thread raising its priority to a real-time level, let alone than the ability to disable preemption at user level.
Quoted 5 lines
In addition wakelocks cannot replace the need to write efficient code. all that wakelocks do is to prevent the system from doing a suspend, you still want to have the code written to not do unneccessary wakeups that would prevent you from using the low-power modes other than suspend.
If you had said "wakelocks cannot -completely- replace the need to write efficient code", I might agree with you. Just as I would agree that a compiler cannot -completely- replace the need to write assembly from time to time. This is no more an argument against suspend blockers (or something like them) than the occasional need to write assembly is an argument against compilers.
Quoted 2 lines
On the other hand, it _is_ possible for
the idle/sleep states to be extended to also cover suspend.
Nice try, but please take a look at any of the prior discussion of how idle and suspend differ, and then feel free to try again.
Quoted 29 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
today there are two ways of this happening, via the idle approach (on everything except Android), or via suspend (on Android)
Given that many platforms cannot go to into suspend while still playing audio, the idle approach is not going to be able to be eliminated (and in fact will be the most common approach to be used/deugged in terms of the types of platforms), it seems to me that there may be a significant amount of value in seeing if there is a way to change Android to use this approach as well instead of having two different systems competing to do the same job.
Quoted 8 lines
Quoted 3 lines
There is a fundamental obstacle to that, though. Namely, the Android developers say that the idle-based approach doesn't lead to sufficient energy savings due to periodic timers and "polling applications".
polling applications can be solved by deciding that they aren't going to be allowed to affect the power management decision (don't consider their CPU useage when deciding to go to sleep, don't consider their timers when deciding when to wake back up)
Quoted 8 lines
Agreed, and the focus is on how one decides which applications need to be considered. After all, the activity of a highly optimized audio-playback application looks exactly like that of a stupid polling application -- they both periodically consume some CPU. But this is something that you and the Android guys are actually agreeing about. You are only arguing about exactly what mechanism should be used to make this determination. The Android guys want suspend blockers, and you want to extend cgroups.
Quoted 11 lines
I want the kernel to be explicitly told that this application is important (or alternativly that these other applications are not). I suggested cgroups as a possible way to do this, but anything that could tell the kernel what processes to care about and what ones to not care about would work. My initial thought had actually been to do something like echo the pid of important processes into a /proc or /sys file, but I was under the impression that there were a lot of processes that would get this state and therefore a more general tool like cgroups (which as I understand it automatically puts children of a process into the same cgroup as the parent) seemed moreuseful
Again, the Android guys just use a different mechanism. So, as I said in my earlier email, that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Please keep in mind that the Android guys really do have code that works in production, which, despite real and perceived imperfections, carries serious weight. Rafael and Alan have some code that meets some but apparently not all of the Android guys' requirements. You have some serious work to do if you want to catch up to them.
I am sorry, but until you actually have something credible running, I have to place much more weight on Arve's, Brian's, Rafael's, and Alan's opinions than on yours.
Quoted 14 lines
Quoted 14 lines
So I believe that the next step for you is to implement your approach so that it can be compared in terms of energy efficiency, code size, intrusiveness, performance, and compatibility with existing code.
Quoted 9 lines
Quoted 5 lines
Technically that
boils down to the interrupt sources that remain active in the idle-based case and that are shut down during suspend. If you found a way to deactivate all of them from the idle context in a non-racy fashion, that would probably satisfy the Android's needs too.well, we already have similar capibility for other peripherals (I keep pointing to drive spin down as an example), the key to avoiding the races seems to be in the drivers supporting this.
Quoted 8 lines
Quoted 4 lines
The difference is that the CPU stays active in the drive spin down case -- if the drive turns out to be needed, the CPU can spin it up. The added complication in the suspend case is that the CPU goes away, so that you must more carefully plan for all of the power-up cases.
I agree tha the power down and restart needs to be planned, but it's not like you are going to wake up the drive (or the audio hardware0 without waking up the CPU first.
On servers, desktops, and laptops, agreed. In contrast, the embedded guys have facilities that allows hardware to activate without the CPU being active at the time. So there is a difference.
Quoted 4 lines
even with idle sleep modes and drive spin-down there is no provision for the drive to be restarted if the CPU is asleep, you first have something happen that wakes up the CPU and it then wakes up the drive. This same approach should work for other things.
It will indeed work, but it can be quite energy inefficient, given the capabilities of embedded hardware.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
the fact that Android is making it possible for suspend to selectivly avoid disabling them makes me think that a lot of the work needed to make this happen has probably been done. look at what would happen in a suspend if it decided to leave everything else on and just disable the one thing, that should e the same thing that happens if you are just disabling that one thing for idle sleep.
Quoted 6 lines
Quoted 2 lines
We already covered the differences between suspend and idle, now didn't we? ;-)
we did, however at the time suspend was to stop everything, now we are finding that Android has multiple flavors of suspend, one of which stops everything, the others leave some things running.
Suspend never has stopped the time-of-day clock, so Android's approach is nothing new. Besides, in the embedded world, the ability to leave other types of hardware running during a suspend long predates Android. It might well be new to you, but it is not at all new.
Thanx, Paul
Quoted 113 lines · kevin granade
Quoted 104 lines · Paul E. McKenney
Quoted 96 lines · kevin granade
Quoted 70 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 47 lines · Paul E. McKenney
Quoted 6 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 4 lines · Paul E. McKenney
Quoted 2 lines · On Wed, Aug 04, 2010 at 05:25:53PM -0700, [email protected] wrote:
On Wed, 4 Aug 2010, Paul E. McKenney wrote:
[ . . . ]
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
The music player is an interesting example. It would be idle most of the time, given that audio output doesn't consume very much CPU. So you would not want to suspend the system just because there were no runnable processes. In contrast, allowing the music player to hold a wake lock lets the system know that it would not be appropriate to suspend.
Or am I misunderstanding what you are proposing?
Quoted 7 lines
Quoted 3 lines
the system would need to be idle for 'long enough' (configurable) before deciding to suspend, so as long as 'long enough' is longer than the music player is idle this would not be a problem.
From a user standpoint, having the music player tell the system when it is OK to suspend (e.g., when the user has paused playback) seems a lot nicer than having configurable timeouts that need tweaking.
Quoted 8 lines
every system that I have seen has a configurable "sleep if it's idle for this long" knob. On the iphone (work issue, I didn't want it) that I am currently using it can be configured from 1 min to 5 min.
this is the sort of timeout I am talking about.
with something in the multi-minute range for the 'do a full suspend' doing a wakeup every few 10s of seconds is perfectly safe.
Ah, I was assuming -much- shorter "do full suspend" timeouts.
My (possibly incorrect) assumption is based on the complaint that led to my implementing
RCU_FAST_NO_HZ. A (non-Android) embedded person was quite annoyed (to put it mildly) at the earlier version of RCU because it prevented the system from entering the power-saving dyntick-idle mode, not for minutes, or even for seconds, but for a handful of -milliseconds-. This was my first hint that "energy efficiency" means something completely different in embedded systems than it does in the servers that I am used to.Quoted 2 lines
But I must defer to the Android guys on this -- who knows, perhaps multi-minute delays to enter full-suspend mode are OK for them.
if the system was looking at all applications I would agree that the timeout should be much shorter.
I have a couple devices that are able to have the display usable, even if the CPU is asleep (the OLPC and the Kindle, two different display technologies). With these devices I would like to see the suspend happen so fast that it can suspend between keystrokes.
however, in the case of Android I think the timeouts have to end up being _much_ longer. Otherwise you have the problem of loading an untrusted book reader app on the device and the device suspends while you are reading the page.
currently Android works around this by having a wakelock held whenever the display is on. This seems backwards to me, the display should be on because the system is not suspended, not the system is prevented from suspending because the display is on.
Quoted 5 lines
Rather than having the display be on causing a wavelock to be held (with the code that is controls the display having a timeout for how long it leaves the display on), I would invert this and have the timeout be based on system activity, and when it decides the system is not active, turn off the display (along with other things as it suspends)
IIRC, this was a major point of their (Android's) power management policy. User input of any kind would reset the "display active" timeout, which is the primary thing keeping random untrusted user-facing programs from being suspended while in use. They seemed to consider this to be a special case in their policy, but from the kernel's point of view it is just another suspend blocker being held.
I'm not sure this is the best use case to look at though, because since it is user-facing, the timeout durations are on a different scale than the ones they are really worried about. I think another category of use case that they are worried about is:
(in suspend) -> wakeup due to network -> process network activity -> suspend
or an example that has been mentioned previously:
(in suspend) -> wakeup due to alarm for audio processing -> process batch of audio -> suspend
Quoted 6 lines
In both of these cases, the display may never power on (phone might beep to indicate txt message or email, audio just keeps playing), so the magnitude of the "timeout" for suspending again should be very small. Specifically, they don't want there to be a timeout at all, so as little time as possible time is spent out of suspend in addition to the time required to handle the event that caused wakeup.
Quoted 6 lines
It would be good to get some sort of range for the "timeout". In the audio-output case, my understanding that the spacing between bursts of audio-processing activity is measured in some hundreds of milliseconds, in which case one would want the delays until suspend to be on the millisecond scale. But does Android really suspend between bursts of audio processing while playing music? Very cool if so! ;-)
Quoted 8 lines
Oops, yea that's actually a really bad example, that's probably something that would be handled by low-power states. I think the incoming text message example is a good one though. There seemed to be a focus on user-interaction scale time scales, and I wanted to point out that there are also very short duration time scales to consider as well.
*back to lurking*
I really don't know the answer myself, so I was really asking the question rather than trying to catch you out.
Thanx, Paul
Quoted 102 lines
Kevin
Quoted 95 lines
Thanx, Paul
Quoted 91 lines
Quoted 91 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 3 lines
if the backlight being on holds the wakelock, it would seem that almost every other use of the wakelock could (and probably should) be replaced by something that tickles the display to stay on longer.
The problem with this approach is that the display consumes quite a bit of power, so you don't want to leave it on unnecessarily. So if the system is doing something (for example, playing music) that does not require the display, you really want the display to be off.
what percentage (and types) of apps are really useful with the display off. I think that there are relativly few apps that you really want to keep running if the display is off.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The length of time those apps are running is the governing factor for battery life, and not the number of such apps, right?
correct, but the number of such apps indicates the scope of the problem.
The number of such apps certainly indicates the amount of effort required to modify them, if required. Is that what you are getting at?
yes.
Quoted 14 lines
Quoted 14 lines
Quoted 2 lines
From another e-mail tonight it sounds like almost everything already talks
to a userspace daemon, so if "(the power management service in the
system_server, possibly themedia_serverand the radio interface glue)" (plus possibly some kernel activity) are the only things looked at when considering if it's safe to sleep or not, all of these can (or already do) do 'something' every few seconds, making this problem sound significantly smaller than it sounded like before.Android could even keep it's user-space API between the system power daemon and the rest of userspace the same if they want to.
Quoted 6 lines
Quoted 3 lines
over time, additional apps could be considered 'trusted' (or flagged that way by the user) and not have to interact with the power daemon to keep things alive.
Hmmm... Isn't it the "trusted" (AKA PM-driving) apps that interact with the power daemon via suspend blockers, rather than the other way around?
I was looking at it from a kernel point of view, "trusted" (AKA PM-driving) apps are ones that have permission to grab the wakelock. Any app/daemon that is so trusted can communicate with anything else in userspace as part of making it's decision on whento take the wakelock, but those other applications would not qualify as "trusted" in my eyes.
Quoted 14 lines
Quoted 2 lines
as for intramentation, the key tool to use to see why a system isn't going to sleep would be powertop, just like on other linux systems.
Powertop is indeed an extremely valuable tool, but I am not certain that it really provides the information that the Android guys need. If I understand Arve's and Brian's posts, here is the scenario that they are trying to detect:
o Some PM-driving application has a bug in which it fails to release a wakelock, thus blocking suspend indefinitely.
o This PM-driving application, otherwise being a good citizen, blocks.
Quoted 6 lines
o There are numerous power-oblivious apps running, consuming significant CPU.
What the Android developers need to know is that the trusted application is wrongly holding a wakelock. Won't powertop instead tell them about all the power-oblivious apps?
in my proposal (without a wakelock), powertop would tell you what applications are running and setting timers. If we can modify the kernel/suspend decision code to only look at processes in one cgroup when deciding if the system should go to sleep, a similar modification to poewrtop should let you only show stats on the "trusted" applications.
If you have a userspace power management daemon that accepts requests from untrusted programs and does something to keep the system from sleeping (either taking a wakelock or setting a 'short' timer), it needs to keep the records of this itself because otherwise all the kernel will see (with either powertop or wakelock reporting) is that the power management daemon is what kept the system from sleeping.
David Lang
--
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/--
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/
Quoted 113 lines · kevin granade
Quoted 104 lines · Paul E. McKenney
Quoted 96 lines · kevin granade
Quoted 70 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 47 lines · Paul E. McKenney
Quoted 6 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 4 lines · Paul E. McKenney
Quoted 2 lines · On Wed, Aug 04, 2010 at 05:25:53PM -0700, [email protected] wrote:
On Wed, 4 Aug 2010, Paul E. McKenney wrote:
[ . . . ]
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
The music player is an interesting example. It would be idle most of the time, given that audio output doesn't consume very much CPU. So you would not want to suspend the system just because there were no runnable processes. In contrast, allowing the music player to hold a wake lock lets the system know that it would not be appropriate to suspend.
Or am I misunderstanding what you are proposing?
Quoted 7 lines
Quoted 3 lines
the system would need to be idle for 'long enough' (configurable) before deciding to suspend, so as long as 'long enough' is longer than the music player is idle this would not be a problem.
From a user standpoint, having the music player tell the system when it is OK to suspend (e.g., when the user has paused playback) seems a lot nicer than having configurable timeouts that need tweaking.
Quoted 8 lines
every system that I have seen has a configurable "sleep if it's idle for this long" knob. On the iphone (work issue, I didn't want it) that I am currently using it can be configured from 1 min to 5 min.
this is the sort of timeout I am talking about.
with something in the multi-minute range for the 'do a full suspend' doing a wakeup every few 10s of seconds is perfectly safe.
Ah, I was assuming -much- shorter "do full suspend" timeouts.
My (possibly incorrect) assumption is based on the complaint that led to my implementing
RCU_FAST_NO_HZ. A (non-Android) embedded person was quite annoyed (to put it mildly) at the earlier version of RCU because it prevented the system from entering the power-saving dyntick-idle mode, not for minutes, or even for seconds, but for a handful of -milliseconds-. This was my first hint that "energy efficiency" means something completely different in embedded systems than it does in the servers that I am used to.Quoted 2 lines
But I must defer to the Android guys on this -- who knows, perhaps multi-minute delays to enter full-suspend mode are OK for them.
if the system was looking at all applications I would agree that the timeout should be much shorter.
I have a couple devices that are able to have the display usable, even if the CPU is asleep (the OLPC and the Kindle, two different display technologies). With these devices I would like to see the suspend happen so fast that it can suspend between keystrokes.
however, in the case of Android I think the timeouts have to end up being _much_ longer. Otherwise you have the problem of loading an untrusted book reader app on the device and the device suspends while you are reading the page.
currently Android works around this by having a wakelock held whenever the display is on. This seems backwards to me, the display should be on because the system is not suspended, not the system is prevented from suspending because the display is on.
Quoted 5 lines
Rather than having the display be on causing a wavelock to be held (with the code that is controls the display having a timeout for how long it leaves the display on), I would invert this and have the timeout be based on system activity, and when it decides the system is not active, turn off the display (along with other things as it suspends)
IIRC, this was a major point of their (Android's) power management policy. User input of any kind would reset the "display active" timeout, which is the primary thing keeping random untrusted user-facing programs from being suspended while in use. They seemed to consider this to be a special case in their policy, but from the kernel's point of view it is just another suspend blocker being held.
I'm not sure this is the best use case to look at though, because since it is user-facing, the timeout durations are on a different scale than the ones they are really worried about. I think another category of use case that they are worried about is:
(in suspend) -> wakeup due to network -> process network activity -> suspend
or an example that has been mentioned previously:
(in suspend) -> wakeup due to alarm for audio processing -> process batch of audio -> suspend
Quoted 6 lines
In both of these cases, the display may never power on (phone might beep to indicate txt message or email, audio just keeps playing), so the magnitude of the "timeout" for suspending again should be very small. Specifically, they don't want there to be a timeout at all, so as little time as possible time is spent out of suspend in addition to the time required to handle the event that caused wakeup.
Quoted 6 lines
It would be good to get some sort of range for the "timeout". In the audio-output case, my understanding that the spacing between bursts of audio-processing activity is measured in some hundreds of milliseconds, in which case one would want the delays until suspend to be on the millisecond scale. But does Android really suspend between bursts of audio processing while playing music? Very cool if so! ;-)
Quoted 8 lines
Oops, yea that's actually a really bad example, that's probably something that would be handled by low-power states. I think the incoming text message example is a good one though. There seemed to be a focus on user-interaction scale time scales, and I wanted to point out that there are also very short duration time scales to consider as well.
*back to lurking*
I really don't know the answer myself, so I was really asking the question rather than trying to catch you out.
Thanx, Paul
Quoted 102 lines
Kevin
Quoted 95 lines
Thanx, Paul
Quoted 91 lines
Quoted 91 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 3 lines
if the backlight being on holds the wakelock, it would seem that almost every other use of the wakelock could (and probably should) be replaced by something that tickles the display to stay on longer.
The problem with this approach is that the display consumes quite a bit of power, so you don't want to leave it on unnecessarily. So if the system is doing something (for example, playing music) that does not require the display, you really want the display to be off.
what percentage (and types) of apps are really useful with the display off. I think that there are relativly few apps that you really want to keep running if the display is off.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
The length of time those apps are running is the governing factor for battery life, and not the number of such apps, right?
correct, but the number of such apps indicates the scope of the problem.
The number of such apps certainly indicates the amount of effort required to modify them, if required. Is that what you are getting at?
yes.
Quoted 14 lines
Quoted 14 lines
Quoted 2 lines
From another e-mail tonight it sounds like almost everything already talks
to a userspace daemon, so if "(the power management service in the
system_server, possibly themedia_serverand the radio interface glue)" (plus possibly some kernel activity) are the only things looked at when considering if it's safe to sleep or not, all of these can (or already do) do 'something' every few seconds, making this problem sound significantly smaller than it sounded like before.Android could even keep it's user-space API between the system power daemon and the rest of userspace the same if they want to.
Quoted 6 lines
Quoted 3 lines
over time, additional apps could be considered 'trusted' (or flagged that way by the user) and not have to interact with the power daemon to keep things alive.
Hmmm... Isn't it the "trusted" (AKA PM-driving) apps that interact with the power daemon via suspend blockers, rather than the other way around?
I was looking at it from a kernel point of view, "trusted" (AKA PM-driving) apps are ones that have permission to grab the wakelock. Any app/daemon that is so trusted can communicate with anything else in userspace as part of making it's decision on whento take the wakelock, but those other applications would not qualify as "trusted" in my eyes.
Quoted 14 lines
Quoted 2 lines
as for intramentation, the key tool to use to see why a system isn't going to sleep would be powertop, just like on other linux systems.
Powertop is indeed an extremely valuable tool, but I am not certain that it really provides the information that the Android guys need. If I understand Arve's and Brian's posts, here is the scenario that they are trying to detect:
o Some PM-driving application has a bug in which it fails to release a wakelock, thus blocking suspend indefinitely.
o This PM-driving application, otherwise being a good citizen, blocks.
Quoted 6 lines
o There are numerous power-oblivious apps running, consuming significant CPU.
What the Android developers need to know is that the trusted application is wrongly holding a wakelock. Won't powertop instead tell them about all the power-oblivious apps?
in my proposal (without a wakelock), powertop would tell you what applications are running and setting timers. If we can modify the kernel/suspend decision code to only look at processes in one cgroup when deciding if the system should go to sleep, a similar modification to poewrtop should let you only show stats on the "trusted" applications.
If you have a userspace power management daemon that accepts requests from untrusted programs and does something to keep the system from sleeping (either taking a wakelock or setting a 'short' timer), it needs to keep the records of this itself because otherwise all the kernel will see (with either powertop or wakelock reporting) is that the power management daemon is what kept the system from sleeping.
David Lang
--
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/--
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/
Quoted 10 lines · Paul E. McKenney
Quoted 2 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
as for intramentation, the key tool to use to see why a system isn't going to sleep would be powertop, just like on other linux systems.
Powertop is indeed an extremely valuable tool, but I am not certain that it really provides the information that the Android guys need. If I understand Arve's and Brian's posts, here is the scenario that they are trying to detect:
Quoted 8 lines
o Some PM-driving application has a bug in which it fails to
release a wakelock, thus blocking suspend indefinitely.o This PM-driving application, otherwise being a good citizen,
blocks.o There are numerous power-oblivious apps running, consuming
significant CPU.
Or otherwise doing something power hungry.
Quoted 3 lines
What the Android developers need to know is that the trusted application is wrongly holding a wakelock. Won't powertop instead tell them about all the power-oblivious apps?
Right, and this isn't just information for developers - Android handsets expose this information to end users (so they can indentify any badly behaved applications they have installed or otherwise modify their handset usage if they are disappointed by their battery life). That said, powertop and similar applications could always be extended to also include data from wakelocks.
Quoted 10 lines · Paul E. McKenney
Quoted 2 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
as for intramentation, the key tool to use to see why a system isn't going to sleep would be powertop, just like on other linux systems.
Powertop is indeed an extremely valuable tool, but I am not certain that it really provides the information that the Android guys need. If I understand Arve's and Brian's posts, here is the scenario that they are trying to detect:
Quoted 8 lines
o Some PM-driving application has a bug in which it fails to
release a wakelock, thus blocking suspend indefinitely.o This PM-driving application, otherwise being a good citizen,
blocks.o There are numerous power-oblivious apps running, consuming
significant CPU.
Or otherwise doing something power hungry.
Quoted 3 lines
What the Android developers need to know is that the trusted application is wrongly holding a wakelock. Won't powertop instead tell them about all the power-oblivious apps?
Right, and this isn't just information for developers - Android handsets expose this information to end users (so they can indentify any badly behaved applications they have installed or otherwise modify their handset usage if they are disappointed by their battery life). That said, powertop and similar applications could always be extended to also include data from wakelocks.
Quoted 26 lines · Mark Brown
Quoted 10 lines · Paul E. McKenney
Quoted 2 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
as for intramentation, the key tool to use to see why a system isn't going to sleep would be powertop, just like on other linux systems.
Powertop is indeed an extremely valuable tool, but I am not certain that it really provides the information that the Android guys need. If I understand Arve's and Brian's posts, here is the scenario that they are trying to detect:
Quoted 8 lines
o Some PM-driving application has a bug in which it fails to
release a wakelock, thus blocking suspend indefinitely.o This PM-driving application, otherwise being a good citizen,
blocks.o There are numerous power-oblivious apps running, consuming
significant CPU.Or otherwise doing something power hungry.
Quoted 3 lines
What the Android developers need to know is that the trusted application is wrongly holding a wakelock. Won't powertop instead tell them about all the power-oblivious apps?
Quoted 6 lines
Right, and this isn't just information for developers - Android handsets expose this information to end users (so they can indentify any badly behaved applications they have installed or otherwise modify their handset usage if they are disappointed by their battery life). That said, powertop and similar applications could always be extended to also include data from wakelocks.
Good point!!! Of course, powertop would need to interact with Android's user-level daemon for this to work, but perhaps this could be arranged. (There is a user-level daemon in Android that acquires kernel-level suspend blockers on behalf of applications, so a naive mod to powertop would just finger the user-level daemon.)
Thanx, Paul
Quoted 26 lines · Mark Brown
Quoted 10 lines · Paul E. McKenney
Quoted 2 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
as for intramentation, the key tool to use to see why a system isn't going to sleep would be powertop, just like on other linux systems.
Powertop is indeed an extremely valuable tool, but I am not certain that it really provides the information that the Android guys need. If I understand Arve's and Brian's posts, here is the scenario that they are trying to detect:
Quoted 8 lines
o Some PM-driving application has a bug in which it fails to
release a wakelock, thus blocking suspend indefinitely.o This PM-driving application, otherwise being a good citizen,
blocks.o There are numerous power-oblivious apps running, consuming
significant CPU.Or otherwise doing something power hungry.
Quoted 3 lines
What the Android developers need to know is that the trusted application is wrongly holding a wakelock. Won't powertop instead tell them about all the power-oblivious apps?
Quoted 6 lines
Right, and this isn't just information for developers - Android handsets expose this information to end users (so they can indentify any badly behaved applications they have installed or otherwise modify their handset usage if they are disappointed by their battery life). That said, powertop and similar applications could always be extended to also include data from wakelocks.
Good point!!! Of course, powertop would need to interact with Android's user-level daemon for this to work, but perhaps this could be arranged. (There is a user-level daemon in Android that acquires kernel-level suspend blockers on behalf of applications, so a naive mod to powertop would just finger the user-level daemon.)
Thanx, Paul
2010/8/4 <[email protected]>:
Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines
2010/8/4 <[email protected]>:
Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM, <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines
No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progressQuoted 5 lines
What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.Quoted 4 lines
I _think_ you can use the just-merged
/sys/power/wakeup_countmechanism
to
avoid the race (ifpm_wakeup_event()is called at 2)).Quoted 7 lines
Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.Quoted 9 lines
the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.Quoted 5 lines
That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.
and if you don't have a wakelock the same thing will happen. If you expect
Quoted 8 lines
Quoted 3 lines
Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.
in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally
If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going
Quoted 9 lines
Quoted 4 lines
I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?
I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout
How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)
Quoted 8 lines
Quoted 1 line
We suspend as soon as no wakelocks are held. There is no delay.
So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?
how can any application run without wakelock privilages?
A wakelock is active when the screen is on.
Signature · 1 line
Arve Hjønnevåg
2010/8/4 <[email protected]>:
Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines
2010/8/4 <[email protected]>:
Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM, <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines
No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progressQuoted 5 lines
What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.Quoted 4 lines
I _think_ you can use the just-merged
/sys/power/wakeup_countmechanism
to
avoid the race (ifpm_wakeup_event()is called at 2)).Quoted 7 lines
Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.Quoted 9 lines
the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.Quoted 5 lines
That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.
and if you don't have a wakelock the same thing will happen. If you expect
Quoted 8 lines
Quoted 3 lines
Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.
in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally
If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going
Quoted 9 lines
Quoted 4 lines
I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?
I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout
How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)
Quoted 8 lines
Quoted 1 line
We suspend as soon as no wakelocks are held. There is no delay.
So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?
how can any application run without wakelock privilages?
A wakelock is active when the screen is on.
Signature · 1 line
Arve Hjønnevåg
Quoted 78 lines · Arve Hj?nnev?g
2010/8/4 <[email protected]>:
Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines
2010/8/4 <[email protected]>:
Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM, <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines
No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progressQuoted 5 lines
What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.Quoted 4 lines
I _think_ you can use the just-merged
/sys/power/wakeup_countmechanism
to
avoid the race (ifpm_wakeup_event()is called at 2)).Quoted 7 lines
Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.Quoted 9 lines
the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.Quoted 5 lines
That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.
and if you don't have a wakelock the same thing will happen. If you expect
Quoted 8 lines
Quoted 3 lines
Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.
in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally
Quoted 4 lines
If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.
since the premise is that we only consider the activity of some processes when we are deciding if the system is idle, it's very possible that not all CPUs will be idle when we decide to suspend.
will suspend wake up the application threads? or will it create it's own processes (and/or use processes that can be tagged ahead of time)?
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going
I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?
Quoted 8 lines
Quoted 4 lines
I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout
How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.
no, I want recent activity from a privilaged/trusted process to prevent suspend. I'm saying that such a process can wake up infrequently enough that the wakeups themselves are not a significant amount of processing if it wants to keep the system awake so that other things can keep running.
you say below that the system will never suspend while the backlight is on, well the process that monitors/controlls the backlight would be one of these trusted processes.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)
We suspend as soon as no wakelocks are held. There is no delay.
Quoted 8 lines
Quoted 6 lines
So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?
how can any application run without wakelock privilages?
A wakelock is active when the screen is on.
so what controls when the screen is on? what still needs to run (and keep the system awake) if the screen is off?
David Lang
Quoted 78 lines · Arve Hj?nnev?g
2010/8/4 <[email protected]>:
Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines
2010/8/4 <[email protected]>:
Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM, <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines
No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progressQuoted 5 lines
What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.Quoted 4 lines
I _think_ you can use the just-merged
/sys/power/wakeup_countmechanism
to
avoid the race (ifpm_wakeup_event()is called at 2)).Quoted 7 lines
Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.Quoted 9 lines
the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.Quoted 5 lines
That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.
and if you don't have a wakelock the same thing will happen. If you expect
Quoted 8 lines
Quoted 3 lines
Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.
in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally
Quoted 4 lines
If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.
since the premise is that we only consider the activity of some processes when we are deciding if the system is idle, it's very possible that not all CPUs will be idle when we decide to suspend.
will suspend wake up the application threads? or will it create it's own processes (and/or use processes that can be tagged ahead of time)?
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going
I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?
Quoted 8 lines
Quoted 4 lines
I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout
How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.
no, I want recent activity from a privilaged/trusted process to prevent suspend. I'm saying that such a process can wake up infrequently enough that the wakeups themselves are not a significant amount of processing if it wants to keep the system awake so that other things can keep running.
you say below that the system will never suspend while the backlight is on, well the process that monitors/controlls the backlight would be one of these trusted processes.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)
We suspend as soon as no wakelocks are held. There is no delay.
Quoted 8 lines
Quoted 6 lines
So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?
how can any application run without wakelock privilages?
A wakelock is active when the screen is on.
so what controls when the screen is on? what still needs to run (and keep the system awake) if the screen is off?
David Lang
Hi!
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · Pavel Machek
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines · Pavel Machek
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Matthew Garrett
Quoted 4 lines · Pavel Machek
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?
how much do you care? (not from a theoretical point of view, but from a practical point of view, how much difference does it make)
how much "unwanted" processing would you allow a process to do before shutting down?
how likely are apps that you would trust to just assert "I know better than the system or the user how important I am, don't you dare sleep now" that do this properly, but then do other processing that you really don't want to have happen? (I expect that if the authors of those apps ever ran into this case, they would just add another wakelock to prevent it)
If the only things you have running are apps that are trusted to take the wakelock, are you really going to sleep any more frequently with the wakelock infrastructure than you would with just idle detection? (this can be tested today by just stubbing out the wakelock checks so they have no effect on sleeping)
David Lang
Quoted 9 lines · Matthew Garrett
Quoted 4 lines · Pavel Machek
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?
how much do you care? (not from a theoretical point of view, but from a practical point of view, how much difference does it make)
how much "unwanted" processing would you allow a process to do before shutting down?
how likely are apps that you would trust to just assert "I know better than the system or the user how important I am, don't you dare sleep now" that do this properly, but then do other processing that you really don't want to have happen? (I expect that if the authors of those apps ever ran into this case, they would just add another wakelock to prevent it)
If the only things you have running are apps that are trusted to take the wakelock, are you really going to sleep any more frequently with the wakelock infrastructure than you would with just idle detection? (this can be tested today by just stubbing out the wakelock checks so they have no effect on sleeping)
David Lang
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
Quoted 5 lines
Quoted 2 lines
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
Thanx, Paul
Quoted 13 lines
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
PavelSignature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 8 lines · Pavel Machek
Hi!
Quoted 6 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
Quoted 5 lines
Quoted 2 lines
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
Thanx, Paul
Quoted 13 lines
This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...
(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
PavelSignature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
Quoted 6 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel
Message-ID: <[email protected]>
Arve said:
If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
Quoted 6 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel
Message-ID: <[email protected]>
Arve said:
If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
Quoted 6 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
PavelMessage-ID: <[email protected]>
Arve said:
Quoted 10 lines
If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?
They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.
Cheers,
Flo
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
Quoted 6 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
PavelMessage-ID: <[email protected]>
Arve said:
Quoted 10 lines
If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?
They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.
Cheers,
Flo
Quoted 40 lines · Florian Mickler
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
Quoted 6 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
PavelMessage-ID: <[email protected]>
Arve said:
Quoted 10 lines
If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?
Quoted 3 lines
They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.
Yes, you will always get gains if you shutdown while there is still work to do.
the question I am raising is.
If, instead of doing opportunistic suspend (with wakelocks to keep things awake, requiring explicit application code changes to implement), how close would you be able to get if instead you just were able to tell the system to ignore some processes when considering if the system can sleep or not?
With badly written 'trusted' apps you will have poor power useage, but with badly written apps grabbing wakelocks inappropriately you will have poor power useage.
David Lang
Quoted 40 lines · Florian Mickler
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
Quoted 6 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Hello, Pavel,
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
PavelMessage-ID: <[email protected]>
Arve said:
Quoted 10 lines
If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?
Quoted 3 lines
They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.
Yes, you will always get gains if you shutdown while there is still work to do.
the question I am raising is.
If, instead of doing opportunistic suspend (with wakelocks to keep things awake, requiring explicit application code changes to implement), how close would you be able to get if instead you just were able to tell the system to ignore some processes when considering if the system can sleep or not?
With badly written 'trusted' apps you will have poor power useage, but with badly written apps grabbing wakelocks inappropriately you will have poor power useage.
David Lang
Quoted 7 lines · Pavel Machek
Quoted 4 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
This is all massively system dependant. On some systems when the system is in the same idle state in the lowest power idle mode as in suspend however as a result of not doing the suspend (which causes Linux to quiesce most of the hardware) many more things will be able to generate wake events. On other systems you will achieve a lower power state by using suspend for various reasons, some fixable and some not. I rather suspect Arve was talking about the former case.
Quoted 7 lines · Pavel Machek
Quoted 4 lines
Quoted 2 lines
In different message, Arve said they are actually using low-power idle to emulate suspend on Android.
Could you please point me at this message?
AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
This is all massively system dependant. On some systems when the system is in the same idle state in the lowest power idle mode as in suspend however as a result of not doing the suspend (which causes Linux to quiesce most of the hardware) many more things will be able to generate wake events. On other systems you will achieve a lower power state by using suspend for various reasons, some fixable and some not. I rather suspect Arve was talking about the former case.
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.
Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.
One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.
When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do fcntl() on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.
Then it's just a matter of choosing when to freeze the naive cgroup. That requires a userspace implementation of the suspend blockers API plus opportunistic suspend but does not require any other kernel pieces. Then you can use sigprocmask to prevent the freeze/wake-event race. You would probably even merge the waker with the daemon which implements opportunistic suspend.
Cheers,
-Matt Helsley
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney
If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.
Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.
One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.
When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do fcntl() on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.
Then it's just a matter of choosing when to freeze the naive cgroup. That requires a userspace implementation of the suspend blockers API plus opportunistic suspend but does not require any other kernel pieces. Then you can use sigprocmask to prevent the freeze/wake-event race. You would probably even merge the waker with the daemon which implements opportunistic suspend.
Cheers,
-Matt Helsley
Quoted 17 lines · Matt Helsley
Quoted 3 lines · Matthew Garrett
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.
Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.
One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.
Quoted 6 lines
When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do
fcntl()on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.
The Android execution model includes native code in addition to the dalvik VM, and in the future could include other runtimes -- there are many standard libraries that directly make posix file IO calls, and apps can bundle native libraries which can also directly make syscalls. It's not practical to instrument every piece of userspace code that opens a fd somehow to make additional fcntl calls in various places.
Brian
Quoted 17 lines · Matt Helsley
Quoted 3 lines · Matthew Garrett
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.
Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.
One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.
Quoted 6 lines
When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do
fcntl()on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.
The Android execution model includes native code in addition to the dalvik VM, and in the future could include other runtimes -- there are many standard libraries that directly make posix file IO calls, and apps can bundle native libraries which can also directly make syscalls. It's not practical to instrument every piece of userspace code that opens a fd somehow to make additional fcntl calls in various places.
Brian
Quoted 25 lines · Brian Swetland
Quoted 17 lines · Matt Helsley
Quoted 3 lines · Matthew Garrett
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.
Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.
One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.
Quoted 6 lines
When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do
fcntl()on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.
Quoted 7 lines
The Android execution model includes native code in addition to the dalvik VM, and in the future could include other runtimes -- there are many standard libraries that directly make posix file IO calls, and apps can bundle native libraries which can also directly make syscalls. It's not practical to instrument every piece of userspace code that opens a fd somehow to make additional fcntl calls in various places.
Perhaps using an LD_PRELOAD will work.
Cheers,
-Matt Helsley
Quoted 25 lines · Brian Swetland
Quoted 17 lines · Matt Helsley
Quoted 3 lines · Matthew Garrett
The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.
cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.
Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.
One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.
Quoted 6 lines
When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do
fcntl()on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.
Quoted 7 lines
The Android execution model includes native code in addition to the dalvik VM, and in the future could include other runtimes -- there are many standard libraries that directly make posix file IO calls, and apps can bundle native libraries which can also directly make syscalls. It's not practical to instrument every piece of userspace code that opens a fd somehow to make additional fcntl calls in various places.
Perhaps using an LD_PRELOAD will work.
Cheers,
-Matt Helsley
Quoted 13 lines · On Mon, 2 Aug 2010 21:56:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 2 lines
non-obvious dependencies.
The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.
one of the solutions we're looking at to solve this is to unfreeze the cgroup on a regular basis (say, every 15 to 30 seconds) briefly to avoid this kind of deadlock...
Signature · 7 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 13 lines · On Sat, 31 Jul 2010 22:48:16 -0700 "Paul E. McKenney"…
Quoted 12 lines · Arjan van de Ven
Quoted 8 lines · On Sat, 31 Jul 2010 10:58:42 -0700 "Paul E. McKenney"…
o "Power-aware application" are applications that are
permitted to acquire suspend blockers on Android. Verion 8 of the
suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.More generally, power-aware applications seem to be those
that have permission to exert some control over the system's
power state.
Quoted 7 lines
Quoted 2 lines
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
I do not like the term "aware". At all.
It implies "awareness", and implies it does things based on the power circumstances.
It's about *behaving well*. (not polling, not having activity when there is nothing to do etc etc). Not about being aware that power matters.
I can write a very shitty application that polls all the time and otherwise keeps the CPU and system busy, but it'll be aware that power matters.. it just doesn't behave accordingly.
Quoted 7 lines
The choice between power-aware and power-naive will depend on who is available to do the programming and how valuable power-awareness is for the application in question. Given that people who program PC-class applications are much more common than are people who program with energy efficiency in mind, the power-naive choice will be attractive in many cases.
I'm not sure I buy that.
4 years ago.. yes.
Today.. with PowerTOP and co out there for a long time?
I don't believe that anymore. Most of our open source PC apps are actually very well behaving in the power sense.
Yes an occasional bug slips in, and then gets fixed quickly. (speaking as someone who does this sort of work for a Linux distribution... yes bugs happen on a whole distro level, but they're also not all that common, and get fixed quickly)
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 5 lines · Paul E. McKenney
available to do the programming and how valuable power-awareness is for the application in question. Given that people who program PC-class applications are much more common than are people who program with energy efficiency in mind, the power-naive choice will be attractive in many cases.
I own a Nokia N900. Some applications are ported straight from regular Linux and they're definitely power-naive, as they have little or no optimization for mobile. I agree that this is not "sloppy" or "bad", it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Just like some people will burn CPU cycles by writing their application in a high-level language because it requires fewer man-hours and that you get thousands of cpu-hours for the cost of a man-hour programming the thing (often by externalising the true cost of power which makes power even less of a problem), not caring much about power is rational behaviour when creating an application for pc.
Just look at flash ads, they consume huge amounts of power and they commonly never stop. I imagine that the power used by PCs around the world displaying web pages with advertising with the monitor in power-save mode (powered down) can be counted in gigawatts. When I need my battery to last on my laptop I make sure I don't have any unneccessary tabs enabled because it seriously affects my battery time. I think laptop users would benefit from more power optimized applications as well, so if the OS could do the same for laptop/desktop use as well (spending less time on programs updating display when the display is off), I think there are real world benefits for every desktop/laptop/mobile user.
If nothing else, it's environmentally friendly.
Signature · 1 line
Mikael Abrahamsson email: [email protected]
Quoted 1 line · Paul E. McKenney
available to do the programming and how valuable power-awareness is for the application in question. Given that people who program PC-class applications are much more common than are people who program with energy efficiency in mind, the power-naive choice will be attractive in many cases.
I own a Nokia N900. Some applications are ported straight from regular Linux and they're definitely power-naive, as they have little or no optimization for mobile. I agree that this is not "sloppy" or "bad", it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Just like some people will burn CPU cycles by writing their application in a high-level language because it requires fewer man-hours and that you get thousands of cpu-hours for the cost of a man-hour programming the thing (often by externalising the true cost of power which makes power even less of a problem), not caring much about power is rational behaviour when creating an application for pc.
Just look at flash ads, they consume huge amounts of power and they commonly never stop. I imagine that the power used by PCs around the world displaying web pages with advertising with the monitor in power-save mode (powered down) can be counted in gigawatts. When I need my battery to last on my laptop I make sure I don't have any unneccessary tabs enabled because it seriously affects my battery time. I think laptop users would benefit from more power optimized applications as well, so if the OS could do the same for laptop/desktop use as well (spending less time on programs updating display when the display is off), I think there are real world benefits for every desktop/laptop/mobile user.
If nothing else, it's environmentally friendly.
Signature · 1 line
Mikael Abrahamsson email: [email protected]
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
Signature · 1 line
Mikael Abrahamsson email: [email protected]
Quoted 1 line · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
Signature · 1 line
Mikael Abrahamsson email: [email protected]
Quoted 4 lines · Mikael Abrahamsson
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Good points in both this and your earlier post!!!
Quoted 23 lines
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Quoted 10 lines
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
This is a good point. Within some limits, the timer-aggregation changes that have gone into Linux can handle this, but I am not sure whether or not 180 seconds is within the reasonable boundaries for timer jitter.
Of course, the timers might be synchronized upon wakeup after a sufficiently long suspension, but they would not necessarily stay synchronized without the help of some other mechanism, such as the afore-mentioned timer-aggregation changes.
Thanx, Paul
Quoted 4 lines · Mikael Abrahamsson
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Good points in both this and your earlier post!!!
Quoted 23 lines
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Quoted 10 lines
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
This is a good point. Within some limits, the timer-aggregation changes that have gone into Linux can handle this, but I am not sure whether or not 180 seconds is within the reasonable boundaries for timer jitter.
Of course, the timers might be synchronized upon wakeup after a sufficiently long suspension, but they would not necessarily stay synchronized without the help of some other mechanism, such as the afore-mentioned timer-aggregation changes.
Thanx, Paul
Quoted 42 lines · On Sun, 1 Aug 2010 12:27:08 -0700 "Paul E. McKenney"…
Quoted 4 lines · Mikael Abrahamsson
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Good points in both this and your earlier post!!!
Quoted 23 lines
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Quoted 10 lines
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
Quoted 4 lines
This is a good point. Within some limits, the timer-aggregation changes that have gone into Linux can handle this, but I am not sure whether or not 180 seconds is within the reasonable boundaries for timer jitter.
this is why operating systems for mobile devices offer heartbeat services... where apps subscribe to and do background work like checking email at "convenient" times.
I'm not sure if the OS you use on your desktop has one, but MeeGo and Maemo and I'm pretty sure Android and most other mobile Linux OSes have one. It's a higher level activity alignment layer, well above the kernel.
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 50 lines · Arjan van de Ven
Quoted 42 lines · On Sun, 1 Aug 2010 12:27:08 -0700 "Paul E. McKenney"…
Quoted 4 lines · Mikael Abrahamsson
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Good points in both this and your earlier post!!!
Quoted 23 lines
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Quoted 10 lines
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
Quoted 4 lines
This is a good point. Within some limits, the timer-aggregation changes that have gone into Linux can handle this, but I am not sure whether or not 180 seconds is within the reasonable boundaries for timer jitter.
Quoted 8 lines
this is why operating systems for mobile devices offer heartbeat services... where apps subscribe to and do background work like checking email at "convenient" times.
I'm not sure if the OS you use on your desktop has one, but MeeGo and Maemo and I'm pretty sure Android and most other mobile Linux OSes have one. It's a higher level activity alignment layer, well above the kernel.
Thank you, good to know!
Thanx, Paul
Quoted 50 lines · Arjan van de Ven
Quoted 42 lines · On Sun, 1 Aug 2010 12:27:08 -0700 "Paul E. McKenney"…
Quoted 4 lines · Mikael Abrahamsson
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Good points in both this and your earlier post!!!
Quoted 23 lines
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Quoted 10 lines
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
Quoted 4 lines
This is a good point. Within some limits, the timer-aggregation changes that have gone into Linux can handle this, but I am not sure whether or not 180 seconds is within the reasonable boundaries for timer jitter.
Quoted 8 lines
this is why operating systems for mobile devices offer heartbeat services... where apps subscribe to and do background work like checking email at "convenient" times.
I'm not sure if the OS you use on your desktop has one, but MeeGo and Maemo and I'm pretty sure Android and most other mobile Linux OSes have one. It's a higher level activity alignment layer, well above the kernel.
Thank you, good to know!
Thanx, Paul
Quoted 42 lines · On Sun, 1 Aug 2010 12:27:08 -0700 "Paul E. McKenney"…
Quoted 4 lines · Mikael Abrahamsson
Quoted 2 lines · Mikael Abrahamsson
it's just that mobile (low power) wasn't the intended target of the application when it was written, and this commonly shows.
Good points in both this and your earlier post!!!
Quoted 23 lines
I have another aspect I just thought about. I work for a telephony company. We provide Internet connectivity throught various means, DSL, Ethernet to the Home, mobile etc.
For ETTH and DSL, network usage is pretty straight forward, you send packets, they get delivered pretty quickly with low marginal cost per packet. For mobile, this is not quite so simple. Mobile networks are designed for terminal/UE (user equipment) to use low power, so they go down in low power state after a while. Let's take the case of 3G/HSPA:
After a short while (second) of idleness (no packets being sent), the mobile network negotiates away the high speed resources (the one that enables multimegabit/s transfers) and tries to give it to someone else. After approximately 30 seconds, the terminal goes to "idle", meaning it has no network resources at all. Next time it wants to send something (or the network wants to deliver something to it), network resources need to be negotiated again. This can take 1-2 seconds and uses battery power of course. It also consumes resources in the operator network (because mobility control units need to talk to base stations, tunnels need to be re-negotiated etc).
Quoted 10 lines
Anyhow, my point is that not only is there a benefit in having multiple applications wake up at the same time for power reasons within the device, there is also a point in having coordination of their network access. If a device is running 3 IM programs at the same time, it'd be beneficial if they were coordinated in their communication with their Internet servers. Same goes for the "check for new email" application. If they all were optimized to only wake up the network connectivity once every 180 seconds instead of doing it when the individual application felt like it, power and other resources would be saved by all involved parties.
Quoted 4 lines
This is a good point. Within some limits, the timer-aggregation changes that have gone into Linux can handle this, but I am not sure whether or not 180 seconds is within the reasonable boundaries for timer jitter.
this is why operating systems for mobile devices offer heartbeat services... where apps subscribe to and do background work like checking email at "convenient" times.
I'm not sure if the OS you use on your desktop has one, but MeeGo and Maemo and I'm pretty sure Android and most other mobile Linux OSes have one. It's a higher level activity alignment layer, well above the kernel.
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 17 lines · Paul E. McKenney
Quoted 11 lines
Quoted 8 lines
o "Power-aware application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.More generally, power-aware applications seem to be those that have permission to exert some control over the system's power state.
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
Quoted 5 lines
I am of course open to suggestions for alternatives to the term "power aware application", but most definitely not to obfuscating the difference between power awareness (or whatever name one wishes to call it) and the overall quality of the application, whatever "quality" might mean in a given context.
This is a false dichotomy. The two of you have fallen into a logical trap. I forget the word used to describe an argument based on a fundamental misunderstanding, but it applies here.
The term "power-aware" has _nothing_ to do with how well behaved an application is, or its quality (in any sense). Go back and re-read the definition; you'll see what I mean.
Alan Stern
Quoted 17 lines · Paul E. McKenney
Quoted 11 lines
Quoted 8 lines
o "Power-aware application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.More generally, power-aware applications seem to be those that have permission to exert some control over the system's power state.
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
Quoted 5 lines
I am of course open to suggestions for alternatives to the term "power aware application", but most definitely not to obfuscating the difference between power awareness (or whatever name one wishes to call it) and the overall quality of the application, whatever "quality" might mean in a given context.
This is a false dichotomy. The two of you have fallen into a logical trap. I forget the word used to describe an argument based on a fundamental misunderstanding, but it applies here.
The term "power-aware" has _nothing_ to do with how well behaved an application is, or its quality (in any sense). Go back and re-read the definition; you'll see what I mean.
Alan Stern
Quoted 21 lines · Paul E. McKenney
Quoted 8 lines · Arjan van de Ven
Quoted 5 lines · On Sat, 31 Jul 2010 10:58:42 -0700 "Paul E. McKenney"…
o "Power-aware application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.Quoted 6 lines
Quoted 3 lines
More generally, power-aware applications seem to be those that have permission to exert some control over the system's power state.
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
Quoted 5 lines
I am of course open to suggestions for alternatives to the term "power aware application", but most definitely not to obfuscating the difference between power awareness (or whatever name one wishes to call it) and the overall quality of the application, whatever "quality" might mean in a given context.
So the reason everyone's having trouble with this definition is that it actually conflates two separate axes of power management.
There are good and bad applications in the power sense ... burns less vs burns more.
And there are user mandated vs user optional processes ... necessary/wanted vs unnecessary/unwanted.
What android actually does is reward well written applications because they "just work" and they don't have to be power aware at all ... they're usually event driven and split into the android provider/consumer model.
Badly written applications that are not suspend block aware get shut down (by system suspend) when the screen turns off, so they're also power/suspend unaware.
Applications that want to present the user with a choice in android are power/suspend aware because the only way they get to present the choice is via suspend blockers.
The "power problem" always devolves to resolving a set of choices around a given set of control axes. The problem is that the set of control axes isn't unique and doesn't have a well agreed upon selection. This makes it hard to make definitive terminology because you have to pick the set of axes (implicitly or explicitly) before defining terms ...
James
Quoted 21 lines · Paul E. McKenney
Quoted 8 lines · Arjan van de Ven
Quoted 5 lines · On Sat, 31 Jul 2010 10:58:42 -0700 "Paul E. McKenney"…
o "Power-aware application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.Quoted 6 lines
Quoted 3 lines
More generally, power-aware applications seem to be those that have permission to exert some control over the system's power state.
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
Quoted 5 lines
I am of course open to suggestions for alternatives to the term "power aware application", but most definitely not to obfuscating the difference between power awareness (or whatever name one wishes to call it) and the overall quality of the application, whatever "quality" might mean in a given context.
So the reason everyone's having trouble with this definition is that it actually conflates two separate axes of power management.
There are good and bad applications in the power sense ... burns less vs burns more.
And there are user mandated vs user optional processes ... necessary/wanted vs unnecessary/unwanted.
What android actually does is reward well written applications because they "just work" and they don't have to be power aware at all ... they're usually event driven and split into the android provider/consumer model.
Badly written applications that are not suspend block aware get shut down (by system suspend) when the screen turns off, so they're also power/suspend unaware.
Applications that want to present the user with a choice in android are power/suspend aware because the only way they get to present the choice is via suspend blockers.
The "power problem" always devolves to resolving a set of choices around a given set of control axes. The problem is that the set of control axes isn't unique and doesn't have a well agreed upon selection. This makes it hard to make definitive terminology because you have to pick the set of axes (implicitly or explicitly) before defining terms ...
James
Quoted 50 lines · James Bottomley
Quoted 21 lines · Paul E. McKenney
Quoted 8 lines · Arjan van de Ven
Quoted 5 lines · On Sat, 31 Jul 2010 10:58:42 -0700 "Paul E. McKenney"…
o "Power-aware application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.Quoted 6 lines
Quoted 3 lines
More generally, power-aware applications seem to be those that have permission to exert some control over the system's power state.
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
Quoted 5 lines
I am of course open to suggestions for alternatives to the term "power aware application", but most definitely not to obfuscating the difference between power awareness (or whatever name one wishes to call it) and the overall quality of the application, whatever "quality" might mean in a given context.
So the reason everyone's having trouble with this definition is that it actually conflates two separate axes of power management.
There are good and bad applications in the power sense ... burns less vs burns more.
And there are user mandated vs user optional processes ... necessary/wanted vs unnecessary/unwanted.
What android actually does is reward well written applications because they "just work" and they don't have to be power aware at all ... they're usually event driven and split into the android provider/consumer model.
Badly written applications that are not suspend block aware get shut down (by system suspend) when the screen turns off, so they're also power/suspend unaware.
Applications that want to present the user with a choice in android are power/suspend aware because the only way they get to present the choice is via suspend blockers.
Quoted 5 lines
The "power problem" always devolves to resolving a set of choices around a given set of control axes. The problem is that the set of control axes isn't unique and doesn't have a well agreed upon selection. This makes it hard to make definitive terminology because you have to pick the set of axes (implicitly or explicitly) before defining terms ...
That does seem to be about the size of it... :-/
Thanx, Paul
Quoted 50 lines · James Bottomley
Quoted 21 lines · Paul E. McKenney
Quoted 8 lines · Arjan van de Ven
Quoted 5 lines · On Sat, 31 Jul 2010 10:58:42 -0700 "Paul E. McKenney"…
o "Power-aware application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to
determine which applications are classified as power aware.Quoted 6 lines
Quoted 3 lines
More generally, power-aware applications seem to be those that have permission to exert some control over the system's power state.
I don't like the term "Power aware application". An application is well behaved or it isn't. "aware" has nothing to do with it.
Applications are often complex enough to be aware of some things, naive about others, well behaved in some ways, and ill-behaved in others. This has been the case for some decades now, so it should not come as a surprise.
Quoted 5 lines
I am of course open to suggestions for alternatives to the term "power aware application", but most definitely not to obfuscating the difference between power awareness (or whatever name one wishes to call it) and the overall quality of the application, whatever "quality" might mean in a given context.
So the reason everyone's having trouble with this definition is that it actually conflates two separate axes of power management.
There are good and bad applications in the power sense ... burns less vs burns more.
And there are user mandated vs user optional processes ... necessary/wanted vs unnecessary/unwanted.
What android actually does is reward well written applications because they "just work" and they don't have to be power aware at all ... they're usually event driven and split into the android provider/consumer model.
Badly written applications that are not suspend block aware get shut down (by system suspend) when the screen turns off, so they're also power/suspend unaware.
Applications that want to present the user with a choice in android are power/suspend aware because the only way they get to present the choice is via suspend blockers.
Quoted 5 lines
The "power problem" always devolves to resolving a set of choices around a given set of control axes. The problem is that the set of control axes isn't unique and doesn't have a well agreed upon selection. This makes it hard to make definitive terminology because you have to pick the set of axes (implicitly or explicitly) before defining terms ...
That does seem to be about the size of it... :-/
Thanx, Paul
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
Quoted 41 lines
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend battery life and (2) preserve state until AC power can be obtained.
o It is necessary to be able to use power-naive applications. Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of AC power or (2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-naive applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-naive applications are available.
o If the display is powered off, there is no need to run any application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-naive applications that do not use blocking system calls.
o In order to avoid overrunning hardware and/or kernel buffers, input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a low-power state is received while the system is transitioning into a low-power state, the system must transition back out of the low-power state so that it can hand the user input off to the corresponding application.
o If a power-aware application receives user input, then that application must be given the opportunity to process that input.
Quoted 6 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats. The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Quoted 8 lines
o Power-naive applications must be prohibited from controlling the system power state. One acceptable approach is through use of group permissions on a special power-control device.
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to pm_stay_awake here, etc not pm-qos.)
Quoted 6 lines
o Power-aware applications can make use of power-naive infrastructure. This means that a power-aware application must have some way, whether explicit or implicit, to ensure that any power-naive infrastructure is permitted to run when a power-aware application needs it to run.
Quoted 6 lines
o When a power-aware application is preventing the system from shutting down, and is also waiting on a power-naive application, the power-aware application must set a timeout to handle the possibility that the power-naive application might halt or otherwise fail. (Such timeouts are also used to limit the number of kernel modifications required.)
wake-lock/suspend-blocker timeouts have nothing to do with the timeout used by applications when waiting for a response from a less trusted application.
Quoted 6 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
Quoted 5 lines
o Transition to low-power state must be efficient. In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
It must be power-efficient. Repeated attempts to suspend will kill the idle battery life.
Quoted 10 lines
o Individual peripherals and CPUs must still use standard power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system power state must be accessible both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
Quoted 5 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Quoted 19 lines
o The API that controls the system power state must operate correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
o Transitioning to extremely low power states requires saving and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order to support existing device software.
Signature · 1 line
Arve Hjønnevåg
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
Quoted 41 lines
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend battery life and (2) preserve state until AC power can be obtained.
o It is necessary to be able to use power-naive applications. Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of AC power or (2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-naive applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-naive applications are available.
o If the display is powered off, there is no need to run any application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-naive applications that do not use blocking system calls.
o In order to avoid overrunning hardware and/or kernel buffers, input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a low-power state is received while the system is transitioning into a low-power state, the system must transition back out of the low-power state so that it can hand the user input off to the corresponding application.
o If a power-aware application receives user input, then that application must be given the opportunity to process that input.
Quoted 6 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats. The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Quoted 8 lines
o Power-naive applications must be prohibited from controlling the system power state. One acceptable approach is through use of group permissions on a special power-control device.
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to pm_stay_awake here, etc not pm-qos.)
Quoted 6 lines
o Power-aware applications can make use of power-naive infrastructure. This means that a power-aware application must have some way, whether explicit or implicit, to ensure that any power-naive infrastructure is permitted to run when a power-aware application needs it to run.
Quoted 6 lines
o When a power-aware application is preventing the system from shutting down, and is also waiting on a power-naive application, the power-aware application must set a timeout to handle the possibility that the power-naive application might halt or otherwise fail. (Such timeouts are also used to limit the number of kernel modifications required.)
wake-lock/suspend-blocker timeouts have nothing to do with the timeout used by applications when waiting for a response from a less trusted application.
Quoted 6 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
Quoted 5 lines
o Transition to low-power state must be efficient. In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
It must be power-efficient. Repeated attempts to suspend will kill the idle battery life.
Quoted 10 lines
o Individual peripherals and CPUs must still use standard power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system power state must be accessible both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
Quoted 5 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Quoted 19 lines
o The API that controls the system power state must operate correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
o Transitioning to extremely low power states requires saving and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order to support existing device software.
Signature · 1 line
Arve Hjønnevåg
Quoted 3 lines · Arve Hjønnevåg
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
First, thank you very much for your review and feedback!
Quoted 47 lines
Quoted 41 lines
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend battery life and (2) preserve state until AC power can be obtained.
o It is necessary to be able to use power-naive applications. Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of AC power or (2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-naive applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-naive applications are available.
o If the display is powered off, there is no need to run any application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-naive applications that do not use blocking system calls.
o In order to avoid overrunning hardware and/or kernel buffers, input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a low-power state is received while the system is transitioning into a low-power state, the system must transition back out of the low-power state so that it can hand the user input off to the corresponding application.
o If a power-aware application receives user input, then that application must be given the opportunity to process that input.
Quoted 5 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.
Quoted 8 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats. The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Ah, I missed this point. What I am doing to adjust is to strike the above requirement, and to add verbiage to the "statistics" requirement about using ioctl() to implement suspend-blocker operations, so that the statistics can be tracked based on the device being open throughout the application's lifetime.
Quoted 4 lines
Quoted 4 lines
o Power-naive applications must be prohibited from controlling the system power state. One acceptable approach is through use of group permissions on a special power-control device.
Quoted 8 lines
Quoted 3 lines
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to
pm_stay_awakehere, etc not pm-qos.)
OK, maybe I was confused earlier. So you do not track statistics via the device being open throughout the application's lifetime?
I am not familiar with pm_stay_awake(), but will take a look at it.
Quoted 13 lines
Quoted 6 lines
o Power-aware applications can make use of power-naive infrastructure. This means that a power-aware application must have some way, whether explicit or implicit, to ensure that any power-naive infrastructure is permitted to run when a power-aware application needs it to run.
Quoted 6 lines
o When a power-aware application is preventing the system from shutting down, and is also waiting on a power-naive application, the power-aware application must set a timeout to handle the possibility that the power-naive application might halt or otherwise fail. (Such timeouts are also used to limit the number of kernel modifications required.)
Quoted 3 lines
wake-lock/suspend-blocker timeouts have nothing to do with the timeout used by applications when waiting for a response from a less trusted application.
OK, I moved this to a new "SUGGESTED USAGE" section and removed the last (parenthesized) sentence.
Quoted 8 lines
Quoted 5 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
The point being that a power-aware application does not block suspend -unless- it holds a suspend blocker, correct?
Or am I missing some other subtlety?
Quoted 6 lines
Quoted 3 lines
o Transition to low-power state must be efficient. In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
It must be power-efficient. Repeated attempts to suspend will kill the idle battery life.
Good point! I changed "Transition to low-power state must be efficient" to instead read "Transition to low-power state must be power-efficient."
Quoted 10 lines
Quoted 10 lines
o Individual peripherals and CPUs must still use standard power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system power state must be accessible both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
Quoted 8 lines
Quoted 4 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Ah, that makes more sense! I moved this to a new "NICE-TO-HAVES" section. I also changed the last parenthesized sentence to read "Such unconditional initialization reduces the intrusiveness of the the Android patchset." Does that work?
Quoted 9 lines
Quoted 9 lines
o The API that controls the system power state must operate correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
Quoted 8 lines
Quoted 8 lines
o Transitioning to extremely low power states requires saving and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order to support existing device software.
Thank you again for looking this over and for your comments!!!
Thanx, Paul
Quoted 3 lines · Arve Hjønnevåg
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
First, thank you very much for your review and feedback!
Quoted 47 lines
Quoted 41 lines
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend battery life and (2) preserve state until AC power can be obtained.
o It is necessary to be able to use power-naive applications. Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of AC power or (2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-naive applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-naive applications are available.
o If the display is powered off, there is no need to run any application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-naive applications that do not use blocking system calls.
o In order to avoid overrunning hardware and/or kernel buffers, input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a low-power state is received while the system is transitioning into a low-power state, the system must transition back out of the low-power state so that it can hand the user input off to the corresponding application.
o If a power-aware application receives user input, then that application must be given the opportunity to process that input.
Quoted 5 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.
Quoted 8 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats. The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Ah, I missed this point. What I am doing to adjust is to strike the above requirement, and to add verbiage to the "statistics" requirement about using ioctl() to implement suspend-blocker operations, so that the statistics can be tracked based on the device being open throughout the application's lifetime.
Quoted 4 lines
Quoted 4 lines
o Power-naive applications must be prohibited from controlling the system power state. One acceptable approach is through use of group permissions on a special power-control device.
Quoted 8 lines
Quoted 3 lines
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to
pm_stay_awakehere, etc not pm-qos.)
OK, maybe I was confused earlier. So you do not track statistics via the device being open throughout the application's lifetime?
I am not familiar with pm_stay_awake(), but will take a look at it.
Quoted 13 lines
Quoted 6 lines
o Power-aware applications can make use of power-naive infrastructure. This means that a power-aware application must have some way, whether explicit or implicit, to ensure that any power-naive infrastructure is permitted to run when a power-aware application needs it to run.
Quoted 6 lines
o When a power-aware application is preventing the system from shutting down, and is also waiting on a power-naive application, the power-aware application must set a timeout to handle the possibility that the power-naive application might halt or otherwise fail. (Such timeouts are also used to limit the number of kernel modifications required.)
Quoted 3 lines
wake-lock/suspend-blocker timeouts have nothing to do with the timeout used by applications when waiting for a response from a less trusted application.
OK, I moved this to a new "SUGGESTED USAGE" section and removed the last (parenthesized) sentence.
Quoted 8 lines
Quoted 5 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
The point being that a power-aware application does not block suspend -unless- it holds a suspend blocker, correct?
Or am I missing some other subtlety?
Quoted 6 lines
Quoted 3 lines
o Transition to low-power state must be efficient. In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
It must be power-efficient. Repeated attempts to suspend will kill the idle battery life.
Good point! I changed "Transition to low-power state must be efficient" to instead read "Transition to low-power state must be power-efficient."
Quoted 10 lines
Quoted 10 lines
o Individual peripherals and CPUs must still use standard power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system power state must be accessible both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
Quoted 8 lines
Quoted 4 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Ah, that makes more sense! I moved this to a new "NICE-TO-HAVES" section. I also changed the last parenthesized sentence to read "Such unconditional initialization reduces the intrusiveness of the the Android patchset." Does that work?
Quoted 9 lines
Quoted 9 lines
o The API that controls the system power state must operate correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
Quoted 8 lines
Quoted 8 lines
o Transitioning to extremely low power states requires saving and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order to support existing device software.
Thank you again for looking this over and for your comments!!!
Thanx, Paul
2010/8/3 Paul E. McKenney <[email protected]>:
Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
Quoted 8 lines
Quoted 4 lines
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to
pm_stay_awakehere, etc not pm-qos.)OK, maybe I was confused earlier. So you do not track statistics via the device being open throughout the application's lifetime?
The suspend blocker patchset does track statistics while the device is open, but it it not keyed of the program name. The name is passed from user-space and a single process can have the device open several times. The wakelock interface that we currently use just creates a new object every time it sees a new name and never frees it.
...
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
The point being that a power-aware application does not block suspend -unless- it holds a suspend blocker, correct?
Yes.
Quoted 2 lines
Or am I missing some other subtlety?
No.
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Quoted 9 lines
Quoted 3 lines
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Ah, that makes more sense! I moved this to a new "NICE-TO-HAVES" section. I also changed the last parenthesized sentence to read "Such unconditional initialization reduces the intrusiveness of the the Android patchset." Does that work?
Sure.
Signature · 1 line
Arve Hjønnevåg
2010/8/3 Paul E. McKenney <[email protected]>:
Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
Quoted 8 lines
Quoted 4 lines
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to
pm_stay_awakehere, etc not pm-qos.)OK, maybe I was confused earlier. So you do not track statistics via the device being open throughout the application's lifetime?
The suspend blocker patchset does track statistics while the device is open, but it it not keyed of the program name. The name is passed from user-space and a single process can have the device open several times. The wakelock interface that we currently use just creates a new object every time it sees a new name and never frees it.
...
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
The point being that a power-aware application does not block suspend -unless- it holds a suspend blocker, correct?
Yes.
Quoted 2 lines
Or am I missing some other subtlety?
No.
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Quoted 9 lines
Quoted 3 lines
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Ah, that makes more sense! I moved this to a new "NICE-TO-HAVES" section. I also changed the last parenthesized sentence to read "Such unconditional initialization reduces the intrusiveness of the the Android patchset." Does that work?
Sure.
Signature · 1 line
Arve Hjønnevåg
Quoted 14 lines · Arve Hjønnevåg
2010/8/3 Paul E. McKenney <[email protected]>:
Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to
pm_stay_awakehere, etc not pm-qos.)
Quoted 8 lines
Quoted 2 lines
OK, maybe I was confused earlier. So you do not track statistics via the device being open throughout the application's lifetime?
The suspend blocker patchset does track statistics while the device is open, but it it not keyed of the program name. The name is passed from user-space and a single process can have the device open several times. The wakelock interface that we currently use just creates a new object every time it sees a new name and never frees it.
Ah, good to know!
Thanx, Paul
Quoted 42 lines
...
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
The point being that a power-aware application does not block suspend -unless- it holds a suspend blocker, correct?
Yes.
Quoted 2 lines
Or am I missing some other subtlety?
No.
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Quoted 9 lines
Quoted 3 lines
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Ah, that makes more sense! I moved this to a new "NICE-TO-HAVES" section. I also changed the last parenthesized sentence to read "Such unconditional initialization reduces the intrusiveness of the the Android patchset." Does that work?
Sure.
Signature · 1 line
Arve Hjønnevåg
Quoted 14 lines · Arve Hjønnevåg
2010/8/3 Paul E. McKenney <[email protected]>:
Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines
On Sat, Jul 31, 2010 at 10:58 AM, Paul E. McKenney <[email protected]> wrote:
...
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
o Statistics of the power-control actions taken by power-aware applications must be provided, and must be keyed off of program name.
We don't key the stats off the program name, but having useful statistics is critical too us. The current code in linux-next does not appear to allow this (I'm referring to
pm_stay_awakehere, etc not pm-qos.)
Quoted 8 lines
Quoted 2 lines
OK, maybe I was confused earlier. So you do not track statistics via the device being open throughout the application's lifetime?
The suspend blocker patchset does track statistics while the device is open, but it it not keyed of the program name. The name is passed from user-space and a single process can have the device open several times. The wakelock interface that we currently use just creates a new object every time it sees a new name and never frees it.
Ah, good to know!
Thanx, Paul
Quoted 42 lines
...
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
o If no power-aware or power-optimized application are indicating a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, even if power-naive applications are runnable. (This requirement did appear to be somewhat controversial.)
I would say it should suspend even if power aware applications are runnable. Most applications do not exclusively perform critical work.
The point being that a power-aware application does not block suspend -unless- it holds a suspend blocker, correct?
Yes.
Quoted 2 lines
Or am I missing some other subtlety?
No.
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
o Any initialization of the API that controls the system power state must be unconditional, so as to be free from failure. (I don't currently understand how this relates, probably due to my current insufficient understanding of the proposed patch set.)
Quoted 9 lines
Quoted 3 lines
Unconditional initialization makes it easier to add suspend blockers to existing kernel code since you don't have to add new failure exit paths. It is not a strong requirement.
Ah, that makes more sense! I moved this to a new "NICE-TO-HAVES" section. I also changed the last parenthesized sentence to read "Such unconditional initialization reduces the intrusiveness of the the Android patchset." Does that work?
Sure.
Signature · 1 line
Arve Hjønnevåg
Quoted 9 lines · Arve Hjønnevåg
Quoted 6 lines
o A power-aware application must be able to efficiently communicate
its needs to the system, so that such communication can be performed on hot code paths. Communication viaopen()andclose()is considered too slow, but communication viaioctl()is acceptable.The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
This is an implementation detail only. The pm-qos objects are long lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.
James
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 9 lines · Arve Hjønnevåg
Quoted 6 lines
o A power-aware application must be able to efficiently communicate
its needs to the system, so that such communication can be performed on hot code paths. Communication viaopen()andclose()is considered too slow, but communication viaioctl()is acceptable.The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
This is an implementation detail only. The pm-qos objects are long lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.
James
2010/8/3 James Bottomley <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.
Quoted 7 lines
Quoted 2 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.
Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?
Quoted 8 lines
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
This is an implementation detail only.
There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.
Quoted 4 lines
The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.
Which pm-qos objects are you referring to? The struct pm_qos_object that backs each pm-qos class is long lived (I don't know why this is named pm_qos_object), but we need stats in struct pm_qos_request_list.
Signature · 1 line
Arve Hjønnevåg
2010/8/3 James Bottomley <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.
Quoted 7 lines
Quoted 2 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.
Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?
Quoted 8 lines
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
This is an implementation detail only.
There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.
Quoted 4 lines
The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.
Which pm-qos objects are you referring to? The struct pm_qos_object that backs each pm-qos class is long lived (I don't know why this is named pm_qos_object), but we need stats in struct pm_qos_request_list.
Signature · 1 line
Arve Hjønnevåg
Quoted 17 lines · Arve Hjønnevåg
2010/8/3 James Bottomley <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines
o A power-aware application must be able to efficiently communicate
its needs to the system, so that such communication can be performed on hot code paths. Communication viaopen()andclose()is considered too slow, but communication viaioctl()is acceptable.Quoted 7 lines
Quoted 2 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
Quoted 4 lines
The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.
? right at the moment it doesn't do stats. I don't see why adding a per pid or per name stat count on the long lived object won't work here.
Quoted 2 lines
Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?
There is no stat interface yet; it's for us to define.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Quoted 5 lines
Quoted 1 line
This is an implementation detail only.
There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.
They're freed on destruction of the long lived kernel object or on user space clear request. Surely that's definitive enough?
Quoted 8 lines
Quoted 4 lines
The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.Which pm-qos objects are you referring to? The struct
pm_qos_objectthat backs each pm-qos class is long lived (I don't know why this is namedpm_qos_object), but we need stats in structpm_qos_request_list.
Actually, why not two separate lists? one for the request and one for the stats?
OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).
James
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 17 lines · Arve Hjønnevåg
2010/8/3 James Bottomley <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines
o A power-aware application must be able to efficiently communicate
its needs to the system, so that such communication can be performed on hot code paths. Communication viaopen()andclose()is considered too slow, but communication viaioctl()is acceptable.Quoted 7 lines
Quoted 2 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
Quoted 4 lines
The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.
? right at the moment it doesn't do stats. I don't see why adding a per pid or per name stat count on the long lived object won't work here.
Quoted 2 lines
Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?
There is no stat interface yet; it's for us to define.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Quoted 5 lines
Quoted 1 line
This is an implementation detail only.
There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.
They're freed on destruction of the long lived kernel object or on user space clear request. Surely that's definitive enough?
Quoted 8 lines
Quoted 4 lines
The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.Which pm-qos objects are you referring to? The struct
pm_qos_objectthat backs each pm-qos class is long lived (I don't know why this is namedpm_qos_object), but we need stats in structpm_qos_request_list.
Actually, why not two separate lists? one for the request and one for the stats?
OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).
James
2010/8/3 James Bottomley <[email protected]>:
Quoted 23 lines · Arve Hjønnevåg
Quoted 17 lines
2010/8/3 James Bottomley <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.Quoted 7 lines
Quoted 2 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
Quoted 4 lines
The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.
Quoted 8 lines
? right at the moment it doesn't do stats. I don't see why adding a per pid or per name stat count on the long lived object won't work here.
Quoted 2 lines
Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?
There is no stat interface yet; it's for us to define.
Then I don't know what you are asking. This specific requirement was about the userspace interface to block and unblock suspend. The existing pm-qos interface to update pm-qos requests is similar to the user space suspend blocker interface (it has the same object lifetime).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
This is an implementation detail only.
There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.
They're freed on destruction of the long lived kernel object or on user space clear request. Surely that's definitive enough?
What is a user-space clear request? Clearing all stats. Deleting a suspend blocker? Unblocking suspend?
The android wakelock interface to userspace creates new wakelocks every time it sees a new name. This was rejected on this list because it does not put any limit on the amount of kernel memory used as a result of calls from user space.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.
Quoted 7 lines
Quoted 3 lines
Which pm-qos objects are you referring to? The struct
pm_qos_objectthat backs each pm-qos class is long lived (I don't know why this is namedpm_qos_object), but we need stats in structpm_qos_request_list.Actually, why not two separate lists? one for the request and one for the stats?
Why do you want to do another lookup? Is there a reason you don't want stats in pm_qos_request_list?
Quoted 6 lines
OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).
I don't think adding stats to pm-qos is hard. It is not as easy as the wakelock/suspend blocker interface since the number of possible request values is unknown, but we could for instance have stats on default vs non-default request values. However, it is not at all clear that switching our code to the pm-qos interface would make it acceptable for mainline inclusion. The main objections to the last suspend blocker patchset seemed to be that we should not use suspend at all. There are also some new api in linux-next that try to solve the same problem in an non android compatible way. Are drivers supposed to use both this interface and pm-qos to prevent suspend?
Signature · 1 line
Arve Hjønnevåg
2010/8/3 James Bottomley <[email protected]>:
Quoted 23 lines · Arve Hjønnevåg
Quoted 17 lines
2010/8/3 James Bottomley <[email protected]>:
Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines
o A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths. Communication via
open()andclose()is considered too slow, but communication viaioctl()is acceptable.Quoted 7 lines
Quoted 2 lines
The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.
Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?
Quoted 4 lines
The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.
Quoted 8 lines
? right at the moment it doesn't do stats. I don't see why adding a per pid or per name stat count on the long lived object won't work here.
Quoted 2 lines
Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?
There is no stat interface yet; it's for us to define.
Then I don't know what you are asking. This specific requirement was about the userspace interface to block and unblock suspend. The existing pm-qos interface to update pm-qos requests is similar to the user space suspend blocker interface (it has the same object lifetime).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
This is an implementation detail only.
There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.
They're freed on destruction of the long lived kernel object or on user space clear request. Surely that's definitive enough?
What is a user-space clear request? Clearing all stats. Deleting a suspend blocker? Unblocking suspend?
The android wakelock interface to userspace creates new wakelocks every time it sees a new name. This was rejected on this list because it does not put any limit on the amount of kernel memory used as a result of calls from user space.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.
Quoted 7 lines
Quoted 3 lines
Which pm-qos objects are you referring to? The struct
pm_qos_objectthat backs each pm-qos class is long lived (I don't know why this is namedpm_qos_object), but we need stats in structpm_qos_request_list.Actually, why not two separate lists? one for the request and one for the stats?
Why do you want to do another lookup? Is there a reason you don't want stats in pm_qos_request_list?
Quoted 6 lines
OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).
I don't think adding stats to pm-qos is hard. It is not as easy as the wakelock/suspend blocker interface since the number of possible request values is unknown, but we could for instance have stats on default vs non-default request values. However, it is not at all clear that switching our code to the pm-qos interface would make it acceptable for mainline inclusion. The main objections to the last suspend blocker patchset seemed to be that we should not use suspend at all. There are also some new api in linux-next that try to solve the same problem in an non android compatible way. Are drivers supposed to use both this interface and pm-qos to prevent suspend?
Signature · 1 line
Arve Hjønnevåg
Attempted summary of suspend-blockers LKML thread, take two
In reply to Paul E. McKenneyContinuing to rush in where angels fear to tread...
This is an updated version of my list posted a couple of days ago at
http://lkml.org/lkml/2010/7/31/73. Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve my understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
But first I am going to look at nomenclature, as it appears to me that at least some of the flamage was due to conflicting definitions.
Ducking into the nearest bunker to avoid the hailstorm of frozen fish...
Thanx, Paul
------------------------------------------------------------------------
DEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing. I have also added a section entitled "CATEGORIES OF APPLICATION BEHAVIOR" based on a suggestion from James Bottomley.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".
Assuming I have correctly guessed what the Android guys were thinking of, perhaps "power-oblivious applications" would be a better description, which I will use until someone convinces me otherwise.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.
o Individual devices in an embedded system can enter "device
low-power states" when not in use.
o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.
o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in the the current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":
1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)
Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled normally when idle.
3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.
CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?
The Linux kernel already has many controls over application behavior:
o the CAP_ capabilities from include/linux/capability.h.
o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.
o The chroot() system call limits a process's access to the
specified subtree of the filesystem.
o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.
o The mlockall() system call provides privileged access
to memory, avoiding page-fault overhead.
But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the ire towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT.
o What degree of control is an application permitted over the power
state of individual devices within the system?
Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?
Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.
o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as suggested by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. Of course, the response latency to such input events can be unbounded.
o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.
o Statistics of the power-control actions taken by PM-driving
applications must be provided. Given the current Android
implementation, the suspend blockers are manipulated via ioctl(), so that a given application's activity can be tracked via the suspend-blocker device, which remains open throughout the application's lifetime. Statistics are aggregated by name, which is passed by the application in through the suspend-blocker interface.
o PM-driving applications can make use of power-oblivious
infrastructure. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure is permitted to run when a PM-driving application needs it to run.
o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)
In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order
to support existing device software.
o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)
NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.
There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example the application might be tagged by its developer.
2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.
Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful.
o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.
APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that this will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)
That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.
o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. (One can argue that suspend blockers will aggregate timers after a sufficiently long suspension, but they would not necessarily stay aggregated during the wakeup period without some other mechanism helping out.)
SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.
POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.
2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.
3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.
4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.
5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.
6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Arjan van de Ven
Arve Hjønnevåg
David Brownell
David Lang
Florian Mickler
James Bottomley
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Rafael J. Wysocki
Ted Ts'o
Attempted summary of suspend-blockers LKML thread, take two
In reply to Paul E. McKenneyContinuing to rush in where angels fear to tread...
This is an updated version of my list posted a couple of days ago at
http://lkml.org/lkml/2010/7/31/73. Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve my understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
But first I am going to look at nomenclature, as it appears to me that at least some of the flamage was due to conflicting definitions.
Ducking into the nearest bunker to avoid the hailstorm of frozen fish...
Thanx, Paul
------------------------------------------------------------------------
DEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing. I have also added a section entitled "CATEGORIES OF APPLICATION BEHAVIOR" based on a suggestion from James Bottomley.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".
Assuming I have correctly guessed what the Android guys were thinking of, perhaps "power-oblivious applications" would be a better description, which I will use until someone convinces me otherwise.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.
o Individual devices in an embedded system can enter "device
low-power states" when not in use.
o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.
o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in the the current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":
1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)
Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled normally when idle.
3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.
CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?
The Linux kernel already has many controls over application behavior:
o the CAP_ capabilities from include/linux/capability.h.
o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.
o The chroot() system call limits a process's access to the
specified subtree of the filesystem.
o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.
o The mlockall() system call provides privileged access
to memory, avoiding page-fault overhead.
But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the ire towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT.
o What degree of control is an application permitted over the power
state of individual devices within the system?
Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?
Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.
o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as suggested by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. Of course, the response latency to such input events can be unbounded.
o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.
o Statistics of the power-control actions taken by PM-driving
applications must be provided. Given the current Android
implementation, the suspend blockers are manipulated via ioctl(), so that a given application's activity can be tracked via the suspend-blocker device, which remains open throughout the application's lifetime. Statistics are aggregated by name, which is passed by the application in through the suspend-blocker interface.
o PM-driving applications can make use of power-oblivious
infrastructure. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure is permitted to run when a PM-driving application needs it to run.
o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)
In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order
to support existing device software.
o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)
NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.
There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example the application might be tagged by its developer.
2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.
Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful.
o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.
APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that this will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)
That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.
o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. (One can argue that suspend blockers will aggregate timers after a sufficiently long suspension, but they would not necessarily stay aggregated during the wakeup period without some other mechanism helping out.)
SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.
POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.
2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.
3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.
4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.
5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.
6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Arjan van de Ven
Arve Hjønnevåg
David Brownell
David Lang
Florian Mickler
James Bottomley
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Rafael J. Wysocki
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take two
Quoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
David Lang
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's suspend_blocker patch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.
In the current model, only a few processes need to specifically interact with the kernel (the power management service in the system_server, possibly the media_server and the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to Paul E. McKenneyQuoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
David Lang
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's suspend_blocker patch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.
In the current model, only a few processes need to specifically interact with the kernel (the power management service in the system_server, possibly the media_server and the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take two
Quoted 21 lines · On Thu, Aug 5, 2010 at 6:18 AM, <[email protected]> wrote:
Quoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
Quoted 3 lines
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
I think I need to clarify here. When I say "app" in the context of Android, I mean "an application running under the Android app model -- sandboxed under a per-app or app-group uid", not "a process". The vast majority of processes on an Android device are "apps" in this sense, but some (usually low level services or daemons) are not. Also I use "wakelock" as a place holder for "suspend blocker" or whatever exact API we're trying to hash out here, because it's shorter and I'm lazy.
Any app may obtain a wakelock through the standard Android APIs, provided it has permission to do so. In the current implementation, apps obtain wakelocks via making a binder RPC call to the power manager service which tracks high level wakelocks (for apps!) and backs them by a single kernel wakelock. Access control is at the RPC level. This implementation could be changed to have the app API simply open /dev/suspendblock or whatnot, with access control enforced by unix permissions (the framework would arrange for apps with the android "can block sleep" permission to be in a unix group that has access to the device).
For native services (native daemons that run "underneath" the android app framework -- for example the media service, the radio interface, etc), the kernel interface is used directly (ok, usually via a very thin C convenience wrapper).
Brian
Quoted 24 lines
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.
Quoted 3 lines
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to [email protected]Quoted 21 lines · On Thu, Aug 5, 2010 at 6:18 AM, <[email protected]> wrote:
Quoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
Quoted 3 lines
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
I think I need to clarify here. When I say "app" in the context of Android, I mean "an application running under the Android app model -- sandboxed under a per-app or app-group uid", not "a process". The vast majority of processes on an Android device are "apps" in this sense, but some (usually low level services or daemons) are not. Also I use "wakelock" as a place holder for "suspend blocker" or whatever exact API we're trying to hash out here, because it's shorter and I'm lazy.
Any app may obtain a wakelock through the standard Android APIs, provided it has permission to do so. In the current implementation, apps obtain wakelocks via making a binder RPC call to the power manager service which tracks high level wakelocks (for apps!) and backs them by a single kernel wakelock. Access control is at the RPC level. This implementation could be changed to have the app API simply open /dev/suspendblock or whatnot, with access control enforced by unix permissions (the framework would arrange for apps with the android "can block sleep" permission to be in a unix group that has access to the device).
For native services (native daemons that run "underneath" the android app framework -- for example the media service, the radio interface, etc), the kernel interface is used directly (ok, usually via a very thin C convenience wrapper).
Brian
Quoted 27 lines
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.Brian
Re: Attempted summary of suspend-blockers LKML thread, take two
Quoted 46 lines · Brian Swetland
Quoted 21 lines · On Thu, Aug 5, 2010 at 6:18 AM, <[email protected]> wrote:
Quoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
Quoted 3 lines
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
I think I need to clarify here. When I say "app" in the context of Android, I mean "an application running under the Android app model -- sandboxed under a per-app or app-group uid", not "a process". The vast majority of processes on an Android device are "apps" in this sense, but some (usually low level services or daemons) are not. Also I use "wakelock" as a place holder for "suspend blocker" or whatever exact API we're trying to hash out here, because it's shorter and I'm lazy.
Any app may obtain a wakelock through the standard Android APIs, provided it has permission to do so. In the current implementation, apps obtain wakelocks via making a binder RPC call to the power manager service which tracks high level wakelocks (for apps!) and backs them by a single kernel wakelock. Access control is at the RPC level. This implementation could be changed to have the app API simply open
/dev/suspendblockor whatnot, with access control enforced by unix permissions (the framework would arrange for apps with the android "can block sleep" permission to be in a unix group that has access to the device).
Quoted 4 lines
For native services (native daemons that run "underneath" the android app framework -- for example the media service, the radio interface, etc), the kernel interface is used directly (ok, usually via a very thin C convenience wrapper).
Thank you for the added detail on Android user-space operation!!!
Thanx, Paul
Quoted 30 lines
Brian
Quoted 27 lines
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.Brian
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to Brian SwetlandQuoted 46 lines · Brian Swetland
Quoted 21 lines · On Thu, Aug 5, 2010 at 6:18 AM, <[email protected]> wrote:
Quoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.
Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
Quoted 3 lines
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
I think I need to clarify here. When I say "app" in the context of Android, I mean "an application running under the Android app model -- sandboxed under a per-app or app-group uid", not "a process". The vast majority of processes on an Android device are "apps" in this sense, but some (usually low level services or daemons) are not. Also I use "wakelock" as a place holder for "suspend blocker" or whatever exact API we're trying to hash out here, because it's shorter and I'm lazy.
Any app may obtain a wakelock through the standard Android APIs, provided it has permission to do so. In the current implementation, apps obtain wakelocks via making a binder RPC call to the power manager service which tracks high level wakelocks (for apps!) and backs them by a single kernel wakelock. Access control is at the RPC level. This implementation could be changed to have the app API simply open
/dev/suspendblockor whatnot, with access control enforced by unix permissions (the framework would arrange for apps with the android "can block sleep" permission to be in a unix group that has access to the device).
Quoted 4 lines
For native services (native daemons that run "underneath" the android app framework -- for example the media service, the radio interface, etc), the kernel interface is used directly (ok, usually via a very thin C convenience wrapper).
Thank you for the added detail on Android user-space operation!!!
Thanx, Paul
Quoted 30 lines
Brian
Quoted 27 lines
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.Brian
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to [email protected]Quoted 21 lines · On Thu, Aug 05, 2010 at 06:18:42AM -0700, [email protected] wrote:
Quoted 1 line · Paul E. McKenney
Continuing to rush in where angels fear to tread...
here here :-)
Quoted 7 lines
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.Quoted 7 lines
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
Quoted 4 lines
One thing that I think it's important to document here is theinformation that Brian provided in response to your question about how many (or actually how few) applications fall into this catefory
Agreed!!! I have added this, and it will appear in the next version.
Thanx, Paul
Quoted 28 lines
David Lang
Quote:
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.Brian
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to [email protected]Hi!
Quoted 8 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to [email protected]Hi!
Quoted 8 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: Attempted summary of suspend-blockers LKML thread, take two
Quoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
Quoted 7 lines
Quoted 3 lines
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
For the high level Java API, yes. For lower level userspace code, like the code that processes keypresses, the kernel interface is used directly. I think an open/close per keypress would be a bit excessive, for example. In any case, that ignores the fact that it's useful to have statistics, which are tricky to maintain meaningfully if you destroy the handle after use every time (by closing the fd).
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: Attempted summary of suspend-blockers LKML thread, take two
In reply to Pavel MachekQuoted 7 lines · Pavel Machek
Hi!
Quoted 5 lines
Quoted 4 lines
I should have asked this earlier... What exactly are the apps' compatibility constraints? Source-level APIs? Byte-code class-library invocations? C/C++ dynamic linking? C/C++ static linking (in other words, syscall)?
Quoted 7 lines
Quoted 3 lines
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within
Strange. Arve claimed that open/close is too slow, and few microseconds faster ioctl is needed, and now we learn it actually uses RPC.
For the high level Java API, yes. For lower level userspace code, like the code that processes keypresses, the kernel interface is used directly. I think an open/close per keypress would be a bit excessive, for example. In any case, that ignores the fact that it's useful to have statistics, which are tricky to maintain meaningfully if you destroy the handle after use every time (by closing the fd).
Brian
Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTS
DEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".
This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.
o Individual devices in an embedded system can enter "device
low-power states" when not in use.
o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.
o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":
1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)
Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.
3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.
CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?
The Linux kernel already has many controls over application behavior:
o the CAP_ capabilities from include/linux/capability.h.
o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.
o The chroot() system call limits a process's access to the
specified subtree of the filesystem.
o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.
o The mlockall() system call provides privileged access
to memory, avoiding page-fault overhead.
But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT.
o What degree of control is an application permitted over the power
state of individual devices within the system?
Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?
Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.
o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.
In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)
o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.
o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:
o total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.
o active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.
o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination with total_time, as it allows you to calculate the average hold time for the suspend blocker.
o expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.
o max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast, active_since is more useful in the held-forever case.)
o sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)
o wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.
Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.
o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)
In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).
o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's suspend_blocker patch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.
In the current model, only a few processes need to specifically interact with the kernel (the power management service in the system_server, possibly the media_server and the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.
o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)
NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.
There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.
2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.
Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.
b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.
o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.
APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)
That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.
o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:
o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.
o The applications would not necessarily stay aggregated
without some other mechanism helping out.
SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.
POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.
2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.
3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.
4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.
5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.
6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hjønnevåg
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTS
DEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".
This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.
Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.
o Individual devices in an embedded system can enter "device
low-power states" when not in use.
o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.
o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":
1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)
Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.
3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.
CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?
The Linux kernel already has many controls over application behavior:
o the CAP_ capabilities from include/linux/capability.h.
o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.
o The chroot() system call limits a process's access to the
specified subtree of the filesystem.
o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.
o The mlockall() system call provides privileged access
to memory, avoiding page-fault overhead.
But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT.
o What degree of control is an application permitted over the power
state of individual devices within the system?
Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?
Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.
o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.
In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.
Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.
In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)
o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.
o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:
o total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.
o active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.
o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination with total_time, as it allows you to calculate the average hold time for the suspend blocker.
o expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.
o max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast, active_since is more useful in the held-forever case.)
o sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)
o wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.
Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.
o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)
In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.
o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).
o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.
o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).
o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)
o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.
o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.
o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:
For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's suspend_blocker patch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.
In the current model, only a few processes need to specifically interact with the kernel (the power management service in the system_server, possibly the media_server and the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.
o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)
NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.
There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.
2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.
Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.
b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.
o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.
APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)
That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.
o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:
o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.
o The applications would not necessarily stay aggregated
without some other mechanism helping out.
SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.
POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.
2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.
3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.
4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.
5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.
6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hjønnevåg
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take three
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Paul E. McKenneyone other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 11 lines · On Fri, Aug 06, 2010 at 04:59:54PM -0700, [email protected] wrote:
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
Yes, I believe that Android would require most power-optimized application be modified to use wakelocks. But power-optimized applications require so much tweaking that the addition of suspend blockers (or whatever other power-control mechanism) is pretty much a non-issue by comparison.
And the number of power-optimized applications should be small, which, as you noted earlier, greatly eases the overall pain of modifying them.
Quoted 3 lines
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
Many application developers do indeed value portability. But this in turn means that most application developers will not be writing power-optimized applications, because the process of power-optimization significantly degrades portability. Just as does the process of performance tuning, beyond a certain point.
Of course, the reason that application developers value portability is that this is one way to gain large unit volumes. Another way to gain large unit volumes is to code for a very popular platform, which explains the large number of apps that run only on iPhone, Android, and Windows.
And in my experience, developers who have decided to commit to a single platform are usually not at all shy about exploiting special facilities of that platform to the fullest.
Quoted 3 lines
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
It seems to me that PM-driving and power-optimized applications are going to be highly platform specific, whether that platform be Linux or some other OS.
Quoted 7 lines
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
There certainly does seem to be a large and growing number of Android apps, so I might be reluctant to bet against them. And the Android guys appear to be making another bet as well -- that almost all applications will be power-oblivious. Their design handles this rather well, given that such applications need not worry about special power-control features.
Thanx, Paul
Quoted 676 lines
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 11 lines · On Fri, Aug 06, 2010 at 04:59:54PM -0700, [email protected] wrote:
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
Yes, I believe that Android would require most power-optimized application be modified to use wakelocks. But power-optimized applications require so much tweaking that the addition of suspend blockers (or whatever other power-control mechanism) is pretty much a non-issue by comparison.
And the number of power-optimized applications should be small, which, as you noted earlier, greatly eases the overall pain of modifying them.
Quoted 3 lines
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
Many application developers do indeed value portability. But this in turn means that most application developers will not be writing power-optimized applications, because the process of power-optimization significantly degrades portability. Just as does the process of performance tuning, beyond a certain point.
Of course, the reason that application developers value portability is that this is one way to gain large unit volumes. Another way to gain large unit volumes is to code for a very popular platform, which explains the large number of apps that run only on iPhone, Android, and Windows.
And in my experience, developers who have decided to commit to a single platform are usually not at all shy about exploiting special facilities of that platform to the fullest.
Quoted 3 lines
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
It seems to me that PM-driving and power-optimized applications are going to be highly platform specific, whether that platform be Linux or some other OS.
Quoted 7 lines
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
There certainly does seem to be a large and growing number of Android apps, so I might be reluctant to bet against them. And the Android guys appear to be making another bet as well -- that almost all applications will be power-oblivious. Their design handles this rather well, given that such applications need not worry about special power-control features.
Thanx, Paul
Quoted 676 lines
David Lang
Quoted 672 lines · Paul E. McKenney
Date: Fri, 6 Aug 2010 15:54:53 -0700
From: Paul E. McKenney <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Attempted summary of suspend-blockers LKML thread, take threeFinal report from this particular angel-free zone for the time being...
This is the third and final version of my Android requirements list (last version available at http://lkml.org/lkml/2010/8/4/409). Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions. This past week's discussion was quite productive, and I thank everyone who took part.
Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve our collective understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.
Thanx, Paul
------------------------------------------------------------------------
CONTENTS
o DEFINITIONS
o CATEGORIES OF APPLICATION BEHAVIOR
o REQUIREMENTS
o NICE-TO-HAVES
o APPARENT NON-REQUIREMENTS
o SUGGESTED USAGE
o POWER-OPTIMIZED APPLICATIONS
o OTHER EXAMPLE APPLICATIONS
o ACKNOWLEDGMENTSDEFINITIONS
These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing.
o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".This document uses "power-oblivious applications" to mean applications that are well-designed and well-implemented in in general, but which do not take power consumption or battery life into account.
o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine
which processes are classified as power aware. Android uses a
user-level daemon to classify app-store apps as PM-driving or not. More generally, PM-driving applications are those that have permission to exert some control over the system's sleep state.Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.
o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.o Individual devices in an embedded system can enter "device
low-power states" when not in use.o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.
2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled when idle.3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.CATEGORIES OF APPLICATION BEHAVIOR
There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?
These categories are discussed below.
o What degree of control is an application permitted over its
own behavior?The Linux kernel already has many controls over application behavior:
o the
CAP_capabilities frominclude/linux/capability.h.o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.o The
chroot()system call limits a process's access to the
specified subtree of the filesystem.o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.o The
mlockall()system call provides privileged access
to memory, avoiding page-fault overhead.But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the annoyance towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.
After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's
OPPORTUNISTIC_SUSPENDdepend on !PREEMPT_RT.o What degree of control is an application permitted over the power
state of individual devices within the system?Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.
o What degree of control is an application permitted over the
system sleep state?Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?
o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.
REQUIREMENTS
o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.In other words, it must be possible to automate the incorporation of a power-oblivious application into the Android environment, but without significantly degrading battery lifetime.
o If the display is powered off, there is no need to run any
application whose only effect is to update the display.Although one could simply block such an application when it next tries to access the display, it it is highly desirable that the application also be prevented from consuming power computing something that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.
There might well be similar requirements for other output-only devices, as noted by Alan Stern.
o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.
Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. The response latency to such input events can of course be unbounded.
o Because Android acquires a suspend blocker as soon as an
input event is noticed and holds it until some application reads that input event, there must be a way to cause the suspend blocker to timeout. If there was no such timeout facility, a power-oblivious application could block suspend by opening an input device and then refusing to ever read from it. (Yes, this can be considered to be a energy-efficiency bug in the power-oblivious application. Please see the statistics requirement below.)o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.o Statistics of the power-control actions taken by PM-driving
applications must be provided. Statistics are aggregated by name,
which is passed by the application in through the suspend-blocker interface. The following specific statistics are collected in the kernel, in roughly decreasing order of importance:o
total_time, which accumulates the total amount of time
that the corresponding suspend blocker has been held.o
active_since, which tracks how long a suspend blocker has
been held since it was last acquired, or (presumably) zero if it is not currently held.o count, which is the number of times that the suspend
blocker has been acquired. This is useful in combination withtotal_time, as it allows you to calculate the average hold time for the suspend blocker.o
expire_count, which is the number of times that the
suspend blocker has timed out. This indicates that some application has an input device open, but is not reading from it, which is a bug, as noted earlier.o
max_time, which is the longest hold time for the suspend
blocker. This allows finding cases where suspend blockers are held for too long, but are eventually released. (In contrast,active_sinceis more useful in the held-forever case.)o
sleep_time, which is the total time that the suspend
blocker was held while the display was powered off. (This might have interesting implications should E-ink displays every become capable of full-motion color video, but it is easy to imagine that the definition of "powered off" would then include only those times during which the display wasn't actively being updated.)o
wake_count, which is the number of times that the
suspend blocker was the first to be acquired in the resume path. This is less than useful on some Android platforms; Arve is dissatisfied with it on Nexus One.Presumably, the userspace code collects similar statistics on application suspend-blocker activity, but that is out of the scope of this document, which focuses instead on kernel requirements. Given that the overhead of maintaining these statistics is quite low, it seems that it would be worthwhile to have them enabled in production systems, for example, in order to flag power-buggy applications that the user has naively downloaded.
o Some PM-driving applications use power-oblivious infrastructure
code. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure code is permitted to run when a PM-driving application needs it to run.o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.
o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.o Transition to system sleep state must occur very soon after
all PM-driving and power-optimized applications have indicated that they have no need for the system to remain operating. Quick transition is expecially important in cases where the wakeup was momentary, for example, when processing sporadic network input or processing widely spaced batches of audio output. For an example of the latter, MP3 playback allows 1-4 minute spacing between bursts of CPU activity).o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.o The current Android userspace API must be supported in order
to support existing device software. According to Brian Swetland:For Java/Dalvik apps, the wakelock API is pertty high level -- it talks to a service via RPC (Binder) that actually interacts with the kernel. Changing the basic kernel<->userspace interface (within reason) is not unthinkable. For example, Arve's
suspend_blockerpatch provides a device interface rather than the proc interface the older wakelock patches use. We'd have to make some userspace changes to support that but they're pretty low level and minor.In the current model, only a few processes need to specifically interact with the kernel (the power management service in the
system_server, possibly themedia_serverand the radio interface glue). A model where every process needs to have a bunch of instrumentation is not very desirable from our point of view. We definitely do need reasonable statistics in order to enable debugging and to enable reporting to endusers (through the Battery Usage UI) what's keeping the device awake.o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)NICE-TO-HAVES
o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.There are two obstacles to meeting this requirement:
1. There must be a reliable way to identify such
applications. This should be doable, for example, the application might be tagged by its developer.2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful:
a. Unfreeze this group periodically to ensure
that any such resource is eventually released, while keeping power consumption down to a dull roar.b. Perform the freeze at application level, where
it is possible to determine whether an application-level resource is held.o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.APPARENT NON-REQUIREMENTS
o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that high scalability will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.
o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. Although one could implement suspend blockers so as to aggregate timers after a sufficiently long suspension, there are problems with this approach:o There would be a "thundering herd" problem just after
resume completed as almost every timer in the system would expire simultaneously.o The applications would not necessarily stay aggregated
without some other mechanism helping out.SUGGESTED USAGE
These are constraints that the developer is expected to abide by, "for best results" and all that.
o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.POWER-OPTIMIZED APPLICATIONS
A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.
Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.
If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.
Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).
There are a number of ways to achieve this:
1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.6. Your favorite solution here.
Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.
OTHER EXAMPLE APPLICATIONS
GPS application that silently displays position.
There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.
GPS application that alerts the user when a given location is reached.
This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.
I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.
Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.
MP3 playback.
This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.
Bouncing cows.
This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.
ACKNOWLEDGMENTS
Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)
Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.
Alan Stern
Anca Emanuel
Arjan van de Ven
Arve Hj?nnev?g
Brian Swetland
David Brownell
David Lang
Florian Mickler
James Bottomley
Kevin Granade
Mark Brown
Matt Helsley
Matthew Garrett
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Pavel Machek
Rafael J. Wysocki
Richard Woodruff
Ted Ts'o
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 13 lines · Paul E. McKenney
Quoted 11 lines · On Fri, Aug 06, 2010 at 04:59:54PM -0700, [email protected] wrote:
one other nice-to-have (or conflicting requirement, depending on your point of view), and I think one of the big things causing people to dislike wavelocks, is the desire to not have to modify applications to have them work with the infrastructure.
you sort of touch on this when you say that power oblivious applications need to be able to be intergrated, but it goes beyond what that statement implies.
with wavelocka, even power optimized applications need to be modified, or the system may halt them at any time.
Quoted 7 lines
Yes, I believe that Android would require most power-optimized application be modified to use wakelocks. But power-optimized applications require so much tweaking that the addition of suspend blockers (or whatever other power-control mechanism) is pretty much a non-issue by comparison.
And the number of power-optimized applications should be small, which, as you noted earlier, greatly eases the overall pain of modifying them.
except, power optimized applications aren't just written for android, they are also written for many other battery powered devices, many of which don't use wavelocks (and in fact, have no real reason to as they don't also have the untrusted apps running)
As such the pool of power optmized software will grow faster than the pool of wakelock enabled software.
Quoted 9 lines
Quoted 3 lines
one thing that has been very clear over the years is that if an API only exists on Linux, no matter how good it is, most application developers won't use it.
Many application developers do indeed value portability. But this in turn means that most application developers will not be writing power-optimized applications, because the process of power-optimization significantly degrades portability. Just as does the process of performance tuning, beyond a certain point.
just like performance tuning, power optimization only degrades portability beyond a certin point. A lot of power optimization is like a lot of performance tuning, find algorithms that you are using (usually frequent polling in the case of power optimizations) and change them. These changes are very frequently very portable.
In this case we are talking about changes that not only aren't portable across different Operating systems, they would not even be portable across Linux itself.
Quoted 8 lines
Of course, the reason that application developers value portability is that this is one way to gain large unit volumes. Another way to gain large unit volumes is to code for a very popular platform, which explains the large number of apps that run only on iPhone, Android, and Windows.
And in my experience, developers who have decided to commit to a single platform are usually not at all shy about exploiting special facilities of that platform to the fullest.
and they are not shy about ignoring other variations of a platform either (for example, Adobe has flash for i386 linux, but not amd64 linux, arm linux, powerpc linux, etc)
I see this as a bad thing to be discouraged.
Quoted 7 lines
Quoted 3 lines
In this case we are in an even worse situation, it's not only specific to Linux, it's specific to a subset of Linux systems, and not using it will cause no problems most of the time.
It seems to me that PM-driving and power-optimized applications are going to be highly platform specific, whether that platform be Linux or some other OS.
The thing is, they don't need to be.
Quoted 8 lines
Quoted 7 lines
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
Quoted 6 lines
There certainly does seem to be a large and growing number of Android apps, so I might be reluctant to bet against them. And the Android guys appear to be making another bet as well -- that almost all applications will be power-oblivious. Their design handles this rather well, given that such applications need not worry about special power-control features.
there is also a growing population of nook applications, kindle applications (ok, in this category there are only two released, both in the last week, but the SDK has not hit public release yet ;-), maemo applications, OLPC applications, tom-tom applications, .....
unless all of these platforms are going to start using wavelocks there are going to be power optimized applications out there that don't use wavelocks.
Quoted 1 line
From this discussion, it looks to me like Android wants two key features
that they don't see a way to get today
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
Today Android uses wakelocks to indicate that there is something 'important' running and trigger a suspend when nothing 'important' is running.
they have cusomized suspend to sometimes not shut everythng down.
My straw-man to address these is the following
1. create the ability to tag cgroups with power management values track their timers separatly
be able to set idle time before sleep per-group instead of system-wide other things in the future
eventually this could be things like preventing processes in
different cgroups from sharing userspace mutexes (or at least detecting when this is the case) to support being able to freeze one cgroup without affectng others.
2. modify the schedular/idle thread to be able to decide to go to a low-power state based on the cgroup information
In addition to checking this in the idle thread, optionally check
this at other times so that you can trigger low-power states even if not completely idle (possibly during the scheduler rebalancing check??)
3. modify the move to low-power modes to include disabling more components in the system (including clocks), in the extreme case this would be a full suspend.
This may include doing work to standardize power management for
devices more than it is to more readily be able to power down components.
this may include making an idle mode of 'stop all clocks except for
one alarm, until the alarm goes off, then advance the clocks to reflect the time passed'
This probably does require the conceptual change from the fairly
monolithic 'you are in this C state' approach to a more fine grained 'the CPU is in this C state, the video card is in that power management state, the audio is in this other state.....'
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 2 lines · On Fri, 6 Aug 2010 [email protected] wrote:
From this discussion, it looks to me like Android wants two key features that they don't see a way to get today
I have largely kept out of this discussion, but this was so outrageous I had to say something.
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
All of these issues are addressed by Raphael's new wakeup_events code.
Quoted 4 lines
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Quoted 6 lines
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
By now, I think most of these questions have been answered.
On a slightly different tack, I have noticed that email discussions concerning Android's wakelocks tend to evolve (I almost wrote "devolve") along one of two paths: Either they start talking about ways to integrate Android's goals into the mainline kernel, or else they start complaining about the fact that Android uses system suspend so aggressively and try to find ways to use deep-idle to achieve equivalent results. Although the second path generally ends up being much less productive than the first, it is the one that most discussions seem to end up taking. Large portions of _this_ thread have tended in that direction.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 2 lines · On Fri, 6 Aug 2010 [email protected] wrote:
From this discussion, it looks to me like Android wants two key features that they don't see a way to get today
I have largely kept out of this discussion, but this was so outrageous I had to say something.
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
All of these issues are addressed by Raphael's new wakeup_events code.
Quoted 4 lines
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Quoted 6 lines
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
By now, I think most of these questions have been answered.
On a slightly different tack, I have noticed that email discussions concerning Android's wakelocks tend to evolve (I almost wrote "devolve") along one of two paths: Either they start talking about ways to integrate Android's goals into the mainline kernel, or else they start complaining about the fact that Android uses system suspend so aggressively and try to find ways to use deep-idle to achieve equivalent results. Although the second path generally ends up being much less productive than the first, it is the one that most discussions seem to end up taking. Large portions of _this_ thread have tended in that direction.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 7 lines · Alan Stern
Quoted 2 lines · On Fri, 6 Aug 2010 [email protected] wrote:
From this discussion, it looks to me like Android wants two key features that they don't see a way to get today
I have largely kept out of this discussion, but this was so outrageous I had to say something.
sorry for misunderstanding things, thank you for speaking up to correct the misunderstanding.
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.
Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific? the heated replys from some people about what Android needs (from people who I assumed were Android maintainers due to the way they were answering questions) sure didn't sound like this was a solved problem.
Quoted 5 lines
Quoted 4 lines
2. changes to idle/suspend so that they can get into a state of lower power consumption thatn any existing idle state (by being able to disable clocks), but still have some parts of the system powered (so that they are more awake than suspend)
Quoted 7 lines
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
the difference is that not all suspends on Android are the same, sometimes when you suspend you power down the audio components, sometimes you don't.
As far as I am aware (and please correct meif I am mistaken), this is significantly different from suspend elsewhere where suspend always takes you to the same state.
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
Quoted 9 lines
Quoted 6 lines
In addition to these key features, the fact that they use suspend much more frequently means that the race condition between deciding to freeze and wake events happening is far more likely to cause them problems, so improvements in this area are needed. I don't think that there is any fundamental opposition to these improvements, just questions on how best to do it without causing performance problems.
By now, I think most of these questions have been answered.
Quoted 10 lines
On a slightly different tack, I have noticed that email discussions concerning Android's wakelocks tend to evolve (I almost wrote "devolve") along one of two paths: Either they start talking about ways to integrate Android's goals into the mainline kernel, or else they start complaining about the fact that Android uses system suspend so aggressively and try to find ways to use deep-idle to achieve equivalent results. Although the second path generally ends up being much less productive than the first, it is the one that most discussions seem to end up taking. Large portions of _this_ thread have tended in that direction.
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 11 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
Quoted 10 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
Quoted 4 lines
the heated replys from some people about what Android needs (from people who I assumed were Android maintainers due to the way they were answering questions) sure didn't sound like this was a solved problem.
The solution is still in its early stages, and it hasn't yet been accepted into Android. Things will improve over time. (Or they won't, and Android will continue to go its separate way...)
Quoted 11 lines
Quoted 7 lines
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
the difference is that not all suspends on Android are the same, sometimes when you suspend you power down the audio components, sometimes you don't.
That's not a difference; it is their decision. For all you or I know, other platforms have been doing the same thing for years.
Quoted 3 lines
As far as I am aware (and please correct meif I am mistaken), this is significantly different from suspend elsewhere where suspend always takes you to the same state.
You are mistaken. Or at best, you are overgeneralizing. It may be true now that all other suspend implementations always go to the same state, but there is no requirement that they do so.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
The set of wakeup sources (including timers) is different.
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
There may be others I have left out.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 11 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
Quoted 10 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
Quoted 4 lines
the heated replys from some people about what Android needs (from people who I assumed were Android maintainers due to the way they were answering questions) sure didn't sound like this was a solved problem.
The solution is still in its early stages, and it hasn't yet been accepted into Android. Things will improve over time. (Or they won't, and Android will continue to go its separate way...)
Quoted 11 lines
Quoted 7 lines
This is nonsense. Nothing was changed. Instead, Android implemented system suspend on their platform in a way that would leave some devices running while the rest of the system powered down. There's nothing out of the ordinary about this. Platforms are free to implement system suspend in whatever way they deem most appropriate. On modern PCs, the most appropriate technique is to go into ACPI's S3 or S4 state. On embedded systems, the technique will vary from one platform to another.
the difference is that not all suspends on Android are the same, sometimes when you suspend you power down the audio components, sometimes you don't.
That's not a difference; it is their decision. For all you or I know, other platforms have been doing the same thing for years.
Quoted 3 lines
As far as I am aware (and please correct meif I am mistaken), this is significantly different from suspend elsewhere where suspend always takes you to the same state.
You are mistaken. Or at best, you are overgeneralizing. It may be true now that all other suspend implementations always go to the same state, but there is no requirement that they do so.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
The set of wakeup sources (including timers) is different.
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
There may be others I have left out.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 11 lines · Alan Stern
Quoted 9 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Quoted 5 lines
Quoted 2 lines
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
makes sense.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
Quoted 8 lines
Quoted 3 lines
Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
And the question to the Android people is if they consider this acceptable or think that this means that the vanilla can't support them.
Quoted 10 lines
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
Quoted 7 lines
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
I'll admit to that, but it seems like there is still new information comeing up about the requirements, as well as the current implementation.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Since they are following this thread, this was intended to be asking them torespond.
Quoted 11 lines
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
I know that Rafael disagrees with Linus, because he has not implemented what Linus suggested.
Quoted 7 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
Quoted 8 lines
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
as I see it
Sleep
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Alan SternQuoted 11 lines · Alan Stern
Quoted 9 lines · On Fri, 6 Aug 2010 [email protected] wrote:
Quoted 8 lines
Quoted 2 lines
1. the ability to decide to suspend while there are still some 'unimportant' apps running.
While this may be true in some literal sense, it certainly is not the best way to view the situation. Linux already has the ability to suspend (or to decide to suspend) whenever you want. What Android has added is the ability to suspend conditionally, based on whether or not some applications or drivers want to keep the system running.
Quoted 5 lines
Quoted 2 lines
Ok, aside from possibly drivers, what' stopping this from being done on a valilla system today?
Nothing much. Mainly just the fact that Rafael's code is so new. It hasn't yet been integrated into the drivers that should use it.
makes sense.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Furthermore, this statement leaves out the primary purpose of
wakelocks: to avoid races between suspending and wakeup events. And it also ignores a very important distinction: the difference between drivers and applications. Wakelocks are used by both, but it has been shown that only the wakelocks used by drivers need to be implemented in the kernel -- the others can be implemented entirely in userspace.
Quoted 8 lines
Quoted 3 lines
Ok, this is the first I've heard in this discussion that wakelocks would not be available to userspace. In fact it was explicitly stated that userspace applications called IOCTLs to get/release the wakelock.
Android's wakelock implementation does make wakelocks available to userspace. In Rafael's approach there is nothing comparable. Instead "userspace wakelock"-equivalents have to be handled by a power manager program.
And the question to the Android people is if they consider this acceptable or think that this means that the vanilla can't support them.
Quoted 10 lines
Quoted 9 lines
many of my objections (voiced in another thread) about Android specific features are not relavent if the wakelock in userspace is just part of that application framework and not tied into the kernel.
Quoted 1 line
All of these issues are addressed by Raphael's new
wakeup_eventscode.Ok, then why is there still discussion about wakelocks at all if Raphael has implemnetd the needed kernel functionality and userspace is Android SDK specific?
Quoted 7 lines
This thread started when Paul posted his list of requirements for Android power management (or power management in general). It wasn't really specific to wakelocks, but people brought them up when discussing how those requirements are currently being met.
In fact, it seems to me that _you_ are the person most responsible for prolonging this discussion.
I'll admit to that, but it seems like there is still new information comeing up about the requirements, as well as the current implementation.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If these two features were available, I think that the rest of what they are looking for could be built up without requireing other changes.
They already _are_ available. Admittedly, only since quite recently. (Rafael's new code was accepted during the 2.6.36 merge window.)
Do Brian and Arve agree that this solves their problem?
I think you should ask them instead of asking me.
Since they are following this thread, this was intended to be asking them torespond.
Quoted 11 lines
Quoted 5 lines
to be fair, there have been numerous complaints about suspend being separate from deep sleep long before Android. Linus' blow-up that resulted in Hibernation and Suspend being separated from each other is a case in point. He was making the point that there shouldn't be a difference between the deepest sleep and suspend.
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
I know that Rafael disagrees with Linus, because he has not implemented what Linus suggested.
Quoted 7 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
Quoted 8 lines
I disagree. There are critical differences between them:
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
as I see it
Sleep
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 8 lines · On Sat, 7 Aug 2010 [email protected] wrote:
Quoted 5 lines
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
Actually I meant that _attempting_ to get rid of them would be wrong, because it would be a futile attempt to carry out an impossible task.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Quoted 8 lines
Quoted 6 lines
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
It isn't. Suspend does not have the capability to leave a device at full power for 100 ms and then switch it to low power if it hasn't been used in that time. (Or, it requires special hardware support to be able to do this.) Idle does have this capability.
Quoted 4 lines
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
But the difference between idle and suspend can be orders of magnitude larger. That makes it qualitatively different, not just quantitatively different.
Quoted 4 lines
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Suspend _is_ a form of sleep. (The other form is hibernation.) It's true that the set of wakeup sources can be customized to some extent. But in the usual implementations, timers are never a wakeup source for suspend whereas they always are for idle.
Quoted 6 lines
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
Sure, the mechanism is platform-specific. That doesn't change the fact that ACPI systems can achieve lower power usage with suspend than they can with idle.
Quoted 3 lines
as I see it
Sleep
Do you mean "idle" or "deep-idle" rather than "sleep"?
Quoted 5 lines
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
Quoted 7 lines
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
Suspend is initiated entirely by userspace, not by the kernel. Wakelocks provide a means for the kernel to delay or cancel a suspend request, not to initiate one.
Quoted 2 lines
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
The freezer is not platform specific.
Quoted 10 lines
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
There are multiple policy engines because one of them is in the kernel and the other is in userspace. I don't see how you can merge the two.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 8 lines · On Sat, 7 Aug 2010 [email protected] wrote:
Quoted 5 lines
This may be controversial, but I think Rafael will agree when I say that (in this one respect) Linus was wrong. Separating hibernation from suspend makes sense, and I agree that the differences between deepest idle and suspend should be minimized. But to get rid of them altogether would be wrong (and probably not possible anyway).
if you thing the differences should be minimized, why do you think that getting rid of them would be wrong?
Actually I meant that _attempting_ to get rid of them would be wrong, because it would be a futile attempt to carry out an impossible task.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
As deep sleep gains the ability to use even less power and as suspend gains the ability to leave things on sometimes, the difference between them is dissapearing. I wouldn't be at all surprised to see them start overlaping soon. So it's not that I think Android should use deep sleeps instead of suspend, but rather that suspend should just be the deepest sleep, one mechanism instead of two.
I disagree. There are critical differences between them:
Quoted 8 lines
Quoted 6 lines
Suspend uses the freezer and idle doesn't.
Suspend generally forces devices to go into their low-power states immediately, whereas idle tends to leave unused devices at full power for some time before going to low power (to minimize average latency).
this sounds like policy, not capability.
It isn't. Suspend does not have the capability to leave a device at full power for 100 ms and then switch it to low power if it hasn't been used in that time. (Or, it requires special hardware support to be able to do this.) Idle does have this capability.
Quoted 4 lines
Quoted 2 lines
Overall, suspend generally has longer latency than idle. (This varies among platforms.)
even different idle modes have different latency
But the difference between idle and suspend can be orders of magnitude larger. That makes it qualitatively different, not just quantitatively different.
Quoted 4 lines
Quoted 1 line
The set of wakeup sources (including timers) is different.
I agree that they are different, but don't they also vary within sleep or suspend as well?
Suspend _is_ a form of sleep. (The other form is hibernation.) It's true that the set of wakeup sources can be customized to some extent. But in the usual implementations, timers are never a wakeup source for suspend whereas they always are for idle.
Quoted 6 lines
Quoted 2 lines
On some systems, suspend uses platform-specific mechanisms to go into lower power states than are available to idle.
the exact mechanism to go into low-power states is platform specific to start with (there are some very popular platforms admittedly, like the PC ACPI modes)
Sure, the mechanism is platform-specific. That doesn't change the fact that ACPI systems can achieve lower power usage with suspend than they can with idle.
Quoted 3 lines
as I see it
Sleep
Do you mean "idle" or "deep-idle" rather than "sleep"?
Quoted 5 lines
a policy engine to decide when to sleep, how deeply to sleep, what to disable, what will wake you up (this includes taking into account desired latency, and the amount of power/time needed to get in and out of the various modes)
Quoted 7 lines
platform specific mechanisms for transitioning in and out of the modes.
Suspend
a policy engine to decide when to suspend, what to leave enabled when you supend, what will wake you i[
Suspend is initiated entirely by userspace, not by the kernel. Wakelocks provide a means for the kernel to delay or cancel a suspend request, not to initiate one.
Quoted 2 lines
platform specific mechanisms for transition in and out of suspend. I view use of the freezer to be one of these mechansims.
The freezer is not platform specific.
Quoted 10 lines
Somewhere amoung this mess are things like spinning down drives, disabling inactive network interfaces, etc. I don't knwo if those are run from the sleep policy engine, or if there is a third policy engine to decide these things.
why should there be multiple different policy engines making power management decisions? it seems to me like these policy engines can and should be merged, with the resulting engine able to trigger all the existing mechanisms for transitioning between modes.
There are multiple policy engines because one of them is in the kernel and the other is in userspace. I don't see how you can merge the two.
Alan Stern
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 7 lines · On Fri, Aug 6, 2010 at 4:59 PM, <[email protected]> wrote:
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
"Normal" apps work reasonably well -- they get halted when the screen turns off, just like they do when my laptop suspends.
Wakelocks are useful for mobile-centric apps that you want to keep running in the background, wake up and do work when the device is "asleep", etc.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 7 lines · On Fri, Aug 6, 2010 at 4:59 PM, <[email protected]> wrote:
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
"Normal" apps work reasonably well -- they get halted when the screen turns off, just like they do when my laptop suspends.
Wakelocks are useful for mobile-centric apps that you want to keep running in the background, wake up and do work when the device is "asleep", etc.
Brian
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 9 lines · Brian Swetland
Quoted 7 lines · On Fri, Aug 6, 2010 at 4:59 PM, <[email protected]> wrote:
now, android is betting that the apps are all developed specifically for the android from scratch, so having a different API is acceptable, even if it cuts them off from the rest of the *nix applications. For a phone this is not neccessarily an unreasonable stance, but as Android moves into the spaces where normal applications are in use (netbooks and tablets), this becomes a much shakier stance to take.
Quoted 6 lines
"Normal" apps work reasonably well -- they get halted when the screen turns off, just like they do when my laptop suspends.
Wakelocks are useful for mobile-centric apps that you want to keep running in the background, wake up and do work when the device is "asleep", etc.
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
2. the current logic for deciding to sleep can't ignore the other apps on the system.
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Best regards,
- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to [email protected]Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
So the reason why this doesn't work is that power management for small mobile devices *is* different from power management for laptops and data center servers, and if you want a rich application ecosystem, it's best if you don't require them to be specially tuned to use the absolute minimum power. (And that means waking up every 30 seconds might be too much; as Brian and Arve have pointed out, with the G1 in airplane mode, the CPU might be waking up once every half hour or more --- and at that rate, powertop will be waking up the CPU more than Android system would be doing so.)
So the real key here is to take most applications, which may be written using techniques that might be considered well written from a laptop point of view, but not for a cell phone, and not require modifications. Even though the application writer might think it's doing well by waking up every 15 seconds, if the laptop lid is down, or if the screen is off, for **most** applications, it should be forcibly put to sleep.
It's only the rare applications that should really be allowed to run while screen is off. And it's only those applications that need modifications to use suspend blocker. From your earlier comments, it seems that this is the key point which you are missing. (No doubt, some of these applications that do need to know about suspend blockers are important ones; ones that make sure the battery isn't about to blow up, or ones which silently wake up every 10-15 minutes to pull down fresh mail for you from your mail server. But those applications are the exception, not the rule.)
Best regards,
- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
Thanks,
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Ted Ts'oQuoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
Thanks,
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
Quoted 5 lines
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
s/prevent deactivate/deactivate/
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Rafael J. WysockiQuoted 29 lines · Rafael J. Wysocki
Quoted 17 lines · Ted Ts'o
Quoted 9 lines · On Fri, Aug 06, 2010 at 08:14:09PM -0700, [email protected] wrote:
that description sounds far more like normal sleep power management that suspending. especially since they want to set timers to wake the system up and the defining characteristic of suspend (according to this thread) is that timers don't fire while suspended.
as I am seeing it, there are two reasons why this don't "just work"
1. sleeping can't currently save as much power as suspending
No, I don't think that's the case at all. The key thing here is that *most* applications don't need to be modified to use suspend locks, because even though they might be in an event loop, when the user user turns off the display, the user generally doesn't want it doing things on their behalf.
Quoted 10 lines
Again, take for example the Mac Book, since Apple has gotten this right for most users' use cases. When you close the lid, you even if the application is under the misguided belief that it should be checking every five seconds to see whether or not the web page has reloaded --- actually, that's not what you want. You probably want the application to be forcibly put to sleep. So the whole point of the suspend blocker design is that you don't have to modify most applications; they just simply get put to sleep when you close the MacBook lid, or, in the case of the Android device, you push the button that turns off the screen.
Quoted 5 lines
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
s/prevent deactivate/deactivate/
Rafael
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker" which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
-- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker" which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
-- Ted
Re: Attempted summary of suspend-blockers LKML thread, take three
Quoted 8 lines · Theodore Tso
Quoted 5 lines · Rafael J. Wysocki
But in principle that need not mean suspending the entire system. To get applications out of the way, you need to freeze user space. However, that's not sufficient, because in addition to that you need to prevent deactivate the majority of interrupt sources to avoid waking up the CPU (from C-states) too often.
Quoted 9 lines
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker" which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep.
nobody has proposed a polling process to decide the system can suspend, what I proposed was to have idle detection decide the system can suspend, which would mean that if you don't want the system to suspend you have to do something to keep it from being idle.
At the time I didn't know that Android always disabled suspend for the entire time the display was on, so I made the assumption that timouts had to be long enough for input events to keep the system awake, which would put them on the order of 30 seconds or longer.
If all that is wanted is to disable the suspend for the entire time the backlight is on you don't need wakelocks, and you don't need a privilaged thread waking up, all you need is to tell the power management system not to suspend through the existing mechanism. you could create a new mechanism (wakelock) to pass the same information, but what is the advantage of doing so?
David Lang
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Theodore TsoQuoted 4 lines · Theodore Tso
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker"
Quoted 8 lines
which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
On the contrary, I suspect that it's precisely equivalent to userspace suspend blockers. There's no way to conditionalise USB wakeups - the system comes up when you plug or unplug any USB device. The system is then fully awake and I'd *guess* that ipods are magically exempted in some way, with itunes sending a signal when it's complete in order to allow the suspend policy daemon to trigger a suspend again.
Quoted 3 lines
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
gnome-power-manager supports applications inhibiting suspend, but right now I suspect that it'll never deal with the case where you resume with the lid closed. It's a simple matter of coding, though.
Signature · 1 line
Matthew Garrett | [email protected]
Re: Attempted summary of suspend-blockers LKML thread, take three
In reply to Theodore TsoQuoted 4 lines · Theodore Tso
True, but again, consider the MacBook. If you plug in an iPod, the machine will wake up for *just* long enough to let the iTunes sync the iPod, but once its done, the machine goes back to sleep again immediately. I doubt MacOS has something called a "suspend blocker"
Quoted 8 lines
which prevents the machine from sleeping until iTunes finished, which when released, allows the machine to suspend again immediately. But neither did I see any evidence that it took 30 seconds for some kludgy polling process to decide that iTunes was done, and to allow the MacBook to go back to sleep. Clearly, the MacBook allows some interrupts through, and some USB insert events through, but clearly not all. (Inserting a USB drive doesn't wake up the laptop; at least, not for long.)
On the contrary, I suspect that it's precisely equivalent to userspace suspend blockers. There's no way to conditionalise USB wakeups - the system comes up when you plug or unplug any USB device. The system is then fully awake and I'd *guess* that ipods are magically exempted in some way, with itunes sending a signal when it's complete in order to allow the suspend policy daemon to trigger a suspend again.
Quoted 3 lines
Can we do something as smooth with a Linux desktop? And if not, why not? (Oh yeah, and wasn't this supposed to be the year of the Linux Desktop? :-)
gnome-power-manager supports applications inhibiting suspend, but right now I suspect that it'll never deal with the case where you resume with the lid closed. It's a simple matter of coding, though.
Signature · 1 line
Matthew Garrett | [email protected]