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 2 of 6

Subsystems (4)
lore
Share & tools
lore
#533 lore raw
In reply to Arve Hjønnevåg
Quoted 17 lines · Arve Hjønnevåg

2010/8/3 James Bottomley <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines

o A power-aware application must be able to efficiently communicate
its needs to the system, so that such communication can be performed on hot code paths. Communication via open() and close() is considered too slow, but communication via ioctl() is acceptable.

Quoted 7 lines
Quoted 2 lines

The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.

Please elaborate on this. I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works. What's the problem?

Quoted 4 lines

The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.

? right at the moment it doesn't do stats. I don't see why adding a per pid or per name stat count on the long lived object won't work here.

Quoted 2 lines

Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?

There is no stat interface yet; it's for us to define.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.

Quoted 5 lines
Quoted 1 line

This is an implementation detail only.

There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.

They're freed on destruction of the long lived kernel object or on user space clear request. Surely that's definitive enough?

Quoted 8 lines
Quoted 4 lines

The pm-qos objects are long
lived, so their stats would be too. I would guess that explicit stat clearing might be a useful option.

Which pm-qos objects are you referring to? The struct pm_qos_object that backs each pm-qos class is long lived (I don't know why this is named pm_qos_object), but we need stats in struct pm_qos_request_list.

Actually, why not two separate lists? one for the request and one for the stats?

OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).

James

#93 lore raw
In reply to Arve Hjønnevåg
Quoted 79 lines · Arve Hj?nnev?g
Quoted 71 lines · On Tue, Aug 3, 2010 at 5:51 PM, <[email protected]> wrote:
Quoted 43 lines · Paul E. McKenney
Quoted 42 lines · On Tue, Aug 03, 2010 at 04:19:25PM -0700, [email protected] wrote:
Quoted 11 lines · Arve Hj?nnev?g

2010/8/2  <[email protected]>:

Quoted 9 lines

so what is the fundamental difference between deciding to go into low-power
idle modes to wake up back up on a given point in the future and deciding
that you are going to be idle for so long that you may as well suspend until
there is user input?

Quoted 5 lines

Low power idle modes are supposed to be transparent. Suspend stops the monotonic clock, ignores ready threads and switches over to a separate set of wakeup events/interrupts. We don't suspend until there is user input, we suspend until there is a wakeup event (user-input, incoming network data/phone-calls, alarms etc..).

s/user input/wakeup event/ and my question still stands.

low power modes are not transparent to the user in all cases (if the screen backlight dimms/shuts off a user reading something will notice, if the system switches to a lower clock speed it can impact user response time, etc) The system is making it's best guess as to how to best srve the user by sacraficing some capibilities to save power now so that the power can be available later.

as I see it, suspending until a wakeup event (button press, incoming call, alarm, etc) is just another datapoint along the same path.

If the system could not wake itself up to respond to user input, phone call, alarm, etc and needed the power button pressed to wake up (or shut down to the point where the battery could be removed and reinstalled a long time later), I would see things moving into a different category, but as long as the system has the ability to wake itself up later (and is still consuming power) I see the suspend as being in the same category as the other low-power modes (it's just more expensive to go in and out of)

Quoted 4 lines
Quoted 2 lines

why should the suspend be put into a different category from the other low-power states?

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 5 lines

From an Android perspective, the differences are as follows:

1.      Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in it's calculations than this would work.

Quoted 5 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

Quoted 6 lines

I see this as simply being a matter of what devices are still enabled at the different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not seeing input from it until something else wakes the system)

Quoted 5 lines

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

are you talking about Android here or are you talking genricly across all platforms?

Quoted 15 lines
Quoted 10 lines
Quoted 9 lines

3.      The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 4 lines

