Skip to contentSkip to conversation

Attempted summary of suspend-blockers LKML thread

RFC PATCH New Paul E. McKenney 32 participants 817 messages Jul 31, 2010 – Sep 17, 2010 Page 3 of 6

Subsystems (4)
lore
Share & tools
lore
#327 lore raw
In reply to Paul E. McKenney

2010/8/4 Paul E. McKenney <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 1 line · Matthew Garrett

[ . . . ]

Quoted 10 lines
Quoted 2 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting). The proposed in user-space interface of calling into every process that receives wakeup events before every suspend call is also not compatible with existing apps.

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
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

#328 lore raw
In reply to Paul E. McKenney

2010/8/4 Paul E. McKenney <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 1 line · Matthew Garrett

[ . . . ]

Quoted 10 lines
Quoted 2 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting). The proposed in user-space interface of calling into every process that receives wakeup events before every suspend call is also not compatible with existing apps.

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

#500 lore raw
In reply to Brian Swetland
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

#501 lore raw
In reply to Brian Swetland
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

#223 lore raw
In reply to Arve Hjønnevåg
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 4 lines
Quoted 1 line

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Arve, you say that like it is a bad thing. ;-)

Seriously, the hope is that Rafael's implementation is useful to other projects in addition to Android. And, all else being equal, the more people who need a given facility, the more likely that facility is to make it to mainline, right?

And yes, I see you call out some additional things that Android needs, but hopefully this gap can be closed one way or another.

Thanx, Paul

Quoted 61 lines
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 8 lines
Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system. If the system does not suspend at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 10 lines
Quoted 1 line

is also not compatible with existing apps.

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 4 lines
Quoted 1 line

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Arve, you say that like it is a bad thing. ;-)

Seriously, the hope is that Rafael's implementation is useful to other projects in addition to Android. And, all else being equal, the more people who need a given facility, the more likely that facility is to make it to mainline, right?

And yes, I see you call out some additional things that Android needs, but hopefully this gap can be closed one way or another.

Thanx, Paul

Quoted 61 lines
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 8 lines
Quoted 5 lines

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system. If the system does not suspend at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 10 lines
Quoted 1 line

is also not compatible with existing apps.

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

Signature · 1 line
Arve Hjønnevåg
#329 lore raw
In reply to Brian Swetland
Quoted 30 lines · Brian Swetland

2010/8/4 Paul E. McKenney <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 1 line · Matthew Garrett

[ . . . ]

Quoted 10 lines
Quoted 2 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting). The proposed in user-space interface of calling into every process that receives wakeup events before every suspend call is also not compatible with existing apps.

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.

Quoted 8 lines

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.

Thank you for the info!

Thanx, Paul

#330 lore raw
In reply to Brian Swetland
Quoted 30 lines · Brian Swetland

2010/8/4 Paul E. McKenney <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 1 line · Matthew Garrett

[ . . . ]

Quoted 10 lines
Quoted 2 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting). The proposed in user-space interface of calling into every process that receives wakeup events before every suspend call is also not compatible with existing apps.

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.

Quoted 8 lines

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.

Thank you for the info!

Thanx, Paul

#381 lore raw
In reply to Paul E. McKenney
Quoted 33 lines · Paul E. McKenney
Quoted 32 lines · On Wed, Aug 04, 2010 at 05:25:53PM -0700, [email protected] wrote:
Quoted 30 lines · Paul E. McKenney
Quoted 13 lines · On Wed, Aug 04, 2010 at 04:49:22PM -0700, [email protected] wrote:
Quoted 11 lines · Paul E. McKenney
Quoted 10 lines · On Wed, Aug 04, 2010 at 04:23:43PM -0700, [email protected] wrote:
Quoted 2 lines · Arve Hj?nnev?g

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?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

how can any application run without wakelock privilages?

Isn't a wakelock held as long as the display is lit, so that the system would continue running as long as the page was visible?

what holds this wakelock, and what sort of timeout does it have? (and why could that same timeout be used in other ways instead)

I defer to the Android guys on what exactly holds the display's wakelock. The timeout is the display-blank timeout.

Quoted 4 lines

how many apps really need to keep running after the screen blanks? there are a few (audio output apps, including music player and Navigation directions), but I don't have see a problem with them being marked as the 'trusted' apps to pay attention instead.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Downloading is another.

this is definantly an interesting case, do you want an active network connection to keep the machine awake? if so do you want it for all network connections, or only for some...

The Android approach is that everything is permitted to run when the device is not suspended. So that would be all network connections.

I wasn't suggesting freezing some network connections while letting others run, I was thinking in terms of 'if the system patcher daemon is downloading, don't go to sleep, but if it's dancing cows (or mail client to an IMAP server) go ahead and sleep, even if there is some data passing over the connection.

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.

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.

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

Quoted 6 lines
Quoted 3 lines

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.

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.

Quoted 1 line

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 the media_server and 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.

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.

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.

David Lang

#361 lore raw
In reply to Paul E. McKenney
Quoted 63 lines · On Wed, 4 Aug 2010 16:10:03 -0700 "Paul E. McKenney"…
Quoted 47 lines · On Wed, Aug 04, 2010 at 03:56:42PM -0700, [email protected] wrote:
Quoted 39 lines · Arve Hj?nnev?g
Quoted 32 lines · On Wed, Aug 4, 2010 at 3:31 PM, <[email protected]> wrote:
Quoted 24 lines · Matthew Garrett
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett

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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to
avoid the race (if pm_wakeup_event() is called at 2)).

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

Quoted 6 lines

and if you don't have a wakelock the same thing will happen. If you expect 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 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)

The difference between the Android scheme and your proposal is that the Android scheme freezes -all- the processes, not just a subset of them. Therefore, in the Android scheme, the case of one process attempting to acquire a resource held by a frozen process. In contrast, any scheme that attempts to freeze only a subset of the processes must somehow either avoid or properly handle the situation where a frozen process is holding a resource that a running process is trying to acquire.

Quoted 1 line

Thanx, Paul

No no. In the David-Lang-CGroup-Scheme[1](tm?) suspend-from-idle is used. For idle decision a certain subset of tasks is ignored.

Where suspend is prevented by the trusted
process in android-world taking a wakelock, here it would just prevent the system from going idle by arming timers.

This would be pretty equivalent to the suspend-blocker scheme and not introduce new userspace api. But the downside is, as Arve pointed out, that now one can not get full-idle-power-leverage while suspend is blocked.

[1] http://permalink.gmane.org/gmane.linux.kernel/1018452 and following

Cheers,
Flo

#362 lore raw
In reply to Paul E. McKenney
Quoted 63 lines · On Wed, 4 Aug 2010 16:10:03 -0700 "Paul E. McKenney"…
Quoted 47 lines · On Wed, Aug 04, 2010 at 03:56:42PM -0700, [email protected] wrote:
Quoted 39 lines · Arve Hj?nnev?g
Quoted 32 lines · On Wed, Aug 4, 2010 at 3:31 PM, <[email protected]> wrote:
Quoted 24 lines · Matthew Garrett
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett

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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to
avoid the race (if pm_wakeup_event() is called at 2)).

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

Quoted 6 lines

and if you don't have a wakelock the same thing will happen. If you expect 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 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)

The difference between the Android scheme and your proposal is that the Android scheme freezes -all- the processes, not just a subset of them. Therefore, in the Android scheme, the case of one process attempting to acquire a resource held by a frozen process. In contrast, any scheme that attempts to freeze only a subset of the processes must somehow either avoid or properly handle the situation where a frozen process is holding a resource that a running process is trying to acquire.

Quoted 1 line

Thanx, Paul

No no. In the David-Lang-CGroup-Scheme[1](tm?) suspend-from-idle is used. For idle decision a certain subset of tasks is ignored.

Where suspend is prevented by the trusted
process in android-world taking a wakelock, here it would just prevent the system from going idle by arming timers.

This would be pretty equivalent to the suspend-blocker scheme and not introduce new userspace api. But the downside is, as Arve pointed out, that now one can not get full-idle-power-leverage while suspend is blocked.

[1] http://permalink.gmane.org/gmane.linux.kernel/1018452 and following

Cheers,
Flo

#363 lore raw
Quoted 16 lines · On Thu, 5 Aug 2010 07:33:59 +0200 Florian Mickler <[email protected]> wrote:

On Wed, 4 Aug 2010 16:10:03 -0700
"Paul E. McKenney" <[email protected]> wrote:

No no. In the David-Lang-CGroup-Scheme[1](tm?) suspend-from-idle is used. For idle decision a certain subset of tasks is ignored.

Where suspend is prevented by the trusted
process in android-world taking a wakelock, here it would just prevent the system from going idle by arming timers.

This would be pretty equivalent to the suspend-blocker scheme and not introduce new userspace api. But the downside is, as Arve pointed out, that now one can not get full-idle-power-leverage while suspend is blocked.

Quoted 7 lines

[1] http://permalink.gmane.org/gmane.linux.kernel/1018452 and following

Cheers,
Flo

There are a few downsides that got mentioned already in reponse.. I got a little lagged behind.

There are upsides to this approach like not
having a special purpose userspace api, conceptually integrating suspend into the idle mechanism ..

Short summary of the cons that got mentioned:

- applications need to resort to polling to keep the system

	out of idle (->  system will never be fully idle)

- the race between deciding to suspend and becoming active again is not handled

- no special statistics available

- the timers of the ignored applications will behave unexpected (as the monotonic clock is not stopped)... while applications have already to cope with network-loss, other side effects of suspend without monotonic clock stopped are to be expected...

Cheers,
Flo

#364 lore raw
In reply to Florian Mickler
Quoted 16 lines · On Thu, 5 Aug 2010 07:33:59 +0200 Florian Mickler <[email protected]> wrote:

On Wed, 4 Aug 2010 16:10:03 -0700
"Paul E. McKenney" <[email protected]> wrote:

No no. In the David-Lang-CGroup-Scheme[1](tm?) suspend-from-idle is used. For idle decision a certain subset of tasks is ignored.

Where suspend is prevented by the trusted
process in android-world taking a wakelock, here it would just prevent the system from going idle by arming timers.

This would be pretty equivalent to the suspend-blocker scheme and not introduce new userspace api. But the downside is, as Arve pointed out, that now one can not get full-idle-power-leverage while suspend is blocked.

Quoted 7 lines

[1] http://permalink.gmane.org/gmane.linux.kernel/1018452 and following

Cheers,
Flo

There are a few downsides that got mentioned already in reponse.. I got a little lagged behind.

There are upsides to this approach like not
having a special purpose userspace api, conceptually integrating suspend into the idle mechanism ..

Short summary of the cons that got mentioned:

- applications need to resort to polling to keep the system

	out of idle (->  system will never be fully idle)

- the race between deciding to suspend and becoming active again is not handled

- no special statistics available

- the timers of the ignored applications will behave unexpected (as the monotonic clock is not stopped)... while applications have already to cope with network-loss, other side effects of suspend without monotonic clock stopped are to be expected...

Cheers,
Flo

#365 lore raw
Quoted 27 lines · Florian Mickler
Quoted 16 lines · On Thu, 5 Aug 2010 07:33:59 +0200 Florian Mickler <[email protected]> wrote:

On Wed, 4 Aug 2010 16:10:03 -0700
"Paul E. McKenney" <[email protected]> wrote:

No no. In the David-Lang-CGroup-Scheme[1](tm?) suspend-from-idle is used. For idle decision a certain subset of tasks is ignored.

Where suspend is prevented by the trusted
process in android-world taking a wakelock, here it would just prevent the system from going idle by arming timers.

This would be pretty equivalent to the suspend-blocker scheme and not introduce new userspace api. But the downside is, as Arve pointed out, that now one can not get full-idle-power-leverage while suspend is blocked.

Quoted 7 lines

[1] http://permalink.gmane.org/gmane.linux.kernel/1018452 and following

Cheers,
Flo

Quoted 6 lines

There are a few downsides that got mentioned already in reponse.. I got a little lagged behind.

There are upsides to this approach like not
having a special purpose userspace api, conceptually integrating suspend into the idle mechanism ..

first off, a good summary of that I've been saying, thanks.

Quoted 4 lines

Short summary of the cons that got mentioned:

- applications need to resort to polling to keep the system

	out of idle (->  system will never be fully idle)

true, although the power difference between a system that is completelyidle (but with a wavelock held) and a system where one application is polling every 10 seconds or so is _really_ low.

Quoted 2 lines

- the race between deciding to suspend and becoming active again is not handled

this one I will admit to not fully understanding, it sounds like there are opptions here, but I don't understand them or their trade-offs

Quoted 1 line

- no special statistics available

or no special statistics needed. Powertop is already avaible to analyse a system and report what processes are keeping it awake. Why would this not be enough?

Quoted 4 lines

- the timers of the ignored applications will behave unexpected (as the monotonic clock is not stopped)... while applications have already to cope with network-loss, other side effects of suspend without monotonic clock stopped are to be expected...

I'm not sure this is true. there's nothing stopping the suspend (when it finally does happen) from stopping the monotonic clock. The core of my proposal is tweaking how we decide to suspend. Other than the possibility that we decide to suspend between timers (and set an alarm to wake up when a timer would go off) I'm not suggesting that the suspend itself change once it's finally triggered.

David Lang

#366 lore raw
In reply to Florian Mickler
Quoted 27 lines · Florian Mickler
Quoted 16 lines · On Thu, 5 Aug 2010 07:33:59 +0200 Florian Mickler <[email protected]> wrote:

On Wed, 4 Aug 2010 16:10:03 -0700
"Paul E. McKenney" <[email protected]> wrote:

No no. In the David-Lang-CGroup-Scheme[1](tm?) suspend-from-idle is used. For idle decision a certain subset of tasks is ignored.

Where suspend is prevented by the trusted
process in android-world taking a wakelock, here it would just prevent the system from going idle by arming timers.

This would be pretty equivalent to the suspend-blocker scheme and not introduce new userspace api. But the downside is, as Arve pointed out, that now one can not get full-idle-power-leverage while suspend is blocked.

Quoted 7 lines

[1] http://permalink.gmane.org/gmane.linux.kernel/1018452 and following

Cheers,
Flo

Quoted 6 lines

There are a few downsides that got mentioned already in reponse.. I got a little lagged behind.

There are upsides to this approach like not
having a special purpose userspace api, conceptually integrating suspend into the idle mechanism ..

first off, a good summary of that I've been saying, thanks.

Quoted 4 lines

Short summary of the cons that got mentioned:

- applications need to resort to polling to keep the system

	out of idle (->  system will never be fully idle)

true, although the power difference between a system that is completelyidle (but with a wavelock held) and a system where one application is polling every 10 seconds or so is _really_ low.

Quoted 2 lines

- the race between deciding to suspend and becoming active again is not handled

this one I will admit to not fully understanding, it sounds like there are opptions here, but I don't understand them or their trade-offs

Quoted 1 line

- no special statistics available

or no special statistics needed. Powertop is already avaible to analyse a system and report what processes are keeping it awake. Why would this not be enough?

Quoted 4 lines

- the timers of the ignored applications will behave unexpected (as the monotonic clock is not stopped)... while applications have already to cope with network-loss, other side effects of suspend without monotonic clock stopped are to be expected...

I'm not sure this is true. there's nothing stopping the suspend (when it finally does happen) from stopping the monotonic clock. The core of my proposal is tweaking how we decide to suspend. Other than the possibility that we decide to suspend between timers (and set an alarm to wake up when a timer would go off) I'm not suggesting that the suspend itself change once it's finally triggered.

David Lang

#538 lore raw

Re: Attempted summary of suspend-blockers LKML thread, take two

In reply to Paul E. McKenney
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

#539 lore raw

Re: Attempted summary of suspend-blockers LKML thread, take two

In reply to Paul E. McKenney
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

#116 lore raw
In reply to Rafael J. Wysocki
Quoted 41 lines · Rafael J. Wysocki
Quoted 25 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 23 lines · Rafael J. Wysocki
Quoted 21 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 10 lines · Rafael J. Wysocki

Subject: Re: Attempted summary of suspend-blockers LKML thread

Quoted 7 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 5 lines · Rafael J. Wysocki

In the suspend case, when you have frozen all applications, you can sequentially disable all interrupts except for a few selected ("wakeup") ones
in a safe way. By disabling them, you ensure that the CPU will only be
"revived" by a limited set of events and that allows the system to stay low-power for extended time intervals.

Quoted 6 lines
Quoted 3 lines

the benifit of this will depend on what wakeups you are able to avoid by putting the hardware to sleep. Depending on the hardware, this may be not matter that much.

That's correct, but evidently it does make a difference with the hardware Android commonly runs on.

Ok, but is there a way to put some of this to sleep without involving a full suspend?

Quoted 7 lines
Quoted 2 lines

Technically, maybe, but we have no generic infrastructure in the kernel for that. There may be SoC-specific implementations, but nothing general enough.

well, I know that we have specific cases of this (drive spin-down, cpu speed, display backlight for a few examples), is it worth trying to define a generic way to do this sort of thing? or should it be left as a per-device thing (with per-device knobs to control it)

The ability to put specific devices into low-power states in certain well-defined situations is clearly not sufficient. For one example, usually you can easily put an Ethernet adapter into a low-power state when the network cable is detached from it. It is not clear, however, what criteria should be used for deciding to put that adapter into the low-power state when the cable is attached to it (and open() has been called).

Quoted 3 lines

To mimic suspend you'll have to be able to put _all_ devices into low-power states and shut down the interrupts that allow the monotonic clock to advance. That's much more than simple runtime power management of selected devices.

true for the generic case, my thought was that for specially built hardware it may be possible to select hardware that lets you get very close.

Quoted 4 lines
Quoted 2 lines

I thought I had seen discussion on how to define such a generic power management interface, and I thought the results had been acceptable.

If you have a pointer to that discussion, I'm interested. :-)

sorry, it was several months ago.

David Lang

#117 lore raw
In reply to Rafael J. Wysocki
Quoted 41 lines · Rafael J. Wysocki
Quoted 25 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 23 lines · Rafael J. Wysocki
Quoted 21 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 10 lines · Rafael J. Wysocki

Subject: Re: Attempted summary of suspend-blockers LKML thread

Quoted 7 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 5 lines · Rafael J. Wysocki

In the suspend case, when you have frozen all applications, you can sequentially disable all interrupts except for a few selected ("wakeup") ones
in a safe way. By disabling them, you ensure that the CPU will only be
"revived" by a limited set of events and that allows the system to stay low-power for extended time intervals.

Quoted 6 lines
Quoted 3 lines

the benifit of this will depend on what wakeups you are able to avoid by putting the hardware to sleep. Depending on the hardware, this may be not matter that much.

That's correct, but evidently it does make a difference with the hardware Android commonly runs on.

Ok, but is there a way to put some of this to sleep without involving a full suspend?

Quoted 7 lines
Quoted 2 lines

Technically, maybe, but we have no generic infrastructure in the kernel for that. There may be SoC-specific implementations, but nothing general enough.

well, I know that we have specific cases of this (drive spin-down, cpu speed, display backlight for a few examples), is it worth trying to define a generic way to do this sort of thing? or should it be left as a per-device thing (with per-device knobs to control it)

The ability to put specific devices into low-power states in certain well-defined situations is clearly not sufficient. For one example, usually you can easily put an Ethernet adapter into a low-power state when the network cable is detached from it. It is not clear, however, what criteria should be used for deciding to put that adapter into the low-power state when the cable is attached to it (and open() has been called).

Quoted 3 lines

To mimic suspend you'll have to be able to put _all_ devices into low-power states and shut down the interrupts that allow the monotonic clock to advance. That's much more than simple runtime power management of selected devices.

true for the generic case, my thought was that for specially built hardware it may be possible to select hardware that lets you get very close.

Quoted 4 lines
Quoted 2 lines

I thought I had seen discussion on how to define such a generic power management interface, and I thought the results had been acceptable.

If you have a pointer to that discussion, I'm interested. :-)

sorry, it was several months ago.

David Lang

#351 lore raw
In reply to Rafael J. Wysocki
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 7 lines · On Thursday, August 05, 2010, [email protected] wrote:

My proposal would never freeze a subset of processes.

what my proposal:

only consider the activity of a subset of processes when deciding if we should suspend or not. If the decision is to suspend, freeze everything.

That alone doesn't allow you to handle the race Matthew was referring to (ie. wakeup event happening right after you've decided to suspend).

A mechanism of making a decision alone is not sufficient, you also need a mechanism to avoid races between wakeup events and suspend process.

Quoted 8 lines
Quoted 2 lines

I thought you just posted that there was a new feature that would be able to abort the suspend and so that race was closed.

Yes, you can use that for this purpose, but then you'd need a user space power manager who would decide whether or not to suspend. Then, however, the problem boils down to setting up appropriate communication between the power manager and the other applications in user space (ie. the kernel doesn't need to be involved in that at all).

This race sounds like it's generic across all platforms and not an Android specific problem. Android is just more sensitive to it as they do a suspend more frequently.

one thought on this, as a generic solution to the problem would it be possible for the suspend controller (whatever it is) to do the following

1. decide to suspend

2. setup monitors for the wake events

3. double check if it still wants to suspend

this way you don't pay the overhead of the wake monitors while you are running normally, but if one hits while you are suspending you wake up again as quickly as you can (which could involve aborting the suspend and backing out, or going fully into suspend and waking up immediatly, depending on which is better/easier at the time you get the wakeup)

David Lang

#352 lore raw
In reply to Rafael J. Wysocki
Quoted 19 lines · Rafael J. Wysocki
Quoted 18 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 15 lines · Rafael J. Wysocki
Quoted 7 lines · On Thursday, August 05, 2010, [email protected] wrote:

My proposal would never freeze a subset of processes.

what my proposal:

only consider the activity of a subset of processes when deciding if we should suspend or not. If the decision is to suspend, freeze everything.

That alone doesn't allow you to handle the race Matthew was referring to (ie. wakeup event happening right after you've decided to suspend).

A mechanism of making a decision alone is not sufficient, you also need a mechanism to avoid races between wakeup events and suspend process.

Quoted 8 lines
Quoted 2 lines

I thought you just posted that there was a new feature that would be able to abort the suspend and so that race was closed.

Yes, you can use that for this purpose, but then you'd need a user space power manager who would decide whether or not to suspend. Then, however, the problem boils down to setting up appropriate communication between the power manager and the other applications in user space (ie. the kernel doesn't need to be involved in that at all).

This race sounds like it's generic across all platforms and not an Android specific problem. Android is just more sensitive to it as they do a suspend more frequently.

one thought on this, as a generic solution to the problem would it be possible for the suspend controller (whatever it is) to do the following

1. decide to suspend

2. setup monitors for the wake events

3. double check if it still wants to suspend

this way you don't pay the overhead of the wake monitors while you are running normally, but if one hits while you are suspending you wake up again as quickly as you can (which could involve aborting the suspend and backing out, or going fully into suspend and waking up immediatly, depending on which is better/easier at the time you get the wakeup)

David Lang

#540 lore raw

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

Quoted 3 lines

Brian

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

#195 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

on the other hand, making an application avoid consuming inappropriate background resources helps everywhere. an explicit "don't let the machine sleep" only works if you are trusted by a system that implements this flag.

yes, it is painful to make the change, but the end result is better (and there are more tools out there to figure things out)

Nobody's denying that it's better, but people are saying they want to design a platform that's capable of handling the software we have rather than the software we'd like to have.

Quoted 6 lines

but if you have an application in the mid-level trust situation, go ahead and have it talk to a 'keepalive' daemon that is in the 'trusted' set and let the rest of the app run untrusted. As I noted elsewhere, the keepalive daemon would need very little in the way of resources and can implement much more complex policies than anyone is going to be willing to put in the kernel.

That doesn't work. You'll race with wakeup events.

Quoted 2 lines

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

Signature · 1 line
Matthew Garrett | [email protected]
#196 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

on the other hand, making an application avoid consuming inappropriate background resources helps everywhere. an explicit "don't let the machine sleep" only works if you are trusted by a system that implements this flag.