if you have the ability to wake for an alarm, you have the ability to wake for a timer (if from no other method than to set the alarm to when the timer tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

even if they wake up at the same time, you would use suspend instead of idle if it saved more power (allowing for the power to get in and out of suspend vs the power to get in and out of idle)

in this case, another reason you would consider using suspend over idle is that you can suspend until the next timer that your privilaged applications have set, and skip timers set by the non-privilaged applications, resulting in more time asleep.

Quoted 17 lines
Quoted 8 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion.  But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

Quoted 8 lines

these big distinction that I see as significant seem to be in the decision of when to go into the different states, and the difference between the states  themselves seem to be less significant (and either very close to, or within the variation that already exists for power saving modes)

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

If this is the case it seems even more so that the android suspend should be addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the applications need to be fooled into thinking no time has passed?

or is it to prevent extranious wakeups?

or is it to save additional power?

Quoted 10 lines
Quoted 7 lines

you have many different power saving modes, the daemon (or kernel code) that is determining which mode to go into would need different logic (including, but not limited to the ability to be able to ignore one or more cgroups of processes). different power saving modes have different trade-offs, and some of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

Quoted 7 lines
Quoted 7 lines

This all depends on the ability for the code that decides to switch power modes (including to trigger suspend) to be able to see things in sufficient detail to be able to do different things depending on the class of programs. I don't know enough about this code to know if this is the case or not, I really wish that someone familiar with the power saving code could either confirm that this is possible, or state that it's not possible (or at least, not without major surgery)

#130 lore raw
In reply to Arjan van de Ven
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

note that what I'm speculating about would never freeze some of the tasks, it would run everything if anything is run, but it would not consider the actions of some of the programs when deciding if it can shutdown.

so if you have all your privilaged applications in long sleeps, but still have your bouncing cows running, peggng the CPU, making noise, and updating the screen, the system would decide the system is 'idle' and go into the 'suspend' low power state until there is a wake activity.

but if you have a privilaged application doing other stuff (say you are talking on the phone, have a GPS mapping program running and giving you directions, etc), the bouncing cows would continue to run and there would never be an attempt to freeze them while leaving the other stuff active.

David Lang

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

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

You're supposed to fix the clock after you wake up. That's part of the cost of going suspend.

OG.

#135 lore raw
In reply to Arjan van de Ven
Quoted 47 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1.    Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

Quoted 6 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

Quoted 9 lines

3.    The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 11 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

I disagree. On the msm platform the low level timer that brings us out of the low power state is the same for idle and suspend. The difference is where which kernel api the request comes from. In idle, the next event on the clockevents device is usually the first event. In suspend the generic kernel timekeeping code cancels this event and the rtc wakeup event remains.

Signature · 1 line
Arve Hjønnevåg
#136 lore raw
In reply to Arjan van de Ven
Quoted 47 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1.    Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

Quoted 6 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

Quoted 9 lines

3.    The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 11 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

I disagree. On the msm platform the low level timer that brings us out of the low power state is the same for idle and suspend. The difference is where which kernel api the request comes from. In idle, the next event on the clockevents device is usually the first event. In suspend the generic kernel timekeeping code cancels this event and the rtc wakeup event remains.

Signature · 1 line
Arve Hjønnevåg
#534 lore raw
In reply to James Bottomley

2010/8/3 James Bottomley <[email protected]>:

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

2010/8/3 James Bottomley <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines

o       A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths.  Communication via open() and close() is considered too slow, but communication via ioctl() is acceptable.

Quoted 7 lines
Quoted 2 lines

The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.

Please elaborate on this.  I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works.  What's the problem?

Quoted 4 lines

The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.

Quoted 8 lines

? right at the moment it doesn't do stats.  I don't see why adding a per pid or per name stat count on the long lived object won't work here.

Quoted 2 lines

Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?

There is no stat interface yet; it's for us to define.

Then I don't know what you are asking. This specific requirement was about the userspace interface to block and unblock suspend. The existing pm-qos interface to update pm-qos requests is similar to the user space suspend blocker interface (it has the same object lifetime).

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

This is an implementation detail only.

There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.

They're freed on destruction of the long lived kernel object or on user space clear request.  Surely that's definitive enough?

What is a user-space clear request? Clearing all stats. Deleting a suspend blocker? Unblocking suspend?

The android wakelock interface to userspace creates new wakelocks every time it sees a new name. This was rejected on this list because it does not put any limit on the amount of kernel memory used as a result of calls from user space.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The pm-qos objects are long
lived, so their stats would be too.  I would guess that explicit stat clearing might be a useful option.

Quoted 7 lines
Quoted 3 lines

Which pm-qos objects are you referring to? The struct pm_qos_object that backs each pm-qos class is long lived (I don't know why this is named pm_qos_object), but we need stats in struct pm_qos_request_list.

Actually, why not two separate lists?  one for the request and one for the stats?

Why do you want to do another lookup? Is there a reason you don't want stats in pm_qos_request_list?

Quoted 6 lines

OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).

I don't think adding stats to pm-qos is hard. It is not as easy as the wakelock/suspend blocker interface since the number of possible request values is unknown, but we could for instance have stats on default vs non-default request values. However, it is not at all clear that switching our code to the pm-qos interface would make it acceptable for mainline inclusion. The main objections to the last suspend blocker patchset seemed to be that we should not use suspend at all. There are also some new api in linux-next that try to solve the same problem in an non android compatible way. Are drivers supposed to use both this interface and pm-qos to prevent suspend?

Signature · 1 line
Arve Hjønnevåg
#535 lore raw
In reply to James Bottomley

2010/8/3 James Bottomley <[email protected]>:

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

2010/8/3 James Bottomley <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 7 lines
Quoted 6 lines

o       A power-aware application must be able to efficiently communicate its needs to the system, so that such communication can be performed on hot code paths.  Communication via open() and close() is considered too slow, but communication via ioctl() is acceptable.

Quoted 7 lines
Quoted 2 lines

The problem with using open and close to prevent an allow suspend is not that it is too slow but that it interferes with collecting stats.

Please elaborate on this.  I expect the pm-qos stats interface will collect stats across user open/close because that's how it currently works.  What's the problem?

Quoted 4 lines

The pm-qos interface creates the request object in open and destroys it in release just like the suspend blocker interface. We need stats for each client which is lost if you free the object every time you unblock suspend.

Quoted 8 lines

? right at the moment it doesn't do stats.  I don't see why adding a per pid or per name stat count on the long lived object won't work here.

Quoted 2 lines

Or are you talking about user space opening and closing the stats interface (which does not cause any problems)?

There is no stat interface yet; it's for us to define.

Then I don't know what you are asking. This specific requirement was about the userspace interface to block and unblock suspend. The existing pm-qos interface to update pm-qos requests is similar to the user space suspend blocker interface (it has the same object lifetime).

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

The wakelock code has a sysfs interface that allow you to use a open/write/close sequence to block or unblock suspend. There is no limit to the amount of kernel memory that a process can consume with this interface, so the suspend blocker patchset uses a /dev interface with ioctls to block or unblock suspend and it destroys the kernel object when the file descriptor is closed.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

This is an implementation detail only.

There is no way fix it without changing the user space visible behavior of the API. The kernel does not know when it is safe to free the objects.

They're freed on destruction of the long lived kernel object or on user space clear request.  Surely that's definitive enough?

What is a user-space clear request? Clearing all stats. Deleting a suspend blocker? Unblocking suspend?

The android wakelock interface to userspace creates new wakelocks every time it sees a new name. This was rejected on this list because it does not put any limit on the amount of kernel memory used as a result of calls from user space.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The pm-qos objects are long
lived, so their stats would be too.  I would guess that explicit stat clearing might be a useful option.

Quoted 7 lines
Quoted 3 lines

Which pm-qos objects are you referring to? The struct pm_qos_object that backs each pm-qos class is long lived (I don't know why this is named pm_qos_object), but we need stats in struct pm_qos_request_list.

Actually, why not two separate lists?  one for the request and one for the stats?

Why do you want to do another lookup? Is there a reason you don't want stats in pm_qos_request_list?

Quoted 6 lines

OK, so I'm tired and I've had a long flight to get to where I am, so I may be a bit jaded, but this isn't fucking rocket science the question is how do we implement what you want on what we have ... there looks to be multiple useful solutions ... we just have to pick one and agree on it (that's standard open source).

I don't think adding stats to pm-qos is hard. It is not as easy as the wakelock/suspend blocker interface since the number of possible request values is unknown, but we could for instance have stats on default vs non-default request values. However, it is not at all clear that switching our code to the pm-qos interface would make it acceptable for mainline inclusion. The main objections to the last suspend blocker patchset seemed to be that we should not use suspend at all. There are also some new api in linux-next that try to solve the same problem in an non android compatible way. Are drivers supposed to use both this interface and pm-qos to prevent suspend?

Signature · 1 line
Arve Hjønnevåg
#94 lore raw
In reply to [email protected]

Hi,

Quoted 8 lines · On Tue, 3 Aug 2010 21:47:49 -0700 (PDT) [email protected] wrote:
Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Quoted 7 lines

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

I think my laptop (x86-64) uses the same notion of suspend as Android. I am confused now. Android 'suspend' is equivalent to
'echo "mem" > /sys/power/state'

Which distros call it "low-power mode with different wakeup rules"? Gentoo doesnt. In KDE/Gnome it's also called suspend or suspend-to-ram iirc.

Cheers,
Flo

#95 lore raw
In reply to [email protected]

Hi,

Quoted 8 lines · On Tue, 3 Aug 2010 21:47:49 -0700 (PDT) [email protected] wrote:
Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Quoted 7 lines

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

I think my laptop (x86-64) uses the same notion of suspend as Android. I am confused now. Android 'suspend' is equivalent to
'echo "mem" > /sys/power/state'

Which distros call it "low-power mode with different wakeup rules"? Gentoo doesnt. In KDE/Gnome it's also called suspend or suspend-to-ram iirc.

Cheers,
Flo

#96 lore raw
In reply to [email protected]

2010/8/3 <[email protected]>:

Quoted 88 lines · Arve Hj?nnev?g
Quoted 87 lines · On Tue, Aug 3, 2010 at 5:51 PM,  <[email protected]> wrote:
Quoted 84 lines · Paul E. McKenney
Quoted 45 lines · On Tue, Aug 03, 2010 at 04:19:25PM -0700, [email protected] wrote:
Quoted 43 lines · Arve Hj?nnev?g
Quoted 13 lines

2010/8/2 á<[email protected]>:

Quoted 10 lines

so what is the fundamental difference between deciding to go into low-power
idle modes to wake up back up on a given point in the future and deciding
that you are going to be idle for so long that you may as well suspend
until
there is user input?

Quoted 5 lines

Low power idle modes are supposed to be transparent. Suspend stops the monotonic clock, ignores ready threads and switches over to a separate set of wakeup events/interrupts. We don't suspend until there is user input, we suspend until there is a wakeup event (user-input, incoming network data/phone-calls, alarms etc..).

s/user input/wakeup event/ and my question still stands.

low power modes are not transparent to the user in all cases (if the screen backlight dimms/shuts off a user reading something will notice, if the system switches to a lower clock speed it can impact user response time, etc) The system is making it's best guess as to how to best srve the user by sacraficing some capibilities to save power now so that the power can be available later.

as I see it, suspending until a wakeup event (button press, incoming call, alarm, etc) is just another datapoint along the same path.

If the system could not wake itself up to respond to user input, phone call, alarm, etc and needed the power button pressed to wake up (or shut down to the point where the battery could be removed and reinstalled a long time later), I would see things moving into a different category, but as long as the system has the ability to wake itself up later (and is still consuming power) I see the suspend as being in the same category as the other low-power modes (it's just more expensive to go in and out of)

Quoted 4 lines
Quoted 2 lines

why should the suspend be put into a different category from the other low-power states?

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 6 lines

From an Android perspective, the differences are as follows:

1. á á áDeep idle states are entered only if there are no runnable tasks.
á á á áIn contrast, opportunistic suspend can happen even when there á á á áare tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in
it's calculations than this would work.

Quoted 5 lines

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 a deep á á á áidle state. áFor example, I believe that it was stated that one á á á áof the Android-based smartphones ignores touchscreen input while á á á ásuspended, but pays attention to it while in deep idle states.

I see this as simply being a matter of what devices are still enabled at the
different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have
to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not
seeing input from it until something else wakes the system)

Quoted 9 lines
Quoted 5 lines

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

are you talking about Android here or are you talking genricly across all platforms?

This appears to be the current Linux driver model. Old platform code hardcoded the wakeup interrupts.

Quoted 26 lines
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

3. á á áThe system comes out of a deep idle state when a timer á á á áexpires. áIn contrast, timers cannot expire while the á á á ásystem is suspended. á(This one is debatable: some people á á á áargue that timers are subject to jitter, and the suspend á á á ácase for timers is the same as that for deep idle states, á á á ábut with unbounded timer jitter. áOthers disagree. áThe á á á áresulting discussions have produced much heat, but little á á á álight. áSuch is life.)

Quoted 6 lines

if you have the ability to wake for an alarm, you have the ability to wake
for a timer (if from no other method than to set the alarm to when the timer
tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Quoted 6 lines

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

even if they wake up at the same time, you would use suspend instead of idle if it saved more power (allowing for the power to get in and out of suspend vs the power to get in and out of idle)

Suspend and idle use the same power state on the devices we shipped. The power saving we get from suspend if from ignoring the timers.

Quoted 5 lines

in this case, another reason you would consider using suspend over idle is that you can suspend until the next timer that your privilaged applications have set, and skip timers set by the non-privilaged applications, resulting in more time asleep.

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

Quoted 28 lines
Quoted 20 lines
Quoted 16 lines
Quoted 8 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. áBut the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states áthemselves seem to be less significant (and either very close to, or
within the variation that already exists for power saving modes)

Quoted 3 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Quoted 7 lines

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

No. Android suspend is Linux suspend. We just enter it more frequently.

Quoted 7 lines

If this is the case it seems even more so that the android suspend should be addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the applications need to be fooled into thinking no time has passed?

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

This all depends on the ability for the code that decides to switch power modes (including to trigger suspend) to be able to see things in sufficient
detail to be able to do different things depending on the class of programs.
I don't know enough about this code to know if this is the case or not, I really wish that someone familiar with the power saving code could either confirm that this is possible, or state that it's not possible (or at least,
not without major surgery)

Signature · 1 line
Arve Hjønnevåg
#97 lore raw
In reply to [email protected]

2010/8/3 <[email protected]>:

Quoted 88 lines · Arve Hj?nnev?g
Quoted 87 lines · On Tue, Aug 3, 2010 at 5:51 PM,  <[email protected]> wrote:
Quoted 84 lines · Paul E. McKenney
Quoted 45 lines · On Tue, Aug 03, 2010 at 04:19:25PM -0700, [email protected] wrote:
Quoted 43 lines · Arve Hj?nnev?g
Quoted 13 lines

2010/8/2 á<[email protected]>:

Quoted 10 lines

so what is the fundamental difference between deciding to go into low-power
idle modes to wake up back up on a given point in the future and deciding
that you are going to be idle for so long that you may as well suspend
until
there is user input?

Quoted 5 lines

Low power idle modes are supposed to be transparent. Suspend stops the monotonic clock, ignores ready threads and switches over to a separate set of wakeup events/interrupts. We don't suspend until there is user input, we suspend until there is a wakeup event (user-input, incoming network data/phone-calls, alarms etc..).

s/user input/wakeup event/ and my question still stands.

low power modes are not transparent to the user in all cases (if the screen backlight dimms/shuts off a user reading something will notice, if the system switches to a lower clock speed it can impact user response time, etc) The system is making it's best guess as to how to best srve the user by sacraficing some capibilities to save power now so that the power can be available later.

as I see it, suspending until a wakeup event (button press, incoming call, alarm, etc) is just another datapoint along the same path.

If the system could not wake itself up to respond to user input, phone call, alarm, etc and needed the power button pressed to wake up (or shut down to the point where the battery could be removed and reinstalled a long time later), I would see things moving into a different category, but as long as the system has the ability to wake itself up later (and is still consuming power) I see the suspend as being in the same category as the other low-power modes (it's just more expensive to go in and out of)

Quoted 4 lines
Quoted 2 lines

why should the suspend be put into a different category from the other low-power states?

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 6 lines

From an Android perspective, the differences are as follows:

1. á á áDeep idle states are entered only if there are no runnable tasks.
á á á áIn contrast, opportunistic suspend can happen even when there á á á áare tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in
it's calculations than this would work.

Quoted 5 lines

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 a deep á á á áidle state. áFor example, I believe that it was stated that one á á á áof the Android-based smartphones ignores touchscreen input while á á á ásuspended, but pays attention to it while in deep idle states.

I see this as simply being a matter of what devices are still enabled at the
different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have
to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not
seeing input from it until something else wakes the system)

Quoted 9 lines
Quoted 5 lines

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

are you talking about Android here or are you talking genricly across all platforms?

This appears to be the current Linux driver model. Old platform code hardcoded the wakeup interrupts.

Quoted 26 lines
Quoted 17 lines
Quoted 10 lines
Quoted 9 lines

3. á á áThe system comes out of a deep idle state when a timer á á á áexpires. áIn contrast, timers cannot expire while the á á á ásystem is suspended. á(This one is debatable: some people á á á áargue that timers are subject to jitter, and the suspend á á á ácase for timers is the same as that for deep idle states, á á á ábut with unbounded timer jitter. áOthers disagree. áThe á á á áresulting discussions have produced much heat, but little á á á álight. áSuch is life.)

Quoted 6 lines

if you have the ability to wake for an alarm, you have the ability to wake
for a timer (if from no other method than to set the alarm to when the timer
tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Quoted 6 lines

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

even if they wake up at the same time, you would use suspend instead of idle if it saved more power (allowing for the power to get in and out of suspend vs the power to get in and out of idle)

Suspend and idle use the same power state on the devices we shipped. The power saving we get from suspend if from ignoring the timers.

Quoted 5 lines

in this case, another reason you would consider using suspend over idle is that you can suspend until the next timer that your privilaged applications have set, and skip timers set by the non-privilaged applications, resulting in more time asleep.

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

Quoted 28 lines
Quoted 20 lines
Quoted 16 lines
Quoted 8 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. áBut the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states áthemselves seem to be less significant (and either very close to, or
within the variation that already exists for power saving modes)

Quoted 3 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Quoted 7 lines

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

No. Android suspend is Linux suspend. We just enter it more frequently.

Quoted 7 lines

If this is the case it seems even more so that the android suspend should be addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the applications need to be fooled into thinking no time has passed?

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

This all depends on the ability for the code that decides to switch power modes (including to trigger suspend) to be able to see things in sufficient
detail to be able to do different things depending on the class of programs.
I don't know enough about this code to know if this is the case or not, I really wish that someone familiar with the power saving code could either confirm that this is possible, or state that it's not possible (or at least,
not without major surgery)

Signature · 1 line
Arve Hjønnevåg
#119 lore raw
In reply to Olivier Galibert

2010/8/3 Olivier Galibert <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 4 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

You're supposed to fix the clock after you wake up.  That's part of the cost of going suspend.

I'm not sure what you are referring to. The generic Linux timekeeping code makes sure the monotonic clock stops while the system is suspended regardless of what values the (hardware specific) clocksource returns.

Signature · 1 line
Arve Hjønnevåg
#120 lore raw
In reply to Olivier Galibert

2010/8/3 Olivier Galibert <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 4 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

You're supposed to fix the clock after you wake up.  That's part of the cost of going suspend.

I'm not sure what you are referring to. The generic Linux timekeeping code makes sure the monotonic clock stops while the system is suspended regardless of what values the (hardware specific) clocksource returns.

Signature · 1 line
Arve Hjønnevåg
#131 lore raw
In reply to [email protected]
Quoted 29 lines · On Tue, 3 Aug 2010 21:55:07 -0700 (PDT) [email protected] wrote:
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

note that what I'm speculating about would never freeze some of the tasks, it would run everything if anything is run, but it would not consider the actions of some of the programs when deciding if it can shutdown.

so if you have all your privilaged applications in long sleeps, but still have your bouncing cows running, peggng the CPU, making noise, and updating the screen, the system would decide the system is 'idle' and go into the 'suspend' low power state until there is a wake activity.

Quoted 6 lines

but if you have a privilaged application doing other stuff (say you are talking on the phone, have a GPS mapping program running and giving you directions, etc), the bouncing cows would continue to run and there would never be an attempt to freeze them while leaving the other stuff active.

David Lang

I think the only difference between your proposition and the current android practice is that in your scheme the partition is along the process/task boundary (i.e. good apps vs bad apps) whereas the android looks at actions or events or ... let's call it "stuff" and blocks suspend whenever "stuff" needs to be done.

The main thing is that even an process that is allowed to block suspend doesn't do so all the time. Only when it is critical that "stuff" get's done right away.

One way to make an application work the same way with your scheme (as I understand it) on android could be to split the application into an "blocker" part, that is not part of the "ignore-cgroup" (the "trusted" part) and another one that is in the "ignore-cgroup" (the "untrusted" part). Whenever the untrusted part needs to block suspend it notices the "trusted" part via ipc and the trusted part goes into some sort of "activity loop". This looks kind of stupid. But I bet it is what application developers are going to do if there is no provision for a flexible runtime enable/disable "suspend blocker".

hmmm...

Cheers,
Flo

#132 lore raw
In reply to [email protected]
Quoted 29 lines · On Tue, 3 Aug 2010 21:55:07 -0700 (PDT) [email protected] wrote:
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

note that what I'm speculating about would never freeze some of the tasks, it would run everything if anything is run, but it would not consider the actions of some of the programs when deciding if it can shutdown.

so if you have all your privilaged applications in long sleeps, but still have your bouncing cows running, peggng the CPU, making noise, and updating the screen, the system would decide the system is 'idle' and go into the 'suspend' low power state until there is a wake activity.

Quoted 6 lines

but if you have a privilaged application doing other stuff (say you are talking on the phone, have a GPS mapping program running and giving you directions, etc), the bouncing cows would continue to run and there would never be an attempt to freeze them while leaving the other stuff active.

David Lang

I think the only difference between your proposition and the current android practice is that in your scheme the partition is along the process/task boundary (i.e. good apps vs bad apps) whereas the android looks at actions or events or ... let's call it "stuff" and blocks suspend whenever "stuff" needs to be done.

The main thing is that even an process that is allowed to block suspend doesn't do so all the time. Only when it is critical that "stuff" get's done right away.

One way to make an application work the same way with your scheme (as I understand it) on android could be to split the application into an "blocker" part, that is not part of the "ignore-cgroup" (the "trusted" part) and another one that is in the "ignore-cgroup" (the "untrusted" part). Whenever the untrusted part needs to block suspend it notices the "trusted" part via ipc and the trusted part goes into some sort of "activity loop". This looks kind of stupid. But I bet it is what application developers are going to do if there is no provision for a flexible runtime enable/disable "suspend blocker".

hmmm...

Cheers,
Flo

#121 lore raw
In reply to Arve Hjønnevåg
Quoted 7 lines · Arve Hjønnevåg

2010/8/3 Olivier Galibert <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

Quoted 7 lines
Quoted 2 lines

You're supposed to fix the clock after you wake up.  That's part of the cost of going suspend.

I'm not sure what you are referring to. The generic Linux timekeeping code makes sure the monotonic clock stops while the system is suspended regardless of what values the (hardware specific) clocksource returns.

That just means the android-like suspend should not act in that specific area the same as the generic suspend to ram. Which is not entirely surprising. In any case, it's not "keep the monotonic clock running", which would cost power. It's fix it up afterwards, using the same means you already do but perhaps at a higher level currently. People don't want to see the wrong time of the day just because the phone went to suspend. Laptop STR is different in perception because it shuts down things people don't want to see shutdown just by being idle, namely wifi connectivity.

If your next polling timer is in half an hour and the screen/touchpad are off, you want to go as low in power as possible until then, and that's the deepest level of idle you can find that responds to alarms which may happen to be called suspend. But from a user point of view, it's just another idle level. And from a power management code/policy decisions point of view, it should be the same.

OG.

#122 lore raw
In reply to Arve Hjønnevåg
Quoted 7 lines · Arve Hjønnevåg

2010/8/3 Olivier Galibert <[email protected]>:

Quoted 6 lines · Arve Hjønnevåg
Quoted 4 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

Quoted 7 lines
Quoted 2 lines

You're supposed to fix the clock after you wake up.  That's part of the cost of going suspend.

I'm not sure what you are referring to. The generic Linux timekeeping code makes sure the monotonic clock stops while the system is suspended regardless of what values the (hardware specific) clocksource returns.

That just means the android-like suspend should not act in that specific area the same as the generic suspend to ram. Which is not entirely surprising. In any case, it's not "keep the monotonic clock running", which would cost power. It's fix it up afterwards, using the same means you already do but perhaps at a higher level currently. People don't want to see the wrong time of the day just because the phone went to suspend. Laptop STR is different in perception because it shuts down things people don't want to see shutdown just by being idle, namely wifi connectivity.

If your next polling timer is in half an hour and the screen/touchpad are off, you want to go as low in power as possible until then, and that's the deepest level of idle you can find that responds to alarms which may happen to be called suspend. But from a user point of view, it's just another idle level. And from a power management code/policy decisions point of view, it should be the same.

OG.

#98 lore raw
In reply to Arve Hjønnevåg
Quoted 48 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 47 lines · Arve Hj?nnev?g
Quoted 45 lines · On Tue, Aug 3, 2010 at 5:51 PM,  <[email protected]> wrote:
Quoted 28 lines · Paul E. McKenney
Quoted 2 lines

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 6 lines

From an Android perspective, the differences are as follows:

1. ? ? ?Deep idle states are entered only if there are no runnable tasks.
? ? ? ?In contrast, opportunistic suspend can happen even when there ? ? ? ?are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in
it's calculations than this would work.

Quoted 5 lines

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 a deep ? ? ? ?idle state. ?For example, I believe that it was stated that one ? ? ? ?of the Android-based smartphones ignores touchscreen input while ? ? ? ?suspended, but pays attention to it while in deep idle states.

Quoted 9 lines

I see this as simply being a matter of what devices are still enabled at the
different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have
to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not
seeing input from it until something else wakes the system)

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

Quoted 6 lines
Quoted 3 lines

are you talking about Android here or are you talking genricly across all platforms?

This appears to be the current Linux driver model. Old platform code hardcoded the wakeup interrupts.

not quite the question I was trying (and failing) to ask, but from the answer it sounds like setting suspend to wake up on all interrupts is the same as idle.

so here suspend is looking like just a variation of low-power idle (different wakeup criteria)

Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

3. ? ? ?The system comes out of a deep idle state when a timer ? ? ? ?expires. ?In contrast, timers cannot expire while the ? ? ? ?system is suspended. ?(This one is debatable: some people ? ? ? ?argue that timers are subject to jitter, and the suspend ? ? ? ?case for timers is the same as that for deep idle states, ? ? ? ?but with unbounded timer jitter. ?Others disagree. ?The ? ? ? ?resulting discussions have produced much heat, but little ? ? ? ?light. ?Such is life.)

Quoted 6 lines

if you have the ability to wake for an alarm, you have the ability to wake
for a timer (if from no other method than to set the alarm to when the timer
tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

Quoted 6 lines
Quoted 3 lines

even if they wake up at the same time, you would use suspend instead of idle if it saved more power (allowing for the power to get in and out of suspend vs the power to get in and out of idle)

Suspend and idle use the same power state on the devices we shipped. The power saving we get from suspend if from ignoring the timers.

Ok, so if you set the alarm to the next time the timer for a privilaged task would run and wake up then to be completely transparent to the privilaged task, or you could decide to disable the timers as well

again, this looks like suspend and idle are very closely related.

Quoted 8 lines
Quoted 4 lines

in this case, another reason you would consider using suspend over idle is that you can suspend until the next timer that your privilaged applications have set, and skip timers set by the non-privilaged applications, resulting in more time asleep.

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

since the non-privilaged application is never frozen when a privilaged application is running, I'm not sure how you would get this to happen that wouldn't also be a problem with wakelocks.

if you want to have a privilaged application keep the system awake while it waits for a non-privilaged application, all it would need to do is to set a timer near enough in the future that it's considered 'awake' all the time. this will cost a context switch every timeout period (for the application to check that it's still waiting and set the next timer), but that's pretty cheap.

one thing this would destroy is the stats currently built around the wakelock, but since they would be replaced by stats of exactly the type of thing that powertop was written to deal with, I don't see this as a problem (powertop would just have to learn a mode where it ignores the non-privilaged tasks).consolodating tools is a good thing.

Quoted 29 lines
Quoted 29 lines
Quoted 19 lines
Quoted 15 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. ?But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states ?themselves seem to be less significant (and either very close to, or
within the variation that already exists for power saving modes)

Quoted 3 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Ok, If I am understanding you correctly I think this is an important point.

Quoted 7 lines
Quoted 5 lines

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

No. Android suspend is Linux suspend. We just enter it more frequently.

In Linux, a full suspend normally takes the system down to a mode that can't be reached by the normal idle mechnism (including powering down peripherals). It also takes significantly different actions to wake up. What you are describing seems much milder than that.

Quoted 10 lines
Quoted 7 lines

If this is the case it seems even more so that the android suspend should be addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the applications need to be fooled into thinking no time has passed?

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

no, as noted by others in this thread, normal linux suspend/resume modifies the clock to show that time has passed since the suspend happened.

Quoted 3 lines
Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

as noted above, this sounds like it's configurable.

Quoted 5 lines
Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

so I'm left not understanding the huge desire to stop the monotonic clock.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

David Lang

#99 lore raw
In reply to Arve Hjønnevåg
Quoted 48 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 47 lines · Arve Hj?nnev?g
Quoted 45 lines · On Tue, Aug 3, 2010 at 5:51 PM,  <[email protected]> wrote:
Quoted 28 lines · Paul E. McKenney
Quoted 2 lines

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 6 lines

From an Android perspective, the differences are as follows:

1. ? ? ?Deep idle states are entered only if there are no runnable tasks.
? ? ? ?In contrast, opportunistic suspend can happen even when there ? ? ? ?are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in
it's calculations than this would work.

Quoted 5 lines

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 a deep ? ? ? ?idle state. ?For example, I believe that it was stated that one ? ? ? ?of the Android-based smartphones ignores touchscreen input while ? ? ? ?suspended, but pays attention to it while in deep idle states.

Quoted 9 lines

I see this as simply being a matter of what devices are still enabled at the
different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have
to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not
seeing input from it until something else wakes the system)

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

Quoted 6 lines
Quoted 3 lines

are you talking about Android here or are you talking genricly across all platforms?

This appears to be the current Linux driver model. Old platform code hardcoded the wakeup interrupts.

not quite the question I was trying (and failing) to ask, but from the answer it sounds like setting suspend to wake up on all interrupts is the same as idle.

so here suspend is looking like just a variation of low-power idle (different wakeup criteria)

Quoted 28 lines
Quoted 28 lines
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

3. ? ? ?The system comes out of a deep idle state when a timer ? ? ? ?expires. ?In contrast, timers cannot expire while the ? ? ? ?system is suspended. ?(This one is debatable: some people ? ? ? ?argue that timers are subject to jitter, and the suspend ? ? ? ?case for timers is the same as that for deep idle states, ? ? ? ?but with unbounded timer jitter. ?Others disagree. ?The ? ? ? ?resulting discussions have produced much heat, but little ? ? ? ?light. ?Such is life.)

Quoted 6 lines

if you have the ability to wake for an alarm, you have the ability to wake
for a timer (if from no other method than to set the alarm to when the timer
tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

Quoted 6 lines
Quoted 3 lines

even if they wake up at the same time, you would use suspend instead of idle if it saved more power (allowing for the power to get in and out of suspend vs the power to get in and out of idle)

Suspend and idle use the same power state on the devices we shipped. The power saving we get from suspend if from ignoring the timers.

Ok, so if you set the alarm to the next time the timer for a privilaged task would run and wake up then to be completely transparent to the privilaged task, or you could decide to disable the timers as well

again, this looks like suspend and idle are very closely related.

Quoted 8 lines
Quoted 4 lines

in this case, another reason you would consider using suspend over idle is that you can suspend until the next timer that your privilaged applications have set, and skip timers set by the non-privilaged applications, resulting in more time asleep.

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

since the non-privilaged application is never frozen when a privilaged application is running, I'm not sure how you would get this to happen that wouldn't also be a problem with wakelocks.

if you want to have a privilaged application keep the system awake while it waits for a non-privilaged application, all it would need to do is to set a timer near enough in the future that it's considered 'awake' all the time. this will cost a context switch every timeout period (for the application to check that it's still waiting and set the next timer), but that's pretty cheap.

one thing this would destroy is the stats currently built around the wakelock, but since they would be replaced by stats of exactly the type of thing that powertop was written to deal with, I don't see this as a problem (powertop would just have to learn a mode where it ignores the non-privilaged tasks).consolodating tools is a good thing.

Quoted 29 lines
Quoted 29 lines
Quoted 19 lines
Quoted 15 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. ?But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states ?themselves seem to be less significant (and either very close to, or
within the variation that already exists for power saving modes)

Quoted 3 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Ok, If I am understanding you correctly I think this is an important point.

Quoted 7 lines
Quoted 5 lines

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

No. Android suspend is Linux suspend. We just enter it more frequently.

In Linux, a full suspend normally takes the system down to a mode that can't be reached by the normal idle mechnism (including powering down peripherals). It also takes significantly different actions to wake up. What you are describing seems much milder than that.

Quoted 10 lines
Quoted 7 lines

If this is the case it seems even more so that the android suspend should be addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the applications need to be fooled into thinking no time has passed?

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

no, as noted by others in this thread, normal linux suspend/resume modifies the clock to show that time has passed since the suspend happened.

Quoted 3 lines
Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

as noted above, this sounds like it's configurable.

Quoted 5 lines
Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

so I'm left not understanding the huge desire to stop the monotonic clock.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

David Lang

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

On 08/04/2010 08:22 AM, ext Arve Hjønnevåg wrote:

[snip ... discussion about wakeup sources]

Quoted 8 lines

I disagree. On the msm platform the low level timer that brings us out of the low power state is the same for idle and suspend. The difference is where which kernel api the request comes from. In idle, the next event on the clockevents device is usually the first event. In suspend the generic kernel timekeeping code cancels this event and the rtc wakeup event remains.

wrt wakeup sources: why isn't it possible to just expect the interrupt associated to the undesired wakeup src to be masked?
That should be possible on any platform, and I would expect the hw to keep track that at least 1 irq has happened for a specific device:
I'm assuming that the system is fast enough to serve the irq before another one of same type is generated, should it be considered worth of waking up the system.

Timers might be tricky (iirc only 2 out of 12 timers are wakeup sources on OMAP3), but many other peripherals should be easier to handle.

cheers, igor

#133 lore raw
In reply to Florian Mickler
Quoted 39 lines · Florian Mickler

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

Quoted 34 lines · On Tue, 3 Aug 2010 21:55:07 -0700 (PDT) [email protected] wrote:
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

note that what I'm speculating about would never freeze some of the tasks, it would run everything if anything is run, but it would not consider the actions of some of the programs when deciding if it can shutdown.

so if you have all your privilaged applications in long sleeps, but still have your bouncing cows running, peggng the CPU, making noise, and updating the screen, the system would decide the system is 'idle' and go into the 'suspend' low power state until there is a wake activity.

but if you have a privilaged application doing other stuff (say you are talking on the phone, have a GPS mapping program running and giving you directions, etc), the bouncing cows would continue to run and there would never be an attempt to freeze them while leaving the other stuff active.

Quoted 7 lines
Quoted 1 line

David Lang

I think the only difference between your proposition and the current android practice is that in your scheme the partition is along the process/task boundary (i.e. good apps vs bad apps) whereas the android looks at actions or events or ... let's call it "stuff" and blocks suspend whenever "stuff" needs to be done.

with the caviot that only privilaged applications are allowed to define that "stuff" needs to be done

Quoted 3 lines

The main thing is that even an process that is allowed to block suspend doesn't do so all the time. Only when it is critical that "stuff" get's done right away.

effectivly, only when it's important that "stuff" gets done at all. With current smartphone battery capacities it's not uncommon that the phone could be in suspend until the battery dies, since suspend is not zero power.

Quoted 10 lines

One way to make an application work the same way with your scheme (as I understand it) on android could be to split the application into an "blocker" part, that is not part of the "ignore-cgroup" (the "trusted" part) and another one that is in the "ignore-cgroup" (the "untrusted" part). Whenever the untrusted part needs to block suspend it notices the "trusted" part via ipc and the trusted part goes into some sort of "activity loop". This looks kind of stupid. But I bet it is what application developers are going to do if there is no provision for a flexible runtime enable/disable "suspend blocker".

remember that only "trusted" applications were allowed to set the suspend-blocker/wakelock flag in the first place.

my thinking is that since "trusted" applications are assumed to be well written (or they can just raise the suspend-blocker/wakelock and keep the phone from ever sleeping) they should be able to be trusted to sleep appropriately so that if they aren't actually doing anything important the system can go ahead and go to sleep.

Since powertop was designed to find ill-bahaved applications, you would still be able to point the finger at the offenders.

yes, you could trivially have a 'keep me awake' daemon that other apps can talk to to request the system stay awake (the same way you could with a suspend-blocker/wakelock). The "activity loop" for such a daemon can be pretty trivial, set a timer just a little shorter than the idle-go-to-suspend timeout, sleep that long and reset the timer.

I could be mistaken here, but my assumption is that since normal applications running would never get trigger the wakelock except when there is user input, the timeout here is on the order of 10s of seconds, if not a few minutes. having a privilaged application wake up once every several seconds is not going to be significant to anything other than things looking for the system being idle for X amount of time..

Even if this is done, having a userspace 'wakelock' daemon that works this way is significantly better in many people's eyes than having the kernel implement this policy. It's much easier to put application/platform specific logic in the userspace daemon than into the kernel (say, things like 'any app can request a delay for up to X amount of time, but after that they cannot request it again for Y amount of time, except ....)

David Lang

#134 lore raw
In reply to Florian Mickler
Quoted 39 lines · Florian Mickler

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

Quoted 34 lines · On Tue, 3 Aug 2010 21:55:07 -0700 (PDT) [email protected] wrote:
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

note that what I'm speculating about would never freeze some of the tasks, it would run everything if anything is run, but it would not consider the actions of some of the programs when deciding if it can shutdown.

so if you have all your privilaged applications in long sleeps, but still have your bouncing cows running, peggng the CPU, making noise, and updating the screen, the system would decide the system is 'idle' and go into the 'suspend' low power state until there is a wake activity.

but if you have a privilaged application doing other stuff (say you are talking on the phone, have a GPS mapping program running and giving you directions, etc), the bouncing cows would continue to run and there would never be an attempt to freeze them while leaving the other stuff active.

Quoted 7 lines
Quoted 1 line

David Lang

I think the only difference between your proposition and the current android practice is that in your scheme the partition is along the process/task boundary (i.e. good apps vs bad apps) whereas the android looks at actions or events or ... let's call it "stuff" and blocks suspend whenever "stuff" needs to be done.

with the caviot that only privilaged applications are allowed to define that "stuff" needs to be done

Quoted 3 lines

The main thing is that even an process that is allowed to block suspend doesn't do so all the time. Only when it is critical that "stuff" get's done right away.

effectivly, only when it's important that "stuff" gets done at all. With current smartphone battery capacities it's not uncommon that the phone could be in suspend until the battery dies, since suspend is not zero power.

Quoted 10 lines

One way to make an application work the same way with your scheme (as I understand it) on android could be to split the application into an "blocker" part, that is not part of the "ignore-cgroup" (the "trusted" part) and another one that is in the "ignore-cgroup" (the "untrusted" part). Whenever the untrusted part needs to block suspend it notices the "trusted" part via ipc and the trusted part goes into some sort of "activity loop". This looks kind of stupid. But I bet it is what application developers are going to do if there is no provision for a flexible runtime enable/disable "suspend blocker".

remember that only "trusted" applications were allowed to set the suspend-blocker/wakelock flag in the first place.

my thinking is that since "trusted" applications are assumed to be well written (or they can just raise the suspend-blocker/wakelock and keep the phone from ever sleeping) they should be able to be trusted to sleep appropriately so that if they aren't actually doing anything important the system can go ahead and go to sleep.

Since powertop was designed to find ill-bahaved applications, you would still be able to point the finger at the offenders.

yes, you could trivially have a 'keep me awake' daemon that other apps can talk to to request the system stay awake (the same way you could with a suspend-blocker/wakelock). The "activity loop" for such a daemon can be pretty trivial, set a timer just a little shorter than the idle-go-to-suspend timeout, sleep that long and reset the timer.

I could be mistaken here, but my assumption is that since normal applications running would never get trigger the wakelock except when there is user input, the timeout here is on the order of 10s of seconds, if not a few minutes. having a privilaged application wake up once every several seconds is not going to be significant to anything other than things looking for the system being idle for X amount of time..

Even if this is done, having a userspace 'wakelock' daemon that works this way is significantly better in many people's eyes than having the kernel implement this policy. It's much easier to put application/platform specific logic in the userspace daemon than into the kernel (say, things like 'any app can request a delay for up to X amount of time, but after that they cannot request it again for Y amount of time, except ....)

David Lang

#123 lore raw
In reply to Olivier Galibert

2010/8/3 Olivier Galibert <[email protected]>:

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

2010/8/3 Olivier Galibert <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 4 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

You're supposed to fix the clock after you wake up.  That's part of the cost of going suspend.

Quoted 7 lines
Quoted 4 lines

I'm not sure what you are referring to. The generic Linux timekeeping code makes sure the monotonic clock stops while the system is suspended regardless of what values the (hardware specific) clocksource returns.

That just means the android-like suspend should not act in that specific area the same as the generic suspend to ram.  Which is not

Huh? Android uses the generic suspend code.

Quoted 5 lines

entirely surprising.  In any case, it's not "keep the monotonic clock running", which would cost power.  It's fix it up afterwards, using the same means you already do but perhaps at a higher level currently. People don't want to see the wrong time of the day just because the phone went to suspend.  Laptop STR is different in perception because

The monotonic clock is not the same as the realtime clock which is used for time of day.

Quoted 7 lines

it shuts down things people don't want to see shutdown just by being idle, namely wifi connectivity.

If your next polling timer is in half an hour and the screen/touchpad are off, you want to go as low in power as possible until then, and that's the deepest level of idle you can find that responds to alarms which may happen to be called suspend.  But from a user point of view,

Calling the deepest idle state suspend is just confusing. Linux suspend has a different api than idle. In suspend every driver that has a suspend hook is notified. Also, once cpu can be idle while another cpu is running. Suspend is a system wide.

Quoted 3 lines

it's just another idle level.  And from a power management code/policy decisions point of view, it should be the same.

Signature · 1 line
Arve Hjønnevåg
#124 lore raw
In reply to Olivier Galibert

2010/8/3 Olivier Galibert <[email protected]>:

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

2010/8/3 Olivier Galibert <[email protected]>:

Quoted 8 lines · Arve Hjønnevåg
Quoted 4 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running?

You're supposed to fix the clock after you wake up.  That's part of the cost of going suspend.

Quoted 7 lines
Quoted 4 lines

I'm not sure what you are referring to. The generic Linux timekeeping code makes sure the monotonic clock stops while the system is suspended regardless of what values the (hardware specific) clocksource returns.

That just means the android-like suspend should not act in that specific area the same as the generic suspend to ram.  Which is not

Huh? Android uses the generic suspend code.

Quoted 5 lines

entirely surprising.  In any case, it's not "keep the monotonic clock running", which would cost power.  It's fix it up afterwards, using the same means you already do but perhaps at a higher level currently. People don't want to see the wrong time of the day just because the phone went to suspend.  Laptop STR is different in perception because

The monotonic clock is not the same as the realtime clock which is used for time of day.

Quoted 7 lines

it shuts down things people don't want to see shutdown just by being idle, namely wifi connectivity.

If your next polling timer is in half an hour and the screen/touchpad are off, you want to go as low in power as possible until then, and that's the deepest level of idle you can find that responds to alarms which may happen to be called suspend.  But from a user point of view,

Calling the deepest idle state suspend is just confusing. Linux suspend has a different api than idle. In suspend every driver that has a suspend hook is notified. Also, once cpu can be idle while another cpu is running. Suspend is a system wide.

Quoted 3 lines

it's just another idle level.  And from a power management code/policy decisions point of view, it should be the same.

Signature · 1 line
Arve Hjønnevåg
#100 lore raw
In reply to [email protected]

2010/8/3 <[email protected]>:

Quoted 62 lines · Arve Hj?nnev?g
Quoted 61 lines

2010/8/3  <[email protected]>:

Quoted 58 lines · Arve Hj?nnev?g
Quoted 47 lines · On Tue, Aug 3, 2010 at 5:51 PM,  <[email protected]> wrote:
Quoted 34 lines · Paul E. McKenney
Quoted 2 lines

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 6 lines

From an Android perspective, the differences are as follows:

1. ? ? ?Deep idle states are entered only if there are no runnable tasks.
? ? ? ?In contrast, opportunistic suspend can happen even when there ? ? ? ?are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd,
but I can see how it can work), but not neccessarily a major problem. it
depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at
either all activity or ignore one cgroup of processes at different times
in
it's calculations than this would work.

Quoted 7 lines

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 a deep ? ? ? ?idle state. ?For example, I believe that it was stated that one ? ? ? ?of the Android-based smartphones ignores touchscreen input while
? ? ? ?suspended, but pays attention to it while in deep idle states.

Quoted 10 lines

I see this as simply being a matter of what devices are still enabled at
the
different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have
to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not
seeing input from it until something else wakes the system)

Quoted 5 lines

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

are you talking about Android here or are you talking genricly across all platforms?

Quoted 7 lines
Quoted 2 lines

This appears to be the current Linux driver model. Old platform code hardcoded the wakeup interrupts.

not quite the question I was trying (and failing) to ask, but from the answer it sounds like setting suspend to wake up on all interrupts is the same as idle.

No, suspend does a lot more than idle.

Quoted 55 lines

so here suspend is looking like just a variation of low-power idle (different wakeup criteria)

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

3. ? ? ?The system comes out of a deep idle state when a timer ? ? ? ?expires. ?In contrast, timers cannot expire while the ? ? ? ?system is suspended. ?(This one is debatable: some people ? ? ? ?argue that timers are subject to jitter, and the suspend ? ? ? ?case for timers is the same as that for deep idle states, ? ? ? ?but with unbounded timer jitter. ?Others disagree. ?The ? ? ? ?resulting discussions have produced much heat, but little ? ? ? ?light. ?Such is life.)

Quoted 6 lines

if you have the ability to wake for an alarm, you have the ability to wake
for a timer (if from no other method than to set the alarm to when the timer
tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

Quoted 8 lines
Quoted 5 lines

even if they wake up at the same time, you would use suspend instead of idle
if it saved more power (allowing for the power to get in and out of suspend
vs the power to get in and out of idle)

Suspend and idle use the same power state on the devices we shipped. The power saving we get from suspend if from ignoring the timers.

Ok, so if you set the alarm to the next time the timer for a privilaged task would run and wake up then to be completely transparent to the privilaged task, or you could decide to disable the timers as well

again, this looks like suspend and idle are very closely related.

Quoted 8 lines
Quoted 7 lines

in this case, another reason you would consider using suspend over idle is
that you can suspend until the next timer that your privilaged applications
have set, and skip timers set by the non-privilaged applications, resulting
in more time asleep.

Quoted 7 lines
Quoted 3 lines

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

since the non-privilaged application is never frozen when a privilaged application is running, I'm not sure how you would get this to happen that wouldn't also be a problem with wakelocks.

With wakelocks we annotate that we have important work to do, until that work is accomplished we do not suspend. If you modify the idle code ignore some processes' timers the system may get stuck in idle while waiting for a non-privileged application to release a resource.

Quoted 7 lines

if you want to have a privilaged application keep the system awake while it waits for a non-privilaged application, all it would need to do is to set a timer near enough in the future that it's considered 'awake' all the time. this will cost a context switch every timeout period (for the application to check that it's still waiting and set the next timer), but that's pretty cheap.

No, this will kill your idle power.

Quoted 45 lines

one thing this would destroy is the stats currently built around the wakelock, but since they would be replaced by stats of exactly the type of thing that powertop was written to deal with, I don't see this as a problem (powertop would just have to learn a mode where it ignores the non-privilaged tasks).consolodating tools is a good thing.

Quoted 38 lines
Quoted 37 lines
Quoted 21 lines
Quoted 16 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. ?But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states ?themselves seem to be less significant (and either very close to,
or
within the variation that already exists for power saving modes)

Quoted 4 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case
variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

Quoted 6 lines
Quoted 1 line

No. Android suspend is Linux suspend. We just enter it more frequently.

In Linux, a full suspend normally takes the system down to a mode that can't be reached by the normal idle mechnism (including powering down peripherals). It also takes significantly different actions to wake up. What you are describing seems much milder than that.

We use the normal suspend sequence. The shipping hardware we have just don't need to do lot

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

If this is the case it seems even more so that the android suspend should be
addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the
applications need to be fooled into thinking no time has passed?

Quoted 6 lines
Quoted 2 lines

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

no, as noted by others in this thread, normal linux suspend/resume modifies the clock to show that time has passed since the suspend happened.

The monotonic clock always stops. There are a few different ways to maintain the realtime clock and we use one of them.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

as noted above, this sounds like it's configurable.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

so I'm left not understanding the huge desire to stop the monotonic clock.

If you ignore the timers and don't stop the clock they are based on, you break a lot of apps when you resume (watchdogs and timeouts trigger). If you don't ignore timers, you can't sleep very long with existing software.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Signature · 1 line
Arve Hjønnevåg
#101 lore raw
In reply to [email protected]

2010/8/3 <[email protected]>:

Quoted 62 lines · Arve Hj?nnev?g
Quoted 61 lines

2010/8/3  <[email protected]>:

Quoted 58 lines · Arve Hj?nnev?g
Quoted 47 lines · On Tue, Aug 3, 2010 at 5:51 PM,  <[email protected]> wrote:
Quoted 34 lines · Paul E. McKenney
Quoted 2 lines

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 6 lines

From an Android perspective, the differences are as follows:

1. ? ? ?Deep idle states are entered only if there are no runnable tasks.
? ? ? ?In contrast, opportunistic suspend can happen even when there ? ? ? ?are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd,
but I can see how it can work), but not neccessarily a major problem. it
depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at
either all activity or ignore one cgroup of processes at different times
in
it's calculations than this would work.