yes, it is painful to make the change, but the end result is better (and there are more tools out there to figure things out)

Nobody's denying that it's better, but people are saying they want to design a platform that's capable of handling the software we have rather than the software we'd like to have.

Quoted 6 lines

but if you have an application in the mid-level trust situation, go ahead and have it talk to a 'keepalive' daemon that is in the 'trusted' set and let the rest of the app run untrusted. As I noted elsewhere, the keepalive daemon would need very little in the way of resources and can implement much more complex policies than anyone is going to be willing to put in the kernel.

That doesn't work. You'll race with wakeup events.

Quoted 2 lines

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

Signature · 1 line
Matthew Garrett | [email protected]
#225 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Signature · 1 line
Matthew Garrett | [email protected]
#226 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Signature · 1 line
Matthew Garrett | [email protected]
#541 lore raw

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

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

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Signature · 1 line
Matthew Garrett | [email protected]
#353 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Aug 04, 2010 at 04:19:20PM -0700, [email protected] wrote:

only consider the activity of a subset of processes when deciding if we should suspend or not. If the decision is to suspend, freeze everything.

you (and many other people) are confusing what I've proposed (use cgroups to indicate what processes to care about and what ones to not care about when deciding to suspend/go to idle) with the prior cgroup proposal (use cgroups to freeze a subset of tasks while leaving others runnable)

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

Signature · 1 line
Matthew Garrett | [email protected]
#354 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Aug 04, 2010 at 04:19:20PM -0700, [email protected] wrote:

only consider the activity of a subset of processes when deciding if we should suspend or not. If the decision is to suspend, freeze everything.

you (and many other people) are confusing what I've proposed (use cgroups to indicate what processes to care about and what ones to not care about when deciding to suspend/go to idle) with the prior cgroup proposal (use cgroups to freeze a subset of tasks while leaving others runnable)

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

Signature · 1 line
Matthew Garrett | [email protected]
#355 lore raw
Quoted 5 lines · Matthew Garrett
Quoted 3 lines · On Wed, Aug 04, 2010 at 04:19:20PM -0700, [email protected] wrote:

only consider the activity of a subset of processes when deciding if we should suspend or not. If the decision is to suspend, freeze everything.

Quoted 7 lines
Quoted 4 lines

you (and many other people) are confusing what I've proposed (use cgroups to indicate what processes to care about and what ones to not care about when deciding to suspend/go to idle) with the prior cgroup proposal (use cgroups to freeze a subset of tasks while leaving others runnable)

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

but isn't that all that wakelocks do? affect the decision on whether or not to go to sleep.

David Lang

#356 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett
Quoted 3 lines · On Wed, Aug 04, 2010 at 04:19:20PM -0700, [email protected] wrote:

only consider the activity of a subset of processes when deciding if we should suspend or not. If the decision is to suspend, freeze everything.

Quoted 7 lines
Quoted 4 lines

you (and many other people) are confusing what I've proposed (use cgroups to indicate what processes to care about and what ones to not care about when deciding to suspend/go to idle) with the prior cgroup proposal (use cgroups to freeze a subset of tasks while leaving others runnable)

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

but isn't that all that wakelocks do? affect the decision on whether or not to go to sleep.

David Lang

#357 lore raw
Quoted 6 lines · On Thu, Aug 05, 2010 at 07:07:06AM -0700, [email protected] wrote:
Quoted 2 lines · Matthew Garrett

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

but isn't that all that wakelocks do? affect the decision on whether or not to go to sleep.

You could think of them that way, but it's not the useful aspect of them
- that much could be implemented entirely in userspace. Wakelocks provide a mechanism for userspace to ensure that it's handled all received events before a system suspend takes place.

Signature · 1 line
Matthew Garrett | [email protected]
#358 lore raw
In reply to [email protected]
Quoted 6 lines · On Thu, Aug 05, 2010 at 07:07:06AM -0700, [email protected] wrote:
Quoted 2 lines · Matthew Garrett

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

but isn't that all that wakelocks do? affect the decision on whether or not to go to sleep.

You could think of them that way, but it's not the useful aspect of them
- that much could be implemented entirely in userspace. Wakelocks provide a mechanism for userspace to ensure that it's handled all received events before a system suspend takes place.

Signature · 1 line
Matthew Garrett | [email protected]
#228 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · Arve Hj?nnev?g

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

David Lang

#359 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett
Quoted 4 lines · On Thu, Aug 05, 2010 at 07:07:06AM -0700, [email protected] wrote:
Quoted 2 lines · Matthew Garrett

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

Quoted 7 lines
Quoted 2 lines

but isn't that all that wakelocks do? affect the decision on whether or not to go to sleep.

You could think of them that way, but it's not the useful aspect of them
- that much could be implemented entirely in userspace. Wakelocks provide a mechanism for userspace to ensure that it's handled all received events before a system suspend takes place.

For userspace or the kernel -- some events may not require userspace intervention, but do require the kernel to stay awake long enough to finish chewing on them. Say perhaps a wifi irq comes in, the wifi driver/stack needs to process some beacon packets or whatnot.

Brian

#360 lore raw
In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett
Quoted 4 lines · On Thu, Aug 05, 2010 at 07:07:06AM -0700, [email protected] wrote:
Quoted 2 lines · Matthew Garrett

The decision on whether or not to go to sleep isn't the difficult bit of this problem space.

Quoted 7 lines
Quoted 2 lines

but isn't that all that wakelocks do? affect the decision on whether or not to go to sleep.

You could think of them that way, but it's not the useful aspect of them
- that much could be implemented entirely in userspace. Wakelocks provide a mechanism for userspace to ensure that it's handled all received events before a system suspend takes place.

For userspace or the kernel -- some events may not require userspace intervention, but do require the kernel to stay awake long enough to finish chewing on them. Say perhaps a wifi irq comes in, the wifi driver/stack needs to process some beacon packets or whatnot.

Brian

#229 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · Arve Hj?nnev?g

Which makes the driver and/or network stack changes identical to using wakelocks, right?

I think we're resigned to the fact that we need to indicate wakeup events in a manner that's pretty equivalent to wakelocks. The only real issue is what the API looks like. Anyone who's still talking about cgroups seems to be trying to solve a different problem.

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

David Lang

#230 lore raw
Quoted 7 lines · On Thu, Aug 5, 2010 at 7:22 AM, <[email protected]> wrote:

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

Quoted 7 lines

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

The transition into sleep is race-free in the wakelock model -- either the wakeup event happens during the kernel suspend (and grabs a wakelock), in which case suspend is aborted (and not attempted again until there are once again no more wakelocks held), or the system fully suspends to its lowest power mode until a wakeup event brings it back out again. Entry to lowest power mode must abort if a wakeup event/interrupt occurs while it's in process -- exactly how the handoff happens here is hardware dependent but in practice this is doable on just about any modern system.

Brian

#231 lore raw
In reply to [email protected]
Quoted 7 lines · On Thu, Aug 5, 2010 at 7:22 AM, <[email protected]> wrote:

Ok, it is now sounding to me like there are two different (but somewhat related) purposes that wakelocks are being used for

1. deciding if the system should go to sleep now or not (what most of the discussion has been about)

Quoted 7 lines

2. narrowing the race between going to sleep and wakeup events.

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

The transition into sleep is race-free in the wakelock model -- either the wakeup event happens during the kernel suspend (and grabs a wakelock), in which case suspend is aborted (and not attempted again until there are once again no more wakelocks held), or the system fully suspends to its lowest power mode until a wakeup event brings it back out again. Entry to lowest power mode must abort if a wakeup event/interrupt occurs while it's in process -- exactly how the handoff happens here is hardware dependent but in practice this is doable on just about any modern system.

Brian

#232 lore raw
In reply to [email protected]
Quoted 5 lines · On Thu, Aug 05, 2010 at 07:22:53AM -0700, [email protected] wrote:

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

It's typically the case that you can - we've even seen that on x86 with ACPI GPEs.

Signature · 1 line
Matthew Garrett | [email protected]
#233 lore raw
In reply to [email protected]
Quoted 5 lines · On Thu, Aug 05, 2010 at 07:22:53AM -0700, [email protected] wrote:

I'm not sure it's possible to completely eliminate the race, even with wakelocks there is some time between the time you last check if the wakelock is set and when the hardware finishes responding to your commands to go to sleep (Unless you can set a level-based interrupt that will wake you up as soon as you finish going to sleep)

It's typically the case that you can - we've even seen that on x86 with ACPI GPEs.

Signature · 1 line
Matthew Garrett | [email protected]
#197 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

infrequent polling (on the order of seconds or 10s of seconds) is not a very significant impact on your power

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

on some devices (my kindle for example) the cell network dwarfs my other power consumption today.

Quoted 8 lines
Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

Quoted 4 lines

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

I think the issue is confusion between the different purposes of the wakelock.

as you say, I don't think anyone is opposed to the kernel being modified to eliminate this race. The disagreement is far more about the interface to userspace and userspace use of wakelocks.

the kernel implementation of this doesn't have to set a single flag, and it doesn't have to notify userspace directly. The kernel already produces many stats today and it may be appropriate for the kernel to produce some more.

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

David Lang

#198 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 03:20:04PM -0700, [email protected] wrote:

similar to the current implementation, the arrival of a packet could be counted as activity that keeps the system awake for a bit (your timeout)

How? You're either polling in order to know whether there's network activity, or you're having every network packet wake up the policy daemon, or you've got something that looks like the kernel side of wakelocks.

infrequent polling (on the order of seconds or 10s of seconds) is not a very significant impact on your power

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Cell networks typically have no background traffic, for obvious reasons.

but don't most new smartphones also connect up to wifi networks? those are FAR from quiet.

Wifi radio typically dwarfs your other power consumption anyway. The typical situation is one where you're not attached to a wifi network.

on some devices (my kindle for example) the cell network dwarfs my other power consumption today.

Quoted 8 lines
Quoted 7 lines

I'm not suggesting running all events through some central server (unless you count the kernel as that server), I'm saying that the decision that the system is idle and therefor can be stopped should be able to take this infomation into account, and if there's a race here, it should be a race that exists everywhere else, so there should be a general solution, not something specific to one use-case. (and definantly not something that requires all software to be modified and trusted to implement)

Quoted 4 lines

You're right. It's a race that exists everywhere else, and it's inherent unless you have some handshaking between userspace and the kernel when entering suspend. Which is what wakelocks provide. Nobody has proposed a solution that works without modifying existing code.

I think the issue is confusion between the different purposes of the wakelock.

as you say, I don't think anyone is opposed to the kernel being modified to eliminate this race. The disagreement is far more about the interface to userspace and userspace use of wakelocks.

the kernel implementation of this doesn't have to set a single flag, and it doesn't have to notify userspace directly. The kernel already produces many stats today and it may be appropriate for the kernel to produce some more.

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

David Lang

#544 lore raw

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

#382 lore raw
In reply to [email protected]
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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.

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.

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

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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.

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?

Quoted 11 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 the media_server and 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.

Quoted 6 lines

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.

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?

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.

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?

Thanx, Paul

#383 lore raw
In reply to [email protected]
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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.

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.

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

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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.

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?

Quoted 11 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 the media_server and 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.

Quoted 6 lines

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.

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?

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.

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?

Thanx, Paul

#199 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, Aug 5, 2010 at 7:34 AM, <[email protected]> wrote:

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

Quoted 3 lines

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

If your network interrupt happens before the network driver's suspend() hook is called this works -- the check in the suspend hook observes the change and returns an abort status.

If your network interrupt happens after the suspend() hook is called this does not work -- the event comes after your opportunity to abort suspend has happened, your interrupt handler processed it, set the flag, but the system proceeds to suspend anyway, missing the event.

The wakelock/suspendblock mechanism avoids races like the above.

Brian

#200 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, Aug 5, 2010 at 7:34 AM, <[email protected]> wrote:

for example, if you want to abort the suspend because there is network activity, you can check the packet count of your network interface, decide to go to sleep, setup the network interface to raise a 'wake me up' interrupt (because you have decided in a userspace policy that you want this), and then check to see if the packet count has changed. If it has, abort the suspend, if not continue the suspend and once you are suspended if the 'wake me up' interrupt is set you will wake back up.

Quoted 3 lines

there are probably cleaner/better ways of doing this than the simple logic that I'm listing, but why wouldn't the simple logic provide the correct result?

If your network interrupt happens before the network driver's suspend() hook is called this works -- the check in the suspend hook observes the change and returns an abort status.

If your network interrupt happens after the suspend() hook is called this does not work -- the event comes after your opportunity to abort suspend has happened, your interrupt handler processed it, set the flag, but the system proceeds to suspend anyway, missing the event.

The wakelock/suspendblock mechanism avoids races like the above.

Brian

#234 lore raw
In reply to Arve Hjønnevåg
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Thanks,
Rafael

#235 lore raw
In reply to Arve Hjønnevåg
Quoted 32 lines · Arve Hjønnevåg

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Thanks,
Rafael

#384 lore raw
In reply to Paul E. McKenney
Quoted 44 lines · Paul E. McKenney
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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.

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)

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 the media_server and 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

#385 lore raw
In reply to Paul E. McKenney
Quoted 44 lines · Paul E. McKenney
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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.

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)

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 the media_server and 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

#472 lore raw
In reply to Paul E. McKenney
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.

#473 lore raw
In reply to Paul E. McKenney
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.

#386 lore raw
In reply to [email protected]
Quoted 67 lines · On Thu, Aug 05, 2010 at 08:46:54AM -0700, [email protected] wrote:
Quoted 44 lines · Paul E. McKenney
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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 8 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)

From what I can see, the decision between these two approaches comes down

to their energy efficiencies, and thus their battery lifetimes. Are you in a position to benchmark these two approaches against each other?

Quoted 44 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 the media_server and 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?

Quoted 6 lines

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.

So you are saying that PM-driving apps can check up on power-oblivious apps as part of their decision process. Sounds reasonable to me, though such checking increases the dependencies among apps, which might increase complexity.

Quoted 21 lines
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?

Quoted 6 lines

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.

Mark Brown suggests adding suspend-blocker information to powertop, which might well be a very good way to handle this. This sounds plausible to me, but then again, I have never chased down wakelock bugs on Android systems.

A key point is that it is not enough to focus on PM-driving apps, you instead need to focus on only those PM-driving apps that currently hold a suspend blocker.

Quoted 7 lines

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.

According to Brian Swetland, Android does in fact have such a power-management daemon. I would guess that this daemon tracks which apps it is holding suspend blockers on behalf of. This approach might well make it harder to bring powertop to bear, as powertop would need to communicate with Android's power-management daemon. But perhaps something could be arranged.

Thanx, Paul

#387 lore raw
In reply to [email protected]
Quoted 67 lines · On Thu, Aug 05, 2010 at 08:46:54AM -0700, [email protected] wrote:
Quoted 44 lines · Paul E. McKenney
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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 8 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)

From what I can see, the decision between these two approaches comes down

to their energy efficiencies, and thus their battery lifetimes. Are you in a position to benchmark these two approaches against each other?

Quoted 44 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 the media_server and 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?

Quoted 6 lines

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.

So you are saying that PM-driving apps can check up on power-oblivious apps as part of their decision process. Sounds reasonable to me, though such checking increases the dependencies among apps, which might increase complexity.

Quoted 21 lines
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?

Quoted 6 lines

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.

Mark Brown suggests adding suspend-blocker information to powertop, which might well be a very good way to handle this. This sounds plausible to me, but then again, I have never chased down wakelock bugs on Android systems.

A key point is that it is not enough to focus on PM-driving apps, you instead need to focus on only those PM-driving apps that currently hold a suspend blocker.

Quoted 7 lines

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.

According to Brian Swetland, Android does in fact have such a power-management daemon. I would guess that this daemon tracks which apps it is holding suspend blockers on behalf of. This approach might well make it harder to bring powertop to bear, as powertop would need to communicate with Android's power-management daemon. But perhaps something could be arranged.

Thanx, Paul

#390 lore raw
In reply to [email protected]
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

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 92 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 9 lines
Quoted 4 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 the media_server and 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/

#391 lore raw
In reply to [email protected]
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

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 92 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 9 lines
Quoted 4 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 the media_server and 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/

#392 lore raw
Quoted 6 lines · kevin granade

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.

The display being on should not prevent suspend unless the particular platform is incapable of suspending while the display is on.

Quoted 12 lines

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.

Yeah, we much prefer the wakelock model where the moment the resource (system-needing-to-not-be-suspended) is released we return to the lowest power state, rather than waiting for a timer to expire (and/or burning cycles polling for "can we suspend yet?" when we're definitely not ready to suspend).

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

#393 lore raw
In reply to kevin granade
Quoted 6 lines · kevin granade

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.

The display being on should not prevent suspend unless the particular platform is incapable of suspending while the display is on.

Quoted 12 lines

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.

Yeah, we much prefer the wakelock model where the moment the resource (system-needing-to-not-be-suspended) is released we return to the lowest power state, rather than waiting for a timer to expire (and/or burning cycles polling for "can we suspend yet?" when we're definitely not ready to suspend).

Brian

#474 lore raw
In reply to Mark Brown
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

#475 lore raw
In reply to Mark Brown
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

#388 lore raw
In reply to Paul E. McKenney
Quoted 77 lines · Paul E. McKenney

Subject: Re: Attempted summary of suspend-blockers LKML thread

Quoted 67 lines · On Thu, Aug 05, 2010 at 08:46:54AM -0700, [email protected] wrote:
Quoted 44 lines · Paul E. McKenney
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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 6 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)

Quoted 3 lines

From what I can see, the decision between these two approaches comes down to their energy efficiencies, and thus their battery lifetimes. Are you in a position to benchmark these two approaches against each other?

no, I'm not in a position to benchmark them against each other.

I am claiming that (in this area) the two are equivalent (or at lease very close to equivalent given the approximate magnatude of the timeouts that are involved)

1. a daemon controls the screen, monitors input and holds a wakelock until a configurable timeout after input, after which the system sleeps

2. a daemon monitors input, it wakes up every few seconds (to 10s of seconds) when there is no input for a configurable timeout the daemon sleep without waking up periodically. when the daemon sleeps for longer than a configurable period the system is considered idle and goes to sleep.

in both cases the system will be awake as long as there is input within the initial timeout period.

the second case could eata smidge power as there can be an additional lag before the system sleeps (the second timeout), that depends on exactly how the input is detected.

Quoted 28 lines
Quoted 21 lines
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 the media_server and 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?

Quoted 6 lines

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 4 lines

So you are saying that PM-driving apps can check up on power-oblivious apps as part of their decision process. Sounds reasonable to me, though such checking increases the dependencies among apps, which might increase complexity.

more to the point, I'm saying that that's how it works currently with wavelocks. the unprivilaged processes can ask the privilaged process to hold a wavelock for them.

Quoted 28 lines
Quoted 21 lines
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?

Quoted 6 lines

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.

Quoted 8 lines

Mark Brown suggests adding suspend-blocker information to powertop, which might well be a very good way to handle this. This sounds plausible to me, but then again, I have never chased down wakelock bugs on Android systems.

A key point is that it is not enough to focus on PM-driving apps, you instead need to focus on only those PM-driving apps that currently hold a suspend blocker.

if you have wavelocks, then you just need info on the use of wavelocks

with my proposal staying awake is based on process activity, which is exactly what powertop is monitoring now, it just needs to be able to filter out the activity of the untrusted apps.

Quoted 8 lines
Quoted 7 lines

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.

Quoted 6 lines

According to Brian Swetland, Android does in fact have such a power-management daemon. I would guess that this daemon tracks which apps it is holding suspend blockers on behalf of. This approach might well make it harder to bring powertop to bear, as powertop would need to communicate with Android's power-management daemon. But perhaps something could be arranged.

My expectation is that instead of modifying apps to talk to the power management daemon, the apps would be classified as 'trusted' or 'untrusted' more appropriatly.

if user input is activity that keeps the system alive, then only applications that will run for extended period with no user input need to be trusted.

David Lang

#389 lore raw
In reply to Paul E. McKenney
Quoted 77 lines · Paul E. McKenney

Subject: Re: Attempted summary of suspend-blockers LKML thread

Quoted 67 lines · On Thu, Aug 05, 2010 at 08:46:54AM -0700, [email protected] wrote:
Quoted 44 lines · Paul E. McKenney
Quoted 3 lines · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · 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 6 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)

Quoted 3 lines

From what I can see, the decision between these two approaches comes down to their energy efficiencies, and thus their battery lifetimes. Are you in a position to benchmark these two approaches against each other?

no, I'm not in a position to benchmark them against each other.

I am claiming that (in this area) the two are equivalent (or at lease very close to equivalent given the approximate magnatude of the timeouts that are involved)

1. a daemon controls the screen, monitors input and holds a wakelock until a configurable timeout after input, after which the system sleeps

2. a daemon monitors input, it wakes up every few seconds (to 10s of seconds) when there is no input for a configurable timeout the daemon sleep without waking up periodically. when the daemon sleeps for longer than a configurable period the system is considered idle and goes to sleep.

in both cases the system will be awake as long as there is input within the initial timeout period.

the second case could eata smidge power as there can be an additional lag before the system sleeps (the second timeout), that depends on exactly how the input is detected.

Quoted 28 lines
Quoted 21 lines
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 the media_server and 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?

Quoted 6 lines

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 4 lines

So you are saying that PM-driving apps can check up on power-oblivious apps as part of their decision process. Sounds reasonable to me, though such checking increases the dependencies among apps, which might increase complexity.

more to the point, I'm saying that that's how it works currently with wavelocks. the unprivilaged processes can ask the privilaged process to hold a wavelock for them.

Quoted 28 lines
Quoted 21 lines
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?

Quoted 6 lines

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.

Quoted 8 lines

Mark Brown suggests adding suspend-blocker information to powertop, which might well be a very good way to handle this. This sounds plausible to me, but then again, I have never chased down wakelock bugs on Android systems.

A key point is that it is not enough to focus on PM-driving apps, you instead need to focus on only those PM-driving apps that currently hold a suspend blocker.

if you have wavelocks, then you just need info on the use of wavelocks

with my proposal staying awake is based on process activity, which is exactly what powertop is monitoring now, it just needs to be able to filter out the activity of the untrusted apps.

Quoted 8 lines
Quoted 7 lines

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.

Quoted 6 lines

According to Brian Swetland, Android does in fact have such a power-management daemon. I would guess that this daemon tracks which apps it is holding suspend blockers on behalf of. This approach might well make it harder to bring powertop to bear, as powertop would need to communicate with Android's power-management daemon. But perhaps something could be arranged.

My expectation is that instead of modifying apps to talk to the power management daemon, the apps would be classified as 'trusted' or 'untrusted' more appropriatly.

if user input is activity that keeps the system alive, then only applications that will run for extended period with no user input need to be trusted.

David Lang

#396 lore raw
In reply to kevin granade
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

David Lang

#397 lore raw
In reply to kevin granade
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

David Lang

#394 lore raw
In reply to Brian Swetland
Quoted 10 lines · Brian Swetland
Quoted 6 lines · kevin granade

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.

The display being on should not prevent suspend unless the particular platform is incapable of suspending while the display is on.

if that is the case, I'll go back to my question about the untrusted reader app.

what is it that will prevent the system from going to sleep while I am reading the page?

Quoted 19 lines
Quoted 12 lines

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 5 lines

Yeah, we much prefer the wakelock model where the moment the resource (system-needing-to-not-be-suspended) is released we return to the lowest power state, rather than waiting for a timer to expire (and/or burning cycles polling for "can we suspend yet?" when we're definitely not ready to suspend).

at the micro level it is definantly better for power, but at the macro level I don't think it needs to make much difference in the overall battery life of the device. To borrow a phrase, I think you may be into premature optimization of power :-)

David Lang

#406 lore raw
In reply to kevin granade
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.

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! ;-)

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 the media_server and 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/

#407 lore raw
In reply to kevin granade
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.

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! ;-)

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 the media_server and 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/

#395 lore raw
In reply to Brian Swetland
Quoted 10 lines · Brian Swetland
Quoted 6 lines · kevin granade

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.