Quoted 7 lines

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 a deep ? ? ? ?idle state. ?For example, I believe that it was stated that one ? ? ? ?of the Android-based smartphones ignores touchscreen input while
? ? ? ?suspended, but pays attention to it while in deep idle states.

Quoted 10 lines

I see this as simply being a matter of what devices are still enabled at
the
different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have
to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not
seeing input from it until something else wakes the system)

Quoted 5 lines

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

are you talking about Android here or are you talking genricly across all platforms?

Quoted 7 lines
Quoted 2 lines

This appears to be the current Linux driver model. Old platform code hardcoded the wakeup interrupts.

not quite the question I was trying (and failing) to ask, but from the answer it sounds like setting suspend to wake up on all interrupts is the same as idle.

No, suspend does a lot more than idle.

Quoted 55 lines

so here suspend is looking like just a variation of low-power idle (different wakeup criteria)

Quoted 29 lines
Quoted 29 lines
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

3. ? ? ?The system comes out of a deep idle state when a timer ? ? ? ?expires. ?In contrast, timers cannot expire while the ? ? ? ?system is suspended. ?(This one is debatable: some people ? ? ? ?argue that timers are subject to jitter, and the suspend ? ? ? ?case for timers is the same as that for deep idle states, ? ? ? ?but with unbounded timer jitter. ?Others disagree. ?The ? ? ? ?resulting discussions have produced much heat, but little ? ? ? ?light. ?Such is life.)

Quoted 6 lines

if you have the ability to wake for an alarm, you have the ability to wake
for a timer (if from no other method than to set the alarm to when the timer
tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

no, I was thinking that you set the alarm to go off, and when it goes off and wakes you up, you correct other local clocks before doing anything else.

Quoted 8 lines
Quoted 5 lines

even if they wake up at the same time, you would use suspend instead of idle
if it saved more power (allowing for the power to get in and out of suspend
vs the power to get in and out of idle)

Suspend and idle use the same power state on the devices we shipped. The power saving we get from suspend if from ignoring the timers.

Ok, so if you set the alarm to the next time the timer for a privilaged task would run and wake up then to be completely transparent to the privilaged task, or you could decide to disable the timers as well

again, this looks like suspend and idle are very closely related.

Quoted 8 lines
Quoted 7 lines

in this case, another reason you would consider using suspend over idle is
that you can suspend until the next timer that your privilaged applications
have set, and skip timers set by the non-privilaged applications, resulting
in more time asleep.

Quoted 7 lines
Quoted 3 lines

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

since the non-privilaged application is never frozen when a privilaged application is running, I'm not sure how you would get this to happen that wouldn't also be a problem with wakelocks.

With wakelocks we annotate that we have important work to do, until that work is accomplished we do not suspend. If you modify the idle code ignore some processes' timers the system may get stuck in idle while waiting for a non-privileged application to release a resource.

Quoted 7 lines

if you want to have a privilaged application keep the system awake while it waits for a non-privilaged application, all it would need to do is to set a timer near enough in the future that it's considered 'awake' all the time. this will cost a context switch every timeout period (for the application to check that it's still waiting and set the next timer), but that's pretty cheap.

No, this will kill your idle power.

Quoted 45 lines

one thing this would destroy is the stats currently built around the wakelock, but since they would be replaced by stats of exactly the type of thing that powertop was written to deal with, I don't see this as a problem (powertop would just have to learn a mode where it ignores the non-privilaged tasks).consolodating tools is a good thing.

Quoted 38 lines
Quoted 37 lines
Quoted 21 lines
Quoted 16 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. ?But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states ?themselves seem to be less significant (and either very close to,
or
within the variation that already exists for power saving modes)

Quoted 4 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case
variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

Quoted 6 lines
Quoted 1 line

No. Android suspend is Linux suspend. We just enter it more frequently.

In Linux, a full suspend normally takes the system down to a mode that can't be reached by the normal idle mechnism (including powering down peripherals). It also takes significantly different actions to wake up. What you are describing seems much milder than that.

We use the normal suspend sequence. The shipping hardware we have just don't need to do lot

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

If this is the case it seems even more so that the android suspend should be
addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the
applications need to be fooled into thinking no time has passed?

Quoted 6 lines
Quoted 2 lines

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

no, as noted by others in this thread, normal linux suspend/resume modifies the clock to show that time has passed since the suspend happened.

The monotonic clock always stops. There are a few different ways to maintain the realtime clock and we use one of them.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

as noted above, this sounds like it's configurable.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

so I'm left not understanding the huge desire to stop the monotonic clock.

If you ignore the timers and don't stop the clock they are based on, you break a lot of apps when you resume (watchdogs and timeouts trigger). If you don't ignore timers, you can't sleep very long with existing software.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Signature · 1 line
Arve Hjønnevåg
#102 lore raw
Quoted 5 lines · On Wed, 4 Aug 2010 00:10:21 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 3 lines

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Perhaps transparent is badly worded. Both suspend and idle are in some way "transparent". Idle doesnt happen when an application is runnable. Suspend is transparent in that the application can not easily detect if it happened.

Cheers,
Flo

#103 lore raw
In reply to Arve Hjønnevåg
Quoted 5 lines · On Wed, 4 Aug 2010 00:10:21 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 3 lines

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Perhaps transparent is badly worded. Both suspend and idle are in some way "transparent". Idle doesnt happen when an application is runnable. Suspend is transparent in that the application can not easily detect if it happened.

Cheers,
Flo

#104 lore raw
In reply to Arve Hjønnevåg
Quoted 19 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 18 lines · Arve Hj?nnev?g
Quoted 16 lines

2010/8/3  <[email protected]>:

Quoted 10 lines · Arve Hj?nnev?g

in this case, another reason you would consider using suspend over idle is
that you can suspend until the next timer that your privilaged applications
have set, and skip timers set by the non-privilaged applications, resulting
in more time asleep.

Without wakelock or suspend blockers this can still break since a privileged application may be waiting on a resource held by a non-privileged application.

Quoted 8 lines
Quoted 3 lines

since the non-privilaged application is never frozen when a privilaged application is running, I'm not sure how you would get this to happen that wouldn't also be a problem with wakelocks.

With wakelocks we annotate that we have important work to do, until that work is accomplished we do not suspend. If you modify the idle code ignore some processes' timers the system may get stuck in idle while waiting for a non-privileged application to release a resource.

if you don't have a wakelock the system could go into suspend under the exact same conditions. If the privilaged program wants to be sure of preventing this, all it needs to do is to set of timer to take action before the timeout.

Quoted 9 lines
Quoted 7 lines

if you want to have a privilaged application keep the system awake while it waits for a non-privilaged application, all it would need to do is to set a timer near enough in the future that it's considered 'awake' all the time. this will cost a context switch every timeout period (for the application to check that it's still waiting and set the next timer), but that's pretty cheap.

No, this will kill your idle power.

you are only doing this every several seconds to prevent the system from suspending.

it's possible that I'm making false assumptions about how quickly you want to go into full suspend mode.

if a user is doing nothing that would warrent wakelocks, but has an unprivilaged application running (a dancing cows game), and is doing nothing other than occasionally hitting a button, how short is the timeout that you would set that would have the system go into suspend? (i.e. how frequently must the user do something to keep the system awake)

or let's use a better example, the user has an unprivilaged book-reader application, how quickly must they change pages to prevent the system from suspending?

I'm figuring that these times are in the 1-5 minute range.

therefor the timeout period I am mentioning above could easily be one wakeup every 40-50 seconds.

that is not going to kill your idle power.

is my assumption about the length of the timeout incorrect?

Quoted 88 lines
Quoted 45 lines

one thing this would destroy is the stats currently built around the wakelock, but since they would be replaced by stats of exactly the type of thing that powertop was written to deal with, I don't see this as a problem (powertop would just have to learn a mode where it ignores the non-privilaged tasks).consolodating tools is a good thing.

Quoted 38 lines
Quoted 37 lines
Quoted 21 lines
Quoted 16 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion. ?But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

these big distinction that I see as significant seem to be in the decision
of when to go into the different states, and the difference between the states ?themselves seem to be less significant (and either very close to,
or
within the variation that already exists for power saving modes)

Quoted 4 lines

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case
variation of existing core concepts.