The display being on should not prevent suspend unless the particular platform is incapable of suspending while the display is on.

if that is the case, I'll go back to my question about the untrusted reader app.

what is it that will prevent the system from going to sleep while I am reading the page?

Quoted 19 lines
Quoted 12 lines

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 5 lines

Yeah, we much prefer the wakelock model where the moment the resource (system-needing-to-not-be-suspended) is released we return to the lowest power state, rather than waiting for a timer to expire (and/or burning cycles polling for "can we suspend yet?" when we're definitely not ready to suspend).

at the micro level it is definantly better for power, but at the macro level I don't think it needs to make much difference in the overall battery life of the device. To borrow a phrase, I think you may be into premature optimization of power :-)

David Lang

#408 lore raw
In reply to Paul E. McKenney
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!  ;-)

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*
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 the media_server and 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/

#409 lore raw
In reply to Paul E. McKenney
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!  ;-)

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*
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 the media_server and 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/

#236 lore raw
In reply to Rafael J. Wysocki

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts. But more importantly, calling pm_wakeup_event with a timeout of 0 is incompatible with the android user space code, and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

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

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts. But more importantly, calling pm_wakeup_event with a timeout of 0 is incompatible with the android user space code, and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Signature · 1 line
Arve Hjønnevåg
#410 lore raw
In reply to kevin granade
Quoted 79 lines · kevin granade
Quoted 70 lines · Paul E. McKenney
Quoted 62 lines · kevin granade
Quoted 36 lines · On Thu, Aug 5, 2010 at 10:46 AM,  <[email protected]> wrote:
Quoted 13 lines · Paul E. McKenney

[ . . . ]

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

good point, but I do think the short time scales are less common than people think.

I'd love to get good examples of them

on my iphone when a text message arrives the phone displays an alert for user-interaction times (it even lights the display to show who the message is from, and optionally a preview of the message)

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

David Lang

#411 lore raw
In reply to kevin granade
Quoted 79 lines · kevin granade
Quoted 70 lines · Paul E. McKenney
Quoted 62 lines · kevin granade
Quoted 36 lines · On Thu, Aug 5, 2010 at 10:46 AM,  <[email protected]> wrote:
Quoted 13 lines · Paul E. McKenney

[ . . . ]

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

good point, but I do think the short time scales are less common than people think.

I'd love to get good examples of them

on my iphone when a text message arrives the phone displays an alert for user-interaction times (it even lights the display to show who the message is from, and optionally a preview of the message)

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

David Lang

#412 lore raw
Quoted 10 lines · On Thu, Aug 5, 2010 at 3:09 PM, <[email protected]> wrote:
Quoted 6 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.

good point, but I do think the short time scales are less common than people think.

Quoted 8 lines

I'd love to get good examples of them

on my iphone when a text message arrives the phone displays an alert for user-interaction times (it even lights the display to show who the message is from, and optionally a preview of the message)

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

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

#413 lore raw
In reply to [email protected]
Quoted 10 lines · On Thu, Aug 5, 2010 at 3:09 PM, <[email protected]> wrote:
Quoted 6 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.

good point, but I do think the short time scales are less common than people think.

Quoted 8 lines

I'd love to get good examples of them

on my iphone when a text message arrives the phone displays an alert for user-interaction times (it even lights the display to show who the message is from, and optionally a preview of the message)

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Brian

#414 lore raw
Quoted 20 lines · Brian Swetland
Quoted 10 lines · On Thu, Aug 5, 2010 at 3:09 PM, <[email protected]> wrote:
Quoted 6 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.

good point, but I do think the short time scales are less common than people think.

Quoted 8 lines

I'd love to get good examples of them

on my iphone when a text message arrives the phone displays an alert for user-interaction times (it even lights the display to show who the message is from, and optionally a preview of the message)

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Quoted 11 lines

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Interesting!

So for an mp3 playback, does an Android suspend between data fetches?

Thanx, Paul

#415 lore raw
In reply to Brian Swetland
Quoted 20 lines · Brian Swetland
Quoted 10 lines · On Thu, Aug 5, 2010 at 3:09 PM, <[email protected]> wrote:
Quoted 6 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.

good point, but I do think the short time scales are less common than people think.

Quoted 8 lines

I'd love to get good examples of them

on my iphone when a text message arrives the phone displays an alert for user-interaction times (it even lights the display to show who the message is from, and optionally a preview of the message)

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Quoted 11 lines

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Interesting!

So for an mp3 playback, does an Android suspend between data fetches?

Thanx, Paul

#470 lore raw
In reply to kevin granade
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 the media_server and 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/

#471 lore raw
In reply to kevin granade
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 the media_server and 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/

#398 lore raw
In reply to [email protected]
Quoted 81 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

Quoted 7 lines

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

Especially given different scenarios, for example, audio playback when the device is in airplane mode. ;-)

Thanx, Paul

#399 lore raw
In reply to [email protected]
Quoted 81 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

Quoted 7 lines

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

Especially given different scenarios, for example, audio playback when the device is in airplane mode. ;-)

Thanx, Paul

#542 lore raw

Re: Attempted summary of suspend-blockers LKML thread, take two

In reply to Brian Swetland
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/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).

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

#543 lore raw

Re: Attempted summary of suspend-blockers LKML thread, take two

In reply to Brian Swetland
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/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).

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

#238 lore raw
In reply to Arve Hjønnevåg
Quoted 71 lines · Arve Hjønnevåg

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Quoted 21 lines
Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

Quoted 3 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect. I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael

#239 lore raw
In reply to Arve Hjønnevåg
Quoted 71 lines · Arve Hjønnevåg

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter. I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Quoted 21 lines
Quoted 17 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well, you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Quoted 3 lines

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

Quoted 3 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect. I also have some personal preferences that are not necessarily followed by the kernel code.

Thanks,
Rafael

#416 lore raw
In reply to Paul E. McKenney
Quoted 15 lines · Paul E. McKenney
Quoted 14 lines
Quoted 2 lines

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Quoted 3 lines

Interesting!

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency). For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

Brian

#417 lore raw
In reply to Paul E. McKenney
Quoted 15 lines · Paul E. McKenney
Quoted 14 lines
Quoted 2 lines

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Quoted 3 lines

Interesting!

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency). For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

Brian

#418 lore raw
Quoted 17 lines · Brian Swetland
Quoted 15 lines · Paul E. McKenney
Quoted 14 lines
Quoted 2 lines

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Quoted 8 lines
Quoted 3 lines

Interesting!

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency). For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

David Lang

#419 lore raw
In reply to Brian Swetland
Quoted 17 lines · Brian Swetland
Quoted 15 lines · Paul E. McKenney
Quoted 14 lines
Quoted 2 lines

so what would wake a phone up from suspend where the phone should go back to sleep in under a second?

Here are some real-world examples from shipped android devices:
- battery gauging happens every 10 minutes, need to wake long enough to chatter with the 1w interface and make sure the battery is not exploding
- always on mail/im/calendar/etc sync often has network events that happen every 5-10 minutes which cause devices to briefly wake up and return to sleep
- gps tracker app might wake every couple minutes or every n gps events to log location
- low power audio subsystems can wake you up every 1-4 seconds (pcm) or 1-4 minutes (mp3) to fetch more data

Quoted 8 lines
Quoted 3 lines

Interesting!

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency). For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

David Lang

#420 lore raw
Quoted 11 lines · On Thu, Aug 5, 2010 at 5:16 PM, <[email protected]> wrote:
Quoted 7 lines
Quoted 2 lines

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency).  For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

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

#421 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, Aug 5, 2010 at 5:16 PM, <[email protected]> wrote:
Quoted 7 lines
Quoted 2 lines

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency).  For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

Brian

#240 lore raw
In reply to Rafael J. Wysocki

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

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Brian

#241 lore raw
In reply to Rafael J. Wysocki

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

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Brian

#242 lore raw
Quoted 9 lines · Brian Swetland

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

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Well, I don't think anyone will disagree with that.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

The problem is what kind of stats would be actually sufficient and we haven't seriously discussed that. You said you'd need statistics and we took that for granted, but we didn't really go into details here.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Please remember that I also have spent considerable amount of time trying to push your solution upstream and defending it. I might have spent that time on other things instead, so please don't tell me about "losses".

If you want to stay in your ivory tower, that's perfectly fine by me, but I guess that won't really benefit anyone in the long run.

Thanks,
Rafael

#243 lore raw
In reply to Brian Swetland
Quoted 9 lines · Brian Swetland

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

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Well, I don't think anyone will disagree with that.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

The problem is what kind of stats would be actually sufficient and we haven't seriously discussed that. You said you'd need statistics and we took that for granted, but we didn't really go into details here.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

Please remember that I also have spent considerable amount of time trying to push your solution upstream and defending it. I might have spent that time on other things instead, so please don't tell me about "losses".

If you want to stay in your ivory tower, that's perfectly fine by me, but I guess that won't really benefit anyone in the long run.

Thanks,
Rafael

#422 lore raw
In reply to Brian Swetland
Quoted 9 lines · Brian Swetland
Quoted 8 lines · On Thu, Aug 5, 2010 at 5:16 PM, <[email protected]> wrote:
Quoted 7 lines
Quoted 2 lines

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency).  For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

Quoted 8 lines
Quoted 3 lines

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

David Lang

#423 lore raw
Quoted 19 lines · On Thu, Aug 5, 2010 at 6:01 PM, <[email protected]> wrote:
Quoted 9 lines · Brian Swetland
Quoted 8 lines · On Thu, Aug 5, 2010 at 5:16 PM,  <[email protected]> wrote:
Quoted 7 lines
Quoted 2 lines

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency).  For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

Quoted 8 lines
Quoted 3 lines

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

Quoted 4 lines

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

While the cpu (and the bulk of the system) is suspended, it's not uncommon for some peripherals to continue to operate -- for example a cellular radio, gps, low power audio playback, etc. Details will vary depending on the SoC and board design. It's not so much a different suspend mode (the system is still suspended), just a matter of whether a peripheral can operate independently (and if it is lower power for it to do so).

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

#424 lore raw
In reply to [email protected]
Quoted 19 lines · On Thu, Aug 5, 2010 at 6:01 PM, <[email protected]> wrote:
Quoted 9 lines · Brian Swetland
Quoted 8 lines · On Thu, Aug 5, 2010 at 5:16 PM,  <[email protected]> wrote:
Quoted 7 lines
Quoted 2 lines

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency).  For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

Quoted 8 lines
Quoted 3 lines

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

Quoted 4 lines

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

While the cpu (and the bulk of the system) is suspended, it's not uncommon for some peripherals to continue to operate -- for example a cellular radio, gps, low power audio playback, etc. Details will vary depending on the SoC and board design. It's not so much a different suspend mode (the system is still suspended), just a matter of whether a peripheral can operate independently (and if it is lower power for it to do so).

Brian

#246 lore raw
In reply to Rafael J. Wysocki

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

Quoted 79 lines · Arve Hjønnevåg
Quoted 71 lines

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

total_time, total time the wake lock has been active. This one should be obvious.

sleep_time, total time the wake lock has been active when the screen was off.

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Quoted 3 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

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

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

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

Quoted 79 lines · Arve Hjønnevåg
Quoted 71 lines

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Quoted 6 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

total_time, total time the wake lock has been active. This one should be obvious.

sleep_time, total time the wake lock has been active when the screen was off.

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Quoted 3 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

We need more than that (see above).

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

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

Signature · 1 line
Arve Hjønnevåg
#425 lore raw
In reply to Brian Swetland
Quoted 25 lines · Brian Swetland
Quoted 19 lines · On Thu, Aug 5, 2010 at 6:01 PM, <[email protected]> wrote:
Quoted 9 lines · Brian Swetland
Quoted 8 lines · On Thu, Aug 5, 2010 at 5:16 PM,  <[email protected]> wrote:
Quoted 7 lines
Quoted 2 lines

So for an mp3 playback, does an Android suspend between data fetches?

It can if the latency is long enough (which is why I point out low power audio which is usually high latency).  For low latency (system sounds, etc) 10-25ms between buffers it's not practical to fully suspend but we will go to the lowest power state in idle if possible.

Quoted 8 lines
Quoted 3 lines

the playback is able to continue even with all the clocks stopped? that surprises me. I would hav expected it to be able to sleep while playing audio, but not do a full suspend.

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

Quoted 4 lines

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

Quoted 7 lines

While the cpu (and the bulk of the system) is suspended, it's not uncommon for some peripherals to continue to operate -- for example a cellular radio, gps, low power audio playback, etc. Details will vary depending on the SoC and board design. It's not so much a different suspend mode (the system is still suspended), just a matter of whether a peripheral can operate independently (and if it is lower power for it to do so).

this helps, but isn't quite what I was trying to ask.

on a given piece of hardware, does suspend always leave the same peripherals on, or do you sometimes power more things down than other times when suspending?

David Lang

#400 lore raw
In reply to Paul E. McKenney
Quoted 85 lines · Paul E. McKenney
Quoted 84 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

Quoted 7 lines
Quoted 4 lines

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

Especially given different scenarios, for example, audio playback when the device is in airplane mode. ;-)

hmm, I've been thinking and talking in terms of two classes of cgroups, trusted and untrusted. I wonder if it would be possible to set timeouts for each cgroup instead)

the system would go to sleep IFF all cgroups have been idle longer than the idle time (with -1 idle time being 'ignore this cgroup')

if this could be done you could set longer times for things designed for user-interaction than you do for other purposes.

you could set media to 0 idle time (so that as soon as it finishes processing the system can sleep until the next timer)

to do this, the code making the decision would have to be able to find out the following fairly cheaply.

1. for this cgroup, what was the last time something ran

2. for this cgroup, what is the next timer set

it would be nice to get network traffic/connection stats.

so two questions.

first, what else would you need to get accumulated for the cgroup

second, is there a fairly easy way to have these stats available?

for the 'last time it ran' stat, this seems like you could have a per-cpu variable per cgroup that's fairly cheap to update, but you would need to take a global lock to read accuratly (the lock may be expensive enough that it's worth trying to read the variables from the other cpu without a lock, just to see if it's remotely possible to sleep/suspend)

with timers, is it possible to have multiple timer wheels (one per cgroup)?

David Lang

#401 lore raw
In reply to Paul E. McKenney
Quoted 85 lines · Paul E. McKenney
Quoted 84 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

Quoted 7 lines
Quoted 4 lines

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

Especially given different scenarios, for example, audio playback when the device is in airplane mode. ;-)

hmm, I've been thinking and talking in terms of two classes of cgroups, trusted and untrusted. I wonder if it would be possible to set timeouts for each cgroup instead)

the system would go to sleep IFF all cgroups have been idle longer than the idle time (with -1 idle time being 'ignore this cgroup')

if this could be done you could set longer times for things designed for user-interaction than you do for other purposes.

you could set media to 0 idle time (so that as soon as it finishes processing the system can sleep until the next timer)

to do this, the code making the decision would have to be able to find out the following fairly cheaply.

1. for this cgroup, what was the last time something ran

2. for this cgroup, what is the next timer set

it would be nice to get network traffic/connection stats.

so two questions.

first, what else would you need to get accumulated for the cgroup

second, is there a fairly easy way to have these stats available?

for the 'last time it ran' stat, this seems like you could have a per-cpu variable per cgroup that's fairly cheap to update, but you would need to take a global lock to read accuratly (the lock may be expensive enough that it's worth trying to read the variables from the other cpu without a lock, just to see if it's remotely possible to sleep/suspend)

with timers, is it possible to have multiple timer wheels (one per cgroup)?

David Lang

#428 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, Aug 05, 2010 at 06:01:24PM -0700, [email protected] wrote:
Quoted 4 lines · Brian Swetland

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

This was the core of the issue I was raising in the last thread about this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

Those that stay alive will either have per subsystem handling or will be outside the direct control of the kernel entirely (the modem is a good example of the latter case in many systems - in terms of the software it's essentially a parallel computer that's sitting in the system rather than a perhiperal of the AP).

#429 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, Aug 05, 2010 at 06:01:24PM -0700, [email protected] wrote:
Quoted 4 lines · Brian Swetland

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

This was the core of the issue I was raising in the last thread about this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

Those that stay alive will either have per subsystem handling or will be outside the direct control of the kernel entirely (the modem is a good example of the latter case in many systems - in terms of the software it's essentially a parallel computer that's sitting in the system rather than a perhiperal of the AP).

#426 lore raw
In reply to [email protected]
Quoted 3 lines · On Fri, Aug 06, 2010 at 01:07:47AM -0700, [email protected] wrote:

on a given piece of hardware, does suspend always leave the same peripherals on, or do you sometimes power more things down than other times when suspending?

Different bits of hardware get powered down depending on current system state. In the audio case (which is so far as I know the only case for this sort of stuff that currently does anything in mainline) we'll keep alive any active paths (that is, paths carrying live audio) between endpoints in the audio subsystem which have been explicitly marked as staying alive during suspend. Other audio paths will be powered down when the system suspends. During normal run time only paths that are active will be powered up.

#427 lore raw
In reply to [email protected]
Quoted 3 lines · On Fri, Aug 06, 2010 at 01:07:47AM -0700, [email protected] wrote:

on a given piece of hardware, does suspend always leave the same peripherals on, or do you sometimes power more things down than other times when suspending?

Different bits of hardware get powered down depending on current system state. In the audio case (which is so far as I know the only case for this sort of stuff that currently does anything in mainline) we'll keep alive any active paths (that is, paths carrying live audio) between endpoints in the audio subsystem which have been explicitly marked as staying alive during suspend. Other audio paths will be powered down when the system suspends. During normal run time only paths that are active will be powered up.

#248 lore raw
In reply to Arve Hjønnevåg
Quoted 1 line · Arve Hj?nnev?g

sleep_time, total time the wake lock has been active when the screen was off.

This one seems a little odd, and won't make sense on some devices like those with E Ink displays or those which don't have screens at all. I guess it's really focused on metering when the user is not actively interacting with the device?

#249 lore raw
In reply to Arve Hjønnevåg
Quoted 1 line · Arve Hj?nnev?g

sleep_time, total time the wake lock has been active when the screen was off.

This one seems a little odd, and won't make sense on some devices like those with E Ink displays or those which don't have screens at all. I guess it's really focused on metering when the user is not actively interacting with the device?

#250 lore raw
In reply to Arve Hjønnevåg
Quoted 80 lines · Arve Hjønnevåg

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

Quoted 79 lines · Arve Hjønnevåg
Quoted 77 lines

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Got it!

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

Ah, I hadn't considered that an power-oblivious application could take this approach to waste power. I now better understand the purpose of the timeouts, and have added the corresponding requirement. ;-)

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

Got it!

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

This one is zero if the wakelock is not currently held, correct?

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Got it!

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Hmmm... The statistics for apps are collected in userspace, correct? If so, this would be collecting the total time that suspend blockers that were acquired by some driver have been held while the screen was powered off. So if things were working properly, sleep_time should be quite small -- with the exception of the suspend blocker that the userspace daemon was using as a proxy for all of the userspace suspend blockers.

Or am I confused about this?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Got it!

Thank you for this additional info, it really shines some light on what you are trying to do.

One question: are these statistics enabled in production devices, are is this a debug-only facility?

Quoted 5 lines
Quoted 2 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

So there is a separate set of suspend-blocker statistics collected in userspace, correct? (The kernel probably doesn't need to care about this, and I don't believe that I need anything more than a "yes" or "no" answer, but just want to make sure I understand how these statistics are used.)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

The reason you want the handle is to allow the calling code to indicate which calling points are dealing with the same suspend-blocker entity?

Thaxn, Paul

Quoted 74 lines
Quoted 2 lines

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

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

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

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

Quoted 79 lines · Arve Hjønnevåg
Quoted 77 lines

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

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

2010/8/4 Rafael J. Wysocki <[email protected]>:

Quoted 31 lines · Arve Hjønnevåg
Quoted 29 lines · Matthew Garrett
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Matthew Garrett
Quoted 12 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 progress

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

I _think_ you can use the just-merged /sys/power/wakeup_count mechanism to avoid the race (if pm_wakeup_event() is called at 2)).

Yes, I think that solves the problem. The only question then is whether

How? By passing a timeout to pm_wakeup_event when the network driver gets the packet or by passing 0. If you pass a timeout it is the same as using a wakelock with a timeout and should work (assuming the timeout you picked is long enough). If you don't pass a timeout it does not work, since the packet may not be visible to user-space yet.

Quoted 5 lines
Quoted 2 lines

Alternatively, pm_stay_awake() / pm_relax() can be used.

Which makes the driver and/or network stack changes identical to using wakelocks, right?

Please refer to the Matthew's response.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 2 lines

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

I have seen no proposed way to use cgroups that will work. If you leave some processes running while other processes are frozen you run into problems when a frozen process holds a resource that a running process needs.

Quoted 3 lines

having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