Quoted 7 lines

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Ok, If I am understanding you correctly I think this is an important point.

What Android calls suspend is not what other linux distros call suspend, it's just a low-power mode with different wakeup rules.

Is this correct?

Quoted 6 lines
Quoted 1 line

No. Android suspend is Linux suspend. We just enter it more frequently.

In Linux, a full suspend normally takes the system down to a mode that can't be reached by the normal idle mechnism (including powering down peripherals). It also takes significantly different actions to wake up. What you are describing seems much milder than that.

We use the normal suspend sequence. The shipping hardware we have just don't need to do lot

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

If this is the case it seems even more so that the android suspend should be
addressed by tieing into the power management/idle stuff rather than the suspend/hibernate side of things

is the reason you want to stop the onotonic clock and the timers because the
applications need to be fooled into thinking no time has passed?

Quoted 6 lines
Quoted 2 lines

Yes, but this is not an Android extension, it is part of the normal Linux suspend sequence.

no, as noted by others in this thread, normal linux suspend/resume modifies the clock to show that time has passed since the suspend happened.

The monotonic clock always stops. There are a few different ways to maintain the realtime clock and we use one of them.

Quoted 12 lines
Quoted 3 lines
Quoted 2 lines

or is it to prevent extranious wakeups?

That too.

as noted above, this sounds like it's configurable.

Quoted 5 lines
Quoted 2 lines

or is it to save additional power?

No (assuming you are asking about the clock), the actual hardware clock (on msm) stops even in idle but it is resynchronized on wakeup with a clock that never stops when used from idle.

Quoted 7 lines
Quoted 2 lines

so I'm left not understanding the huge desire to stop the monotonic clock.

If you ignore the timers and don't stop the clock they are based on, you break a lot of apps when you resume (watchdogs and timeouts trigger). If you don't ignore timers, you can't sleep very long with existing software.

if you can stop the clocks they are based on, you could also shift them into the future. but in any case, significant changes in time can cause problems for suspended apps (if nothing else, broken network connections because the machines elsewhere timed you out)

Quoted 31 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines

you have many different power saving modes, the daemon (or kernel code) that
is determining which mode to go into would need different logic (including,
but not limited to the ability to be able to ignore one or more cgroups of
processes). different power saving modes have different trade-offs, and some
of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

Quoted 4 lines

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

This isn't sounding quite right to me. I've seen too many discussions about things like idle and USB devices/hubs/drives/etc getting powered down for power savings modes to make me readily accept that everything must be as transparent as you imply. Just the case of drive spin-down shows that it's possible to do things that would be considered destructive, but you have to have a flag and wake-up path to recover within a 'reasonable' amount of time (I guess that this could be 'transparent' if that only implies that things must work eventually, which isn't what I read into the statement)

David Lang

#105 lore raw
Quoted 8 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 6 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 5 lines · Arve Hj?nnev?g
Quoted 4 lines

2010/8/3 <[email protected]>:

Quoted 2 lines · Arve Hj?nnev?g

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

It would be much better if you gave specific examples. Because, for instance, I'm not sure what platforms you have in mind.

Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

Quoted 4 lines

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Quoted 9 lines

This isn't sounding quite right to me. I've seen too many discussions about things like idle and USB devices/hubs/drives/etc getting powered down for power savings modes to make me readily accept that everything must be as transparent as you imply. Just the case of drive spin-down shows that it's possible to do things that would be considered destructive, but you have to have a flag and wake-up path to recover within a 'reasonable' amount of time (I guess that this could be 'transparent' if that only implies that things must work eventually, which isn't what I read into the statement)

Well, consider a single character device and suppose there is an application talking to the driver using read(), write(), ioctl(), whatever. Now suppose you want to put the device into a low-power state such that the device can't do the I/O in that state. You need to ensure that the app won't be able to reach the device while in that state and you can (1) arrange things so that the device is put into the full-power state whenever the app tries to access it and (2) "freeze" the app so that it won't try to access the device being in the low-power state.

Generally speaking (1) is what idle (and any other form of runtime PM) does and
(2) is what suspend does with respect to the whole system.

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.

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

Thanks,
Rafael

#106 lore raw
In reply to [email protected]
Quoted 8 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 6 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 5 lines · Arve Hj?nnev?g
Quoted 4 lines

2010/8/3 <[email protected]>:

Quoted 2 lines · Arve Hj?nnev?g

...

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

It would be much better if you gave specific examples. Because, for instance, I'm not sure what platforms you have in mind.

Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

Quoted 4 lines

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Quoted 9 lines

This isn't sounding quite right to me. I've seen too many discussions about things like idle and USB devices/hubs/drives/etc getting powered down for power savings modes to make me readily accept that everything must be as transparent as you imply. Just the case of drive spin-down shows that it's possible to do things that would be considered destructive, but you have to have a flag and wake-up path to recover within a 'reasonable' amount of time (I guess that this could be 'transparent' if that only implies that things must work eventually, which isn't what I read into the statement)

Well, consider a single character device and suppose there is an application talking to the driver using read(), write(), ioctl(), whatever. Now suppose you want to put the device into a low-power state such that the device can't do the I/O in that state. You need to ensure that the app won't be able to reach the device while in that state and you can (1) arrange things so that the device is put into the full-power state whenever the app tries to access it and (2) "freeze" the app so that it won't try to access the device being in the low-power state.

Generally speaking (1) is what idle (and any other form of runtime PM) does and
(2) is what suspend does with respect to the whole system.

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.

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

Thanks,
Rafael

#125 lore raw
In reply to Arve Hjønnevåg
Quoted 98 lines · Arve Hjønnevåg
Quoted 71 lines · On Tue, Aug 3, 2010 at 5:51 PM, <[email protected]> wrote:
Quoted 43 lines · Paul E. McKenney
Quoted 42 lines · On Tue, Aug 03, 2010 at 04:19:25PM -0700, [email protected] wrote:
Quoted 11 lines · Arve Hj?nnev?g

2010/8/2  <[email protected]>:

Quoted 9 lines

so what is the fundamental difference between deciding to go into low-power
idle modes to wake up back up on a given point in the future and deciding
that you are going to be idle for so long that you may as well suspend until
there is user input?

Quoted 5 lines

Low power idle modes are supposed to be transparent. Suspend stops the monotonic clock, ignores ready threads and switches over to a separate set of wakeup events/interrupts. We don't suspend until there is user input, we suspend until there is a wakeup event (user-input, incoming network data/phone-calls, alarms etc..).

s/user input/wakeup event/ and my question still stands.

low power modes are not transparent to the user in all cases (if the screen backlight dimms/shuts off a user reading something will notice, if the system switches to a lower clock speed it can impact user response time, etc) The system is making it's best guess as to how to best srve the user by sacraficing some capibilities to save power now so that the power can be available later.

as I see it, suspending until a wakeup event (button press, incoming call, alarm, etc) is just another datapoint along the same path.

If the system could not wake itself up to respond to user input, phone call, alarm, etc and needed the power button pressed to wake up (or shut down to the point where the battery could be removed and reinstalled a long time later), I would see things moving into a different category, but as long as the system has the ability to wake itself up later (and is still consuming power) I see the suspend as being in the same category as the other low-power modes (it's just more expensive to go in and out of)

Quoted 4 lines
Quoted 2 lines

why should the suspend be put into a different category from the other low-power states?

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 5 lines

From an Android perspective, the differences are as follows:

1.      Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in it's calculations than this would work.

Quoted 5 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

Quoted 6 lines

I see this as simply being a matter of what devices are still enabled at the different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not seeing input from it until something else wakes the system)

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

Quoted 9 lines
Quoted 8 lines

3.      The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 3 lines

if you have the ability to wake for an alarm, you have the ability to wake for a timer (if from no other method than to set the alarm to when the timer tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Hmmm... The bit about the monotonic clock not advancing could help explain at least some of the heartburn from the scheduler and real-time folks. ;-)

My guess is that this is not a problem for Android workloads, which probably do not contain aggressive real-time components. (With the possible exception of interactions with the cellphone network, which I believe are handled by a separate core with separate OS.) However, pulling this into the Linux kernel would require that interactions with aggressive real-time workloads be handled, one way or another.

I can see a couple possible resolutions:

1. Make OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT, so that
opportunistic suspend simply doesn't happen on systems that support aggressive real-time workloads.

2. Allow OPPORTUNISTIC_SUSPEND and PREEMPT_RT, but suppress
opportunistic suspend when there is a user-created real-time process. One way to handle this would be with a variation on a tongue-in-cheek suggestion from Peter Zijlstra, namely to have every real-time process hold a wakelock. Note that such a wakelock would need to be held even if the real-time process in question was not runnable, in order to meet possible real-time deadlines when the real-time process was awakened.

3. Your proposal here. ;-)

Thoughts?

Thanx, Paul

Quoted 50 lines
Quoted 8 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion.  But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

Quoted 8 lines

these big distinction that I see as significant seem to be in the decision of when to go into the different states, and the difference between the states  themselves seem to be less significant (and either very close to, or within the variation that already exists for power saving modes)

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Quoted 8 lines

you have many different power saving modes, the daemon (or kernel code) that is determining which mode to go into would need different logic (including, but not limited to the ability to be able to ignore one or more cgroups of processes). different power saving modes have different trade-offs, and some of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

Quoted 8 lines

This all depends on the ability for the code that decides to switch power modes (including to trigger suspend) to be able to see things in sufficient detail to be able to do different things depending on the class of programs. I don't know enough about this code to know if this is the case or not, I really wish that someone familiar with the power saving code could either confirm that this is possible, or state that it's not possible (or at least, not without major surgery)

Signature · 1 line
Arve Hjønnevåg
#126 lore raw
In reply to Arve Hjønnevåg
Quoted 98 lines · Arve Hjønnevåg
Quoted 71 lines · On Tue, Aug 3, 2010 at 5:51 PM, <[email protected]> wrote:
Quoted 43 lines · Paul E. McKenney
Quoted 42 lines · On Tue, Aug 03, 2010 at 04:19:25PM -0700, [email protected] wrote:
Quoted 11 lines · Arve Hj?nnev?g

2010/8/2  <[email protected]>:

Quoted 9 lines

so what is the fundamental difference between deciding to go into low-power
idle modes to wake up back up on a given point in the future and deciding
that you are going to be idle for so long that you may as well suspend until
there is user input?

Quoted 5 lines

Low power idle modes are supposed to be transparent. Suspend stops the monotonic clock, ignores ready threads and switches over to a separate set of wakeup events/interrupts. We don't suspend until there is user input, we suspend until there is a wakeup event (user-input, incoming network data/phone-calls, alarms etc..).

s/user input/wakeup event/ and my question still stands.

low power modes are not transparent to the user in all cases (if the screen backlight dimms/shuts off a user reading something will notice, if the system switches to a lower clock speed it can impact user response time, etc) The system is making it's best guess as to how to best srve the user by sacraficing some capibilities to save power now so that the power can be available later.

as I see it, suspending until a wakeup event (button press, incoming call, alarm, etc) is just another datapoint along the same path.

If the system could not wake itself up to respond to user input, phone call, alarm, etc and needed the power button pressed to wake up (or shut down to the point where the battery could be removed and reinstalled a long time later), I would see things moving into a different category, but as long as the system has the ability to wake itself up later (and is still consuming power) I see the suspend as being in the same category as the other low-power modes (it's just more expensive to go in and out of)

Quoted 4 lines
Quoted 2 lines

why should the suspend be put into a different category from the other low-power states?

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 5 lines

From an Android perspective, the differences are as follows:

1.      Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in it's calculations than this would work.

Quoted 5 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

Quoted 6 lines

I see this as simply being a matter of what devices are still enabled at the different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not seeing input from it until something else wakes the system)

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

Quoted 9 lines
Quoted 8 lines

3.      The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 3 lines

if you have the ability to wake for an alarm, you have the ability to wake for a timer (if from no other method than to set the alarm to when the timer tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Hmmm... The bit about the monotonic clock not advancing could help explain at least some of the heartburn from the scheduler and real-time folks. ;-)

My guess is that this is not a problem for Android workloads, which probably do not contain aggressive real-time components. (With the possible exception of interactions with the cellphone network, which I believe are handled by a separate core with separate OS.) However, pulling this into the Linux kernel would require that interactions with aggressive real-time workloads be handled, one way or another.

I can see a couple possible resolutions:

1. Make OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT, so that
opportunistic suspend simply doesn't happen on systems that support aggressive real-time workloads.

2. Allow OPPORTUNISTIC_SUSPEND and PREEMPT_RT, but suppress
opportunistic suspend when there is a user-created real-time process. One way to handle this would be with a variation on a tongue-in-cheek suggestion from Peter Zijlstra, namely to have every real-time process hold a wakelock. Note that such a wakelock would need to be held even if the real-time process in question was not runnable, in order to meet possible real-time deadlines when the real-time process was awakened.

3. Your proposal here. ;-)

Thoughts?

Thanx, Paul

Quoted 50 lines
Quoted 8 lines
Quoted 7 lines

There may well be others.

Whether these distinctions are a good thing or a bad thing is one of the topics of this discussion.  But the distinctions themselves are certainly very real, from what I can see.

Or am I missing your point?

Quoted 8 lines

these big distinction that I see as significant seem to be in the decision of when to go into the different states, and the difference between the states  themselves seem to be less significant (and either very close to, or within the variation that already exists for power saving modes)

If I'm right bout this, then it would seem to simplify the concept and change it from some really foreign android-only thing into a special case variation of existing core concepts.

Suspend is not an android only concept. The android extensions just allow us to aggressively use suspend without loosing (or delaying) wakeup events. On the hardware that we shipped we can enter the same power mode from idle as we do in suspend, but we still use suspend primarily because it stops the monotonic clock and all the timers that use it. Changing suspend to behave more like an idle mode, which seems to be what you are suggesting, would not buy us anything.

Quoted 8 lines

you have many different power saving modes, the daemon (or kernel code) that is determining which mode to go into would need different logic (including, but not limited to the ability to be able to ignore one or more cgroups of processes). different power saving modes have different trade-offs, and some of them power down different peripherals (which is always a platform specific, if not system specific set of trade-offs)

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

Quoted 8 lines

This all depends on the ability for the code that decides to switch power modes (including to trigger suspend) to be able to see things in sufficient detail to be able to do different things depending on the class of programs. I don't know enough about this code to know if this is the case or not, I really wish that someone familiar with the power saving code could either confirm that this is possible, or state that it's not possible (or at least, not without major surgery)

Signature · 1 line
Arve Hjønnevåg
#177 lore raw
In reply to Arjan van de Ven
Quoted 16 lines · Arjan van de Ven
Quoted 12 lines · On Mon, 2 Aug 2010 21:56:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 2 lines

non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Quoted 3 lines

one of the solutions we're looking at to solve this is to unfreeze the cgroup on a regular basis (say, every 15 to 30 seconds) briefly to avoid this kind of deadlock...

Cute!!! ;-)

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

I must of course defer to the Android folks as to whether or not this would actually work for Android. But if your approach works for them, why worry?

Thanx, Paul

#178 lore raw
In reply to Arjan van de Ven
Quoted 16 lines · Arjan van de Ven
Quoted 12 lines · On Mon, 2 Aug 2010 21:56:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 2 lines

non-obvious dependencies.

The dependencies is what made this solution uninteresting to us. For instance, we currently use cgroup scheduling to reduce the impact of some background tasks, but we occasionally saw a watchdog restart of the system process were critical services were waiting on a kernel mutex owned by a background task for more than 20 seconds. If we froze a cgroup instead, we would not hit this particular problem since tasks cannot be frozen while executing kernel code the same way they can be preempted, but nothing prevents a task from being frozen while holding a user-space resource.

Quoted 3 lines

one of the solutions we're looking at to solve this is to unfreeze the cgroup on a regular basis (say, every 15 to 30 seconds) briefly to avoid this kind of deadlock...

Cute!!! ;-)

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

I must of course defer to the Android folks as to whether or not this would actually work for Android. But if your approach works for them, why worry?

Thanx, Paul

#179 lore raw
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Signature · 1 line
Matthew Garrett | [email protected]
#180 lore raw
In reply to Paul E. McKenney
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Signature · 1 line
Matthew Garrett | [email protected]
#181 lore raw
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

there are two cgroup solutions in discussion at this point.

weeks ago there was the suggestion to put non-privilaged tasks in a cgroup so that they could be frozen as a group. I thought the problem there was that there can be user-space dpendancies that would prevent privilaged tasks from working.

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

David Lang

#140 lore raw
In reply to Arjan van de Ven
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 8 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in

the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

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 a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

Thanx, Paul

Quoted 6 lines
Signature · 4 lines
-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#141 lore raw
In reply to Arjan van de Ven
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 8 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in

the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

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 a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

Thanx, Paul

Quoted 6 lines
Signature · 4 lines
-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#182 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

there are two cgroup solutions in discussion at this point.

weeks ago there was the suggestion to put non-privilaged tasks in a cgroup so that they could be frozen as a group. I thought the problem there was that there can be user-space dpendancies that would prevent privilaged tasks from working.

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

David Lang

#138 lore raw
In reply to Arve Hjønnevåg
Quoted 60 lines · Arve Hjønnevåg
Quoted 47 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1.    Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

Quoted 6 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

Quoted 9 lines

3.    The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 11 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Quoted 6 lines

I disagree. On the msm platform the low level timer that brings us out of the low power state is the same for idle and suspend. The difference is where which kernel api the request comes from. In idle, the next event on the clockevents device is usually the first event. In suspend the generic kernel timekeeping code cancels this event and the rtc wakeup event remains.

OK, good point. This choice of kernel APIs governs what I was calling "policy".

Thanx, Paul

#139 lore raw
In reply to Arve Hjønnevåg
Quoted 60 lines · Arve Hjønnevåg
Quoted 47 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1.    Deep idle states are entered only if there are no runnable tasks. In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

Quoted 6 lines

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 a deep idle state.  For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

Quoted 9 lines

3.    The system comes out of a deep idle state when a timer expires.  In contrast, timers cannot expire while the system is suspended.  (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter.  Others disagree.  The resulting discussions have produced much heat, but little light.  Such is life.)

Quoted 11 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Quoted 6 lines

I disagree. On the msm platform the low level timer that brings us out of the low power state is the same for idle and suspend. The difference is where which kernel api the request comes from. In idle, the next event on the clockevents device is usually the first event. In suspend the generic kernel timekeeping code cancels this event and the rtc wakeup event remains.

OK, good point. This choice of kernel APIs governs what I was calling "policy".

Thanx, Paul

#107 lore raw
In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 6 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 5 lines · Arve Hj?nnev?g
Quoted 4 lines

2010/8/3 <[email protected]>:

Quoted 2 lines · Arve Hj?nnev?g

...

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

It would be much better if you gave specific examples. Because, for instance, I'm not sure what platforms you have in mind.

I gave examples in other messages that included dimming/turning off the screen and spinning down the disk among others.

the definition of 'transparently' was then clarified to not mean transparent to the user, but transparent (except for possibly delays) to the applications (they may have to wait for the disk to spin up for example)

Quoted 37 lines
Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

Quoted 4 lines

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Quoted 9 lines

This isn't sounding quite right to me. I've seen too many discussions about things like idle and USB devices/hubs/drives/etc getting powered down for power savings modes to make me readily accept that everything must be as transparent as you imply. Just the case of drive spin-down shows that it's possible to do things that would be considered destructive, but you have to have a flag and wake-up path to recover within a 'reasonable' amount of time (I guess that this could be 'transparent' if that only implies that things must work eventually, which isn't what I read into the statement)

Well, consider a single character device and suppose there is an application talking to the driver using read(), write(), ioctl(), whatever. Now suppose you want to put the device into a low-power state such that the device can't do the I/O in that state. You need to ensure that the app won't be able to reach the device while in that state and you can (1) arrange things so that the device is put into the full-power state whenever the app tries to access it and (2) "freeze" the app so that it won't try to access the device being in the low-power state.

Quoted 2 lines

Generally speaking (1) is what idle (and any other form of runtime PM) does and
(2) is what suspend does with respect to the whole system.

makes sense

Quoted 5 lines

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.

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.

In addition, there are input devices like a touchscreen that could be disabled even short of a full suspend, as long as there is some way to get them reactivated.

Quoted 5 lines

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and how much userspace interaction is needed. If the kernel can disable the hardware in the driver (so that it can wake it up again when accessed by an application) it would seem that this isn't a problem.

David Lang

#183 lore raw
In reply to [email protected]
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

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.

Signature · 1 line
Matthew Garrett | [email protected]
#184 lore raw
In reply to [email protected]
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

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.

Signature · 1 line
Matthew Garrett | [email protected]
#185 lore raw
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

as I said last night in an e-mail to Arve

Quoted 14 lines

it's possible that I'm making false assumptions about how quickly you want to go into full suspend mode.

if a user is doing nothing that would warrent wakelocks, but has an unprivilaged application running (a dancing cows game), and is doing nothing other than occasionally hitting a button, how short is the timeout that you would set that would have the system go into suspend? (i.e. how frequently must the user do something to keep the system awake)