That is "this"? The merged code? If so, no it does not satisfy our requirements. The in kernel api, while offering similar functionality to the wakelock interface, does not use any handles which makes it impossible to get reasonable stats (You don't know which pm_stay_awake request pm_relax is reverting).

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why is that a problem (out of curiosity)?

Not having stats or not knowing what pm_relax is undoing? We need stats to be able to debug the system.

You have the stats in struct device and they are available via sysfs. I suppose they are insufficient, but I'd like to know why exactly.

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 8 lines
Quoted 3 lines

OK

How much of that is used in practice and what for exactly?

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

Got it!

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

Ah, I hadn't considered that an power-oblivious application could take this approach to waste power. I now better understand the purpose of the timeouts, and have added the corresponding requirement. ;-)

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

Got it!

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

This one is zero if the wakelock is not currently held, correct?

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Got it!

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Hmmm... The statistics for apps are collected in userspace, correct? If so, this would be collecting the total time that suspend blockers that were acquired by some driver have been held while the screen was powered off. So if things were working properly, sleep_time should be quite small -- with the exception of the suspend blocker that the userspace daemon was using as a proxy for all of the userspace suspend blockers.

Or am I confused about this?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Got it!

Thank you for this additional info, it really shines some light on what you are trying to do.

One question: are these statistics enabled in production devices, are is this a debug-only facility?

Quoted 5 lines
Quoted 2 lines

Do you _really_ have to debug the wakelocks in drivers that much?

Wake locks in drivers sometimes need to be debugged. If the api has no accountability, then these problems would take forever to fix.

So there is a separate set of suspend-blocker statistics collected in userspace, correct? (The kernel probably doesn't need to care about this, and I don't believe that I need anything more than a "yes" or "no" answer, but just want to make sure I understand how these statistics are used.)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

If the system does not suspend
at all or is awake for too long, the wakelock stats tells us which component is at fault. Since pm_stay_awake and pm_relax does not operate on a handle, you cannot determine how long it prevented suspend for.

Well, if you need that, you can add a counter of "completed events" into

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

We need more than that (see above).

Quoted 3 lines

struct dev_pm_info and a function similar to pm_relax() that will update that counter.  I don't think anyone will object to that change.

What about adding a handle that is passed to all three functions?

The reason you want the handle is to allow the calling code to indicate which calling points are dealing with the same suspend-blocker entity?

Thaxn, Paul

Quoted 74 lines
Quoted 2 lines

I don't think that will fly at this point.

Why not? I think allowing drivers to modify a global reference count with no accountability is a terrible idea.

Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The proposed in user-space interface
of calling into every process that receives wakeup events before every suspend call

Well,  you don't really need to do that.

Quoted 9 lines

Only if the driver blocks suspend until user-space has read the event. This means that for android to work we need to block suspend when input events are not processed, but a system using your scheme needs a pm_wakeup_event call when the input event is queued. How to you switch between them? Do we add separate ioctls in the input device to enable each scheme? If someone has a single threaded user space power manager that also reads input event it will deadlock if you block suspend until it reads the input events since you block when reading the wake count.

Well, until someone actually tries to implement a power manager in user space it's a bit vague.

Quoted 7 lines
Quoted 5 lines

Not having clear rules for what the drivers should do is a problem. The comments in your code seem to advocate using timeouts instead of overlapping pm_stay_awake/pm_relax sections. I find this recommendation strange given all the opposition to wakelock/suspendblocker timeouts.

There's no recommendation either way.

I'm referring to this paragraph:

* Second, a wakeup event may be detected by one functional unit and processed
* by another one. In that case the unit that has detected it cannot really
* "close" the "no suspend" period associated with it, unless it knows in
* advance what's going to happen to the event during processing. This
* knowledge, however, may not be available to it, so it can simply
specify time
* to wait before the system can be suspended and pass it as the second
* argument of pm_wakeup_event().

Quoted 23 lines
Quoted 4 lines

But more importantly, calling
pm_wakeup_event with a timeout of 0 is incompatible with the android user space code,

Which I don't find really relevant, sorry.

Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Well, that are your personal preferences, which I respect.  I also have some personal preferences that are not necessarily followed by the kernel code.

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

Signature · 1 line
Arve Hjønnevåg
#244 lore raw
In reply to Brian Swetland
Quoted 18 lines · Brian Swetland

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

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

In my case, it has not been "debuggability considered harmful", but rather my lack of understanding of the kinds of bugs that can arise and what information is most helpful in tracking them down. Arve's post listing the meanings of the stats helped me quite a bit, although I am sure that my understanding is still quite rudimentary.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

And this brings up another aspect of Android requirements. Mainlining Android features is not necessarily an all-or-nothing proposition. Here is a prototype list of degrees of mainlining, along with at least a few of the benefits and difficulties of each level:

o Mainline that provides exactly what Android needs.

This is of course the best case, but, as you may have noticed, might not be easy to achieve. The plain fact is that Linux must support a wide variety of workloads, so some give-and-take is usually required.

o Mainline that exactly matches the ideal API, but which fails
to implement some feature or another.

This is still not bad. You have to carry a specific patch to provide the feature(s), but all the calling sites are carried upstream in mainline.

o Mainline provides something that is close to the ideal API, but
some additional constant arguments are required.

This is not so good, but at least the drivers can be upstreamed and the changes required to get to an Android-ready kernel are fairly simple.

o Mainline provides something, but Android requires changes to the
supplied API which require additional data to be passed from call site to call site.

Again, at least drivers can be upstreamed, but the changes required to get to an Android-ready kernel are a bit more involved.

o Mainline provides a stubbed-out API.

Once again, the drivers can at least be upstreamed, but Android is the only project validating the placement of calls to the
API. This means that changes to the drivers are likely to
mess up the placement of the call sites. Therefore, getting to an Android-ready kernel requires careful inspection of the drivers to adjust for bugs introduced by others.

o Mainline provides nothing.

Status quo. This means that some other group will likely introduce the required functionality in an incremental fashion. This process will likely fail to take Android's needs into account, probably leading to...

o Mainline provides functionality that is similar to what
Android needs, but in a completely incompatible manner that cannot be used easily (or perhaps at all) by Android.

My guess is that there is value to Android in a number of the non-perfect cases.

Thanx, Paul

#245 lore raw
In reply to Brian Swetland
Quoted 18 lines · Brian Swetland

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

Quoted 8 lines
Quoted 7 lines

Our wakelock stats currently have (name,)count,expire_count,wake_count,active_since,total_time,sleep_time,max_time and last_change. Not all of these are equally important (total_time is most important followed by active_since), but you only have count. Also as discussed before, many wakelocks/suspendblockers are not associated with a struct device.

Quoted 5 lines

OK

How much of that is used in practice and what for exactly?

Do you _really_ have to debug the wakelocks in drivers that much?

Debugging power related issues is pretty critical to building competitive mobile devices.

Quoted 6 lines

Throughout the several months of this discussion I have been continually scratching my head at this "debugability considered harmful" attitude that I see in reaction to our interest in having the ability (gated behind a config option even -- really, that'd be fine, not everyone need enable it) to gather useful stats and examine the state of the system.

In my case, it has not been "debuggability considered harmful", but rather my lack of understanding of the kinds of bugs that can arise and what information is most helpful in tracking them down. Arve's post listing the meanings of the stats helped me quite a bit, although I am sure that my understanding is still quite rudimentary.

Quoted 6 lines

At this point it sounds like there's no interest in the solution we have, which works and has worked for a few years, and has been revised 10+ times based on feedback here, and no interest in providing a solution that accomplishes similar functionality, so perhaps it's time for us to cut our losses and just go back to maintaining our patches instead of having the same arguments over and over again.

And this brings up another aspect of Android requirements. Mainlining Android features is not necessarily an all-or-nothing proposition. Here is a prototype list of degrees of mainlining, along with at least a few of the benefits and difficulties of each level:

o Mainline that provides exactly what Android needs.

This is of course the best case, but, as you may have noticed, might not be easy to achieve. The plain fact is that Linux must support a wide variety of workloads, so some give-and-take is usually required.

o Mainline that exactly matches the ideal API, but which fails
to implement some feature or another.

This is still not bad. You have to carry a specific patch to provide the feature(s), but all the calling sites are carried upstream in mainline.

o Mainline provides something that is close to the ideal API, but
some additional constant arguments are required.

This is not so good, but at least the drivers can be upstreamed and the changes required to get to an Android-ready kernel are fairly simple.

o Mainline provides something, but Android requires changes to the
supplied API which require additional data to be passed from call site to call site.

Again, at least drivers can be upstreamed, but the changes required to get to an Android-ready kernel are a bit more involved.

o Mainline provides a stubbed-out API.

Once again, the drivers can at least be upstreamed, but Android is the only project validating the placement of calls to the
API. This means that changes to the drivers are likely to
mess up the placement of the call sites. Therefore, getting to an Android-ready kernel requires careful inspection of the drivers to adjust for bugs introduced by others.

o Mainline provides nothing.

Status quo. This means that some other group will likely introduce the required functionality in an incremental fashion. This process will likely fail to take Android's needs into account, probably leading to...

o Mainline provides functionality that is similar to what
Android needs, but in a completely incompatible manner that cannot be used easily (or perhaps at all) by Android.

My guess is that there is value to Android in a number of the non-perfect cases.

Thanx, Paul

#430 lore raw
In reply to Mark Brown
Quoted 19 lines · Mark Brown
Quoted 11 lines · On Thu, Aug 05, 2010 at 06:01:24PM -0700, [email protected] wrote:
Quoted 4 lines · Brian Swetland

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

This was the core of the issue I was raising in the last thread about this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

Quoted 5 lines

Those that stay alive will either have per subsystem handling or will be outside the direct control of the kernel entirely (the modem is a good example of the latter case in many systems - in terms of the software it's essentially a parallel computer that's sitting in the system rather than a perhiperal of the AP).

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Thanx, Paul

#431 lore raw
In reply to Mark Brown
Quoted 19 lines · Mark Brown
Quoted 11 lines · On Thu, Aug 05, 2010 at 06:01:24PM -0700, [email protected] wrote:
Quoted 4 lines · Brian Swetland

Obviously not all clocks are stopped (the DSP and codec are powered and clocked, for example), but yeah we can clock gate and power gate the cpu and most other peripherals while audio is playing on a number of ARM SoC designs available today (and the past few years).

does this then mean that you have multiple variations of suspend?

for example, one where the audio stuff is left powered, and one where it isn't?

This was the core of the issue I was raising in the last thread about this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

Quoted 5 lines

Those that stay alive will either have per subsystem handling or will be outside the direct control of the kernel entirely (the modem is a good example of the latter case in many systems - in terms of the software it's essentially a parallel computer that's sitting in the system rather than a perhiperal of the AP).

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Thanx, Paul

#402 lore raw
In reply to [email protected]
Quoted 130 lines · On Fri, Aug 06, 2010 at 01:29:57AM -0700, [email protected] wrote:
Quoted 85 lines · Paul E. McKenney
Quoted 84 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

Quoted 7 lines
Quoted 4 lines

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

Especially given different scenarios, for example, audio playback when the device is in airplane mode. ;-)

hmm, I've been thinking and talking in terms of two classes of cgroups, trusted and untrusted. I wonder if it would be possible to set timeouts for each cgroup instead)

the system would go to sleep IFF all cgroups have been idle longer than the idle time (with -1 idle time being 'ignore this cgroup')

if this could be done you could set longer times for things designed for user-interaction than you do for other purposes.

you could set media to 0 idle time (so that as soon as it finishes processing the system can sleep until the next timer)

to do this, the code making the decision would have to be able to find out the following fairly cheaply.

1. for this cgroup, what was the last time something ran

2. for this cgroup, what is the next timer set

it would be nice to get network traffic/connection stats.

so two questions.

first, what else would you need to get accumulated for the cgroup

second, is there a fairly easy way to have these stats available?

for the 'last time it ran' stat, this seems like you could have a per-cpu variable per cgroup that's fairly cheap to update, but you would need to take a global lock to read accuratly (the lock may be expensive enough that it's worth trying to read the variables from the other cpu without a lock, just to see if it's remotely possible to sleep/suspend)

Quoted 2 lines

with timers, is it possible to have multiple timer wheels (one per cgroup)?

I apologize in advance for what I am about to write, but...

If you continue in this vein, you are likely to make suspend blockers look very simple and natural. ;-)

Thanx, Paul

#403 lore raw
In reply to [email protected]
Quoted 130 lines · On Fri, Aug 06, 2010 at 01:29:57AM -0700, [email protected] wrote:
Quoted 85 lines · Paul E. McKenney
Quoted 84 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 41 lines · kevin granade
Quoted 22 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 10 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:

[ . . . ]

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:

Quoted 6 lines

(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

when you suspend the audio will shut off, so it's sleep ->wake -> sleep, not 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.

it really depnds on the frequency of the wakeups.

if you get a network packet once every 5 min and need to wake to process it, staying awake for 20 seconds after finishing procesing is FAR more significant than if you get a network packet once every hour. It's not just the factor of 20 that simple math would indicate because the time in suspend eats power as well.

I don't know real numbers, so these are made up for this example

if suspend (with the cell live to receive packets) is 10ma average current and full power is 500ma average current

packets every 5 min with .1 sec wake time will eat ~13maH per hour

packets every 5 min with 10 second wake time will eat ~37maH per hour

packets every hour with .1 sec wake time will eat ~10maH per hour

packets every hour with 10 sec wake time will eat ~11maH per hour

so if you have frequent wakeups, staying awake 100 times as long will cut your battery life to 1/3 what it was before.

Quoted 7 lines
Quoted 4 lines

if your wakeups are rare, it's about a 10% hit to stay awake 100 times as long.

there is a lot of room for tuning the timeouts here.

Especially given different scenarios, for example, audio playback when the device is in airplane mode. ;-)

hmm, I've been thinking and talking in terms of two classes of cgroups, trusted and untrusted. I wonder if it would be possible to set timeouts for each cgroup instead)

the system would go to sleep IFF all cgroups have been idle longer than the idle time (with -1 idle time being 'ignore this cgroup')

if this could be done you could set longer times for things designed for user-interaction than you do for other purposes.

you could set media to 0 idle time (so that as soon as it finishes processing the system can sleep until the next timer)

to do this, the code making the decision would have to be able to find out the following fairly cheaply.

1. for this cgroup, what was the last time something ran

2. for this cgroup, what is the next timer set

it would be nice to get network traffic/connection stats.

so two questions.

first, what else would you need to get accumulated for the cgroup

second, is there a fairly easy way to have these stats available?

for the 'last time it ran' stat, this seems like you could have a per-cpu variable per cgroup that's fairly cheap to update, but you would need to take a global lock to read accuratly (the lock may be expensive enough that it's worth trying to read the variables from the other cpu without a lock, just to see if it's remotely possible to sleep/suspend)

Quoted 2 lines

with timers, is it possible to have multiple timer wheels (one per cgroup)?

I apologize in advance for what I am about to write, but...

If you continue in this vein, you are likely to make suspend blockers look very simple and natural. ;-)

Thanx, Paul

#432 lore raw
In reply to Paul E. McKenney
Quoted 11 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown

this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system is suspended in terms of what Linux has to do, and quite a few servers have lights out management systems which aren't a million miles away from the modem on a phone in terms of their relationship with the host computer.