or let's use a better example, the user has an unprivilaged book-reader application, how quickly must they change pages to prevent the system from suspending?

Quoted 6 lines

I'm figuring that these times are in the 1-5 minute range.

therefor the timeout period I am mentioning above could easily be one wakeup every 40-50 seconds. that is not going to kill your idle power.

is my assumption about the length of the timeout incorrect?

David Lang

#186 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

as I said last night in an e-mail to Arve

Quoted 11 lines

it's possible that I'm making false assumptions about how quickly you want to go into full suspend mode.

if a user is doing nothing that would warrent wakelocks, but has an unprivilaged application running (a dancing cows game), and is doing nothing other than occasionally hitting a button, how short is the timeout that you would set that would have the system go into suspend? (i.e. how frequently must the user do something to keep the system awake)

or let's use a better example, the user has an unprivilaged book-reader application, how quickly must they change pages to prevent the system from suspending?

I'm figuring that these times are in the 1-5 minute range.

therefor the timeout period I am mentioning above could easily be one wakeup every 40-50 seconds. that is not going to kill your idle power.

is my assumption about the length of the timeout incorrect?

David Lang

#187 lore raw
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.The second is that the incoming network packet causes the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

Signature · 1 line
Matthew Garrett | [email protected]
#188 lore raw
In reply to [email protected]
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.The second is that the incoming network packet causes the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

Signature · 1 line
Matthew Garrett | [email protected]
#189 lore raw
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

David Lang

#190 lore raw
In reply to Matthew Garrett
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

David Lang

#536 lore raw

Attempted summary of suspend-blockers LKML thread, take two

In reply to Paul E. McKenney

Continuing to rush in where angels fear to tread...

This is an updated version of my list posted a couple of days ago at
http://lkml.org/lkml/2010/7/31/73. Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions.

Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve my understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.

But first I am going to look at nomenclature, as it appears to me that at least some of the flamage was due to conflicting definitions.

Ducking into the nearest bunker to avoid the hailstorm of frozen fish...

Thanx, Paul

------------------------------------------------------------------------

DEFINITIONS

These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing. I have also added a section entitled "CATEGORIES OF APPLICATION BEHAVIOR" based on a suggestion from James Bottomley.

o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".

Assuming I have correctly guessed what the Android guys were thinking of, perhaps "power-oblivious applications" would be a better description, which I will use until someone convinces me otherwise.

o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.

Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.

o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.

o Individual devices in an embedded system can enter "device
low-power states" when not in use.

o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.

o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in the the current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":

1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)

Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.

2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled normally when idle.

3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.

CATEGORIES OF APPLICATION BEHAVIOR

There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?

These categories are discussed below.

o What degree of control is an application permitted over its
own behavior?

The Linux kernel already has many controls over application behavior:

o the CAP_ capabilities from include/linux/capability.h.

o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.

o The chroot() system call limits a process's access to the
specified subtree of the filesystem.

o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.

o The mlockall() system call provides privileged access
to memory, avoiding page-fault overhead.

But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the ire towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.

After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT.

o What degree of control is an application permitted over the power
state of individual devices within the system?

Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.

o What degree of control is an application permitted over the
system sleep state?

Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?

o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?

See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.

REQUIREMENTS

o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.

o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.

o If the display is powered off, there is no need to run any
application whose only effect is to update the display.

Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.

There might well be similar requirements for other output-only devices, as suggested by Alan Stern.

o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.

In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.

Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. Of course, the response latency to such input events can be unbounded.

o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.

o Statistics of the power-control actions taken by PM-driving
applications must be provided. Given the current Android
implementation, the suspend blockers are manipulated via ioctl(), so that a given application's activity can be tracked via the suspend-blocker device, which remains open throughout the application's lifetime. Statistics are aggregated by name, which is passed by the application in through the suspend-blocker interface.

o PM-driving applications can make use of power-oblivious
infrastructure. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure is permitted to run when a PM-driving application needs it to run.

o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)

In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.

o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.

o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.

o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).

o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)

o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.

o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.

o The current Android userspace API must be supported in order
to support existing device software.

o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)

NICE-TO-HAVES

o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.

There are two obstacles to meeting this requirement:

1. There must be a reliable way to identify such
applications. This should be doable, for example the application might be tagged by its developer.

2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.

Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful.

o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.

APPARENT NON-REQUIREMENTS

o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that this will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)

That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.

o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.

o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. (One can argue that suspend blockers will aggregate timers after a sufficiently long suspension, but they would not necessarily stay aggregated during the wakeup period without some other mechanism helping out.)

SUGGESTED USAGE

These are constraints that the developer is expected to abide by, "for best results" and all that.

o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.

POWER-OPTIMIZED APPLICATIONS

A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.

Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.

If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.

Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).

There are a number of ways to achieve this:

1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.

2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.

3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.

4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.

5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.

6. Your favorite solution here.

Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.

OTHER EXAMPLE APPLICATIONS

GPS application that silently displays position.

There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.

GPS application that alerts the user when a given location is reached.

This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.

I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.

Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.

MP3 playback.

This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.

Bouncing cows.

This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.

ACKNOWLEDGMENTS

Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)

Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.

Alan Stern
Arjan van de Ven
Arve Hjønnevåg
David Brownell
David Lang
Florian Mickler
James Bottomley
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Rafael J. Wysocki
Ted Ts'o

#537 lore raw

Attempted summary of suspend-blockers LKML thread, take two

In reply to Paul E. McKenney

Continuing to rush in where angels fear to tread...

This is an updated version of my list posted a couple of days ago at
http://lkml.org/lkml/2010/7/31/73. Again, this email is an attempt to present the Android guys' requirements, based on my interpretation of LKML discussions.

Please note that I am not proposing a solution that meets these requirements, nor am I attempting to judge the various proposed solutions. In fact, I am not even trying to judge whether the requirements are optimal, or even whether or not they make sense at all. My only goal at the moment is to improve my understanding of what the Android folks' requirements are. That said, I do discuss example mechanisms where needed to clarify the meaning of the requirements. This should not be interpreted as a preference for any given example mechanism.

But first I am going to look at nomenclature, as it appears to me that at least some of the flamage was due to conflicting definitions.

Ducking into the nearest bunker to avoid the hailstorm of frozen fish...

Thanx, Paul

------------------------------------------------------------------------

DEFINITIONS

These have been updated based on LKML and linux-pm discussions. The names are probably still sub-optimal, but incremental progress is nevertheless a very good thing. I have also added a section entitled "CATEGORIES OF APPLICATION BEHAVIOR" based on a suggestion from James Bottomley.

o "Ill-behaved application" AKA "untrusted application" AKA
"crappy application". The Android guys seem to be thinking in terms of applications that are well-designed and well-implemented in general, but which do not take power consumption or battery life into account. Examples include applications designed for externally powered PCs. Many other people seemed to instead be thinking in terms of an ill-conceived or useless application, perhaps exemplified by "bouncing cows".

Assuming I have correctly guessed what the Android guys were thinking of, perhaps "power-oblivious applications" would be a better description, which I will use until someone convinces me otherwise.

o "PM-driving application" are applications that are permitted
to acquire suspend blockers on Android. Verion 8 of the suspend-blocker patch seems to use group permissions to determine which applications are classified as power aware. More generally, PM-driving applications seem to be those that have permission to exert some control over the system's sleep state.

Note that an application might be power-oblivious on one Android device and PM-driving on another, depending on whether the user allows that application to acquire suspend blockers. The classification might even change over time. For example, a user might give an application PM-driving status initially, but change his or her mind after some experience with that application.

o Oddly enough, "power-optimized applications" were not discussed.
See "POWER-OPTIMIZED APPLICATIONS" below for a brief introduction. The short version is that power-optimized applications are those PM-driving applications that have been aggressively tuned to reduce power consumption.

o Individual devices in an embedded system can enter "device
low-power states" when not in use.

o The system as a whole can enter a "system sleep state" when
the system as a whole is not in use. Suspend blockers are about system sleep states rather than device low-power states.

o There was much discussion of "idle" (AKA "deep idle") and
"suspend" (as in the the current Linux-kernel suspend operations). The following characteristics distinguish "idle" from "suspend":

1. Idle states are entered by a given CPU only there are no
runnable tasks for that CPU. In contrast, opportunistic suspend can halt the entire system even when there are tasks that are ready, willing, and able to run. (But please note that this might not apply to real-time tasks.)

Freezing of subsets of applications is somewhat related to the idle/suspend discussion, but is covered in a later section of this document.

2. There can be a set of input events that do not bring
the system out of suspend, but which would bring the system out of idle. Exactly which events are in this set depends both on hardware capabilities and on the platform/application policy. For example, on one of the Android-based smartphones, touchscreen input is ignored when the system is suspended, but is handled normally when idle.

3. The system comes out of idle when a timer expires. In
contrast, timers might or might not bring the system out of suspend, depending on both hardware capabilities and platform/application policy.

CATEGORIES OF APPLICATION BEHAVIOR

There are a number of categories of application behavior with respect to power management and energy efficiency. These can be classified via the following questions: (1) What degree of control is an application permitted over its own behavior? (2) What degree of control is an application permitted over the power state of individual devices within the system? (3) What degree of control is an application permitted over the system sleep state? (4) To what degree has the application been tuned to reduce its power consumption, either in isolation or in conjunction with other applications that might be running concurrently?

These categories are discussed below.

o What degree of control is an application permitted over its
own behavior?

The Linux kernel already has many controls over application behavior:

o the CAP_ capabilities from include/linux/capability.h.

o Processes can be assigned to multiple groups, allowing
them privileged access to portions of the filesystem.

o The chroot() system call limits a process's access to the
specified subtree of the filesystem.

o The ulimit facility can limit CPU consumption, number
of processes, memory, etc. on a per-user basis. The rlimit facility has similar effects on a per-process basis.

o The mlockall() system call provides privileged access
to memory, avoiding page-fault overhead.

But more relevant to this discussion, real-time processes are permitted a much higher degree of control over the timing of their execution than are non-real-time processes. However, suspending the system destroys any pretense of offering real-time guarantees, which might explain much of the ire towards suspend blockers from the real-time and scheduler folks. For but one example, Peter Zijlstra suggested that he would merge a patch that acquired a suspend blocker any time that the runqueues were non-empty. My first reaction was amusement at this vintage Peter Zijlstra response, and my second reaction was that it was a futile gesture, as the Android guys would simply back out any such change.

After more thought, however, a variation of Peter's approach might well be the key to resolving this tension between real-time response on the one hand and Android's desire to conserve power at any cost on the other. Given that suspending destroys real-time response, why not acquire a suspend blocker any time there is a user-created real-time task in the system, whether runnable or not? Of course, a simpler approach would be to make Android's OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT.

o What degree of control is an application permitted over the power
state of individual devices within the system?

Is the application in question permitted to power down the CPU or peripheral devices? As more of the power control is automated based on usage, it is possible that this question will become less relevant. The longer the latency and the greater the energy consumption of a power-up/power-down sequence for a given device, the less suitable that device is for automatic power-up/power-down decisions. Cache SRAMs and main-memory DRAM tend to be less suitable for automation for this reason.

o What degree of control is an application permitted over the
system sleep state?

Is the application permitted to suspend the device? Or in the case of Android, is the application permitted to acquire a suspend blocker, which prevents the device from being suspended?

o To what degree has the application been tuned to reduce its
power consumption, either in isolation or in conjunction with other applications that might be running concurrently?

See the "POWER-OPTIMIZED APPLICATIONS" section below for more detail on the lengths that embedded developers go to in order to conserve power -- or, more accurately, to extend battery life.

REQUIREMENTS

o Reduce the system's power consumption in order to (1) extend
battery life and (2) preserve state until external power can be obtained.

o It is necessary to be able to use power-oblivious applications.
Many of these applications were designed for use in PC platforms where power consumption has historically not been of great concern, due to either (1) the availability of external power or
(2) relatively undemanding laptop battery-lifetime expectations. The system must be capable of running these power-oblivious applications without requiring that these applications be modified, and must be capable of reasonable power efficiency even when power-oblivious applications are in use.

o If the display is powered off, there is no need to run any
application whose only effect is to update the display.

Although one could simply block such an application when it next tries to access the display, it appears that it is highly desirable that the application also be prevented from consuming power computing anything that will not be displayed. Furthermore, whatever mechanism is used must operate on power-oblivious applications that do not use blocking system calls.

There might well be similar requirements for other output-only devices, as suggested by Alan Stern.

o In order to avoid overrunning hardware and/or kernel buffers,
and to minimize response latencies, designated input events must be delivered to the corresponding application in a timely fashion. The application might or might not be required to actually process the events in a timely fashion, depending on the specific application.

In particular, if user input that would prevent the system from entering a sleep state is received while the system is transitioning into a sleep state, the system must transition back out of the sleep state so that it can hand the user input off to the corresponding application.

Other input events do not force a wakeup, and such input events -can- be lost due to buffer overflow in hardware or the kernel. Of course, the response latency to such input events can be unbounded.

o The API must provide a way for PM-driving applications that
receive events to keep themselves running until they have been able to process those events.

o Statistics of the power-control actions taken by PM-driving
applications must be provided. Given the current Android
implementation, the suspend blockers are manipulated via ioctl(), so that a given application's activity can be tracked via the suspend-blocker device, which remains open throughout the application's lifetime. Statistics are aggregated by name, which is passed by the application in through the suspend-blocker interface.

o PM-driving applications can make use of power-oblivious
infrastructure. This means that a PM-driving application must have some way, whether explicit or implicit, to ensure that any power-oblivious infrastructure is permitted to run when a PM-driving application needs it to run.

o If no PM-driving or power-optimized application are indicating
a need for the system to remain operating, the system is permitted (even encouraged!) to suspend all execution, regardless of the
state of power-oblivious applications. (This requirement did
appear to be somewhat controversial, both in terms of what is meant by "runnable" and in terms of what constitutes "execution".)

In Android, this is implemented by suspending even while PM-driving or power-optimized applications are active, -unless- a suspend blocker is held.

o Transition to system sleep state must be power-efficient.
In particular, methods based on repeated attempts to suspend are considered to be too inefficient to be useful.

o Individual peripherals and CPUs must still use standard
power-conservation measures, for example, transitioning CPUs into low-power states on idle and powering down peripheral devices and hardware accelerators that have not been recently used.

o The API that controls the system sleep state must be accessible
both from Android's Java replacement, from userland C code, and from kernel C code (both process level and irq code, but not NMI handlers).

o The API that controls the system sleep state must operate
correctly on SMP systems of modest size. (My guess is that "modest" means up to four CPUs, maybe up to eight CPUs.)

o Any QoS-based solution must take display and user-input
state into account. In other words, the QoS must be expressed as a function of the display and the user-input states.

o Transitioning to extremely low-power sleep states requires saving
and restoring DRAM and/or cache SRAM state, which in itself consumes significant energy. The power savings must therefore be balanced against the energy consumed in the state transitions.

o The current Android userspace API must be supported in order
to support existing device software.

o Any mechanism that freezes some subset of the applications must
ensure that none of the frozen applications hold any user-level resources, such as pthread mutexes. The reason for this is that freezing an application that holds a shared pthread mutex will result in an application-level hang should some unfrozen process attempt to acquire that same pthread mutex. Note that although the current cgroup freezer ensures that frozen applications do not hold any kernel-level mutexes (at least assuming these mutexes are not wrongly held when returning to user-level execution), it currently does nothing to prevent freezing processes holding pthread mutexes. (There are some proposals to address this issue.)

NICE-TO-HAVES

o It would be nice to be able to identify power-oblivious
applications that never were depended on by PM-driving applications. This particular class of power-oblivious applications could be shut down when the screen blanks even if some PM-driving application was preventing the system from powering down.

There are two obstacles to meeting this requirement:

1. There must be a reliable way to identify such
applications. This should be doable, for example the application might be tagged by its developer.

2. There must be a reliable way to freeze them such
that no frozen application holds a resource that might be contended by a non-frozen application.

Although the cgroup freezer does ensure that frozen tasks hold no kernel-level resources, it currently does nothing to ensure that no user-level resources are held. There are some alternative proposals, which might or might not be more successful.

o Any initialization of the API that controls the system power
state should be unconditional, so as to be free from failure. Such unconditional initialization reduces the intrusiveness of the Android patchset.

APPARENT NON-REQUIREMENTS

o Transitioning to system sleep states need not be highly scalable,
as evidenced by the global locks. (If you believe that this will in fact be required, please provide a use case. But please understand that I do know something about scalability trends, but also about uses for transistors beyond more cores.)

That said, it should not be hard to provide a highly scalable implementation of suspend blockers, especially if large systems are allowed to take their time suspending themselves.

o Conserving power in the WiFi and cellular telephony networks.
At the moment, the focus is on increased battery life in the handheld device, perhaps even at the expense of additional power consumed by the externally powered WiFi and cell-telephony equipment.

o Synchronizing wakeups of unrelated applications. This is of
course an important requirement for power savings overall, but seems to be left to other mechanisms (e.g., timer aggregation) by the Android folks. (One can argue that suspend blockers will aggregate timers after a sufficiently long suspension, but they would not necessarily stay aggregated during the wakeup period without some other mechanism helping out.)

SUGGESTED USAGE

These are constraints that the developer is expected to abide by, "for best results" and all that.

o When a PM-driving application is preventing the system from
shutting down, and is also waiting on a power-oblivious application, the PM-driving application should set a timeout to handle the possibility that the power-oblivious application might halt or otherwise fail.

POWER-OPTIMIZED APPLICATIONS

A typical power-optimized application manually controls the power state of many separately controlled hardware subsystems to minimize power consumption. Such optimization normally requires an understanding of the hardware and of the full system's workload: strangely enough, concurrently running two separately power-optimized applications often does -not- result in a power-optimized system. Such optimization also requires knowledge of what the application will be doing in the future, so that needed hardware subsystems can be proactively powered up just when the application will need them. This is especially important when powering down cache SRAMS or banks of main memory, because such components take significant time (and consume significant energy) when preparing them to be powered off and when restoring their state after powering them on.

Consider an MP3 player as an example. Such a player will periodically read MP3-encoded data from flash memory, decode it (possibly using hardware acceleration), and place the resulting audio data into main memory. Different systems have different ways of getting the data from main memory to the audio output device, but let's assume that the audio output device consumes data at a predictable rate such that the software can use timers to schedule refilling of the device's output buffer. The timer duration will of course need to allow for the time required to power up the CPU and L2 cache. The timer can be allowed to happen too soon, albeit with a battery-lifetime penalty, but cannot be permitted to happen too late, as this will cause "skips" in the playback.

If MP3 playback is the only application running in the system, things are quite easy. We calculate when the audio output device will empty its buffer, allow a few milliseconds to power up the needed hardware, and set a timer accordingly. Because modern audio output devices have buffers that can handle roughly a second's worth of output, it is well worthwhile to spend the few milliseconds required to flush the cache SRAMS in order to put the system into an extremely low-power sleep state over the several hundred milliseconds of playback.

Now suppose that this device is also recording audio -- perhaps the device is being used to monitor an area for noise pollution, and the user is also using the device to play music via earphones. The audio input process will be the inverse of the audio output process: the microphone data will fill a data buffer, which must be collected into DRAM, then encoded (perhaps again via MP3) and stored into flash. It would be easy to create an optimal application for audio input, but running this optimal audio input program concurrently with the optimal audio playback program would not necessarily result in a power-optimized combination. This lack of optimality is due to the fact that the input and output programs would each burn power separately powering down and up. In contrast, an optimal solution would align the input and output programs' timers so that a single power-down/power-up event would cover both programs' processing. This would trade off optimal processing of each (for example, by draining the input buffer before it was full) in order to attain global optimality (by sharing power-down/power-up overhead).

There are a number of ways to achieve this:

1. Making the kernel group timers that occur at roughly the same
time, as has been discussed on this list many times. This can work in many cases, but can be problematic in the audio example, due to the presence of hard deadlines.

2. Write the programs to be aware of each other, so that each
adjusts its behavior when the other is present. This seems to be current practice in the battery-powered embedded arena, but is quite complex, sensitive to both hardware configuration and software behavior, and requires that all combinations of programs be anticipated by the designer -- which can be a serious disadvantage given today's app stores.

3. Use new features such as range timers, so that each program
can indicate both its preference and the degree of flexibility that it can tolerate. This also works in some cases, but as far as I know, current proposals do not allow the kernel to take power-consumption penalties into account.

4. Provide "heartbeat" services that allow applications to
synchronize with each other. This seems most applicable for applications that run infrequently, such as email-checking and location-service applications.

5. Use of hardware facilities that allow DMA to be scheduled across
time. This would allow the CPU to be turned on only for decode/encode operations. I am under the impression that this sort of time-based DMA hardware does exist in the embedded space and that it is actually used for this purpose.

6. Your favorite solution here.

Whatever solution is chosen, the key point to keep in mind is that running power-optimized applications in combination does -not- result in optimal system behavior.

OTHER EXAMPLE APPLICATIONS

GPS application that silently displays position.

There is no point in this application consuming CPU cycles or in powering up the GPS hardware unless the display is active. Such an application could be handled by the Android suspend-blocker proposal. Of course, such an application could also periodically poll the display, shutting itself down if the display is inactive. In this case, it would also need to have some way to be reactivated when the display comes back on.

GPS application that alerts the user when a given location is reached.

This application should presumably run even when the display is powered down due to input timeout. The question of whether or not it should continue running when the device is powered off is an interesting one that would be likely to spark much spirited discussion. Regardless of the answer to this question, the GPS application would hopefully run very intermittently, adjusting the delay interval based on the device's velocity and distance from the location in question.

I don't know enough about GPS hardware to say under what circumstances the GPS hardware itself should be powered off. However, my experience indicates that it takes significant time for the GPS hardware to get a position fix after being powered on, so presumably this decision would also be based on device velocity and distance from the location in question.

Assuming that the application can run only intermittently, suspend blockers would work reasonably well for this use case. If the application needed to run continuously, battery life would be quite short regardless of the approach used.

MP3 playback.

This requires a PM-driving (and preferably a power-optimized) application. Because the CPU need only run intermittently, suspend blockers can handle this use case. Presumably switching the device off would halt playback.

Bouncing cows.

This can work with a power-oblivious application that is shut down whenever the display is powered off or the device is switched off, similar to the GPS application that silently displays position.

ACKNOWLEDGMENTS

Of course, just because I acknowledge their contributions does not necessarily mean that I think they agree with my assessment of the requirements behind suspend blockers. ;-)

Nevertheless, I am grateful for any and all feedback, whatever the form of that feedback might be. I am new to this area, and have much to learn.

Alan Stern
Arjan van de Ven
Arve Hjønnevåg
David Brownell
David Lang
Florian Mickler
James Bottomley
Mikael Abrahamsson
Olivier Galibert
Paul Menage
Rafael J. Wysocki
Ted Ts'o

#191 lore raw
In reply to [email protected]
Quoted 2 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

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

Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

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

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

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

Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

Signature · 1 line
Matthew Garrett | [email protected]
#201 lore raw
In reply to [email protected]
Quoted 30 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

Thanx, Paul

#202 lore raw
In reply to [email protected]
Quoted 30 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

Thanx, Paul

#108 lore raw
In reply to [email protected]
Quoted 77 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 6 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 5 lines · Arve Hj?nnev?g
Quoted 4 lines

2010/8/3 <[email protected]>:

Quoted 2 lines · Arve Hj?nnev?g

...

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

It would be much better if you gave specific examples. Because, for instance, I'm not sure what platforms you have in mind.

I gave examples in other messages that included dimming/turning off the screen and spinning down the disk among others.

the definition of 'transparently' was then clarified to not mean transparent to the user, but transparent (except for possibly delays) to the applications (they may have to wait for the disk to spin up for example)

Quoted 37 lines
Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

Quoted 4 lines

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Quoted 9 lines

This isn't sounding quite right to me. I've seen too many discussions about things like idle and USB devices/hubs/drives/etc getting powered down for power savings modes to make me readily accept that everything must be as transparent as you imply. Just the case of drive spin-down shows that it's possible to do things that would be considered destructive, but you have to have a flag and wake-up path to recover within a 'reasonable' amount of time (I guess that this could be 'transparent' if that only implies that things must work eventually, which isn't what I read into the statement)

Well, consider a single character device and suppose there is an application talking to the driver using read(), write(), ioctl(), whatever. Now suppose you want to put the device into a low-power state such that the device can't do the I/O in that state. You need to ensure that the app won't be able to reach the device while in that state and you can (1) arrange things so that the device is put into the full-power state whenever the app tries to access it and (2) "freeze" the app so that it won't try to access the device being in the low-power state.

Quoted 2 lines

Generally speaking (1) is what idle (and any other form of runtime PM) does and
(2) is what suspend does with respect to the whole system.

makes sense

Quoted 5 lines

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

Quoted 3 lines

In addition, there are input devices like a touchscreen that could be disabled even short of a full suspend, as long as there is some way to get them reactivated.

That's correct again, but it doesn't matter too much as far as the difference between "deep idle" and suspend is concerned. These devices are generally not the interrupt sources that are difficult to shut down safely in the "idle" case.

Quoted 10 lines
Quoted 5 lines

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and how much userspace interaction is needed. If the kernel can disable the hardware in the driver (so that it can wake it up again when accessed by an application) it would seem that this isn't a problem.

Well, I guess it's useful to consider the sequence of events in the "idle" case.

We first detect that a CPU is idle, so it can be put into a C-state (or equivalent). It's easy to put that CPU into such a state, but suppose we want to do more and put all devices into low-power states at that point. We have to ensure that there are no devices in the middle of DMA and that the other CPUs are idle (that's kind of easy, but still). Next, we have to figure out the right ordering in which to put devices into low-power states (that is not trivial, because the tasks that use those devices may depend on each other in various ways). If we decide to shut down clock source interrupts, we must ensure that the timekeeping will be correct after that and so on. Moreover, things get ugly if there are shared interrupts.

Suspend kind of works around these difficulties by taking the entire user space out of the picture with one big sledgehammer called the freezer, but these problems would have to be actually _solved_ in the "idle" case.

Thanks,
Rafael

#109 lore raw
In reply to [email protected]
Quoted 77 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 10 lines · Rafael J. Wysocki
Quoted 8 lines · On Wednesday, August 04, 2010, [email protected] wrote:
Quoted 6 lines · Arve Hj?nnev?g

2010/8/3 <[email protected]>:

Quoted 5 lines · Arve Hj?nnev?g
Quoted 4 lines

2010/8/3 <[email protected]>:

Quoted 2 lines · Arve Hj?nnev?g

...

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

The hardware specific idle hook can (and does) decide to go into any power state from idle that does not disrupt any active devices.

This I know is an Andoid specific thing. On other platforms power states very definantly can make user visible changes.

It would be much better if you gave specific examples. Because, for instance, I'm not sure what platforms you have in mind.

I gave examples in other messages that included dimming/turning off the screen and spinning down the disk among others.

the definition of 'transparently' was then clarified to not mean transparent to the user, but transparent (except for possibly delays) to the applications (they may have to wait for the disk to spin up for example)

Quoted 37 lines
Quoted 18 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

How is this Android specific?

you are stating that this must be suspend because low-power idle must be transparent to the user.

It must be transparent to the rest of the system.

Quoted 5 lines

I am saying that on Linux, low-power idle commonly is not transparent to the user, so the requirement for it to be transparent (therefor putting the suspend into a different category) is an Android only requirement.

Quoted 4 lines

I'm am not talking about minor latencies. If you have a platform that for instance turns off you screen dma when entering idle, it is broken whether is running Android or not. If it does the same in suspend it is not a problem.

Quoted 9 lines

This isn't sounding quite right to me. I've seen too many discussions about things like idle and USB devices/hubs/drives/etc getting powered down for power savings modes to make me readily accept that everything must be as transparent as you imply. Just the case of drive spin-down shows that it's possible to do things that would be considered destructive, but you have to have a flag and wake-up path to recover within a 'reasonable' amount of time (I guess that this could be 'transparent' if that only implies that things must work eventually, which isn't what I read into the statement)

Well, consider a single character device and suppose there is an application talking to the driver using read(), write(), ioctl(), whatever. Now suppose you want to put the device into a low-power state such that the device can't do the I/O in that state. You need to ensure that the app won't be able to reach the device while in that state and you can (1) arrange things so that the device is put into the full-power state whenever the app tries to access it and (2) "freeze" the app so that it won't try to access the device being in the low-power state.

Quoted 2 lines

Generally speaking (1) is what idle (and any other form of runtime PM) does and
(2) is what suspend does with respect to the whole system.

makes sense

Quoted 5 lines

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

Quoted 3 lines

In addition, there are input devices like a touchscreen that could be disabled even short of a full suspend, as long as there is some way to get them reactivated.

That's correct again, but it doesn't matter too much as far as the difference between "deep idle" and suspend is concerned. These devices are generally not the interrupt sources that are difficult to shut down safely in the "idle" case.

Quoted 10 lines
Quoted 5 lines

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and how much userspace interaction is needed. If the kernel can disable the hardware in the driver (so that it can wake it up again when accessed by an application) it would seem that this isn't a problem.

Well, I guess it's useful to consider the sequence of events in the "idle" case.

We first detect that a CPU is idle, so it can be put into a C-state (or equivalent). It's easy to put that CPU into such a state, but suppose we want to do more and put all devices into low-power states at that point. We have to ensure that there are no devices in the middle of DMA and that the other CPUs are idle (that's kind of easy, but still). Next, we have to figure out the right ordering in which to put devices into low-power states (that is not trivial, because the tasks that use those devices may depend on each other in various ways). If we decide to shut down clock source interrupts, we must ensure that the timekeeping will be correct after that and so on. Moreover, things get ugly if there are shared interrupts.

Suspend kind of works around these difficulties by taking the entire user space out of the picture with one big sledgehammer called the freezer, but these problems would have to be actually _solved_ in the "idle" case.

Thanks,
Rafael

#480 lore raw
In reply to Matthew Garrett

Hi!

Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
Pavel

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

Hi!

Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#127 lore raw
In reply to Paul E. McKenney
Quoted 108 lines · Paul E. McKenney
Quoted 98 lines · Arve Hjønnevåg
Quoted 71 lines · On Tue, Aug 3, 2010 at 5:51 PM, <[email protected]> wrote:
Quoted 43 lines · Paul E. McKenney
Quoted 42 lines · On Tue, Aug 03, 2010 at 04:19:25PM -0700, [email protected] wrote:
Quoted 11 lines · Arve Hj?nnev?g

2010/8/2 <[email protected]>:

Quoted 9 lines

so what is the fundamental difference between deciding to go into low-power
idle modes to wake up back up on a given point in the future and deciding
that you are going to be idle for so long that you may as well suspend until
there is user input?

Quoted 5 lines

Low power idle modes are supposed to be transparent. Suspend stops the monotonic clock, ignores ready threads and switches over to a separate set of wakeup events/interrupts. We don't suspend until there is user input, we suspend until there is a wakeup event (user-input, incoming network data/phone-calls, alarms etc..).

s/user input/wakeup event/ and my question still stands.

low power modes are not transparent to the user in all cases (if the screen backlight dimms/shuts off a user reading something will notice, if the system switches to a lower clock speed it can impact user response time, etc) The system is making it's best guess as to how to best srve the user by sacraficing some capibilities to save power now so that the power can be available later.

as I see it, suspending until a wakeup event (button press, incoming call, alarm, etc) is just another datapoint along the same path.

If the system could not wake itself up to respond to user input, phone call, alarm, etc and needed the power button pressed to wake up (or shut down to the point where the battery could be removed and reinstalled a long time later), I would see things moving into a different category, but as long as the system has the ability to wake itself up later (and is still consuming power) I see the suspend as being in the same category as the other low-power modes (it's just more expensive to go in and out of)

Quoted 4 lines
Quoted 2 lines

why should the suspend be put into a different category from the other low-power states?

OK, I'll bite...

thanks, this is not intended to be a trap.

Quoted 5 lines

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable tasks.
In contrast, opportunistic suspend can happen even when there are tasks that are ready, willing, and able to run.

Ok, this is a complication to what I'm proposing (and seems a little odd, but I can see how it can work), but not neccessarily a major problem. it depends on exactly how the decision is made to go into low power states and/or suspend. If this is done by an application that is able to look at either all activity or ignore one cgroup of processes at different times in it's calculations than this would work.

Quoted 5 lines

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 a deep idle state. For example, I believe that it was stated that one of the Android-based smartphones ignores touchscreen input while suspended, but pays attention to it while in deep idle states.

Quoted 6 lines

I see this as simply being a matter of what devices are still enabled at the different power savings levels. At one level the touchscreen is still powered, while at another level it isn't, and at yet another level you have to hit the power soft-button. This isn't fundamentally different from powering off a USB peripheral that the system decides is idle (and then not seeing input from it until something else wakes the system)

The touchscreen on android devices is powered down long before we suspend, so that is not a good example. There is still a significant difference between suspend and idle though. In idle all interrupts work, in suspend only interrupts that the driver has called enable_irq_wake on will work (on platforms that support it).

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 3 lines

if you have the ability to wake for an alarm, you have the ability to wake for a timer (if from no other method than to set the alarm to when the timer tick would go off)

Quoted 8 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Quoted 3 lines

Hmmm... The bit about the monotonic clock not advancing could help explain at least some of the heartburn from the scheduler and real-time folks. ;-)

I think that indeed is the case, although they haven't expressed that directly yet (at least not that I know of :-)).

Quoted 13 lines

My guess is that this is not a problem for Android workloads, which probably do not contain aggressive real-time components. (With the possible exception of interactions with the cellphone network, which I believe are handled by a separate core with separate OS.) However, pulling this into the Linux kernel would require that interactions with aggressive real-time workloads be handled, one way or another.

I can see a couple possible resolutions:

1. Make OPPORTUNISTIC_SUSPEND depend on !PREEMPT_RT, so that
opportunistic suspend simply doesn't happen on systems that support aggressive real-time workloads.

Quoted 9 lines

2. Allow OPPORTUNISTIC_SUSPEND and PREEMPT_RT, but suppress
opportunistic suspend when there is a user-created real-time process. One way to handle this would be with a variation on a tongue-in-cheek suggestion from Peter Zijlstra, namely to have every real-time process hold a wakelock. Note that such a wakelock would need to be held even if the real-time process in question was not runnable, in order to meet possible real-time deadlines when the real-time process was awakened.

I guess the scheduler itself would need to hold that wakelock.

Quoted 3 lines

3. Your proposal here. ;-)

Thoughts?

The case when there's a real-time process that's not using its time slices (because it doesn't have anything to do) seems to be hard. You'd probably want to suspend in that case, but then meeting the real-time deadlines would be kind of unrealistic ...

Thanks,
Rafael

#142 lore raw
In reply to Paul E. McKenney
Quoted 73 lines · Paul E. McKenney
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

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 a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Quoted 6 lines

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

That's correct IMO.

Thanks,
Rafael

#143 lore raw
In reply to Paul E. McKenney
Quoted 73 lines · Paul E. McKenney
Quoted 11 lines · Arjan van de Ven
Quoted 8 lines · On Tue, 3 Aug 2010 17:10:15 -0700 "Paul E. McKenney"…

OK, I'll bite...

Quoted 1 line

From an Android perspective, the differences are as follows:

1. Deep idle states are entered only if there are no runnable
tasks. In contrast, opportunistic suspend can happen even when there
are tasks that are ready, willing, and able to run.

Quoted 6 lines

for "system suspend", this is an absolutely valid statement. for "use suspend as idle state", it's not so clearly valid. (but this is sort of a separate problem, basically the "when do we freeze the tasks that we don't like for power reasons" problem, which in first order is independent on what kind of idle power state you pick, and discussed extensively elsewhere in this thread)

From what I can see, the Android folks are are using "suspend" in the "system suspend" sense.

I agree that the proposals for freezing subsets of the tasks in the system are independent of whether idle or suspend is being used. Instead, such freezing depends on (for example) whether or not the display is active.

That said, freezing subsets of tasks is a nice-to-have rather than a hard requirement for Android. Though I suspect that the appearance of a reliable way of freezing subsets of tasks just might promote this to a hard requirement. ;-)

Quoted 6 lines
Quoted 5 lines

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 a deep
idle state. For example, I believe that it was stated that
one of the Android-based smartphones ignores touchscreen input while
suspended, but pays attention to it while in deep idle states.

Quoted 11 lines

I would argue that this is both a hardware specific issue, but also a policy issue. From the user point of view, screen off with idle and screen off with suspend aren't all that different (if my phone would decide to idle rather than suspend because some app blocks suspend... I wouldn't expect a difference in behavior when I touch the screen). "Screen off -> don't honor touch after a bit" is almost an independent, but very real, policy problem (and a forced one in suspend, I'll grant you that). I could even argue that the policy decision "we don't care about the touch screen input" is a pre-condition for entering suspend (or in android speak, caring for touch screen input/having the touch screen path active would be a suspend blocker)

I agree that the subset of input events that do not bring the system out of suspend would be governed both by hardware capabilities and by policy.

Quoted 9 lines
Quoted 8 lines

3. The system comes out of a deep idle state when a timer
expires. In contrast, timers cannot expire while the system is suspended. (This one is debatable: some people argue that timers are subject to jitter, and the suspend case for timers is the same as that for deep idle states, but with unbounded timer jitter. Others disagree. The resulting discussions have produced much heat, but little light. Such is life.)

Quoted 10 lines

I'll debate it even harder in that it's platform specific whether timers can get the system out of suspend or not. Clearly on the Android platform in question that's not the case, but for some of the Intel phone silicon for example, timers CAN be wake sources to get you out of suspend just fine. It just depend on which exact hw you talk about. Generally, even if the fast timers aren't wake up sources, there'll be some sort of alarm thing that you can pre-wake.. but yes you are right in saying that's rather lame.
Either way, it's not a general property of suspend, but a property of suspend on the specific platform in question.

Quoted 6 lines

Good point, I do need to emphasize the fact that whether or not timers pull the system out of suspend also depends both on hardware and on policy. So I will change my statement to say something like "The system comes out of a deep idle state when a timer expires. In contrast, timers do not necessarily expire while the system is suspended, depending on both hardware support and platform/application policy."

That's correct IMO.

Thanks,
Rafael

#482 lore raw
In reply to Pavel Machek
Quoted 4 lines · Pavel Machek

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?

Signature · 1 line
Matthew Garrett | [email protected]
#483 lore raw
In reply to Pavel Machek
Quoted 4 lines · Pavel Machek

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?

Signature · 1 line
Matthew Garrett | [email protected]
#208 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

Thanks,
Rafael

#209 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

Thanks,
Rafael

#486 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

Quoted 5 lines
Quoted 2 lines

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

Thanx, Paul

Quoted 13 lines

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#487 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek

Hi!

Quoted 6 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

Quoted 5 lines
Quoted 2 lines

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

Thanx, Paul

Quoted 13 lines

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

(Of course, you'll also have to fix kernel timers not to beat unneccessarily often; still that's better solution that just stoping them all and then sprinkling wakelocks all over the kernel to deal with obvious bugs it introduces...)
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#210 lore raw
In reply to Matthew Garrett
Quoted 22 lines · Matthew Garrett
Quoted 8 lines · On Wed, Aug 04, 2010 at 11:30:44AM -0700, [email protected] wrote:

a couple days ago I made the suggestion to put non-privilaged tasks in a cgroup so that the idle/suspend decision code could ignore acitivity caused by this cgroup.

in the second version wakeup events would be 'activity' that would be counted and therefor the system would not be idle. As for the race with suspending and new things happening, wouldn't that be handled the same way that it is in a normal linux box?

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

Thanks,
Rafael

#211 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 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 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 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.

Signature · 1 line
Matthew Garrett | [email protected]
#212 lore raw
In reply to Rafael J. Wysocki
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 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 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 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.

Signature · 1 line
Matthew Garrett | [email protected]
#488 lore raw
In reply to Paul E. McKenney

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Quoted 6 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel

Message-ID: <[email protected]>

Arve said:

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#213 lore raw
In reply to Matthew Garrett
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 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

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

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

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

But we do need to hear from the Android guys on these points.

Thanx, Paul

#214 lore raw
In reply to Matthew Garrett
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 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

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

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

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

But we do need to hear from the Android guys on these points.

Thanx, Paul

#489 lore raw
In reply to Paul E. McKenney

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Quoted 6 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel

Message-ID: <[email protected]>

Arve said:

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#215 lore raw
In reply to Paul E. McKenney
Quoted 36 lines · Paul E. McKenney
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 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

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

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

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Quoted 6 lines

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

One can argue that once the download has been completed, the cpuidle framework should make the system reduce its energy consumption to the level achievable by using suspend.

However, the problem is the cpuidle framework only deals with CPUs right now (at least generally) and there's a problem of the interrupt sources that allow the monotonic clock to advance and are deactivated during suspend (which allows more energy to be saved, because periodic timers are then effectively disabled).

So, it seems, system suspend is necessary to maximize energy savings as long as the cpuidle framework cannot take care of I/O devices and interrupt sources in general.

Thanks,
Rafael

#216 lore raw
In reply to Paul E. McKenney
Quoted 36 lines · Paul E. McKenney
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 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

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

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

The issue with cgroup freezer as currently defined is that it can freeze processes that hold user-level resources (pthread mutexes, SysV semas, ...). If some non-frozen process attempts to acquire that resource, you get a hang. There might be some ways to work around this, for example, Arjan suggests momentarily unfreezing periodically, and I suggested doing the freeze in user-space code, but we don't know if either of these will really do what is required.

Quoted 6 lines

Also, I believe that Android's use of cgroups would be in addition to suspending fully rather than instead of. Freezing a subset of the applications allows cutting power drain from output-only apps when the screen blanks but where some app such as a download needs to keep the system active. They still would need to suspend once the download completes.

One can argue that once the download has been completed, the cpuidle framework should make the system reduce its energy consumption to the level achievable by using suspend.

However, the problem is the cpuidle framework only deals with CPUs right now (at least generally) and there's a problem of the interrupt sources that allow the monotonic clock to advance and are deactivated during suspend (which allows more energy to be saved, because periodic timers are then effectively disabled).

So, it seems, system suspend is necessary to maximize energy savings as long as the cpuidle framework cannot take care of I/O devices and interrupt sources in general.

Thanks,
Rafael

#490 lore raw
In reply to Pavel Machek
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Quoted 6 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel

Message-ID: <[email protected]>

Arve said:

Quoted 10 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.

Cheers,
Flo

#491 lore raw
In reply to Pavel Machek
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Quoted 6 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel

Message-ID: <[email protected]>

Arve said:

Quoted 10 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.

Cheers,
Flo

#494 lore raw
In reply to Pavel Machek
Quoted 7 lines · Pavel Machek
Quoted 4 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:

This is all massively system dependant. On some systems when the system is in the same idle state in the lowest power idle mode as in suspend however as a result of not doing the suspend (which causes Linux to quiesce most of the hardware) many more things will be able to generate wake events. On other systems you will achieve a lower power state by using suspend for various reasons, some fixable and some not. I rather suspect Arve was talking about the former case.

#495 lore raw
In reply to Pavel Machek
Quoted 7 lines · Pavel Machek
Quoted 4 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:

This is all massively system dependant. On some systems when the system is in the same idle state in the lowest power idle mode as in suspend however as a result of not doing the suspend (which causes Linux to quiesce most of the hardware) many more things will be able to generate wake events. On other systems you will achieve a lower power state by using suspend for various reasons, some fixable and some not. I rather suspect Arve was talking about the former case.

#217 lore raw
In reply to Matthew Garrett
Quoted 14 lines · Matthew Garrett
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 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 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 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). 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.