#433 lore raw
In reply to Paul E. McKenney
Quoted 11 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown

this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system is suspended in terms of what Linux has to do, and quite a few servers have lights out management systems which aren't a million miles away from the modem on a phone in terms of their relationship with the host computer.

#434 lore raw
Quoted 13 lines · Mark Brown
Quoted 11 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown

this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Quoted 7 lines

Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system is suspended in terms of what Linux has to do, and quite a few servers have lights out management systems which aren't a million miles away from the modem on a phone in terms of their relationship with the host computer.

The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.

Thanx, Paul

#435 lore raw
In reply to Mark Brown
Quoted 13 lines · Mark Brown
Quoted 11 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown

this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Quoted 7 lines

Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system is suspended in terms of what Linux has to do, and quite a few servers have lights out management systems which aren't a million miles away from the modem on a phone in terms of their relationship with the host computer.

The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.

Thanx, Paul

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

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

As noted, we already have this.

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky. Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire. This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0. To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it). It would be nice if we could avoid the need.

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added. But you didn't mention any field saying whether the wakelock is currently active. That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems. Is there anything like it that _would_ apply in general?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added. The only drawback is that all these additions will bloat the size of struct device. Of course, that's why you used separately-allocated structures for your wakelocks. Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this. However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones. With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax. It simply hasn't been implemented yet.

Alan Stern

(*) Speaking of PCI devices, I'm not convinced that the way Rafael is using the pm_wakeup_event interface in the PCI core is entirely correct. The idea is to resolve the race between wakeup events and suspend. The code assumes that a wakeup event will be consumed in 100 ms or less, which is a reasonable assumption.

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

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

count, tells you how many times the wakelock was activated. If a wakelock prevented suspend for a long time a large count tells you it handled a lot of events while a small count tells you it took a long time to process the events, or the wakelock was not released properly.

As noted, we already have this.

Quoted 5 lines

expire_count, tells you how many times the timeout expired. For the input event wakelock in the android kernel (which has a timeout) an expire count that matches the count tells you that someone opened an input device but is not reading from it (this has happened several times).

This is a little tricky. Rafael's model currently does not allow wakeup events started by pm_wakeup_event() to be cancelled any way other than by having their timer expire. This essentially means that for some devices, expire_count will always be the same as count and for others it will always be 0. To change this would require adding an extra timer struct, which could be done (in fact, an earlier version of the code included it). It would be nice if we could avoid the need.

Does Android use any kernel-internal wakelocks both with a timer and with active cancellation?

Quoted 4 lines

wake_count, tells you that this is the first wakelock that was acquired in the resume path. This is currently less useful than I would like on the Nexus One since it is usually "SMD_RPCCALL" which does not tell me a lot.

This could be done easily enough, but if it's not very useful then there's no point.

Quoted 3 lines

active_since, tells you how long a a still active wakelock has been active. If someone activated a wakelock and never released it, it will be obvious here.

Easily added. But you didn't mention any field saying whether the wakelock is currently active. That could be added too (although it would be racy -- but for detecting unreleased wakelocks you wouldn't care).

Quoted 2 lines

total_time, total time the wake lock has been active. This one should be obvious.

Also easily added.

Quoted 1 line

sleep_time, total time the wake lock has been active when the screen was off.

Not applicable to general systems. Is there anything like it that _would_ apply in general?

Quoted 4 lines

max_time, longest time the wakelock was active uninterrupted. This used less often, but the battery on a device was draining fast, but the problem went away before looking at the stats this will show if a wakelock was active for a long time.

Again, easily added. The only drawback is that all these additions will bloat the size of struct device. Of course, that's why you used separately-allocated structures for your wakelocks. Maybe we can change to do the same; it seems likely that the majority of device structures won't ever be used for wakeup events.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and I would prefer that the kernel interfaces would encourage drivers to block suspend until user space has consumed the event, which works for the android user space, instead of just long enough to work with a hypothetical user space power manager.

Rafael doesn't _discourage_ drivers from doing this. However you have to keep in mind that many kernel developers are accustomed to working on systems (mostly PCs) with a different range of hardware devices from embedded systems like your phones. With PCI devices(*), for example, there's no clear point where a wakeup event gets handed off to userspace.

On the other hand, there's no reason the input layer shouldn't use pm_stay_awake and pm_relax. It simply hasn't been implemented yet.

Alan Stern

(*) Speaking of PCI devices, I'm not convinced that the way Rafael is using the pm_wakeup_event interface in the PCI core is entirely correct. The idea is to resolve the race between wakeup events and suspend. The code assumes that a wakeup event will be consumed in 100 ms or less, which is a reasonable assumption.

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

#254 lore raw
Quoted 1 line · Alan Stern

On Thu, 5 Aug 2010, Arve Hjønnevåg wrote:

...

Quoted 18 lines

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

Quoted 4 lines

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

Thanks,
Rafael

#255 lore raw
In reply to Alan Stern
Quoted 1 line · Alan Stern

On Thu, 5 Aug 2010, Arve Hjønnevåg wrote:

...

Quoted 18 lines

But what sorts of things qualify as wakeup events? Right now, the code handles only events coming by way of the PME# signal (or its platform equivalent). But that signal usually gets activated only when a PCI device is in a low-power mode; if the device is at full power then it simply generates an IRQ. It's the same event, but reported to the kernel in a different way. So consider...

Case 1: The system is suspending and the PCI device has already been
placed in D3hot when an event occurs. PME# is activated, the wakeup event is reported, the suspend is aborted, and the system won't try to suspend again for at least 100 ms. Good.

Case 2: The system is running normally and the PCI device is at full
power when an event occurs. PME# isn't activated and pm_wakeup_event doesn't get called. Then when the system tries to suspend 25 ms later, there's nothing to prevent it even though the event is still being processed. Bad.

Quoted 4 lines

In case 2 the race has not been resolved. It seems to me that the only proper solution is to call pm_wakeup_event for _every_ PCI interrupt. This may be too much to add to a hot path, but what's the alternative?

Arguably not every PCI interrupt should be regarded as a wakeup event, so I think we can simply say in the cases when that's necessary the driver should be responsible for using pm_wakeup_event() or pm_stay_awake() / pm_relax() as appropriate.

My patch only added it to the bus-level code which covered the PME-based wakeup events that _cannot_ be handled by device drivers.

Thanks,
Rafael

#404 lore raw
In reply to Paul E. McKenney
Quoted 35 lines · Paul E. McKenney
Quoted 34 lines · On Fri, Aug 06, 2010 at 01:29:57AM -0700, [email protected] wrote:
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 5 lines · kevin granade
Quoted 4 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · Paul E. McKenney
Quoted 4 lines · On Wed, Aug 04, 2010 at 05:25:53PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney

[ . . . ]

it would be nice to get network traffic/connection stats.

so two questions.

first, what else would you need to get accumulated for the cgroup

second, is there a fairly easy way to have these stats available?

for the 'last time it ran' stat, this seems like you could have a per-cpu variable per cgroup that's fairly cheap to update, but you would need to take a global lock to read accuratly (the lock may be expensive enough that it's worth trying to read the variables from the other cpu without a lock, just to see if it's remotely possible to sleep/suspend)

Quoted 7 lines
Quoted 2 lines

with timers, is it possible to have multiple timer wheels (one per cgroup)?

I apologize in advance for what I am about to write, but...

If you continue in this vein, you are likely to make suspend blockers look very simple and natural. ;-)

if that's the case then they should be implemented :-)

on the other hand, this may be something that's desirable for idle-low-power as well.

David Lang

#405 lore raw
In reply to Paul E. McKenney
Quoted 35 lines · Paul E. McKenney
Quoted 34 lines · On Fri, Aug 06, 2010 at 01:29:57AM -0700, [email protected] wrote:
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · On Thu, Aug 05, 2010 at 01:26:18PM -0700, [email protected] wrote:
Quoted 5 lines · kevin granade
Quoted 4 lines · On Thu, Aug 5, 2010 at 10:46 AM, <[email protected]> wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · On Wed, Aug 04, 2010 at 10:18:40PM -0700, [email protected] wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines · Paul E. McKenney
Quoted 4 lines · On Wed, Aug 04, 2010 at 05:25:53PM -0700, [email protected] wrote:
Quoted 2 lines · Paul E. McKenney

[ . . . ]

it would be nice to get network traffic/connection stats.

so two questions.

first, what else would you need to get accumulated for the cgroup

second, is there a fairly easy way to have these stats available?

for the 'last time it ran' stat, this seems like you could have a per-cpu variable per cgroup that's fairly cheap to update, but you would need to take a global lock to read accuratly (the lock may be expensive enough that it's worth trying to read the variables from the other cpu without a lock, just to see if it's remotely possible to sleep/suspend)

Quoted 7 lines
Quoted 2 lines

with timers, is it possible to have multiple timer wheels (one per cgroup)?

I apologize in advance for what I am about to write, but...

If you continue in this vein, you are likely to make suspend blockers look very simple and natural. ;-)

if that's the case then they should be implemented :-)

on the other hand, this may be something that's desirable for idle-low-power as well.

David Lang

#549 lore raw

Attempted summary of suspend-blockers LKML thread, take three

In reply to Paul E. McKenney

Final 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

#550 lore raw

Attempted summary of suspend-blockers LKML thread, take three

In reply to Paul E. McKenney

Final 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

#436 lore raw
In reply to Paul E. McKenney
Quoted 22 lines · Paul E. McKenney
Quoted 13 lines · Mark Brown
Quoted 11 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown

this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Quoted 7 lines

Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system is suspended in terms of what Linux has to do, and quite a few servers have lights out management systems which aren't a million miles away from the modem on a phone in terms of their relationship with the host computer.

Quoted 7 lines

The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.

one other significant issue is that on the PC, things like wake-on-LAN, lights out management cards, etc require nothing from the main system other than power. If they do something, they are sending the signal to the chipset, which then wakes the system up. they don't interact with the main processor/memory/etc at all.

So as I see it, we need to do one of two things.

1. change the suspend definition to allow for some things to not be suspended

or

2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)

to me #2 seems the better thing to do from a design/concept point of view

David Lang

#437 lore raw
In reply to Paul E. McKenney
Quoted 22 lines · Paul E. McKenney
Quoted 13 lines · Mark Brown
Quoted 11 lines · Paul E. McKenney
Quoted 4 lines · Mark Brown

this (the one following the rename to suspend blockers). Essentially what happens in a mainline context is that some subsystems can with varying degress of optionality ignore some or all of the instruction to suspend and keep bits of the system alive during suspend.

This underscores a basic difference between servers and these embedded devices. When you suspend a server, it is doing nothing, because servers rely very heavily on the CPUs. In contrast, many embedded devices can perform useful work even when the CPUs are completely powered down.

Quoted 7 lines

Well, not really from the Linux point of view. It's not massively different to something like keeping an ethernet controller sufficiently alive to allow it to provide wake on LAN functionality while the system is suspended in terms of what Linux has to do, and quite a few servers have lights out management systems which aren't a million miles away from the modem on a phone in terms of their relationship with the host computer.

Quoted 7 lines

The wake-on-LAN and the lights-out management systems are indeed interesting examples, and actually pretty good ones. The reason I excluded them is that they don't do any application processing -- their only purpose is the care and feeding of the system itself. In contrast, the embedded processors are able to do significant applications processing (e.g., play back music) while any CPUs are completely shut down and most of the memory is powered down as well.

one other significant issue is that on the PC, things like wake-on-LAN, lights out management cards, etc require nothing from the main system other than power. If they do something, they are sending the signal to the chipset, which then wakes the system up. they don't interact with the main processor/memory/etc at all.

So as I see it, we need to do one of two things.

1. change the suspend definition to allow for some things to not be suspended

or

2. change the sleep/low-power mode definition to have a more standardized way of turning things off, and extend it to allow clocks to be turned off as well (today we have things able to be turned off, drive spin-down for example, but per comments in this thread it's all one-off methods)

to me #2 seems the better thing to do from a design/concept point of view

David Lang

#551 lore raw

Re: Attempted summary of suspend-blockers LKML thread, take three

In reply to Paul E. McKenney

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 three

Final 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