Signature · 1 line
Arve Hjønnevåg
#218 lore raw
In reply to Matthew Garrett
Quoted 14 lines · Matthew Garrett
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 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 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 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). 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.

Signature · 1 line
Arve Hjønnevåg
#193 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 2 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

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)

Quoted 5 lines
Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 9 lines

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

I'm not sure I buy the distinction, but I'm not a maintainer so it's others you have to convince.

it's better to have one type of problem with one set of tools that document why the machine isn't sleeping, than to have orthoginal ways of influencing power management.

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.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

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)

Quoted 6 lines
Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

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.

Quoted 8 lines
Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

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)

David Lang

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

why would you trust it to take a wakelock, but not trust it the rest of the time?

Because I trust that when the application author says "I explicitly need the machine to stay awake" that they mean it, whereas I don't trust the application author to write an application that avoids consuming background CPU. The distinction is pretty important.

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)

Quoted 5 lines
Quoted 4 lines

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

Quoted 9 lines

When we say "trust", we're not using the same meaning as we do with security. Yes, it's possible that an application that can block suspend will do so at inopportune times. But given that blocking suspend is an explicit act it's much more likely that the developer will only use it in reasonable ways, while it's still entirely plausible that the application will generate unnecessary wakeups. Pretending otherwise is unrealistic. I recently had to fix the fact that the kernel IPMI layer would generate a constant 1000 wakeups a second even if it had an interrupt-driven controller or was entirely idle.

I'm not sure I buy the distinction, but I'm not a maintainer so it's others you have to convince.

it's better to have one type of problem with one set of tools that document why the machine isn't sleeping, than to have orthoginal ways of influencing power management.

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.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

The current implementation uses a timer, but Rafael's implementation should allow userspace to explicitly acknowledge it.

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)

Quoted 6 lines
Quoted 4 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

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.

Quoted 8 lines
Quoted 3 lines

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

If you proxy every potential wakeup event through some central server then this becomes much easier, but it's also a performance hit. The alternative is that you poll for network activity, but that's a power hit.

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)

David Lang

#203 lore raw
In reply to Paul E. McKenney
Quoted 41 lines · Paul E. McKenney
Quoted 30 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

Quoted 3 lines

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

in my proposal, the application is trusted to take the wakelock, so it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

Quoted 6 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Quoted 9 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

Quoted 6 lines

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

The primary thing that I was getting at was the other things above.

David Lang

#331 lore raw
In reply to Matthew Garrett
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 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

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

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

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.

David Lang

#332 lore raw
In reply to Matthew Garrett
Quoted 18 lines · Matthew Garrett
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 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

What stops the system going to sleep between (2) and (3)? cgroups don't, because the voip app is an otherwise untrusted application that you've just told the scheduler to ignore.

Quoted 8 lines
Quoted 2 lines

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

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.

David Lang

#492 lore raw
In reply to Florian Mickler
Quoted 40 lines · Florian Mickler
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Quoted 6 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel

Message-ID: <[email protected]>

Arve said:

Quoted 10 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Quoted 3 lines

They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.

Yes, you will always get gains if you shutdown while there is still work to do.

the question I am raising is.

If, instead of doing opportunistic suspend (with wakelocks to keep things awake, requiring explicit application code changes to implement), how close would you be able to get if instead you just were able to tell the system to ignore some processes when considering if the system can sleep or not?

With badly written 'trusted' apps you will have poor power useage, but with badly written apps grabbing wakelocks inappropriately you will have poor power useage.

David Lang

#493 lore raw
In reply to Florian Mickler
Quoted 40 lines · Florian Mickler
Quoted 26 lines · On Wed, 4 Aug 2010 23:15:13 +0200 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

Quoted 6 lines
Quoted 2 lines

In different message, Arve said they are actually using low-power idle to emulate suspend on Android.

Hello, Pavel,

Could you please point me at this message?

AFAICT, this tells us that idle and suspend is the same hardware state on current Android hardware:
Pavel

Message-ID: <[email protected]>

Arve said:

Quoted 10 lines

If you just program the alarm you will wake up see that the monotonic clock has not advanced and set the alarm another n seconds into the future. Or are proposing that suspend should be changed to keep the monotonic clock running? If you are, why? We can enter the same hardware states from idle, and modifying suspend to wake up more often would increase the average power consumption in suspend, not improve it for idle. In other words, if suspend wakes up as often as idle, why use suspend?

Quoted 3 lines

They always told us from the beginning, that on the msm platform they reach the same powerlevel from suspend and idle. They still get gains from using opportunistic suspend.

Yes, you will always get gains if you shutdown while there is still work to do.

the question I am raising is.

If, instead of doing opportunistic suspend (with wakelocks to keep things awake, requiring explicit application code changes to implement), how close would you be able to get if instead you just were able to tell the system to ignore some processes when considering if the system can sleep or not?

With badly written 'trusted' apps you will have poor power useage, but with badly written apps grabbing wakelocks inappropriately you will have poor power useage.

David Lang

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

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.

Signature · 1 line
Arve Hjønnevåg
#334 lore raw
In reply to [email protected]
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 6 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.

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.

Signature · 1 line
Arve Hjønnevåg
#484 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 4 lines · Pavel Machek

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?

how much do you care? (not from a theoretical point of view, but from a practical point of view, how much difference does it make)

how much "unwanted" processing would you allow a process to do before shutting down?

how likely are apps that you would trust to just assert "I know better than the system or the user how important I am, don't you dare sleep now" that do this properly, but then do other processing that you really don't want to have happen? (I expect that if the authors of those apps ever ran into this case, they would just add another wakelock to prevent it)

If the only things you have running are apps that are trusted to take the wakelock, are you really going to sleep any more frequently with the wakelock infrastructure than you would with just idle detection? (this can be tested today by just stubbing out the wakelock checks so they have no effect on sleeping)

David Lang

#485 lore raw
In reply to Matthew Garrett
Quoted 9 lines · Matthew Garrett
Quoted 4 lines · Pavel Machek

This came like a bit of a shock to me ("why do they make it so complex then"), but... it also means that as soon as you are able to stop "unwanted" processing, you can just leave normal cpuidle mechanisms to deal with the rest...

How do you differentiate between "unwanted" and "wanted" processing in the same task in a race-free manner?

how much do you care? (not from a theoretical point of view, but from a practical point of view, how much difference does it make)

how much "unwanted" processing would you allow a process to do before shutting down?

how likely are apps that you would trust to just assert "I know better than the system or the user how important I am, don't you dare sleep now" that do this properly, but then do other processing that you really don't want to have happen? (I expect that if the authors of those apps ever ran into this case, they would just add another wakelock to prevent it)

If the only things you have running are apps that are trusted to take the wakelock, are you really going to sleep any more frequently with the wakelock infrastructure than you would with just idle detection? (this can be tested today by just stubbing out the wakelock checks so they have no effect on sleeping)

David Lang

#335 lore raw
In reply to Arve Hjønnevåg
Quoted 40 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 6 lines

the proposal that I nade was not to use cgroups to freeze some processes and not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just a way of easily grouping processes (and their children) into different groups.

Quoted 5 lines

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

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

David Lang

#336 lore raw
In reply to Arve Hjønnevåg
Quoted 40 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 6 lines

the proposal that I nade was not to use cgroups to freeze some processes and not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just a way of easily grouping processes (and their children) into different groups.

Quoted 5 lines

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

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

David Lang

#110 lore raw
In reply to Rafael J. Wysocki
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 33 lines
Quoted 3 lines

In addition, there are input devices like a touchscreen that could be disabled even short of a full suspend, as long as there is some way to get them reactivated.

That's correct again, but it doesn't matter too much as far as the difference between "deep idle" and suspend is concerned. These devices are generally not the interrupt sources that are difficult to shut down safely in the "idle" case.

Quoted 10 lines
Quoted 5 lines

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and how much userspace interaction is needed. If the kernel can disable the hardware in the driver (so that it can wake it up again when accessed by an application) it would seem that this isn't a problem.

Well, I guess it's useful to consider the sequence of events in the "idle" case.

We first detect that a CPU is idle, so it can be put into a C-state (or equivalent). It's easy to put that CPU into such a state, but suppose we want to do more and put all devices into low-power states at that point. We have to ensure that there are no devices in the middle of DMA and that the other CPUs are idle (that's kind of easy, but still). Next, we have to figure out the right ordering in which to put devices into low-power states (that is not trivial, because the tasks that use those devices may depend on each other in various ways). If we decide to shut down clock source interrupts, we must ensure that the timekeeping will be correct after that and so on. Moreover, things get ugly if there are shared interrupts.

Quoted 3 lines

Suspend kind of works around these difficulties by taking the entire user space out of the picture with one big sledgehammer called the freezer, but these problems would have to be actually _solved_ in the "idle" case.

I'm not opposed to doing a suspend if the system is idle enough, I'm just questioning if suspend is really that different, or if it can be viewed as yet another low power mode (one that's significantly more expensive to transition in and out of)

David Lang

#204 lore raw
In reply to [email protected]
Quoted 49 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 29 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Understood, but...

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

Quoted 7 lines
Quoted 3 lines

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

in my proposal, the application is trusted to take the wakelock, so it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

Quoted 10 lines
Quoted 6 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

Quoted 6 lines

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

Thanx, Paul

Quoted 3 lines

The primary thing that I was getting at was the other things above.

David Lang

#205 lore raw
In reply to [email protected]
Quoted 49 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 40 lines · Paul E. McKenney
Quoted 29 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 24 lines · Matthew Garrett
Quoted 17 lines · On Wed, Aug 04, 2010 at 12:15:59PM -0700, [email protected] wrote:
Quoted 12 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 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.

Quoted 5 lines

Even in the current implementation (wakelocks), Since the VOIP application isn't allowed to take a wakelock, wouldn't the system go to sleep immediatly anyway, even if the application gets the packet and starts the call? What would ever raise the wakelock to keep the phone from sleeping in the middle of the call?

Quoted 3 lines

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Understood, but...

Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

The second is that the incoming network packet causes
the kernel to take a wakelock that will be released once userspace has processed the network packet. This ensures that at least one wakelock is held for the entire relevant period of time.

how do you determine that userspace has processed the network packet so that the kernel can release the wakelock (or is this one of the cases where there is a timer related to the wakelock)

There are two cases:

1. The application is permitted to acquire suspend blockers.
In this case, the application would acquire a suspend blocker before reading the input. It would then read the input (at which point the kernel releases its suspend blocker), do any needed processing, and finally release the suspend blocker.

Quoted 7 lines
Quoted 3 lines

So in this case, the system knows that the application is done processing the input when that application releases its suspend blocker.

in my proposal, the application is trusted to take the wakelock, so it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

Quoted 10 lines
Quoted 6 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

Quoted 6 lines

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

Thanx, Paul

Quoted 3 lines

The primary thing that I was getting at was the other things above.

David Lang

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

Thanx, Paul

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

Thanx, Paul

#339 lore raw

One suggestion: Get an Android Phone, test your ideas on it, then comment.

#367 lore raw
In reply to [email protected]

2010/8/4 <[email protected]>:

Quoted 46 lines · Arve Hj?nnev?g
Quoted 45 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 26 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett
Quoted 13 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 4 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.

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

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

and if you don't have a wakelock the same thing will happen. If you expect

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

Quoted 2 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

We suspend as soon as no wakelocks are held. There is no delay.

Signature · 1 line
Arve Hjønnevåg
#368 lore raw
In reply to [email protected]

2010/8/4 <[email protected]>:

Quoted 46 lines · Arve Hj?nnev?g
Quoted 45 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 26 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett
Quoted 13 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 4 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.

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

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

and if you don't have a wakelock the same thing will happen. If you expect

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

Quoted 2 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

We suspend as soon as no wakelocks are held. There is no delay.

Signature · 1 line
Arve Hjønnevåg
#206 lore raw
In reply to Paul E. McKenney
Quoted 31 lines · Paul E. McKenney
Quoted 26 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 17 lines · Paul E. McKenney
Quoted 6 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 4 lines · Matthew Garrett

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Quoted 8 lines

Understood, but...

Quoted 2 lines

it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

I am saying that 'trusted to use a wakelock' does imply 'trusted to not waste power'

I am sure that there are apps that do not manage power effectivly, but I don't expect that giving those same developers wakelock power will make them do much better. I expect that any time they discover the system going to sleep on them, they will just add another wakelock to keep it awake. If they were the type to carefully consider what was really important and what wasn't, I would expect them to write fairly power efficiant code in the first place.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

so the systems are pretty much equivalent from this point of view.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 8 lines
Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

well, if you have the kernel take a wakelock when the packet arrives, you are doing the equivalent thing.

Quoted 8 lines
Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

note that here I am talking about thigns that will keep the system awake, not wake it up after it suspends.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

that's not my understanding. my understanding (which could be flawed) is that wake-on-lan programs your IP into the NIC and if the NIC sees traffic for you it will wake you up. I've never had a reason to use it, so I could easily be mistaken.

David Lang

#207 lore raw
In reply to Paul E. McKenney
Quoted 31 lines · Paul E. McKenney
Quoted 26 lines · On Wed, Aug 04, 2010 at 03:29:25PM -0700, [email protected] wrote:
Quoted 17 lines · Paul E. McKenney
Quoted 6 lines · On Wed, Aug 04, 2010 at 12:29:36PM -0700, [email protected] wrote:
Quoted 4 lines · Matthew Garrett

There's two parts of that. The first is that the voip application is allowed to take a wakelock - but that doesn't mean that you trust it the rest of the time.

Quoted 7 lines

why would you trust it to take a wakelock, but not trust it the rest of the time?

in my proposal I'm saying that if you would trust the application to take a wakelock, you instead trust it to be sane in the rest of it's power activity (avoiding polling, etc) and so you consider it for sleep decisions.

The word "trust" does not appear to be helping here. ;-)

Quoted 7 lines

The VOIP application acquires a suspend blocker when it needs to prevent the system from suspending, and releases that suspend blocker when it can tolerate the system suspending. It is important to note that while the VOIP application holds the suspend blocker, the system won't suspend even if it is completely idle (for example, if the VOIP application uses blocking system calls, during the time that the VOIP application is waiting for its next event).

Quoted 3 lines

In the terminology I have been using, the VOIP sofware is then trusted to take the wakelock appropriately, and I'm then saying it would be in the trusted cgroup

Quoted 8 lines

Understood, but...

Quoted 2 lines

it would be trusted to not use the CPU wildly inappropriatly and so it running would make the system active and so it would not sleep.

... here you seem to be assuming that "trusted to properly use a wakelock" implies "coded to optimize power usage when not holding a wakelock." But this does not necessarily follow.

I am saying that 'trusted to use a wakelock' does imply 'trusted to not waste power'

I am sure that there are apps that do not manage power effectivly, but I don't expect that giving those same developers wakelock power will make them do much better. I expect that any time they discover the system going to sleep on them, they will just add another wakelock to keep it awake. If they were the type to carefully consider what was really important and what wasn't, I would expect them to write fairly power efficiant code in the first place.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

2. The application is prohibited from acquiring suspend blockers.
In this case, the system might well be suspended before the application has a chance to do more than read the input.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

But the application will get a chance to process the input when the next input event is directed to it.

In this case the system would go ahead and suspend, but the next time the sustem wakes up for any reason, this application would continue to run and process the input

Yep, that is in fact what I said. ;-)

so the systems are pretty much equivalent from this point of view.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines

two things here,

on the dirty networks that I see as common, refusing to sleep if network packets are arriving will mean that you never go to sleep.

secondly, nothing stops the code doing the idle/suspend decision from considering network activity. I would be surprised if there weren't already options to support this today.

I don't know about the general networking case for Android, but the example of downloading was discussed some time back. The application doing the download acquires a suspend blocker, which it releases once the download is complete (or once a timeout expires, if I remember correctly). In this particular case, the network packets were not bringing the device out of suspend.

Quoted 8 lines
Quoted 3 lines

it would seem reasonable to say that if a packet arrives for an existing connection (which the kernel does know) it is considered activity for purposes of sleeping.

That would be up to the people creating the system in question. In some cases, they might (as you say) want every packet arriving to wake up the system, in other cases they might not. We should not be taking that design decision away from them.

well, if you have the kernel take a wakelock when the packet arrives, you are doing the equivalent thing.

Quoted 8 lines
Quoted 4 lines

I don't know if you would care enough to try and say that packets for untrusted apps network connections don't keep the system awake, or just allow them to (after all, keypresses going to untrusted apps do keep the system awake)

Again, this is up to the people creating the system in question. On some Android systems, there is a particular button you have to press to wake the system up after it has suspended itself.

note that here I am talking about thigns that will keep the system awake, not wake it up after it suspends.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

There might well be other cases where networking packets -do- bring the system out of suspend, but I must leave this to someone who knows more about Android than do I.

this would be the normal wake-on-lan type of functionality that exists without Android.

Although this wake-on-LAN functionality applies only to special wake-up packets, not to normal packets, right?

that's not my understanding. my understanding (which could be flawed) is that wake-on-lan programs your IP into the NIC and if the NIC sees traffic for you it will wake you up. I've never had a reason to use it, so I could easily be mistaken.

David Lang

#343 lore raw
In reply to Paul E. McKenney
Quoted 55 lines · 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)

Quoted 7 lines

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.

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.

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)

David Lang

#344 lore raw
In reply to Paul E. McKenney
Quoted 55 lines · 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)

Quoted 7 lines

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.

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.

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)

David Lang

#369 lore raw
In reply to Arve Hjønnevåg
Quoted 53 lines · Arve Hj?nnev?g

2010/8/4 <[email protected]>:

Quoted 52 lines · Arve Hj?nnev?g
Quoted 50 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 34 lines · Matthew Garrett
Quoted 26 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett
Quoted 13 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 4 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 8 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.

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 5 lines
Quoted 1 line

and if you don't have a wakelock the same thing will happen. If you expect

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

Quoted 7 lines
Quoted 2 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

Quoted 5 lines
Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

We suspend as soon as no wakelocks are held. There is no delay.

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

David Lang

#370 lore raw
In reply to Arve Hjønnevåg
Quoted 53 lines · Arve Hj?nnev?g

2010/8/4 <[email protected]>:

Quoted 52 lines · Arve Hj?nnev?g
Quoted 50 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 34 lines · Matthew Garrett
Quoted 26 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett
Quoted 13 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 4 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 8 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.

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 5 lines
Quoted 1 line

and if you don't have a wakelock the same thing will happen. If you expect

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

Quoted 7 lines
Quoted 2 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

Quoted 5 lines
Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

We suspend as soon as no wakelocks are held. There is no delay.

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

David Lang

#111 lore raw
In reply to [email protected]
Quoted 16 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 14 lines · Rafael J. Wysocki

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

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

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.

Quoted 5 lines
Quoted 2 lines

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?

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

Quoted 33 lines
Quoted 33 lines
Quoted 3 lines

In addition, there are input devices like a touchscreen that could be disabled even short of a full suspend, as long as there is some way to get them reactivated.

That's correct again, but it doesn't matter too much as far as the difference between "deep idle" and suspend is concerned. These devices are generally not the interrupt sources that are difficult to shut down safely in the "idle" case.

Quoted 10 lines
Quoted 5 lines

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and how much userspace interaction is needed. If the kernel can disable the hardware in the driver (so that it can wake it up again when accessed by an application) it would seem that this isn't a problem.

Well, I guess it's useful to consider the sequence of events in the "idle" case.

We first detect that a CPU is idle, so it can be put into a C-state (or equivalent). It's easy to put that CPU into such a state, but suppose we want to do more and put all devices into low-power states at that point. We have to ensure that there are no devices in the middle of DMA and that the other CPUs are idle (that's kind of easy, but still). Next, we have to figure out the right ordering in which to put devices into low-power states (that is not trivial, because the tasks that use those devices may depend on each other in various ways). If we decide to shut down clock source interrupts, we must ensure that the timekeeping will be correct after that and so on. Moreover, things get ugly if there are shared interrupts.

Quoted 8 lines
Quoted 3 lines

Suspend kind of works around these difficulties by taking the entire user space out of the picture with one big sledgehammer called the freezer, but these problems would have to be actually _solved_ in the "idle" case.

I'm not opposed to doing a suspend if the system is idle enough, I'm just questioning if suspend is really that different, or if it can be viewed as yet another low power mode (one that's significantly more expensive to transition in and out of)

Suspend is really different. First, the way it is entered is different (ie. it starts from the freezing of user space and sequentially powers down things going from leaf devices towards the "core" of the system). Second, it shuts down interrupt sources that cannot be easily shut down from idle (at least in general). Finally, on some platforms (eg. ACPI) it requires extra hardware black magic that cannot be triggered from the cpuidle context.

The deactivation of more interrupt sources appears to be the most significant difference from the energy saving point of view, but it is achieved because of the way suspend is entered. It may or may not be achieved in a different way, but (1) no one has implemented anything close to a working alternative solution yet and (2) it is not certain that's worth doing.

Thanks,
Rafael

#112 lore raw
In reply to [email protected]
Quoted 16 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 14 lines · Rafael J. Wysocki

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

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

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.

Quoted 5 lines
Quoted 2 lines

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?

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

Quoted 33 lines
Quoted 33 lines
Quoted 3 lines

In addition, there are input devices like a touchscreen that could be disabled even short of a full suspend, as long as there is some way to get them reactivated.

That's correct again, but it doesn't matter too much as far as the difference between "deep idle" and suspend is concerned. These devices are generally not the interrupt sources that are difficult to shut down safely in the "idle" case.

Quoted 10 lines
Quoted 5 lines

To achieve the same result in the "idle" case, you'll need to have a mechanism to disable interrupts (except for the "wakeup" ones) avoiding synchronization problems (eg. situations in which task A, blocked on a "suspended" device access, holds a mutex waited for by task B that needs to run so that we can "suspend" another device). That, however, is a difficult problem.

I would say that the difficulty of the problem depends on the hardware and how much userspace interaction is needed. If the kernel can disable the hardware in the driver (so that it can wake it up again when accessed by an application) it would seem that this isn't a problem.

Well, I guess it's useful to consider the sequence of events in the "idle" case.

We first detect that a CPU is idle, so it can be put into a C-state (or equivalent). It's easy to put that CPU into such a state, but suppose we want to do more and put all devices into low-power states at that point. We have to ensure that there are no devices in the middle of DMA and that the other CPUs are idle (that's kind of easy, but still). Next, we have to figure out the right ordering in which to put devices into low-power states (that is not trivial, because the tasks that use those devices may depend on each other in various ways). If we decide to shut down clock source interrupts, we must ensure that the timekeeping will be correct after that and so on. Moreover, things get ugly if there are shared interrupts.

Quoted 8 lines
Quoted 3 lines

Suspend kind of works around these difficulties by taking the entire user space out of the picture with one big sledgehammer called the freezer, but these problems would have to be actually _solved_ in the "idle" case.

I'm not opposed to doing a suspend if the system is idle enough, I'm just questioning if suspend is really that different, or if it can be viewed as yet another low power mode (one that's significantly more expensive to transition in and out of)

Suspend is really different. First, the way it is entered is different (ie. it starts from the freezing of user space and sequentially powers down things going from leaf devices towards the "core" of the system). Second, it shuts down interrupt sources that cannot be easily shut down from idle (at least in general). Finally, on some platforms (eg. ACPI) it requires extra hardware black magic that cannot be triggered from the cpuidle context.

The deactivation of more interrupt sources appears to be the most significant difference from the energy saving point of view, but it is achieved because of the way suspend is entered. It may or may not be achieved in a different way, but (1) no one has implemented anything close to a working alternative solution yet and (2) it is not certain that's worth doing.

Thanks,
Rafael

#371 lore raw
In reply to [email protected]
Quoted 81 lines · On Wed, Aug 04, 2010 at 04:23:43PM -0700, [email protected] wrote:
Quoted 53 lines · Arve Hj?nnev?g

2010/8/4 <[email protected]>:

Quoted 52 lines · Arve Hj?nnev?g
Quoted 50 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 34 lines · Matthew Garrett
Quoted 26 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett
Quoted 13 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 4 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 8 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.

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 5 lines
Quoted 1 line

and if you don't have a wakelock the same thing will happen. If you expect

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

Quoted 7 lines
Quoted 2 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

Quoted 4 lines
Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

Quoted 8 lines
Quoted 1 line

We suspend as soon as no wakelocks are held. There is no delay.

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

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?

Thanx, Paul

#372 lore raw
In reply to [email protected]
Quoted 81 lines · On Wed, Aug 04, 2010 at 04:23:43PM -0700, [email protected] wrote:
Quoted 53 lines · Arve Hj?nnev?g

2010/8/4 <[email protected]>:

Quoted 52 lines · Arve Hj?nnev?g
Quoted 50 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 34 lines · Matthew Garrett
Quoted 26 lines · Rafael J. Wysocki
Quoted 15 lines · Matthew Garrett
Quoted 13 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 4 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 8 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.

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 5 lines
Quoted 1 line

and if you don't have a wakelock the same thing will happen. If you expect

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

Quoted 7 lines
Quoted 2 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

Quoted 4 lines
Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

Quoted 8 lines
Quoted 1 line

We suspend as soon as no wakelocks are held. There is no delay.

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

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?

Thanx, Paul

#345 lore raw
In reply to [email protected]
Quoted 65 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 55 lines · 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)

Quoted 7 lines

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

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.

Thanks,
Rafael

#346 lore raw
In reply to [email protected]
Quoted 65 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 55 lines · 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)

Quoted 7 lines

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

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.

Thanks,
Rafael

#113 lore raw
In reply to Rafael J. Wysocki
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 14 lines · Rafael J. Wysocki

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

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

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.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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?

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)

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

David Lang

#476 lore raw
In reply to [email protected]

2010/8/4 <[email protected]>:

Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines

2010/8/4  <[email protected]>:

Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines

No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 5 lines

What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.

Quoted 4 lines

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

Quoted 7 lines

Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 9 lines

the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.

Quoted 5 lines

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

and if you don't have a wakelock the same thing will happen. If you expect

Quoted 8 lines
Quoted 3 lines

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

Quoted 9 lines
Quoted 4 lines

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

Quoted 8 lines
Quoted 1 line

We suspend as soon as no wakelocks are held. There is no delay.

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

A wakelock is active when the screen is on.

Signature · 1 line
Arve Hjønnevåg
#477 lore raw
In reply to [email protected]

2010/8/4 <[email protected]>:

Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines

2010/8/4  <[email protected]>:

Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines

No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 5 lines

What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.

Quoted 4 lines

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

Quoted 7 lines

Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 9 lines

the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.

Quoted 5 lines

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

and if you don't have a wakelock the same thing will happen. If you expect

Quoted 8 lines
Quoted 3 lines

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

Quoted 9 lines
Quoted 4 lines

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

Quoted 8 lines
Quoted 1 line

We suspend as soon as no wakelocks are held. There is no delay.

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

A wakelock is active when the screen is on.

Signature · 1 line
Arve Hjønnevåg
#114 lore raw
In reply to Rafael J. Wysocki
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 14 lines · Rafael J. Wysocki

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

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

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.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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?

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)

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

David Lang

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

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.

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.

David Lang

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

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.

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.

David Lang

#347 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · On Thursday, August 05, 2010, [email protected] wrote:

My proposal would never freeze a subset of processes.

what my proposal:

Quoted 9 lines
Quoted 2 lines

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.

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.

David Lang

#348 lore raw
In reply to Rafael J. Wysocki
Quoted 6 lines · Rafael J. Wysocki
Quoted 5 lines · On Thursday, August 05, 2010, [email protected] wrote:

My proposal would never freeze a subset of processes.

what my proposal:

Quoted 9 lines
Quoted 2 lines

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.

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.

David Lang

#478 lore raw
In reply to Arve Hjønnevåg
Quoted 78 lines · Arve Hj?nnev?g

2010/8/4 <[email protected]>:

Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines

2010/8/4  <[email protected]>:

Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines

No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 5 lines

What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.

Quoted 4 lines

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

Quoted 7 lines

Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 9 lines

the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.

Quoted 5 lines

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

and if you don't have a wakelock the same thing will happen. If you expect

Quoted 8 lines
Quoted 3 lines

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

Quoted 4 lines

If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.

since the premise is that we only consider the activity of some processes when we are deciding if the system is idle, it's very possible that not all CPUs will be idle when we decide to suspend.

will suspend wake up the application threads? or will it create it's own processes (and/or use processes that can be tagged ahead of time)?

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

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

Quoted 8 lines
Quoted 4 lines

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.

no, I want recent activity from a privilaged/trusted process to prevent suspend. I'm saying that such a process can wake up infrequently enough that the wakeups themselves are not a significant amount of processing if it wants to keep the system awake so that other things can keep running.

you say below that the system will never suspend while the backlight is on, well the process that monitors/controlls the backlight would be one of these trusted processes.

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

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

We suspend as soon as no wakelocks are held. There is no delay.

Quoted 8 lines
Quoted 6 lines

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

A wakelock is active when the screen is on.

so what controls when the screen is on? what still needs to run (and keep the system awake) if the screen is off?

David Lang

#479 lore raw
In reply to Arve Hjønnevåg
Quoted 78 lines · Arve Hj?nnev?g

2010/8/4 <[email protected]>:

Quoted 68 lines · Arve Hj?nnev?g
Quoted 67 lines

2010/8/4  <[email protected]>:

Quoted 64 lines · Arve Hj?nnev?g
Quoted 54 lines · On Wed, Aug 4, 2010 at 3:31 PM,  <[email protected]> wrote:
Quoted 42 lines · Matthew Garrett
Quoted 32 lines · Rafael J. Wysocki
Quoted 25 lines · Matthew Garrett
Quoted 17 lines

No! And that's precisely the issue. Android's existing behaviour could
be entirely implemented in the form of binary that manually triggers suspend when (a) the screen is off and (b) no userspace applications have indicated that the system shouldn't sleep, except for the wakeup
event race. Imagine the following:

1) The policy timeout is about to expire. No applications are holding
wakelocks. The system will suspend providing nothing takes a wakelock.
2) A network packet arrives indicating an incoming SIP call
3) The VOIP application takes a wakelock and prevents the phone from suspending while the call is in progress

Quoted 5 lines

What stops the system going to sleep between (2) and (3)? cgroups don't,
because the voip app is an otherwise untrusted application that you've
just told the scheduler to ignore.

Quoted 4 lines

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

Quoted 7 lines

Yes, I think that solves the problem. The only question then is whether
it's preferable to use cgroups or suspend fully, which is pretty much up
to the implementation. In other words, is there a reason we're still having this conversation? :) It'd be good to have some feedback from Google as to whether this satisfies their functional requirements.

Quoted 9 lines

the proposal that I nade was not to use cgroups to freeze some processes
and
not others, but to use cgroups to decide to ignore some processes when deciding if the system is idle, stop everything or nothing. cgroups are just
a way of easily grouping processes (and their children) into different groups.

Quoted 5 lines

That does not avoid the dependency problem. A process may be waiting on a resource that a process you ignore owns. I you ignore the process that owns the resource and enter idle when it is ready to run (or waiting on a timer), you are still effectively blocking the other process.

and if you don't have a wakelock the same thing will happen. If you expect

Quoted 8 lines
Quoted 3 lines

Not the same thing. If you don't hold a wakelock the entire system will suspend and when it wakes up it continues where it left off. Timeout still have time left before they expire.

in what I'm proposing, if the 'privilaged/trusted" processes are idle long enough the entire system will suspend, and when it wakes up everything will continue to process normally

Quoted 4 lines

If you are triggering a system suspend from idle (I assume all cpus idle), you also have to consider when to resume. You cannot abort suspend just because a cpu is not idle anymore, since suspend itself will wake up threads.

since the premise is that we only consider the activity of some processes when we are deciding if the system is idle, it's very possible that not all CPUs will be idle when we decide to suspend.

will suspend wake up the application threads? or will it create it's own processes (and/or use processes that can be tagged ahead of time)?

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

the process to take a while you can set a timeout to wake up every 30 seconds or so and wait again, this would be enough to prevent you from going

I don't think polling is an acceptable solution to this problem. You user space code know needs to know what "idle" timeout you have selected so it can choose a faster poll rate. When is it safe to stop polling?

Quoted 8 lines
Quoted 4 lines

I think the timeouts are of such an order of magnatude that the polling can be infrequent enough to not be a significant amount of load, but be faster than any timeout

How do you ever enter suspend in this system? Currently timers in the kernel and trusted user space code causes a significant power draw and you want insignificant timers to prevent suspend.

no, I want recent activity from a privilaged/trusted process to prevent suspend. I'm saying that such a process can wake up infrequently enough that the wakeups themselves are not a significant amount of processing if it wants to keep the system awake so that other things can keep running.

you say below that the system will never suspend while the backlight is on, well the process that monitors/controlls the backlight would be one of these trusted processes.

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

to sleep (or am I misunderstanding how long before you go into suspend without a wakelock set, see my other e-mail for the full question)

We suspend as soon as no wakelocks are held. There is no delay.

Quoted 8 lines
Quoted 6 lines

So, if I have a bookreader app that is not allowed to get the wakelock, and nothing else is running, the system will suspend immediatly after I click a button to go to the next page? it will not stay awake to give me a chance to read the page at all?

how can any application run without wakelock privilages?

A wakelock is active when the screen is on.

so what controls when the screen is on? what still needs to run (and keep the system awake) if the screen is off?

David Lang

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

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.

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. :-)

Thanks,
Rafael

#349 lore raw
In reply to [email protected]
Quoted 14 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 12 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).

Quoted 6 lines
Quoted 3 lines

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

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

Thanks,
Rafael

#350 lore raw
In reply to [email protected]
Quoted 14 lines · On Thursday, August 05, 2010, [email protected] wrote:
Quoted 12 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).

Quoted 6 lines
Quoted 3 lines

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

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

Thanks,
Rafael

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

Downloading is another.

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

Thanx, Paul

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

Downloading is another.

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

Thanx, Paul

#219 lore raw
In reply to Arve Hjønnevåg
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Matthew Garrett
Quoted 19 lines · Rafael J. Wysocki
Quoted 12 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 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 7 lines
Quoted 1 line

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.

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

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 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)?

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 1 line

is also not compatible with existing apps.

Thanks,
Rafael

#220 lore raw
In reply to Arve Hjønnevåg
Quoted 22 lines · Arve Hjønnevåg
Quoted 21 lines · Matthew Garrett
Quoted 19 lines · Rafael J. Wysocki
Quoted 12 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 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 7 lines
Quoted 1 line

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.

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

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 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)?

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 1 line

is also not compatible with existing apps.

Thanks,
Rafael

#377 lore raw
In reply to Paul E. McKenney
Quoted 25 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 6 lines
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.

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

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?

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.

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.

David Lang

#378 lore raw
In reply to Paul E. McKenney
Quoted 25 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 6 lines
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.

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

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?

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.

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.

David Lang

#379 lore raw
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 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.

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

Quoted 7 lines
Quoted 1 line

Or am I misunderstanding what you are proposing?

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

Quoted 8 lines
Quoted 4 lines

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.

The length of time those apps are running is the governing factor for battery life, and not the number of such apps, right?

Thanx, Paul

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

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

Quoted 7 lines
Quoted 1 line

Or am I misunderstanding what you are proposing?

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

Quoted 8 lines
Quoted 4 lines

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.

The length of time those apps are running is the governing factor for battery life, and not the number of such apps, right?

Thanx, Paul

#221 lore raw
In reply to Rafael J. Wysocki

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

Quoted 25 lines · Arve Hjønnevåg
Quoted 24 lines · Matthew Garrett
Quoted 22 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 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

Quoted 8 lines
Quoted 5 lines

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.

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

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

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

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

Quoted 25 lines · Arve Hjønnevåg
Quoted 24 lines · Matthew Garrett
Quoted 22 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 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

Quoted 8 lines
Quoted 5 lines

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.

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

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

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
#496 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.

Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.

One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.

When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do fcntl() on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.

Then it's just a matter of choosing when to freeze the naive cgroup. That requires a userspace implementation of the suspend blockers API plus opportunistic suspend but does not require any other kernel pieces. Then you can use sigprocmask to prevent the freeze/wake-event race. You would probably even merge the waker with the daemon which implements opportunistic suspend.

Cheers,
-Matt Helsley

#497 lore raw
In reply to Matthew Garrett
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Paul E. McKenney

If this doesn't work for the Android folks for whatever reason, another approach would be to do the freeze in user code, which could track whether any user-level resources (pthread mutexes, SysV semas, whatever) where held, and do the freeze on a thread-by-thread basis within each "victim" application as the threads reach safe points.

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.

Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.

One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.

When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do fcntl() on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.

Then it's just a matter of choosing when to freeze the naive cgroup. That requires a userspace implementation of the suspend blockers API plus opportunistic suspend but does not require any other kernel pieces. Then you can use sigprocmask to prevent the freeze/wake-event race. You would probably even merge the waker with the daemon which implements opportunistic suspend.

Cheers,
-Matt Helsley

#498 lore raw
Quoted 17 lines · Matt Helsley
Quoted 3 lines · Matthew Garrett

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.

Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.

One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.

Quoted 6 lines

When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do fcntl() on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.

The Android execution model includes native code in addition to the dalvik VM, and in the future could include other runtimes -- there are many standard libraries that directly make posix file IO calls, and apps can bundle native libraries which can also directly make syscalls. It's not practical to instrument every piece of userspace code that opens a fd somehow to make additional fcntl calls in various places.

Brian

#499 lore raw
In reply to Matt Helsley
Quoted 17 lines · Matt Helsley
Quoted 3 lines · Matthew Garrett

The main problem I see with the cgroups solution is that it doesn't seem to do anything to handle avoiding loss of wakeup events.

cgroups alone don't but there is a solution which doesn't require routing all event data through a single server -- use SIGIO.

Suppose we've got two cgroups of tasks -- those in the initial freezer cgroup and those in a freezer cgroup meant for power-naive apps. Let's call the second cgroup the naive cgroup.

One task -- let's call it the "waker" -- is in the initial cgroup is normaly asleep waiting for SIGIO. Note it's not an "app" -- it's been trusted/blessed to be a non-power-naive task. It will be signaled via SIGIO by the applications which want to be unfrozen when an event comes in.

Quoted 6 lines

When the power-naive app in the naive cgroup opens a file descriptor it's going through the Android interpretter to make the syscall. The interpretter can do fcntl() on the fd to cause SIGIO to be delivered to the waker task. When the waker gets SIGIO it unfreezes the naive cgroup and thus wakes the power-naive app. When the power-naive app wakes it will poll/return-from-poll/read/return-from-read and thus retrieve the event.

The Android execution model includes native code in addition to the dalvik VM, and in the future could include other runtimes -- there are many standard libraries that directly make posix file IO calls, and apps can bundle native libraries which can also directly make syscalls. It's not practical to instrument every piece of userspace code that opens a fd somehow to make additional fcntl calls in various places.

Brian

#325 lore raw
In reply to Arve Hjønnevåg
Quoted 1 line · Arve Hjønnevåg

On Wed, Aug 4, 2010 at 1:56 PM, Matthew Garrett <[email protected]> wrote:

[ . . . ]

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.

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)?

Thanx, Paul

#326 lore raw
In reply to Arve Hjønnevåg
Quoted 1 line · Arve Hjønnevåg

On Wed, Aug 4, 2010 at 1:56 PM, Matthew Garrett <[email protected]> wrote:

[ . . . ]

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.

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)?

Thanx, Paul