Skip to contentSkip to conversation

suspend blockers & Android integration

DISCUSSION Ingo Molnar 26 participants 370 messages Jun 3, 2010 – Jul 9, 2010 2 messages not in the archive Page 2 of 2

lore
Share & tools
lore
#253 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I still believe containment is a cgroup problem. The freeze/snapshot/resume container folks seem to face many of the same problems. Including the pending timer one I suspect. Lets solve it there.

While talking to Thomas about this, we'd probably need a CLOCK_MONOTONIC namespace to pull this off, so that resumed apps don't see the jump in absolute time.

Quoted 6 lines

This would also help with locating the relevant timers, since they'd be on the related timer base.

The only 'interesting' issue I can see here is that if you create 1000 CLOCK_MONOTONIC namepaces, we'd need to have a tree of trees in order to efficiently find the leftmost timer.

We can do more clever than that. All CLOCK_MONOTONIC timers can live in the CLOCK_MONOTONIC rbtree, we just need proper annotation, i.e.:

struct hrtimer {
       ktime_t expires;
       ......
       struct list_head namespace;
       ktime_t base_offset;
};

So expires would be on CLOCK_MONOTONIC as seen from the kernel, just the user space interfaces would take the base_offset into account.

On freeze we remove the timers from the rbtree (they are easy to find via the namespace list) and on thaw we set the base_offset accordingly and insert them again. So no surprise for user space and no tree of trees to walk through.

Thanks,

tglx

#254 lore raw
Quoted 28 lines · Thomas Gleixner
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I still believe containment is a cgroup problem. The freeze/snapshot/resume container folks seem to face many of the same problems. Including the pending timer one I suspect. Lets solve it there.

While talking to Thomas about this, we'd probably need a CLOCK_MONOTONIC namespace to pull this off, so that resumed apps don't see the jump in absolute time.

Quoted 6 lines

This would also help with locating the relevant timers, since they'd be on the related timer base.

The only 'interesting' issue I can see here is that if you create 1000 CLOCK_MONOTONIC namepaces, we'd need to have a tree of trees in order to efficiently find the leftmost timer.

We can do more clever than that. All CLOCK_MONOTONIC timers can live in the CLOCK_MONOTONIC rbtree, we just need proper annotation, i.e.:

struct hrtimer {
       ktime_t expires;
       ......
       struct list_head namespace;
       ktime_t base_offset;
};
Quoted 7 lines

So expires would be on CLOCK_MONOTONIC as seen from the kernel, just the user space interfaces would take the base_offset into account.

On freeze we remove the timers from the rbtree (they are easy to find via the namespace list) and on thaw we set the base_offset accordingly and insert them again. So no surprise for user space and no tree of trees to walk through.

Ah indeed, much nicer.

#255 lore raw
In reply to Thomas Gleixner
Quoted 28 lines · Thomas Gleixner
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I still believe containment is a cgroup problem. The freeze/snapshot/resume container folks seem to face many of the same problems. Including the pending timer one I suspect. Lets solve it there.

While talking to Thomas about this, we'd probably need a CLOCK_MONOTONIC namespace to pull this off, so that resumed apps don't see the jump in absolute time.

Quoted 6 lines

This would also help with locating the relevant timers, since they'd be on the related timer base.

The only 'interesting' issue I can see here is that if you create 1000 CLOCK_MONOTONIC namepaces, we'd need to have a tree of trees in order to efficiently find the leftmost timer.

We can do more clever than that. All CLOCK_MONOTONIC timers can live in the CLOCK_MONOTONIC rbtree, we just need proper annotation, i.e.:

struct hrtimer {
       ktime_t expires;
       ......
       struct list_head namespace;
       ktime_t base_offset;
};
Quoted 7 lines

So expires would be on CLOCK_MONOTONIC as seen from the kernel, just the user space interfaces would take the base_offset into account.

On freeze we remove the timers from the rbtree (they are easy to find via the namespace list) and on thaw we set the base_offset accordingly and insert them again. So no surprise for user space and no tree of trees to walk through.

Ah indeed, much nicer.

#256 lore raw
In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

I still believe containment is a cgroup problem. The freeze/snapshot/resume container folks seem to face many of the same problems. Including the pending timer one I suspect. Lets solve it there.

While talking to Thomas about this, we'd probably need a CLOCK_MONOTONIC namespace to pull this off, so that resumed apps don't see the jump in absolute time.

Quoted 6 lines

This would also help with locating the relevant timers, since they'd be on the related timer base.

The only 'interesting' issue I can see here is that if you create 1000 CLOCK_MONOTONIC namepaces, we'd need to have a tree of trees in order to efficiently find the leftmost timer.

We can do more clever than that. All CLOCK_MONOTONIC timers can live in the CLOCK_MONOTONIC rbtree, we just need proper annotation, i.e.:

struct hrtimer {
       ktime_t expires;
       ......
       struct list_head namespace;
       ktime_t base_offset;
};

So expires would be on CLOCK_MONOTONIC as seen from the kernel, just the user space interfaces would take the base_offset into account.

On freeze we remove the timers from the rbtree (they are easy to find via the namespace list) and on thaw we set the base_offset accordingly and insert them again. So no surprise for user space and no tree of trees to walk through.

Thanks,

tglx

#257 lore raw
In reply to Peter Zijlstra
Quoted 30 lines · Peter Zijlstra
Quoted 3 lines · Ingo Molnar

Btw., i'd like to summarize the scheduler based suspend scheme proposed by Thomas Gleixner, Peter Zijlstra and myself. I found no good summary of it in the big thread, and there are also new elements of the proposal:

Just to clarify, my proposition doesn't go much further than treating 'suspend' as a genuine idle state (on suitable hardware, which x86 isn't).

Quoted 6 lines

- Create a 'deep idle' mode that suspends. This, if all constraints are met, is triggered by the scheduler automatically: just like the other idle modes are triggered currently. This approach fixes the wakeup races because an incoming wakeup event will set need_resched() and abort the suspend.

Right, so 'suspend' as idle seems (at least on UP/arm) a very sensible idea. On SMP current suspend hot-unplugs all but the boot cpu, I'm not sure we need to do that, since if the system is genuinely idle, what races are there?

And if its not idle...

Quoted 3 lines

( This mode can even use the existing suspend code to bring stuff down,
therefore it also solves the pending timer problem and works even on PC style x86. )

You cannot solve the pending timer issue from idle, unless you allow idle to stop clock_monotonic, which would change idle semantics, and that is not something I can say is a good idea.

Quoted 8 lines

You want all idle states to have the same semantics, otherwise things just get way too confusing.

Quoted 3 lines

- Solve crappy app confinement via the scheduler:

A first proposal was to use the existing cgroup mechanism,

I still believe containment is a cgroup problem.

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

(2) Allow the cpuidle framework to put CPUs into low-power states after the "trusted" apps (ie. the ones that use suspend blockers in the Android world) have gone idle.

(3) Teach the cpuidle framework to schedule runtime suspend of I/O devices before idling the last CPU (*).

(4) Design a mechanism to resume the I/O devices suspended in (3) so that they are not powered up unnecessarily (that's going to be difficult as far as I can see).

This way, in principle, we should be able to save (at least almost) as much energy as the opportunistic suspend currently used by Android, provided that things will be capable of staying idle for extended periods of time.

(*) That may require per-device PM QoS requirements to be used, in which case
devices may even be suspended earlier if the PM QoS requirements of all of their users are met.

I wonder what people think. Is this realistic and if so, would it be difficult to implement?

Rafael

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

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

There is an additional benefit to this approach:

In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 15 lines

(2) Allow the cpuidle framework to put CPUs into low-power states after the "trusted" apps (ie. the ones that use suspend blockers in the Android world) have gone idle.

(3) Teach the cpuidle framework to schedule runtime suspend of I/O devices before idling the last CPU (*).

(4) Design a mechanism to resume the I/O devices suspended in (3) so that they are not powered up unnecessarily (that's going to be difficult as far as I can see).

This way, in principle, we should be able to save (at least almost) as much energy as the opportunistic suspend currently used by Android, provided that things will be capable of staying idle for extended periods of time.

Quoted 6 lines

(*) That may require per-device PM QoS requirements to be used, in which case
devices may even be suspended earlier if the PM QoS requirements of all of their users are met.

I wonder what people think. Is this realistic and if so, would it be difficult to implement?

I think it's realistic and not overly complicated to implement.

Thanks,

tglx

#259 lore raw
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 4 lines
Quoted 4 lines

(2) Allow the cpuidle framework to put CPUs into low-power states after the "trusted" apps (ie. the ones that use suspend blockers in the Android world) have gone idle.

As far as I know this is what we already have on hardware that supports it.

Quoted 3 lines
Quoted 3 lines

(3) Teach the cpuidle framework to schedule runtime suspend of I/O devices before idling the last CPU (*).

I don't think we need this for android phones. We already put I/O devices in low power modes when they are not in use.

Quoted 7 lines
Quoted 7 lines

(4) Design a mechanism to resume the I/O devices suspended in (3) so that they are not powered up unnecessarily (that's going to be difficult as far as I can see).

This way, in principle, we should be able to save (at least almost) as much energy as the opportunistic suspend currently used by Android, provided that things will be capable of staying idle for extended periods of time.

The main reason we use suspend is that the system does not stay idle for extened periods of time. If this gets fixed, and our if user-space framework can deal with a subset of processes being frozen (this is a big if) this solution may work, but it does not help us today.

Quoted 10 lines
Quoted 7 lines

(*) That may require per-device PM QoS requirements to be used, in which case devices may even be suspended earlier if the PM QoS requirements of all of their users are met.

I wonder what people think.  Is this realistic and if so, would it be difficult to implement?

I think it's realistic and not overly complicated to implement.

The kernel support can be easily implemented on most arm hardware, I don't know if it can work on most existing x86 hardware. It does not give us the same power savings as suspend with existing software, but it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing). The biggest hurdle is how to handle dependencies between processes that gets frozen and processes that don't get frozen.

Signature · 1 line
Arve Hjønnevåg
#260 lore raw
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line · Thomas Gleixner

On Sat, 5 Jun 2010, Rafael J. Wysocki wrote:

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

<snip>

Quoted 2 lines

it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing).

I don't see why that would be a problem. The cgroup freezer works independently of the suspend freezer -- even with suspend blockers. So my hunch is this is really the same as the next problem you refer to:

Quoted 3 lines

The biggest hurdle is how
to handle dependencies between processes that gets frozen and processes that don't get frozen.

I'm not sure it covers everything you want, but it should be possible to identify some of those so long as you know which process you're communicating with.

A trusted app can look up the freezer cgroup of a target app in /proc, then look at the cgroup's freezer.state file. If it's FREEZING or FROZEN then you've very likely got a "bad" dependency.

For example, say a trusted app plans on doing a blocking read() to fetch the output of an untrusted app via a pipe. Assuming we know the untrusted app's pid we could then check the dependency and determine that we're likely to block because the untrusted app's freezer cgroup is FREEZING or FROZEN. (certain to block if we see FROZEN)

That said, it involves quite a few system calls compared to a simple read() from the pipe. So my guess is it would be a debugging tool at best -- not something you always have enabled.

It may even be possible to make an lsof-like debugging tool to do that from outside both apps.

Cheers,
-Matt Helsley

#261 lore raw

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored) and I don't know how we can safely freeze cgroups without funneling all potential wakeup events through a process that never gets frozen.

Quoted 13 lines

<snip>

Quoted 2 lines

it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing).

I don't see why that would be a problem. The cgroup freezer works independently of the suspend freezer -- even with suspend blockers. So my hunch is this is really the same as the next problem you refer to:

Quoted 3 lines

The biggest hurdle is how
to handle dependencies between processes that gets frozen and processes that don't get frozen.

Quoted 8 lines

I'm not sure it covers everything you want, but it should be possible to identify some of those so long as you know which process you're communicating with.

A trusted app can look up the freezer cgroup of a target app in /proc, then look at the cgroup's freezer.state file. If it's FREEZING or FROZEN then you've very likely got a "bad" dependency.

I don't think they are "bad" dependencies. Our framework has to communicate with apps.

Quoted 16 lines

For example, say a trusted app plans on doing a blocking read() to fetch the output of an untrusted app via a pipe. Assuming we know the untrusted app's pid we could then check the dependency and determine that we're likely to block because the untrusted app's freezer cgroup is FREEZING or FROZEN. (certain to block if we see FROZEN)

That said, it involves quite a few system calls compared to a simple read() from the pipe. So my guess is it would be a debugging tool at best -- not something you always have enabled.

It may even be possible to make an lsof-like debugging tool to do that from outside both apps.

Cheers,
       -Matt Helsley

Signature · 1 line
Arve Hjønnevåg
#262 lore raw
In reply to Matt Helsley

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored) and I don't know how we can safely freeze cgroups without funneling all potential wakeup events through a process that never gets frozen.

Quoted 13 lines

<snip>

Quoted 2 lines

it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing).

I don't see why that would be a problem. The cgroup freezer works independently of the suspend freezer -- even with suspend blockers. So my hunch is this is really the same as the next problem you refer to:

Quoted 3 lines

The biggest hurdle is how
to handle dependencies between processes that gets frozen and processes that don't get frozen.

Quoted 8 lines

I'm not sure it covers everything you want, but it should be possible to identify some of those so long as you know which process you're communicating with.

A trusted app can look up the freezer cgroup of a target app in /proc, then look at the cgroup's freezer.state file. If it's FREEZING or FROZEN then you've very likely got a "bad" dependency.

I don't think they are "bad" dependencies. Our framework has to communicate with apps.

Quoted 16 lines

For example, say a trusted app plans on doing a blocking read() to fetch the output of an untrusted app via a pipe. Assuming we know the untrusted app's pid we could then check the dependency and determine that we're likely to block because the untrusted app's freezer cgroup is FREEZING or FROZEN. (certain to block if we see FROZEN)

That said, it involves quite a few system calls compared to a simple read() from the pipe. So my guess is it would be a debugging tool at best -- not something you always have enabled.

It may even be possible to make an lsof-like debugging tool to do that from outside both apps.

Cheers,
       -Matt Helsley

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#263 lore raw
Quoted 26 lines · Arve Hjønnevåg

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 1 line

From what you're saying it follows that you're not really willing to accept

any solution different to your suspend blockers. Is that really the case?

Rafael

#264 lore raw

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

Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines

2010/6/4 Matt Helsley <[email protected]>:

Quoted 24 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 8 lines
Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

Quoted 3 lines

From what you're saying it follows that you're not really willing to accept any solution different to your suspend blockers.  Is that really the case?

I don't think that is a fair way to put it. We need to support our user-space framework and I have not seen an alternative solution that clearly will work (other than replacing suspend_blockers with pm_qos constraints that do the same thing).

Signature · 1 line
Arve Hjønnevåg
#265 lore raw
Quoted 37 lines · Arve Hjønnevåg

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

Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines

2010/6/4 Matt Helsley <[email protected]>:

Quoted 24 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 8 lines
Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 4 lines

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Basically, it involves two mechanisms, detection of wakeup events occuring right before suspend is started and aborting suspend if wakeup events occur in the middle of it.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 8 lines

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

It will be able to do that if it causes the frozen part of user space to be thawed.

I think you have this problem already, though, because you use full system suspend and all of your apps are frozen by it. So, to handle the situation you describe above, you need to carry out full system resume that will thaw the tasks for you. I don't see any fundamental difference betwee the two cases.

Quoted 7 lines
Quoted 3 lines

From what you're saying it follows that you're not really willing to accept any solution different to your suspend blockers. Is that really the case?

I don't think that is a fair way to put it. We need to support our user-space framework and I have not seen an alternative solution that clearly will work (other than replacing suspend_blockers with pm_qos constraints that do the same thing).

Then think again of the approach I proposed and explain to me why it won't work, because I haven't seen any convincing argument on that yet.

Rafael

#266 lore raw

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

Quoted 38 lines · Arve Hjønnevåg
Quoted 37 lines

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

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

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 7 lines
Quoted 4 lines

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Basically, it involves two mechanisms, detection of wakeup events occuring right before suspend is started

This sounds like the timeout approach which I thought you did not like.

Quoted 3 lines

and aborting suspend if wakeup events occur
in the middle of it.

Aborting suspend is easy, but when do you allow suspend again?

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 8 lines

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

Quoted 8 lines

It will be able to do that if it causes the frozen part of user space to be thawed.

I think you have this problem already, though, because you use full system suspend and all of your apps are frozen by it.  So, to handle the situation you describe above, you need to carry out full system resume that will thaw the tasks for you.  I don't see any fundamental difference betwee the two cases.

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes. Without annotating the drivers to block the cgroup freezing in the same places as we now block suspend, it also prevents processes in the cgroup that we freeze from directly consuming wakup events.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

From what you're saying it follows that you're not really willing to accept any solution different to your suspend blockers.  Is that really the case?

I don't think that is a fair way to put it. We need to support our user-space framework and I have not seen an alternative solution that clearly will work (other than replacing suspend_blockers with pm_qos constraints that do the same thing).

Then think again of the approach I proposed and explain to me why it won't work, because I haven't seen any convincing argument on that yet.

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption. And, it does not solve the problem for systems that enters lower power states from suspend than it can from idle. The last point my not be relevant to android anymore, but desktop systems already have auto suspend and it would be preferable to have a race free kernel api for this.

Signature · 1 line
Arve Hjønnevåg
#267 lore raw
Quoted 7 lines · Arve Hjønnevåg

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes. Without annotating the drivers to block the cgroup freezing in the same places as we now block suspend, it also prevents processes in the cgroup that we freeze from directly consuming wakup events.

The driver annotations don't need to block the cgroup freezing. They just need to keep the system running long enough to awaken a thread that will handle the wakeup event. (See below.) A pm-qos constraint is good enough for this.

Quoted 4 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way. Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event. When the event occurs, it must then activate a suspend blocker.

Better yet, make it more fine-grained. Instead of trusted apps, have trusted threads. Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

Quoted 5 lines

And, it
does not solve the problem for systems that enters lower power states from suspend than it can from idle. The last point my not be relevant to android anymore, but desktop systems already have auto suspend and it would be preferable to have a race free kernel api for this.

This is an entirely different matter from the rest of the discussion. It would be better to consider this separately after Android's current problems have been addressed.

Alan Stern

#268 lore raw
Quoted 11 lines · Alan Stern
Quoted 4 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way. Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event. When the event occurs, it must then activate a suspend blocker.

Quoted 8 lines

Better yet, make it more fine-grained. Instead of trusted apps, have trusted threads. Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources. (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Here's how you can do it. Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

The power-manager process should keep a list of "active" wakeup sources. A source gets removed from the list when an associated suspend blocker is activated.

When the "active" list is empty and no suspend blockers are activated, the power manager freezes ALL other processes, trusted and untrusted alike. It then does a big poll() on all the wakeup sources. When the poll() returns, its output is used to repopulate the "active" list and processes are unfrozen.

(You can also include some error detection: If a source remains on the "active" list for too long then something has gone wrong.)

To do all this you don't even need to use cgroups. The existing PM implementation allows a user process to freeze everything but itself; that's how swsusp and related programs work.

This is still a big-hammer sort of approach, but it doesn't require any kernel changes.

Alan Stern

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

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way. Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event. When the event occurs, it must then activate a suspend blocker.

Quoted 8 lines

Better yet, make it more fine-grained. Instead of trusted apps, have trusted threads. Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources. (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Here's how you can do it. Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

The power-manager process should keep a list of "active" wakeup sources. A source gets removed from the list when an associated suspend blocker is activated.

When the "active" list is empty and no suspend blockers are activated, the power manager freezes ALL other processes, trusted and untrusted alike. It then does a big poll() on all the wakeup sources. When the poll() returns, its output is used to repopulate the "active" list and processes are unfrozen.

(You can also include some error detection: If a source remains on the "active" list for too long then something has gone wrong.)

To do all this you don't even need to use cgroups. The existing PM implementation allows a user process to freeze everything but itself; that's how swsusp and related programs work.

This is still a big-hammer sort of approach, but it doesn't require any kernel changes.

Alan Stern

#270 lore raw

2010/6/6 Alan Stern <[email protected]>:

Quoted 28 lines · Alan Stern
Quoted 12 lines
Quoted 5 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way.  Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event.  When the event occurs, it must then activate a suspend blocker.

Quoted 8 lines

Better yet, make it more fine-grained.  Instead of trusted apps, have trusted threads.  Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources.  (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Quoted 8 lines

Here's how you can do it.  Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

The power-manager process should keep a list of "active" wakeup sources.  A source gets removed from the list when an associated suspend blocker is activated.

How do you do this safely? If you remove the active wakeup only when activating the suspend blocker, you will never unblock suspend if another wakeup event happens after user-space blocked suspend but before user-space read the events.

Also, I'm not sure we can easily associate a wakeup event with a user space suspend blocker. For instance when an alarm triggers it is sometimes because of a user-space alarm and sometimes because an in-kernel alarm.

Quoted 19 lines

When the "active" list is empty and no suspend blockers are activated, the power manager freezes ALL other processes, trusted and untrusted alike.  It then does a big poll() on all the wakeup sources.  When the poll() returns, its output is used to repopulate the "active" list and processes are unfrozen.

(You can also include some error detection: If a source remains on the "active" list for too long then something has gone wrong.)

To do all this you don't even need to use cgroups.  The existing PM implementation allows a user process to freeze everything but itself; that's how swsusp and related programs work.

This is still a big-hammer sort of approach, but it doesn't require any kernel changes.

Alan Stern

Signature · 1 line
Arve Hjønnevåg
#271 lore raw
Quoted 10 lines · Arve Hjønnevåg
Quoted 10 lines

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources.  (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Here's how you can do it.  Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

Quoted 6 lines
Quoted 4 lines

The power-manager process should keep a list of "active" wakeup sources.  A source gets removed from the list when an associated suspend blocker is activated.

How do you do this safely? If you remove the active wakeup only when

"remove the active wakeup" isn't a good way of expressing this. You remove the wakeup source from the power manager's list of active sources. This is just manipulation of a data structure internal to the power manager; it doesn't affect the actual source.

Quoted 3 lines

activating the suspend blocker, you will never unblock suspend if another wakeup event happens after user-space blocked suspend but before user-space read the events.

I'm not sure what you mean. In this scheme userspace doesn't ever block suspends. Instead the power manager freezes and unfreezes all the other processes. And the system never suspends, it simply goes idle for prolonged periods of time... with all processes frozen except the power manager, and it sitting inside a poll() system call.

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle. But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

Quoted 4 lines

Also, I'm not sure we can easily associate a wakeup event with a user space suspend blocker. For instance when an alarm triggers it is sometimes because of a user-space alarm and sometimes because an in-kernel alarm.

That's okay. The association is optional, and not all suspend blockers will have an associated wakeup source. (However, each wakeup source that needs to percolate up into userspace -- i.e., that isn't handled internally by the kernel -- should have at least one associated suspend blocker.) The purpose of these associations is to make explicit the "handoff" in your original scheme, whereby a source would cause the kernel to activate a wakelock until some user process activated its own and then cleared the kernel's wakelock. In your scheme, the connection between the userspace wakelock and the wakeup source is implicit; in my scheme it is explicit.

For example, a process that uses a suspend blocker in order to read keystrokes would obviously associate its suspend blocker with the keypad-matrix wakeup source.

Or take your example of an alarm. To make it work in my scheme, each user alarm would have to be implemented as a poll-able file descriptor. Processes reading the descriptor would block until the alarm expires. (I don't know of any driver that provides this sort of timer interface, but it would be easy to write one. You could think of it as applying Unix's "Everything is a file" philosophy to alarms.) Each of these descriptors would then be a wakeup source, included among the sources that the power manager polls for, and a suspend blocker could be associated with it.

Alan Stern

#272 lore raw

2010/6/7 Alan Stern <[email protected]>:

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

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources.  (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Here's how you can do it.  Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

Quoted 6 lines
Quoted 4 lines

The power-manager process should keep a list of "active" wakeup sources.  A source gets removed from the list when an associated suspend blocker is activated.

How do you do this safely? If you remove the active wakeup only when

"remove the active wakeup" isn't a good way of expressing this.  You remove the wakeup source from the power manager's list of active sources.  This is just manipulation of a data structure internal to the power manager; it doesn't affect the actual source.

Quoted 3 lines

activating the suspend blocker, you will never unblock suspend if another wakeup event happens after user-space blocked suspend but before user-space read the events.

I'm not sure what you mean.  In this scheme userspace doesn't ever block suspends.  Instead the power manager freezes and unfreezes all the other processes.  And the system never suspends, it simply goes idle for prolonged periods of time... with all processes frozen except the power manager, and it sitting inside a poll() system call.

Quoted 6 lines

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle.  But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

No, you have a different problem. If you open an input device and issue the ioctl to enable the suspend blocker that blocks while the queue is not empty then don't read the event, that is a bug that is easy to fix. What you have is a race condition. If you read an event that occurred after you blocked the task freezing tasks will never get frozen again (until more events occur).

Quoted 16 lines
Quoted 4 lines

Also, I'm not sure we can easily associate a wakeup event with a user space suspend blocker. For instance when an alarm triggers it is sometimes because of a user-space alarm and sometimes because an in-kernel alarm.

That's okay.  The association is optional, and not all suspend blockers will have an associated wakeup source.  (However, each wakeup source that needs to percolate up into userspace -- i.e., that isn't handled internally by the kernel -- should have at least one associated suspend blocker.)  The purpose of these associations is to make explicit the "handoff" in your original scheme, whereby a source would cause the kernel to activate a wakelock until some user process activated its own and then cleared the kernel's wakelock.  In your scheme, the connection between the userspace wakelock and the wakeup source is implicit; in my scheme it is explicit.

Quoted 4 lines

For example, a process that uses a suspend blocker in order to read keystrokes would obviously associate its suspend blocker with the keypad-matrix wakeup source.

We have multiple input devices and one thread reading from them. Do all input devices that can generate wakeup events share a wakeup source?

Quoted 10 lines

Or take your example of an alarm.  To make it work in my scheme, each user alarm would have to be implemented as a poll-able file descriptor. Processes reading the descriptor would block until the alarm expires. (I don't know of any driver that provides this sort of timer interface, but it would be easy to write one.  You could think of it as applying Unix's "Everything is a file" philosophy to alarms.)  Each of these descriptors would then be a wakeup source, included among the sources that the power manager polls for, and a suspend blocker could be associated with it.

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work (ignoring the race if you allow multiple alarms per file) which seems like more work than using a suspend blocker.

Signature · 1 line
Arve Hjønnevåg
#273 lore raw
In reply to Alan Stern

2010/6/7 Alan Stern <[email protected]>:

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

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources.  (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Here's how you can do it.  Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

Quoted 6 lines
Quoted 4 lines

The power-manager process should keep a list of "active" wakeup sources.  A source gets removed from the list when an associated suspend blocker is activated.

How do you do this safely? If you remove the active wakeup only when

"remove the active wakeup" isn't a good way of expressing this.  You remove the wakeup source from the power manager's list of active sources.  This is just manipulation of a data structure internal to the power manager; it doesn't affect the actual source.

Quoted 3 lines

activating the suspend blocker, you will never unblock suspend if another wakeup event happens after user-space blocked suspend but before user-space read the events.

I'm not sure what you mean.  In this scheme userspace doesn't ever block suspends.  Instead the power manager freezes and unfreezes all the other processes.  And the system never suspends, it simply goes idle for prolonged periods of time... with all processes frozen except the power manager, and it sitting inside a poll() system call.

Quoted 6 lines

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle.  But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

No, you have a different problem. If you open an input device and issue the ioctl to enable the suspend blocker that blocks while the queue is not empty then don't read the event, that is a bug that is easy to fix. What you have is a race condition. If you read an event that occurred after you blocked the task freezing tasks will never get frozen again (until more events occur).

Quoted 16 lines
Quoted 4 lines

Also, I'm not sure we can easily associate a wakeup event with a user space suspend blocker. For instance when an alarm triggers it is sometimes because of a user-space alarm and sometimes because an in-kernel alarm.

That's okay.  The association is optional, and not all suspend blockers will have an associated wakeup source.  (However, each wakeup source that needs to percolate up into userspace -- i.e., that isn't handled internally by the kernel -- should have at least one associated suspend blocker.)  The purpose of these associations is to make explicit the "handoff" in your original scheme, whereby a source would cause the kernel to activate a wakelock until some user process activated its own and then cleared the kernel's wakelock.  In your scheme, the connection between the userspace wakelock and the wakeup source is implicit; in my scheme it is explicit.

Quoted 4 lines

For example, a process that uses a suspend blocker in order to read keystrokes would obviously associate its suspend blocker with the keypad-matrix wakeup source.

We have multiple input devices and one thread reading from them. Do all input devices that can generate wakeup events share a wakeup source?

Quoted 10 lines

Or take your example of an alarm.  To make it work in my scheme, each user alarm would have to be implemented as a poll-able file descriptor. Processes reading the descriptor would block until the alarm expires. (I don't know of any driver that provides this sort of timer interface, but it would be easy to write one.  You could think of it as applying Unix's "Everything is a file" philosophy to alarms.)  Each of these descriptors would then be a wakeup source, included among the sources that the power manager polls for, and a suspend blocker could be associated with it.

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work (ignoring the race if you allow multiple alarms per file) which seems like more work than using a suspend blocker.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#274 lore raw
Quoted 9 lines · Arve Hjønnevåg
Quoted 6 lines

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle.  But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

No, you have a different problem. If you open an input device and issue the ioctl to enable the suspend blocker that blocks while the

Um, the suspend blocker that is active while the queue is nonempty is an in-kernel suspend blocker, right? Not a userspace suspend blocker. Hence it doesn't have to be enabled by an ioctl. Or is this some part of the whole wakelock design that hasn't yet been posted? As far as I know, you intended the in-kernel suspend blocker to be enabled whenever the input device file is open.

Quoted 2 lines

queue is not empty then don't read the event, that is a bug that is easy to fix.

I assume you mean "you open an input device but then fail to read from it". When that happens the device's driver will activate its in-kernel suspend blocker, and since the input queue will never become empty, the suspend blocker will never be deactivated. Yes, that's a bug.

Quoted 3 lines

What you have is a race condition. If you read an event that occurred after you blocked the task freezing tasks will never get frozen again (until more events occur).

Sorry, I can't parse that sentence. Could you rephrase it more grammatically?

It seems to say: "If you read an event that occurred after [something], then tasks won't get frozen again until more events occur". Which doesn't make sense, firstly because in my scheme reading events has no direct connection with freezing or unfreezing tasks, and secondly because the occurrence of events doesn't cause tasks to be frozen -- just the opposite: occurrence of events _prevents_ tasks from being frozen.

Quoted 3 lines

We have multiple input devices and one thread reading from them. Do all input devices that can generate wakeup events share a wakeup source?

Basically, a wakeup source is a file descriptor that in your scheme, some user process would read from in order to clear an in-kernel wakelock. Thus, if each of your input devices activates an in-kernel wakelock that is cleared when a user process reads the device, then the file descriptors for these input devices would each be considered a wakeup source.

Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel. However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

[On rereading this, I realized it might not have been clear that in my scheme, suspend blockers have no in-kernel component. They are implemented entirely by IPC between the process owning the suspend blocker and the power manager process. Would it be less confusing if I called them something else?]

Quoted 3 lines

(ignoring the race if
you allow multiple alarms per file) which seems like more work than using a suspend blocker.

It's not very much more: just one additional argument to the routine that creates a suspend blocker.

I get the impression that you don't fully understand how my scheme is meant to work. Would some additional explanation or examples help?

Alan Stern

#275 lore raw

2010/6/7 Alan Stern <[email protected]>:

Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines
Quoted 7 lines

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle.  But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

No, you have a different problem. If you open an input device and issue the ioctl to enable the suspend blocker that blocks while the

Quoted 7 lines

Um, the suspend blocker that is active while the queue is nonempty is an in-kernel suspend blocker, right?  Not a userspace suspend blocker. Hence it doesn't have to be enabled by an ioctl.  Or is this some part of the whole wakelock design that hasn't yet been posted?  As far as I know, you intended the in-kernel suspend blocker to be enabled whenever the input device file is open.

The patch that modifies evdev (posted in this patchset) uses an ioctl to enable the suspend blocker. Not all input devices are used for wakeup events and those don't need to block suspend.

Quoted 8 lines
Quoted 2 lines

queue is not empty then don't read the event, that is a bug that is easy to fix.

I assume you mean "you open an input device but then fail to read from it".  When that happens the device's driver will activate its in-kernel suspend blocker, and since the input queue will never become empty, the suspend blocker will never be deactivated.  Yes, that's a bug.

Quoted 7 lines
Quoted 3 lines

What you have is a race condition. If you read an event that occurred after you blocked the task freezing tasks will never get frozen again (until more events occur).

Sorry, I can't parse that sentence.  Could you rephrase it more grammatically?

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

Quoted 1 line

It seems to say: "If you read an event that occurred after [something],

Block suspend, block task freezing or whatever you want to call it.

Quoted 3 lines

then tasks won't get frozen again until more events occur".  Which doesn't make sense, firstly because in my scheme reading events has no direct connection with freezing or unfreezing tasks, and secondly

It has an indirect connection. You report a wakeup event when it occurs, but clear it when user space calls an api before reading the event. So:
Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space
User space wakes up:
- Calls api to block task freezing for event type A Another wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space
User space continues:
- Read events
- Wait for more events

Result: Task are not frozen again.

Quoted 15 lines

because the occurrence of events doesn't cause tasks to be frozen -- just the opposite: occurrence of events _prevents_ tasks from being frozen.

Quoted 3 lines

We have multiple input devices and one thread reading from them. Do all input devices that can generate wakeup events share a wakeup source?

Basically, a wakeup source is a file descriptor that in your scheme, some user process would read from in order to clear an in-kernel wakelock.  Thus, if each of your input devices activates an in-kernel wakelock that is cleared when a user process reads the device, then the file descriptors for these input devices would each be considered a wakeup source.

Quoted 7 lines
Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel.  However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

Then the source id need to be passed from the kernel to user-space.

Quoted 5 lines

[On rereading this, I realized it might not have been clear that in my scheme, suspend blockers have no in-kernel component.  They are implemented entirely by IPC between the process owning the suspend blocker and the power manager process.  Would it be less confusing if I called them something else?]

No, that is not the unclear part. What is unclear to me is where the source IDs come from. Are they static and hardcoded in the driver and user-space, or are they passed between the driver and user-space client?

Quoted 11 lines
Quoted 4 lines

(ignoring the race if
you allow multiple alarms per file) which seems like more work than using a suspend blocker.

It's not very much more: just one additional argument to the routine that creates a suspend blocker.

I get the impression that you don't fully understand how my scheme is meant to work.  Would some additional explanation or examples help?

I don't understand how you are planning to ensure that the driver and user-space code that consumes the real event use the same source id. The biggest problem I have with it though is that you have created a new race condition between reporting that a wakeup event has occurred and processing of the real event.

Signature · 1 line
Arve Hjønnevåg
#276 lore raw
In reply to Alan Stern

2010/6/7 Alan Stern <[email protected]>:

Quoted 12 lines · Arve Hjønnevåg
Quoted 10 lines
Quoted 7 lines

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle.  But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

No, you have a different problem. If you open an input device and issue the ioctl to enable the suspend blocker that blocks while the

Quoted 7 lines

Um, the suspend blocker that is active while the queue is nonempty is an in-kernel suspend blocker, right?  Not a userspace suspend blocker. Hence it doesn't have to be enabled by an ioctl.  Or is this some part of the whole wakelock design that hasn't yet been posted?  As far as I know, you intended the in-kernel suspend blocker to be enabled whenever the input device file is open.

The patch that modifies evdev (posted in this patchset) uses an ioctl to enable the suspend blocker. Not all input devices are used for wakeup events and those don't need to block suspend.

Quoted 8 lines
Quoted 2 lines

queue is not empty then don't read the event, that is a bug that is easy to fix.

I assume you mean "you open an input device but then fail to read from it".  When that happens the device's driver will activate its in-kernel suspend blocker, and since the input queue will never become empty, the suspend blocker will never be deactivated.  Yes, that's a bug.

Quoted 7 lines
Quoted 3 lines

What you have is a race condition. If you read an event that occurred after you blocked the task freezing tasks will never get frozen again (until more events occur).

Sorry, I can't parse that sentence.  Could you rephrase it more grammatically?

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

Quoted 1 line

It seems to say: "If you read an event that occurred after [something],

Block suspend, block task freezing or whatever you want to call it.

Quoted 3 lines

then tasks won't get frozen again until more events occur".  Which doesn't make sense, firstly because in my scheme reading events has no direct connection with freezing or unfreezing tasks, and secondly

It has an indirect connection. You report a wakeup event when it occurs, but clear it when user space calls an api before reading the event. So:
Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space
User space wakes up:
- Calls api to block task freezing for event type A Another wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space
User space continues:
- Read events
- Wait for more events

Result: Task are not frozen again.

Quoted 15 lines

because the occurrence of events doesn't cause tasks to be frozen -- just the opposite: occurrence of events _prevents_ tasks from being frozen.

Quoted 3 lines

We have multiple input devices and one thread reading from them. Do all input devices that can generate wakeup events share a wakeup source?

Basically, a wakeup source is a file descriptor that in your scheme, some user process would read from in order to clear an in-kernel wakelock.  Thus, if each of your input devices activates an in-kernel wakelock that is cleared when a user process reads the device, then the file descriptors for these input devices would each be considered a wakeup source.

Quoted 7 lines
Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel.  However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

Then the source id need to be passed from the kernel to user-space.

Quoted 5 lines

[On rereading this, I realized it might not have been clear that in my scheme, suspend blockers have no in-kernel component.  They are implemented entirely by IPC between the process owning the suspend blocker and the power manager process.  Would it be less confusing if I called them something else?]

No, that is not the unclear part. What is unclear to me is where the source IDs come from. Are they static and hardcoded in the driver and user-space, or are they passed between the driver and user-space client?

Quoted 11 lines
Quoted 4 lines

(ignoring the race if
you allow multiple alarms per file) which seems like more work than using a suspend blocker.

It's not very much more: just one additional argument to the routine that creates a suspend blocker.

I get the impression that you don't fully understand how my scheme is meant to work.  Would some additional explanation or examples help?

I don't understand how you are planning to ensure that the driver and user-space code that consumes the real event use the same source id. The biggest problem I have with it though is that you have created a new race condition between reporting that a wakeup event has occurred and processing of the real event.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#277 lore raw

On Mon, 7 Jun 2010 20:05:56 -0700
Arve Hjønnevåg <[email protected]> wrote:
Hi,

Quoted 6 lines

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

Here is how I understood Alan's approach:

Userspace manager (UM) does:

<...continuation of function A>
5) unblock from reading a wakeup from wakeupevents-fd
6) thaw userspace
7) return
</function A>

[userspace sees there is an event; blocks suspend at UM; processes event; consume wakeupevent at UM; unblock suspend at UM;]

Unblocking the last suspend-blocker at the UM starts function A:

<function A>
1) non-blocking read of wakeup-events-fd (refills wakeupevents)
2) if all wakeupevents are consumed:
3a) freeze userspace
else

	3b) /* wait for userspace to unblock
	suspend again... this should take care of the races? */ return;

4) blocking read of wakeupevents-fd
<...for continuation see above>

You mitigate the race by freezing and unfreezing userspace. If there occur wakeups between 3a) and 4) you will have frozen userspace in vain.

So I think the feasibility of this solution depends on the performance of freezing/thawing userspace. I can't judge that.

Also I _think_ this is racefree as long as you have the UM properly serialized. Or did I overlook something?

Cheers,
Flo

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

On Mon, 7 Jun 2010 20:05:56 -0700
Arve Hjønnevåg <[email protected]> wrote:
Hi,

Quoted 6 lines

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

Here is how I understood Alan's approach:

Userspace manager (UM) does:

<...continuation of function A>
5) unblock from reading a wakeup from wakeupevents-fd
6) thaw userspace
7) return
</function A>

[userspace sees there is an event; blocks suspend at UM; processes event; consume wakeupevent at UM; unblock suspend at UM;]

Unblocking the last suspend-blocker at the UM starts function A:

<function A>
1) non-blocking read of wakeup-events-fd (refills wakeupevents)
2) if all wakeupevents are consumed:
3a) freeze userspace
else

	3b) /* wait for userspace to unblock
	suspend again... this should take care of the races? */ return;

4) blocking read of wakeupevents-fd
<...for continuation see above>

You mitigate the race by freezing and unfreezing userspace. If there occur wakeups between 3a) and 4) you will have frozen userspace in vain.

So I think the feasibility of this solution depends on the performance of freezing/thawing userspace. I can't judge that.

Also I _think_ this is racefree as long as you have the UM properly serialized. Or did I overlook something?

Cheers,
Flo

#279 lore raw
In reply to Arve Hjønnevåg
Quoted 3 lines · Arve Hjønnevåg

The patch that modifies evdev (posted in this patchset) uses an ioctl to enable the suspend blocker. Not all input devices are used for wakeup events and those don't need to block suspend.

But you do have a 1-1 correspondence, right? That is, the input devices that are used for wakeup events are exactly the ones that block suspend?

Quoted 5 lines

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

I still find your wording a little confusing. Task freezing can be prevented (a more accurate term than "blocked") by two kinds of things:
a suspend blocker or an "active" wakeup source. I'm not sure which kind you mean here.

Quoted 3 lines

It has an indirect connection. You report a wakeup event when it occurs, but clear it when user space calls an api before reading the event. So:

Yes, that's right.

Quoted 3 lines

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps. Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

Quoted 2 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it. The API you're referring to is simply the function that activates a suspend blocker. It does prevent task freezing, but you shouldn't say it prevents freezing for event type A. More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active. Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 3 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

Same as above.

Quoted 5 lines

User space continues:
- Read events
- Wait for more events

Result: Task are not frozen again.

Because the suspend blocker was never deactivated. The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Here's how my scheme is meant to work:

Wakeup event for input device A occurs.

A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources. But it doesn't freeze userspace yet, because now a suspend blocker is active.

The other process consumes events from A and does other stuff. Maybe more input data arrives while this is happening and the process reads it. Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers. Therefore it freezes userspace and does a big poll() on all possible sources. (If there are still events on the input device queue, the poll() returns immediately.)

Rinse and repeat.

I don't see any dangerous races there. The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

The big assumption here is that a user process never consumes wakeup events without first activating a suspend blocker. This seems like a reasonable assumption, but we can work around it if necessary.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel.  However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

Then the source id need to be passed from the kernel to user-space.

A source ID is a file descriptor. File descriptors are passed from the kernel to userspace whenever a file is opened; I can't deny it. And they are passed back to the kernel as part of the read() and poll() system calls. Is that what you mean?

Quoted 4 lines

No, that is not the unclear part. What is unclear to me is where the source IDs come from. Are they static and hardcoded in the driver and user-space, or are they passed between the driver and user-space client?

They are not static; they are file descriptors. I guess this should have been made more clear originally, but this is still pretty new to me too.

Quoted 2 lines

I don't understand how you are planning to ensure that the driver and user-space code that consumes the real event use the same source id.

How can it be otherwise? The userspace code consumes the event by reading from the device file. In order to do so, it has to use the same file descriptor it received when it opened the device file originally.

Quoted 3 lines

The biggest problem I have with it though is that you have created a new race condition between reporting that a wakeup event has occurred and processing of the real event.

There is no race. The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

There's one other thing worth mentioning. All along I've been talking about a power manager process that coordinates all these activities. In theory there's no reason that process couldn't be implemented as a kernel thread. This would improve efficiency by reducing the number of context switches, and it would change IPC calls into plain system calls.

If you did implement it that way, it could be done as a standalone kernel module, totally noninvasive. It would not need to be part of the vanilla kernel and nobody would object to it.

Alan Stern

#280 lore raw

2010/6/8 Alan Stern <[email protected]>:

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

The patch that modifies evdev (posted in this patchset) uses an ioctl to enable the suspend blocker. Not all input devices are used for wakeup events and those don't need to block suspend.

But you do have a 1-1 correspondence, right?  That is, the input devices that are used for wakeup events are exactly the ones that block suspend?

Yes.

Quoted 11 lines
Quoted 6 lines

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

I still find your wording a little confusing.  Task freezing can be prevented (a more accurate term than "blocked") by two kinds of things:
a suspend blocker or an "active" wakeup source.  I'm not sure which kind you mean here.

I mean prevented by a user space suspend blocker.

Quoted 7 lines
Quoted 4 lines

It has an indirect connection. You report a wakeup event when it occurs, but clear it when user space calls an api before reading the event. So:

Yes, that's right.

Quoted 9 lines
Quoted 3 lines

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps.  Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

If you want to ensure that more than one process see the event it has to be two steps, but it does not affect the race I was trying to describe.

Quoted 11 lines
Quoted 2 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it.  The API you're referring to is simply the function that activates a suspend blocker.  It does prevent task freezing, but you shouldn't say it prevents freezing for event type A.  More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active.  Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 8 lines
Quoted 3 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

Same as above.

Quoted 2 lines

User space continues:
- Read events

Sorry, I missed the unblock task freezing step here.

Quoted 7 lines
Quoted 3 lines

- Wait for more events

Result: Task are not frozen again.

Because the suspend blocker was never deactivated.  The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Yes, but with the sequence of events above task will not be frozen again even if the wake-lock/suspend-blocker/task-freezing-preventer is released.

Quoted 13 lines

Here's how my scheme is meant to work:

       Wakeup event for input device A occurs.

       A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

       The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

Quoted 7 lines

       Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

       When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources.  But it doesn't freeze userspace yet, because now a suspend blocker is active.

If another event happens at this point don't you put A back on the list? If so, it never gets removed.

Quoted 57 lines

       The other process consumes events from A and does other stuff.  Maybe more input data arrives while this is happening and the process reads it.  Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

       When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers.  Therefore it freezes userspace and does a big poll() on all possible sources.  (If there are still events on the input device queue, the poll() returns immediately.)

       Rinse and repeat.

I don't see any dangerous races there.  The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

The big assumption here is that a user process never consumes wakeup events without first activating a suspend blocker.  This seems like a reasonable assumption, but we can work around it if necessary.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel.  However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

Then the source id need to be passed from the kernel to user-space.

A source ID is a file descriptor.  File descriptors are passed from the kernel to userspace whenever a file is opened; I can't deny it.  And they are passed back to the kernel as part of the read() and poll() system calls.  Is that what you mean?

Quoted 4 lines

No, that is not the unclear part. What is unclear to me is where the source IDs come from. Are they static and hardcoded in the driver and user-space, or are they passed between the driver and user-space client?

They are not static; they are file descriptors.  I guess this should have been made more clear originally, but this is still pretty new to me too.

Quoted 2 lines

I don't understand how you are planning to ensure that the driver and user-space code that consumes the real event use the same source id.

How can it be otherwise?  The userspace code consumes the event by reading from the device file.  In order to do so, it has to use the same file descriptor it received when it opened the device file originally.

Quoted 9 lines
Quoted 3 lines

The biggest problem I have with it though is that you have created a new race condition between reporting that a wakeup event has occurred and processing of the real event.

There is no race.  The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

If the driver making data available to be read triggers a wakeup event in the power manager process that has to be cleared by the process reading the events, then you have a race. Since the power manager is selecting/polling on the same file descriptor, I don't see what you gain from linking the wakeup events to suspend blockers. If you break this link it think can work, but it does require us to modify all code that reads wakeup events from the kernel to register the file descriptors they get events from. It would also require adding poll/select support to android alarm driver, and any driver that currently uses a wakelock with a timeout would need to notify the user space power manager instead.

Quoted 20 lines

There's one other thing worth mentioning.  All along I've been talking about a power manager process that coordinates all these activities. In theory there's no reason that process couldn't be implemented as a kernel thread.  This would improve efficiency by reducing the number of context switches, and it would change IPC calls into plain system calls.

If you did implement it that way, it could be done as a standalone kernel module, totally noninvasive.  It would not need to be part of the vanilla kernel and nobody would object to it.

Alan Stern

--
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
#281 lore raw
In reply to Alan Stern

2010/6/8 Alan Stern <[email protected]>:

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

The patch that modifies evdev (posted in this patchset) uses an ioctl to enable the suspend blocker. Not all input devices are used for wakeup events and those don't need to block suspend.

But you do have a 1-1 correspondence, right?  That is, the input devices that are used for wakeup events are exactly the ones that block suspend?

Yes.

Quoted 11 lines
Quoted 6 lines

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

I still find your wording a little confusing.  Task freezing can be prevented (a more accurate term than "blocked") by two kinds of things:
a suspend blocker or an "active" wakeup source.  I'm not sure which kind you mean here.

I mean prevented by a user space suspend blocker.

Quoted 7 lines
Quoted 4 lines

It has an indirect connection. You report a wakeup event when it occurs, but clear it when user space calls an api before reading the event. So:

Yes, that's right.

Quoted 9 lines
Quoted 3 lines

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps.  Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

If you want to ensure that more than one process see the event it has to be two steps, but it does not affect the race I was trying to describe.

Quoted 11 lines
Quoted 2 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it.  The API you're referring to is simply the function that activates a suspend blocker.  It does prevent task freezing, but you shouldn't say it prevents freezing for event type A.  More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active.  Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 8 lines
Quoted 3 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

Same as above.

Quoted 2 lines

User space continues:
- Read events

Sorry, I missed the unblock task freezing step here.

Quoted 7 lines
Quoted 3 lines

- Wait for more events

Result: Task are not frozen again.

Because the suspend blocker was never deactivated.  The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Yes, but with the sequence of events above task will not be frozen again even if the wake-lock/suspend-blocker/task-freezing-preventer is released.

Quoted 13 lines

Here's how my scheme is meant to work:

       Wakeup event for input device A occurs.

       A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

       The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

Quoted 7 lines

       Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

       When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources.  But it doesn't freeze userspace yet, because now a suspend blocker is active.

If another event happens at this point don't you put A back on the list? If so, it never gets removed.

Quoted 57 lines

       The other process consumes events from A and does other stuff.  Maybe more input data arrives while this is happening and the process reads it.  Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

       When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers.  Therefore it freezes userspace and does a big poll() on all possible sources.  (If there are still events on the input device queue, the poll() returns immediately.)

       Rinse and repeat.

I don't see any dangerous races there.  The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

The big assumption here is that a user process never consumes wakeup events without first activating a suspend blocker.  This seems like a reasonable assumption, but we can work around it if necessary.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel.  However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

Then the source id need to be passed from the kernel to user-space.

A source ID is a file descriptor.  File descriptors are passed from the kernel to userspace whenever a file is opened; I can't deny it.  And they are passed back to the kernel as part of the read() and poll() system calls.  Is that what you mean?

Quoted 4 lines

No, that is not the unclear part. What is unclear to me is where the source IDs come from. Are they static and hardcoded in the driver and user-space, or are they passed between the driver and user-space client?

They are not static; they are file descriptors.  I guess this should have been made more clear originally, but this is still pretty new to me too.

Quoted 2 lines

I don't understand how you are planning to ensure that the driver and user-space code that consumes the real event use the same source id.

How can it be otherwise?  The userspace code consumes the event by reading from the device file.  In order to do so, it has to use the same file descriptor it received when it opened the device file originally.

Quoted 9 lines
Quoted 3 lines

The biggest problem I have with it though is that you have created a new race condition between reporting that a wakeup event has occurred and processing of the real event.

There is no race.  The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

If the driver making data available to be read triggers a wakeup event in the power manager process that has to be cleared by the process reading the events, then you have a race. Since the power manager is selecting/polling on the same file descriptor, I don't see what you gain from linking the wakeup events to suspend blockers. If you break this link it think can work, but it does require us to modify all code that reads wakeup events from the kernel to register the file descriptors they get events from. It would also require adding poll/select support to android alarm driver, and any driver that currently uses a wakelock with a timeout would need to notify the user space power manager instead.

Quoted 20 lines

There's one other thing worth mentioning.  All along I've been talking about a power manager process that coordinates all these activities. In theory there's no reason that process couldn't be implemented as a kernel thread.  This would improve efficiency by reducing the number of context switches, and it would change IPC calls into plain system calls.

If you did implement it that way, it could be done as a standalone kernel module, totally noninvasive.  It would not need to be part of the vanilla kernel and nobody would object to it.

Alan Stern

--
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 · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#282 lore raw
Quoted 10 lines · Arve Hjønnevåg
Quoted 9 lines
Quoted 3 lines

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps.  Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

Quoted 3 lines

If you want to ensure that more than one process see the event it has to be two steps, but it does not affect the race I was trying to describe.

Are you sure about that? If two processes call poll() for the same file descriptor, don't both calls return when data becomes available? But agreed, it doesn't matter -- especially since I only need one process (the power manager) to see the event.

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it.  The API you're referring to is simply the function that activates a suspend blocker.  It does prevent task freezing, but you shouldn't say it prevents freezing for event type A.  More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active.  Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A

I think this is where you misunderstood. There is no "report wakeup event" as such. All that happens is that data becomes available to be read from the input device file. However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Quoted 13 lines
Quoted 6 lines
Quoted 1 line

- queue event for delivery to user-space

Same as above.

Quoted 2 lines

User space continues:
- Read events

Sorry, I missed the unblock task freezing step here.

Quoted 4 lines
Quoted 3 lines

- Wait for more events

Result: Task are not frozen again.

Quoted 7 lines
Quoted 3 lines

Because the suspend blocker was never deactivated.  The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Yes, but with the sequence of events above task will not be frozen again even if the wake-lock/suspend-blocker/task-freezing-preventer is released.

Yes they will. When the suspend blocker is deactivated, the power manager process will realize that there are no active suspend blockers and it will think there are no active sources. Thus it will freeze processes as usual.

Quoted 15 lines
Quoted 15 lines

Here's how my scheme is meant to work:

       Wakeup event for input device A occurs.

       A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

       The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

       Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

Quoted 7 lines
Quoted 4 lines

       When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources.  But it doesn't freeze userspace yet, because now a suspend blocker is active.

If another event happens at this point don't you put A back on the list? If so, it never gets removed.

No, you don't put A back on the list. Sources get put on the list only when the information returned by poll() indicates they have data available. The power manager doesn't poll while suspend blockers are active.

Quoted 20 lines
Quoted 19 lines

       The other process consumes events from A and does other stuff.  Maybe more input data arrives while this is happening and the process reads it.  Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

       When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers.  Therefore it freezes userspace and does a big poll() on all possible sources.  (If there are still events on the input device queue, the poll() returns immediately.)

       Rinse and repeat.

I don't see any dangerous races there.  The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

Quoted 8 lines
Quoted 5 lines

There is no race.  The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

If the driver making data available to be read triggers a wakeup event in the power manager process

It doesn't. Only return from a poll() causes the power manager process to think a wakeup event has occurred.

Quoted 4 lines

that has to be cleared by the process
reading the events, then you have a race. Since the power manager is selecting/polling on the same file descriptor, I don't see what you gain from linking the wakeup events to suspend blockers.

What I gain is the ability to know when an in-kernel wakelock _could_ have been released, without actually implementing in-kernel wakelocks.

With real in-kernel wakelocks, the wakelock is released when the input queue becomes empty. There's no way for the power manager process to know exactly when that happens without modifying the kernel. However we can use the activation of the corresponding userspace suspend blocker as a proxy. It's nearly as good, and it gets the job done.

If you prefer, an interface could be added whereby a user process tells the power manager explicitly that it's going to read data from an input device, instead of relying on implicit notification through suspend blocker activation. I don't know whether this would be simpler or more complex; it depends on the design of your userspace.

Quoted 4 lines

If you break
this link it think can work, but it does require us to modify all code that reads wakeup events from the kernel to register the file descriptors they get events from.

Yes. I don't know how your user code is structured; if there is a fixed correspondence between file descriptors and suspend blockers (the same wakeup events are always handled by the same suspend blockers) then this will be a simple change -- the file descriptor can be registered when the suspend blocker is created.

If the correspondence is more dynamic (different suspend blockers used for the same wakeup device at different times, or multiple wakeup devices handled by one suspend blocker) then the required changes will be more complicated. Not tremendously more.

Quoted 2 lines

It would also require adding
poll/select support to android alarm driver,

Yes. Is this a platform-specific driver? (I assume so, since you called it the "android alarm driver".) Then poll/select support can be added without provoking a lot of objections from legions of kernel developers.

Quoted 3 lines

and any driver that
currently uses a wakelock with a timeout would need to notify the user space power manager instead.

Hmm. This is symptomatic of a deficiency in the original wakelock implementation -- those timeouts always were arbitrary.

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake. Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources. At those points it could remove wakeup sources that have timed out.

Obviously this proposal would complicate your userspace. Not enormously, since most of the work is confined to the power manager, but somewhat. That's the price to be paid for leaving the kernel essentially untouched. Consider the amount of resistance your wakelock/suspend-blocker patches have already received; you'll have to decide which approach will work out better in the end.

Alan Stern

#283 lore raw

2010/6/9 Alan Stern <[email protected]>:

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

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps.  Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

Quoted 6 lines
Quoted 3 lines

If you want to ensure that more than one process see the event it has to be two steps, but it does not affect the race I was trying to describe.

Are you sure about that?  If two processes call poll() for the same file descriptor, don't both calls return when data becomes available?

Yes if they are both already in the poll call they both return, but if one process reads the data while the second process is not in the poll call the second process will not see anything.

Quoted 2 lines

But agreed, it doesn't matter -- especially since I only need one process (the power manager) to see the event.

The power may not see the event, the process that reads the event will always see it. If the power manager is not in the poll call when the event happens, the process that reads the event can read the event before the power manager calls poll.

Quoted 15 lines
Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it.  The API you're referring to is simply the function that activates a suspend blocker.  It does prevent task freezing, but you shouldn't say it prevents freezing for event type A.  More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active.  Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A

Quoted 7 lines

I think this is where you misunderstood.  There is no "report wakeup event" as such.  All that happens is that data becomes available to be read from the input device file.  However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Yes this is not what I though you were suggesting. I thought you were trying to make sure the power manager sees all wakeup events. If you are only listening for wakeup events while no suspend blockers are active, why latch them?

Quoted 91 lines
Quoted 13 lines
Quoted 6 lines
Quoted 1 line

- queue event for delivery to user-space

Same as above.

Quoted 2 lines

User space continues:
- Read events

Sorry, I missed the unblock task freezing step here.

Quoted 4 lines
Quoted 3 lines

- Wait for more events

Result: Task are not frozen again.

Quoted 7 lines
Quoted 3 lines

Because the suspend blocker was never deactivated.  The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Yes, but with the sequence of events above task will not be frozen again even if the wake-lock/suspend-blocker/task-freezing-preventer is released.

Yes they will.  When the suspend blocker is deactivated, the power manager process will realize that there are no active suspend blockers and it will think there are no active sources.  Thus it will freeze processes as usual.

Quoted 15 lines
Quoted 15 lines

Here's how my scheme is meant to work:

       Wakeup event for input device A occurs.

       A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

       The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

       Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

Quoted 7 lines
Quoted 4 lines

       When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources.  But it doesn't freeze userspace yet, because now a suspend blocker is active.

If another event happens at this point don't you put A back on the list? If so, it never gets removed.

No, you don't put A back on the list.  Sources get put on the list only when the information returned by poll() indicates they have data available.  The power manager doesn't poll while suspend blockers are active.

Quoted 20 lines
Quoted 19 lines

       The other process consumes events from A and does other stuff.  Maybe more input data arrives while this is happening and the process reads it.  Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

       When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers.  Therefore it freezes userspace and does a big poll() on all possible sources.  (If there are still events on the input device queue, the poll() returns immediately.)

       Rinse and repeat.

I don't see any dangerous races there.  The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

Quoted 8 lines
Quoted 5 lines

There is no race.  The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

If the driver making data available to be read triggers a wakeup event in the power manager process

It doesn't.  Only return from a poll() causes the power manager process to think a wakeup event has occurred.

Quoted 4 lines

that has to be cleared by the process
reading the events, then you have a race. Since the power manager is selecting/polling on the same file descriptor, I don't see what you gain from linking the wakeup events to suspend blockers.

Quoted 9 lines

What I gain is the ability to know when an in-kernel wakelock _could_ have been released, without actually implementing in-kernel wakelocks.

With real in-kernel wakelocks, the wakelock is released when the input queue becomes empty.  There's no way for the power manager process to know exactly when that happens without modifying the kernel.  However we can use the activation of the corresponding userspace suspend blocker as a proxy.  It's nearly as good, and it gets the job done.

If you only poll the fd after the last user-space suspend blocker is released, why do you care when the kernel wakelock could have been released? It seem the only thing it saves you is an extra poll call when two wakeup events happen at the same time and one of them is fully processed and unblocks suspend before the other event handler blocks suspend. It seems strange to remove your wakeup event from the list when a specific suspend blocker is acquired when any suspend blocker will prevent that wakeup event from being added to the list in the first place.

Quoted 6 lines

If you prefer, an interface could be added whereby a user process tells the power manager explicitly that it's going to read data from an input device, instead of relying on implicit notification through suspend blocker activation.  I don't know whether this would be simpler or more complex; it depends on the design of your userspace.

I don't think there is a need to tie the fds to anything else. If you poll the fds on the last suspend unblock call, you should get the same behaviour.

Quoted 11 lines
Quoted 4 lines

If you break
this link it think can work, but it does require us to modify all code that reads wakeup events from the kernel to register the file descriptors they get events from.

Yes.  I don't know how your user code is structured; if there is a fixed correspondence between file descriptors and suspend blockers (the same wakeup events are always handled by the same suspend blockers) then this will be a simple change -- the file descriptor can be registered when the suspend blocker is created.

Quoted 4 lines

If the correspondence is more dynamic (different suspend blockers used for the same wakeup device at different times, or multiple wakeup devices handled by one suspend blocker) then the required changes will be more complicated.  Not tremendously more.

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Quoted 9 lines
Quoted 3 lines

It would also require adding
poll/select support to android alarm driver,

Yes.  Is this a platform-specific driver?  (I assume so, since you called it the "android alarm driver".)  Then poll/select support can be added without provoking a lot of objections from legions of kernel developers.

It is not platform specific, but it is not currently in the mainline kernel so I would not expect any objections to a change that adding poll/select support.

Quoted 7 lines
Quoted 3 lines

and any driver that
currently uses a wakelock with a timeout would need to notify the user space power manager instead.

Hmm.  This is symptomatic of a deficiency in the original wakelock implementation -- those timeouts always were arbitrary.

Quoted 7 lines

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake.  Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources.  At those points it could remove wakeup sources that have timed out.

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it. Also, existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Quoted 3 lines

Obviously this proposal would complicate your userspace.  Not enormously, since most of the work is confined to the power manager,

No, the main problem it that it is not confined to the power manager. The power manager does not have a list of file descriptors to monitor, so we have to modify all code that handles wakeup events. This includes vendor supplied code that we don't have the source for, but, on some platforms at least, this code relies on kernel wakelocks with a timeout and could at first be handled the same way we would have to handle existing apps reading from a socket.

Quoted 5 lines

but somewhat.  That's the price to be paid for leaving the kernel essentially untouched.  Consider the amount of resistance your wakelock/suspend-blocker patches have already received; you'll have to decide which approach will work out better in the end.

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Your solution is not immediately useful since depends on removing all periodic kernel timers and adding support to stopping the monotonic clock for set of processes that are frozen.

Your solution forces the user space interface to be more complicated, and it creates a new user space power manager that has to start before any process that handle wakeup events.

Signature · 1 line
Arve Hjønnevåg
#284 lore raw
In reply to Alan Stern

2010/6/9 Alan Stern <[email protected]>:

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

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps.  Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

Quoted 6 lines
Quoted 3 lines

If you want to ensure that more than one process see the event it has to be two steps, but it does not affect the race I was trying to describe.

Are you sure about that?  If two processes call poll() for the same file descriptor, don't both calls return when data becomes available?

Yes if they are both already in the poll call they both return, but if one process reads the data while the second process is not in the poll call the second process will not see anything.

Quoted 2 lines

But agreed, it doesn't matter -- especially since I only need one process (the power manager) to see the event.

The power may not see the event, the process that reads the event will always see it. If the power manager is not in the poll call when the event happens, the process that reads the event can read the event before the power manager calls poll.

Quoted 15 lines
Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it.  The API you're referring to is simply the function that activates a suspend blocker.  It does prevent task freezing, but you shouldn't say it prevents freezing for event type A.  More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active.  Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A

Quoted 7 lines

I think this is where you misunderstood.  There is no "report wakeup event" as such.  All that happens is that data becomes available to be read from the input device file.  However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Yes this is not what I though you were suggesting. I thought you were trying to make sure the power manager sees all wakeup events. If you are only listening for wakeup events while no suspend blockers are active, why latch them?

Quoted 91 lines
Quoted 13 lines
Quoted 6 lines
Quoted 1 line

- queue event for delivery to user-space

Same as above.

Quoted 2 lines

User space continues:
- Read events

Sorry, I missed the unblock task freezing step here.

Quoted 4 lines
Quoted 3 lines

- Wait for more events

Result: Task are not frozen again.

Quoted 7 lines
Quoted 3 lines

Because the suspend blocker was never deactivated.  The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Yes, but with the sequence of events above task will not be frozen again even if the wake-lock/suspend-blocker/task-freezing-preventer is released.

Yes they will.  When the suspend blocker is deactivated, the power manager process will realize that there are no active suspend blockers and it will think there are no active sources.  Thus it will freeze processes as usual.

Quoted 15 lines
Quoted 15 lines

Here's how my scheme is meant to work:

       Wakeup event for input device A occurs.

       A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

       The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

       Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

Quoted 7 lines
Quoted 4 lines

       When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources.  But it doesn't freeze userspace yet, because now a suspend blocker is active.

If another event happens at this point don't you put A back on the list? If so, it never gets removed.

No, you don't put A back on the list.  Sources get put on the list only when the information returned by poll() indicates they have data available.  The power manager doesn't poll while suspend blockers are active.

Quoted 20 lines
Quoted 19 lines

       The other process consumes events from A and does other stuff.  Maybe more input data arrives while this is happening and the process reads it.  Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

       When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers.  Therefore it freezes userspace and does a big poll() on all possible sources.  (If there are still events on the input device queue, the poll() returns immediately.)

       Rinse and repeat.

I don't see any dangerous races there.  The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

Quoted 8 lines
Quoted 5 lines

There is no race.  The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

If the driver making data available to be read triggers a wakeup event in the power manager process

It doesn't.  Only return from a poll() causes the power manager process to think a wakeup event has occurred.

Quoted 4 lines

that has to be cleared by the process
reading the events, then you have a race. Since the power manager is selecting/polling on the same file descriptor, I don't see what you gain from linking the wakeup events to suspend blockers.

Quoted 9 lines

What I gain is the ability to know when an in-kernel wakelock _could_ have been released, without actually implementing in-kernel wakelocks.

With real in-kernel wakelocks, the wakelock is released when the input queue becomes empty.  There's no way for the power manager process to know exactly when that happens without modifying the kernel.  However we can use the activation of the corresponding userspace suspend blocker as a proxy.  It's nearly as good, and it gets the job done.

If you only poll the fd after the last user-space suspend blocker is released, why do you care when the kernel wakelock could have been released? It seem the only thing it saves you is an extra poll call when two wakeup events happen at the same time and one of them is fully processed and unblocks suspend before the other event handler blocks suspend. It seems strange to remove your wakeup event from the list when a specific suspend blocker is acquired when any suspend blocker will prevent that wakeup event from being added to the list in the first place.

Quoted 6 lines

If you prefer, an interface could be added whereby a user process tells the power manager explicitly that it's going to read data from an input device, instead of relying on implicit notification through suspend blocker activation.  I don't know whether this would be simpler or more complex; it depends on the design of your userspace.

I don't think there is a need to tie the fds to anything else. If you poll the fds on the last suspend unblock call, you should get the same behaviour.

Quoted 11 lines
Quoted 4 lines

If you break
this link it think can work, but it does require us to modify all code that reads wakeup events from the kernel to register the file descriptors they get events from.

Yes.  I don't know how your user code is structured; if there is a fixed correspondence between file descriptors and suspend blockers (the same wakeup events are always handled by the same suspend blockers) then this will be a simple change -- the file descriptor can be registered when the suspend blocker is created.

Quoted 4 lines

If the correspondence is more dynamic (different suspend blockers used for the same wakeup device at different times, or multiple wakeup devices handled by one suspend blocker) then the required changes will be more complicated.  Not tremendously more.

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Quoted 9 lines
Quoted 3 lines

It would also require adding
poll/select support to android alarm driver,

Yes.  Is this a platform-specific driver?  (I assume so, since you called it the "android alarm driver".)  Then poll/select support can be added without provoking a lot of objections from legions of kernel developers.

It is not platform specific, but it is not currently in the mainline kernel so I would not expect any objections to a change that adding poll/select support.

Quoted 7 lines
Quoted 3 lines

and any driver that
currently uses a wakelock with a timeout would need to notify the user space power manager instead.

Hmm.  This is symptomatic of a deficiency in the original wakelock implementation -- those timeouts always were arbitrary.

Quoted 7 lines

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake.  Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources.  At those points it could remove wakeup sources that have timed out.

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it. Also, existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Quoted 3 lines

Obviously this proposal would complicate your userspace.  Not enormously, since most of the work is confined to the power manager,

No, the main problem it that it is not confined to the power manager. The power manager does not have a list of file descriptors to monitor, so we have to modify all code that handles wakeup events. This includes vendor supplied code that we don't have the source for, but, on some platforms at least, this code relies on kernel wakelocks with a timeout and could at first be handled the same way we would have to handle existing apps reading from a socket.

Quoted 5 lines

but somewhat.  That's the price to be paid for leaving the kernel essentially untouched.  Consider the amount of resistance your wakelock/suspend-blocker patches have already received; you'll have to decide which approach will work out better in the end.

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Your solution is not immediately useful since depends on removing all periodic kernel timers and adding support to stopping the monotonic clock for set of processes that are frozen.

Your solution forces the user space interface to be more complicated, and it creates a new user space power manager that has to start before any process that handle wakeup events.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#285 lore raw
Quoted 14 lines · Arve Hj?nnev?g

The power may not see the event, the process that reads the event will always see it. If the power manager is not in the poll call when the event happens, the process that reads the event can read the event before the power manager calls poll.

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Quoted 8 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it. Also, existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

why could the suspend blocker process see all events, but the power manager process not see the events?

have the userspace talk to the power manager the way it does to the suspend blocker now and what's the difference?

effectivly think s/suspend blocker/power manager/ (with the power manager doing all the other things that are proposed instead of grabbing the wakelock), the difference should be hidden to the rest of userspace.

what am I missing here?

David Lang

#286 lore raw

2010/6/9 <[email protected]>:

Quoted 25 lines · Arve Hj?nnev?g
Quoted 15 lines

The power may not see the event, the process that reads the event will always see it. If the power manager is not in the poll call when the event happens, the process that reads the event can read the event before the power manager calls poll.

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Quoted 8 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it. Also, existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Quoted 3 lines

why could the suspend blocker process see all events, but the power manager process not see the events?

Because in this proposal the power manager only looks for the events (on the same queue) when no user space suspend blockers are active.

Quoted 9 lines

have the userspace talk to the power manager the way it does to the suspend blocker now and what's the difference?

effectivly think s/suspend blocker/power manager/ (with the power manager doing all the other things that are proposed instead of grabbing the wakelock), the difference should be hidden to the rest of userspace.

what am I missing here?

The current user space interface does not require that clients register the file descriptors that they get wakeup events from with another process.

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

2010/6/9 <[email protected]>:

Quoted 25 lines · Arve Hj?nnev?g
Quoted 15 lines

The power may not see the event, the process that reads the event will always see it. If the power manager is not in the poll call when the event happens, the process that reads the event can read the event before the power manager calls poll.

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Quoted 8 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it. Also, existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Quoted 3 lines

why could the suspend blocker process see all events, but the power manager process not see the events?

Because in this proposal the power manager only looks for the events (on the same queue) when no user space suspend blockers are active.

Quoted 9 lines

have the userspace talk to the power manager the way it does to the suspend blocker now and what's the difference?

effectivly think s/suspend blocker/power manager/ (with the power manager doing all the other things that are proposed instead of grabbing the wakelock), the difference should be hidden to the rest of userspace.

what am I missing here?

The current user space interface does not require that clients register the file descriptors that they get wakeup events from with another process.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#288 lore raw
Quoted 4 lines · On Wed, 9 Jun 2010 21:51:38 -0700 Arve Hjønnevåg <[email protected]> wrote:

The current user space interface does not require that clients register the file descriptors that they get wakeup events from with another process.

However I believe they *do* register these file descriptors with the kernel, via some sort of ioctl (I think you have said that is the case for input devices at least).
Can you confirm that?

If that is the case, is it really such a big change to register with another process instead of with the kernel?

Thanks,
NeilBrown

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

#289 lore raw
In reply to Arve Hjønnevåg
Quoted 4 lines · On Wed, 9 Jun 2010 21:51:38 -0700 Arve Hjønnevåg <[email protected]> wrote:

The current user space interface does not require that clients register the file descriptors that they get wakeup events from with another process.

However I believe they *do* register these file descriptors with the kernel, via some sort of ioctl (I think you have said that is the case for input devices at least).
Can you confirm that?

If that is the case, is it really such a big change to register with another process instead of with the kernel?

Thanks,
NeilBrown

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#290 lore raw
In reply to [email protected]
Quoted 11 lines · On Wed, 9 Jun 2010 [email protected] wrote:

why could the suspend blocker process see all events, but the power manager process not see the events?

have the userspace talk to the power manager the way it does to the suspend blocker now and what's the difference?

effectivly think s/suspend blocker/power manager/ (with the power manager doing all the other things that are proposed instead of grabbing the wakelock), the difference should be hidden to the rest of userspace.

what am I missing here?

The main difference is that with a userspace power manager, programs have to tell the power manager whenever they open or close a wakeup-capable device file (and send it a copy of the file descriptor). With an in-kernel implementation these extra steps aren't needed, because of course kernel drivers already know when their device files are opened or closed.

Alan Stern

#291 lore raw
In reply to [email protected]
Quoted 11 lines · On Wed, 9 Jun 2010 [email protected] wrote:

why could the suspend blocker process see all events, but the power manager process not see the events?

have the userspace talk to the power manager the way it does to the suspend blocker now and what's the difference?

effectivly think s/suspend blocker/power manager/ (with the power manager doing all the other things that are proposed instead of grabbing the wakelock), the difference should be hidden to the rest of userspace.

what am I missing here?

The main difference is that with a userspace power manager, programs have to tell the power manager whenever they open or close a wakeup-capable device file (and send it a copy of the file descriptor). With an in-kernel implementation these extra steps aren't needed, because of course kernel drivers already know when their device files are opened or closed.

Alan Stern

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

The power may not see the event, the process that reads the event will always see it. If the power manager is not in the poll call when the event happens, the process that reads the event can read the event before the power manager calls poll.

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Quoted 8 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it. Also, existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

why could the suspend blocker process see all events, but the power manager process not see the events?

have the userspace talk to the power manager the way it does to the suspend blocker now and what's the difference?

effectivly think s/suspend blocker/power manager/ (with the power manager doing all the other things that are proposed instead of grabbing the wakelock), the difference should be hidden to the rest of userspace.

what am I missing here?

David Lang

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

I think this is where you misunderstood.  There is no "report wakeup event" as such.  All that happens is that data becomes available to be read from the input device file.  However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Yes this is not what I though you were suggesting. I thought you were trying to make sure the power manager sees all wakeup events. If you are only listening for wakeup events while no suspend blockers are active, why latch them?

...

Quoted 9 lines

If you only poll the fd after the last user-space suspend blocker is released, why do you care when the kernel wakelock could have been released? It seem the only thing it saves you is an extra poll call when two wakeup events happen at the same time and one of them is fully processed and unblocks suspend before the other event handler blocks suspend. It seems strange to remove your wakeup event from the list when a specific suspend blocker is acquired when any suspend blocker will prevent that wakeup event from being added to the list in the first place.

...

Quoted 3 lines

I don't think there is a need to tie the fds to anything else. If you poll the fds on the last suspend unblock call, you should get the same behaviour.

You are quite right; there is no need to associate suspend blockers with wakeup sources. The power manager merely needs to poll all wakeup sources whenever no suspend blockers are active. I put those associations in the proposal because of the line of reasoning that led up to it, but they aren't necessary.

Quoted 3 lines

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Correct; the power manager would need to know whenever a wakeup-capable device file was opened or closed.

Quoted 8 lines
Quoted 7 lines

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake.  Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources.  At those points it could remove wakeup sources that have timed out.

Quoted 5 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

If the app activates a suspend blocker before reading the event, this doesn't matter. If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event. This is equally true with wakelocks.

Quoted 3 lines

Also,
existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Now you've put your finger on the key. The main difference between my scheme and the original wakelock scheme is that programs have to inform the power manager whenever they open or close a wakeup-capable device file. With everything implemented inside the kernel this isn't necessary, because obviously a kernel driver already knows when its device file is opened or closed.

As I said before, this additional complication in userspace is the price paid for keeping stuff out of the kernel. If you had implemented wakelocks this way originally, you would not have needed to patch the vanilla kernel and this entire stormy discussion would never have occurred. (But of course you couldn't have used this for the original implementation of wakelocks, because back then the hardware couldn't achieve the lowest power states from idle.)

Quoted 10 lines
Quoted 2 lines

Obviously this proposal would complicate your userspace.  Not enormously, since most of the work is confined to the power manager,

No, the main problem it that it is not confined to the power manager. The power manager does not have a list of file descriptors to monitor, so we have to modify all code that handles wakeup events. This includes vendor supplied code that we don't have the source for, but, on some platforms at least, this code relies on kernel wakelocks with a timeout and could at first be handled the same way we would have to handle existing apps reading from a socket.

Look, I never said this scheme was _better_ than wakelocks. I merely said that it could be used without significant modifications to the kernel.

Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

Quoted 3 lines

Your solution is not immediately useful since depends on removing all periodic kernel timers and adding support to stopping the monotonic clock for set of processes that are frozen.

The monotonic clock is indeed an issue.

Periodic kernel timers... I don't know about them. Has anyone tried to measure them? There are excellent reasons for trimming them when the system goes into low-power idle, independent of Android. This sounds like the kind of thing Arjan might have worked on.

Quoted 3 lines

Your solution forces the user space interface to be more complicated, and it creates a new user space power manager that has to start before any process that handle wakeup events.

That's right.

Alan Stern

#294 lore raw

2010/6/10 Alan Stern <[email protected]>:

Quoted 62 lines · Arve Hjønnevåg
Quoted 13 lines
Quoted 8 lines

I think this is where you misunderstood.  There is no "report wakeup event" as such.  All that happens is that data becomes available to be read from the input device file.  However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Yes this is not what I though you were suggesting. I thought you were trying to make sure the power manager sees all wakeup events. If you are only listening for wakeup events while no suspend blockers are active, why latch them?

...

Quoted 9 lines

If you only poll the fd after the last user-space suspend blocker is released, why do you care when the kernel wakelock could have been released? It seem the only thing it saves you is an extra poll call when two wakeup events happen at the same time and one of them is fully processed and unblocks suspend before the other event handler blocks suspend. It seems strange to remove your wakeup event from the list when a specific suspend blocker is acquired when any suspend blocker will prevent that wakeup event from being added to the list in the first place.

...

Quoted 3 lines

I don't think there is a need to tie the fds to anything else. If you poll the fds on the last suspend unblock call, you should get the same behaviour.

You are quite right; there is no need to associate suspend blockers with wakeup sources.  The power manager merely needs to poll all wakeup sources whenever no suspend blockers are active.  I put those associations in the proposal because of the line of reasoning that led up to it, but they aren't necessary.

Quoted 3 lines

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Correct; the power manager would need to know whenever a wakeup-capable device file was opened or closed.

Quoted 8 lines
Quoted 7 lines

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake.  Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources.  At those points it could remove wakeup sources that have timed out.

Quoted 5 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

Quoted 5 lines

If the app activates a suspend blocker before reading the event, this doesn't matter.  If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event.  This is equally true with wakelocks.

It is not the same. Using a wakelock with a timeout only has a problem if the app did not get a change to run and block suspend before the timeout expires. With the timeout values we use there is only a problem if the system is already unresponsive. If the driver does not block suspend but instead a power manager calls select or poll on a file descriptor while the app does a blocking read, the power manager can easily miss the event and suspend before the app blocks suspend.

Quoted 34 lines
Quoted 3 lines

Also,
existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Now you've put your finger on the key.  The main difference between my scheme and the original wakelock scheme is that programs have to inform the power manager whenever they open or close a wakeup-capable device file.  With everything implemented inside the kernel this isn't necessary, because obviously a kernel driver already knows when its device file is opened or closed.

As I said before, this additional complication in userspace is the price paid for keeping stuff out of the kernel.  If you had implemented wakelocks this way originally, you would not have needed to patch the vanilla kernel and this entire stormy discussion would never have occurred.  (But of course you couldn't have used this for the original implementation of wakelocks, because back then the hardware couldn't achieve the lowest power states from idle.)

Quoted 10 lines
Quoted 2 lines

Obviously this proposal would complicate your userspace.  Not enormously, since most of the work is confined to the power manager,

No, the main problem it that it is not confined to the power manager. The power manager does not have a list of file descriptors to monitor, so we have to modify all code that handles wakeup events. This includes vendor supplied code that we don't have the source for, but, on some platforms at least, this code relies on kernel wakelocks with a timeout and could at first be handled the same way we would have to handle existing apps reading from a socket.

Look, I never said this scheme was _better_ than wakelocks.  I merely said that it could be used without significant modifications to the kernel.

Quoted 7 lines
Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

I'm not sure what you mean by dynamic power management here (frequency of suspends?), but auto suspend is already in use on x86 desktops and laptops. Suspend blockers can fix the race with some wakeup events there.

Quoted 20 lines
Quoted 3 lines

Your solution is not immediately useful since depends on removing all periodic kernel timers and adding support to stopping the monotonic clock for set of processes that are frozen.

The monotonic clock is indeed an issue.

Periodic kernel timers... I don't know about them.  Has anyone tried to measure them?  There are excellent reasons for trimming them when the system goes into low-power idle, independent of Android.  This sounds like the kind of thing Arjan might have worked on.

Quoted 3 lines

Your solution forces the user space interface to be more complicated, and it creates a new user space power manager that has to start before any process that handle wakeup events.

That's right.

Alan Stern

Signature · 1 line
Arve Hjønnevåg
#295 lore raw
Quoted 12 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 5 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

If the app activates a suspend blocker before reading the event, this doesn't matter.  If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event.  This is equally true with wakelocks.

Quoted 7 lines

It is not the same. Using a wakelock with a timeout only has a problem if the app did not get a change to run and block suspend before the timeout expires. With the timeout values we use there is only a problem if the system is already unresponsive. If the driver does not block suspend but instead a power manager calls select or poll on a file descriptor while the app does a blocking read, the power manager can easily miss the event and suspend before the app blocks suspend.

You've lost me. If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend. My scheme can fail in the same way. Is that what you meant?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Quoted 8 lines
Quoted 3 lines

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

I'm not sure what you mean by dynamic power management here (frequency of suspends?), but auto suspend is already in use on x86 desktops and laptops. Suspend blockers can fix the race with some wakeup events there.

You should stress this point more strongly when conversing with others. I doubt it will be enough to change anybody's mind, but it can't hurt. Indeed, if you propose suspend blockers as a way to fix a lost-wakeup bug in existing distributions, rather than as something needed to support Android, people might view it more favorably.

There's one question that I don't remember ever seeing answered. To which kernel drivers do you intend to add suspend blockers?

Alan Stern

#296 lore raw
In reply to Arve Hjønnevåg
Quoted 12 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 5 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

If the app activates a suspend blocker before reading the event, this doesn't matter.  If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event.  This is equally true with wakelocks.

Quoted 7 lines

It is not the same. Using a wakelock with a timeout only has a problem if the app did not get a change to run and block suspend before the timeout expires. With the timeout values we use there is only a problem if the system is already unresponsive. If the driver does not block suspend but instead a power manager calls select or poll on a file descriptor while the app does a blocking read, the power manager can easily miss the event and suspend before the app blocks suspend.

You've lost me. If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend. My scheme can fail in the same way. Is that what you meant?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Quoted 8 lines
Quoted 3 lines

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

I'm not sure what you mean by dynamic power management here (frequency of suspends?), but auto suspend is already in use on x86 desktops and laptops. Suspend blockers can fix the race with some wakeup events there.

You should stress this point more strongly when conversing with others. I doubt it will be enough to change anybody's mind, but it can't hurt. Indeed, if you propose suspend blockers as a way to fix a lost-wakeup bug in existing distributions, rather than as something needed to support Android, people might view it more favorably.

There's one question that I don't remember ever seeing answered. To which kernel drivers do you intend to add suspend blockers?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#297 lore raw

2010/6/10 Alan Stern <[email protected]>:

Quoted 22 lines · Arve Hjønnevåg
Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

Quoted 5 lines

If the app activates a suspend blocker before reading the event, this doesn't matter.  If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event.  This is equally true with wakelocks.

Quoted 7 lines

It is not the same. Using a wakelock with a timeout only has a problem if the app did not get a change to run and block suspend before the timeout expires. With the timeout values we use there is only a problem if the system is already unresponsive. If the driver does not block suspend but instead a power manager calls select or poll on a file descriptor while the app does a blocking read, the power manager can easily miss the event and suspend before the app blocks suspend.

Quoted 4 lines

You've lost me.  If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

It cannot sit inside of select/poll all the time.

Quoted 6 lines

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend.  My scheme can fail in the same way. Is that what you meant?

No, if an app reads from a file descriptor and block suspend when the read call returns, then suspend is blocked while processing the data. If the driver uses a wakelock with a timeout this will fail if the thread does not get to the suspend block call before the timeout expires, but unrelated events that don't prevent the app from running will not cause any problems. In your scheme the user-space power manager may miss events on this file descriptor since select/poll will not see an event if the app read that event right before the power manager called select/poll.

Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Quoted 8 lines
Quoted 3 lines

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

I'm not sure what you mean by dynamic power management here (frequency of suspends?), but auto suspend is already in use on x86 desktops and laptops. Suspend blockers can fix the race with some wakeup events there.

You should stress this point more strongly when conversing with others. I doubt it will be enough to change anybody's mind, but it can't hurt. Indeed, if you propose suspend blockers as a way to fix a lost-wakeup bug in existing distributions, rather than as something needed to support Android, people might view it more favorably.

Quoted 3 lines

There's one question that I don't remember ever seeing answered.  To which kernel drivers do you intend to add suspend blockers?

All drivers that generate wakeup events need to either use suspend blockers directly or call into something else that does. For instance, with the patch to block suspend while input events are queued to user-space, an input driver that fully handles its events in its interrupt handler does not need any additional suspend blockers, but if the driver needs a work function or a timer to run before it reports the event it needs to block suspend until it has reported the event.

Signature · 1 line
Arve Hjønnevåg
#298 lore raw
In reply to Alan Stern

2010/6/10 Alan Stern <[email protected]>:

Quoted 22 lines · Arve Hjønnevåg
Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

Quoted 5 lines

If the app activates a suspend blocker before reading the event, this doesn't matter.  If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event.  This is equally true with wakelocks.

Quoted 7 lines

It is not the same. Using a wakelock with a timeout only has a problem if the app did not get a change to run and block suspend before the timeout expires. With the timeout values we use there is only a problem if the system is already unresponsive. If the driver does not block suspend but instead a power manager calls select or poll on a file descriptor while the app does a blocking read, the power manager can easily miss the event and suspend before the app blocks suspend.

Quoted 4 lines

You've lost me.  If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

It cannot sit inside of select/poll all the time.

Quoted 6 lines

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend.  My scheme can fail in the same way. Is that what you meant?

No, if an app reads from a file descriptor and block suspend when the read call returns, then suspend is blocked while processing the data. If the driver uses a wakelock with a timeout this will fail if the thread does not get to the suspend block call before the timeout expires, but unrelated events that don't prevent the app from running will not cause any problems. In your scheme the user-space power manager may miss events on this file descriptor since select/poll will not see an event if the app read that event right before the power manager called select/poll.

Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Quoted 8 lines
Quoted 3 lines

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

I'm not sure what you mean by dynamic power management here (frequency of suspends?), but auto suspend is already in use on x86 desktops and laptops. Suspend blockers can fix the race with some wakeup events there.

You should stress this point more strongly when conversing with others. I doubt it will be enough to change anybody's mind, but it can't hurt. Indeed, if you propose suspend blockers as a way to fix a lost-wakeup bug in existing distributions, rather than as something needed to support Android, people might view it more favorably.

Quoted 3 lines

There's one question that I don't remember ever seeing answered.  To which kernel drivers do you intend to add suspend blockers?

All drivers that generate wakeup events need to either use suspend blockers directly or call into something else that does. For instance, with the patch to block suspend while input events are queued to user-space, an input driver that fully handles its events in its interrupt handler does not need any additional suspend blockers, but if the driver needs a work function or a timer to run before it reports the event it needs to block suspend until it has reported the event.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#299 lore raw
Quoted 14 lines · Arve Hjønnevåg
Quoted 4 lines

You've lost me.  If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

It cannot sit inside of select/poll all the time.

Quoted 6 lines

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend.  My scheme can fail in the same way. Is that what you meant?

Quoted 6 lines

No, if an app reads from a file descriptor and block suspend when the read call returns, then suspend is blocked while processing the data. If the driver uses a wakelock with a timeout this will fail if the thread does not get to the suspend block call before the timeout expires, but unrelated events that don't prevent the app from running will not cause any problems.

Wait a second. Maybe I have misunderstood how timeouts are supposed to work with wakelocks. I thought the idea was that the wakelock would be released when the timeout expires or the event queue is emptied, whichever comes first. Now it sounds like you're saying that the wakelock doesn't get released until the timeout expires, even if userspace finishes processing all pending events before then.

Quoted 4 lines

In your scheme the user-space power
manager may miss events on this file descriptor since select/poll will not see an event if the app read that event right before the power manager called select/poll.

If the wakelock is supposed to remain active until the timeout expires then you are right. On the other hand, this seems like a rather strange and suspicious way of handling wakelocks. Why would you want to do it that way?

Quoted 4 lines
Quoted 3 lines

There's one question that I don't remember ever seeing answered.  To which kernel drivers do you intend to add suspend blockers?

Quoted 8 lines

All drivers that generate wakeup events need to either use suspend blockers directly or call into something else that does. For instance, with the patch to block suspend while input events are queued to user-space, an input driver that fully handles its events in its interrupt handler does not need any additional suspend blockers, but if the driver needs a work function or a timer to run before it reports the event it needs to block suspend until it has reported the event.

Sure. But specifically, which drivers on Android generate wakeup events? And which of them don't fully handle their events in their interrupt handlers?

Maybe another way to put this is: Where in the kernel do you intend to add suspend blockers?

Alan Stern

#300 lore raw

2010/6/11 Alan Stern <[email protected]>:

Quoted 23 lines · Arve Hjønnevåg
Quoted 15 lines
Quoted 5 lines

You've lost me.  If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

It cannot sit inside of select/poll all the time.

Quoted 6 lines

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend.  My scheme can fail in the same way. Is that what you meant?

Quoted 6 lines

No, if an app reads from a file descriptor and block suspend when the read call returns, then suspend is blocked while processing the data. If the driver uses a wakelock with a timeout this will fail if the thread does not get to the suspend block call before the timeout expires, but unrelated events that don't prevent the app from running will not cause any problems.

Quoted 3 lines

Wait a second.  Maybe I have misunderstood how timeouts are supposed to work with wakelocks.  I thought the idea was that the wakelock would be released when the timeout expires or the event queue is emptied,

That is one way to use it, and I did this so code that opened an input device without reading from it would not prevent suspend forever. In the last patchset I posted, I instead used an ioctl to enable the suspend blocker.

Quoted 4 lines

whichever comes first.  Now it sounds like you're saying that the wakelock doesn't get released until the timeout expires, even if userspace finishes processing all pending events before then.

For incoming network traffic we use a wakelock with a timeout to prevent suspend long enough for the data to make it to user-space since we have not added wakelocks to the network stack.

Quoted 10 lines
Quoted 4 lines

In your scheme the user-space power
manager may miss events on this file descriptor since select/poll will not see an event if the app read that event right before the power manager called select/poll.

If the wakelock is supposed to remain active until the timeout expires then you are right.  On the other hand, this seems like a rather strange and suspicious way of handling wakelocks.  Why would you want to do it that way?

We did this to avoid changing to the network stack, tty layer, etc.

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines

There's one question that I don't remember ever seeing answered.  To which kernel drivers do you intend to add suspend blockers?

Quoted 8 lines

All drivers that generate wakeup events need to either use suspend blockers directly or call into something else that does. For instance, with the patch to block suspend while input events are queued to user-space, an input driver that fully handles its events in its interrupt handler does not need any additional suspend blockers, but if the driver needs a work function or a timer to run before it reports the event it needs to block suspend until it has reported the event.

Quoted 4 lines

Sure.  But specifically, which drivers on Android generate wakeup events?  And which of them don't fully handle their events in their interrupt handlers?

Keypad, network, charger, rtc, but I'm sure I forgot some.

Quoted 3 lines

Maybe another way to put this is: Where in the kernel do you intend to add suspend blockers?

In addition to the drivers that enable the wakeup events, we have added suspend blockers to the input event code and power supply framework. The tty layer and network stack would also need suspend blockers to avoid using timeouts.

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

Wait a second.  Maybe I have misunderstood how timeouts are supposed to work with wakelocks.  I thought the idea was that the wakelock would be released when the timeout expires or the event queue is emptied,

That is one way to use it, and I did this so code that opened an input device without reading from it would not prevent suspend forever. In the last patchset I posted, I instead used an ioctl to enable the suspend blocker.

Quoted 4 lines

whichever comes first.  Now it sounds like you're saying that the wakelock doesn't get released until the timeout expires, even if userspace finishes processing all pending events before then.

Quoted 5 lines

For incoming network traffic we use a wakelock with a timeout to prevent suspend long enough for the data to make it to user-space since we have not added wakelocks to the network stack.

We did this to avoid changing to the network stack, tty layer, etc.

I see. These are examples where wakelocks are _not_ released by any userspace action, so they don't seem to fit well into my all-userspace scheme. At least, not in their current form. On the other hand, if the network/tty wakeup events eventually cause data to become available on a socket or device file, then they wouldn't need any special treatment in my scheme. The socket/file descriptors could be handled the same as any others. (Although you might need to change some apps, to make them follow the usual pattern of poll, activate suspend blocker, read, process, release suspend blocker.)

In other words, the fact that everything has been moved into userspace means that you wouldn't have to worry about the missing wakelocks in the network stack or tty layer, and consequently wouldn't have to worry about using timed wakelocks there.

Quoted 7 lines
Quoted 4 lines

Sure.  But specifically, which drivers on Android generate wakeup events?  And which of them don't fully handle their events in their interrupt handlers?

Keypad, network, charger, rtc, but I'm sure I forgot some.

Quoted 8 lines
Quoted 3 lines

Maybe another way to put this is: Where in the kernel do you intend to add suspend blockers?

In addition to the drivers that enable the wakeup events, we have added suspend blockers to the input event code and power supply framework. The tty layer and network stack would also need suspend blockers to avoid using timeouts.

I see. The keypad, charger (power supply), and rtc drivers sound pretty platform-specific. Probably nobody would complain too strongly about adding suspend blockers there.

The input, network, and tty layers are more general, though. That's where you're most likely to encounter resistance.

People have been complaining about "suspend blockers being added all throughout the kernel". It might help if you pointed out that it's just in these three layers (and maybe at only a few specific points within each layer).

Alan Stern

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

Wait a second.  Maybe I have misunderstood how timeouts are supposed to work with wakelocks.  I thought the idea was that the wakelock would be released when the timeout expires or the event queue is emptied,

That is one way to use it, and I did this so code that opened an input device without reading from it would not prevent suspend forever. In the last patchset I posted, I instead used an ioctl to enable the suspend blocker.

Quoted 4 lines

whichever comes first.  Now it sounds like you're saying that the wakelock doesn't get released until the timeout expires, even if userspace finishes processing all pending events before then.

Quoted 5 lines

For incoming network traffic we use a wakelock with a timeout to prevent suspend long enough for the data to make it to user-space since we have not added wakelocks to the network stack.

We did this to avoid changing to the network stack, tty layer, etc.

I see. These are examples where wakelocks are _not_ released by any userspace action, so they don't seem to fit well into my all-userspace scheme. At least, not in their current form. On the other hand, if the network/tty wakeup events eventually cause data to become available on a socket or device file, then they wouldn't need any special treatment in my scheme. The socket/file descriptors could be handled the same as any others. (Although you might need to change some apps, to make them follow the usual pattern of poll, activate suspend blocker, read, process, release suspend blocker.)

In other words, the fact that everything has been moved into userspace means that you wouldn't have to worry about the missing wakelocks in the network stack or tty layer, and consequently wouldn't have to worry about using timed wakelocks there.

Quoted 7 lines
Quoted 4 lines

Sure.  But specifically, which drivers on Android generate wakeup events?  And which of them don't fully handle their events in their interrupt handlers?

Keypad, network, charger, rtc, but I'm sure I forgot some.

Quoted 8 lines
Quoted 3 lines

Maybe another way to put this is: Where in the kernel do you intend to add suspend blockers?

In addition to the drivers that enable the wakeup events, we have added suspend blockers to the input event code and power supply framework. The tty layer and network stack would also need suspend blockers to avoid using timeouts.

I see. The keypad, charger (power supply), and rtc drivers sound pretty platform-specific. Probably nobody would complain too strongly about adding suspend blockers there.

The input, network, and tty layers are more general, though. That's where you're most likely to encounter resistance.

People have been complaining about "suspend blockers being added all throughout the kernel". It might help if you pointed out that it's just in these three layers (and maybe at only a few specific points within each layer).

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

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

You've lost me.  If the power manager is sitting inside a select/poll, how can it miss the event (given that the event will make data available to be read on one of the descriptors being polled)?

It cannot sit inside of select/poll all the time.

Quoted 6 lines

Or put it another way: With wakelocks, if the app doesn't use a suspend blocker then once it reads the event data and the timed wakelock is deactivated, there is nothing to prevent the system from immediately going into opportunistic suspend.  My scheme can fail in the same way. Is that what you meant?

Quoted 6 lines

No, if an app reads from a file descriptor and block suspend when the read call returns, then suspend is blocked while processing the data. If the driver uses a wakelock with a timeout this will fail if the thread does not get to the suspend block call before the timeout expires, but unrelated events that don't prevent the app from running will not cause any problems.

Wait a second. Maybe I have misunderstood how timeouts are supposed to work with wakelocks. I thought the idea was that the wakelock would be released when the timeout expires or the event queue is emptied, whichever comes first. Now it sounds like you're saying that the wakelock doesn't get released until the timeout expires, even if userspace finishes processing all pending events before then.

Quoted 4 lines

In your scheme the user-space power
manager may miss events on this file descriptor since select/poll will not see an event if the app read that event right before the power manager called select/poll.

If the wakelock is supposed to remain active until the timeout expires then you are right. On the other hand, this seems like a rather strange and suspicious way of handling wakelocks. Why would you want to do it that way?

Quoted 4 lines
Quoted 3 lines

There's one question that I don't remember ever seeing answered.  To which kernel drivers do you intend to add suspend blockers?

Quoted 8 lines

All drivers that generate wakeup events need to either use suspend blockers directly or call into something else that does. For instance, with the patch to block suspend while input events are queued to user-space, an input driver that fully handles its events in its interrupt handler does not need any additional suspend blockers, but if the driver needs a work function or a timer to run before it reports the event it needs to block suspend until it has reported the event.

Sure. But specifically, which drivers on Android generate wakeup events? And which of them don't fully handle their events in their interrupt handlers?

Maybe another way to put this is: Where in the kernel do you intend to add suspend blockers?

Alan Stern

#304 lore raw
In reply to Alan Stern

2010/6/10 Alan Stern <[email protected]>:

Quoted 62 lines · Arve Hjønnevåg
Quoted 13 lines
Quoted 8 lines

I think this is where you misunderstood.  There is no "report wakeup event" as such.  All that happens is that data becomes available to be read from the input device file.  However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Yes this is not what I though you were suggesting. I thought you were trying to make sure the power manager sees all wakeup events. If you are only listening for wakeup events while no suspend blockers are active, why latch them?

...

Quoted 9 lines

If you only poll the fd after the last user-space suspend blocker is released, why do you care when the kernel wakelock could have been released? It seem the only thing it saves you is an extra poll call when two wakeup events happen at the same time and one of them is fully processed and unblocks suspend before the other event handler blocks suspend. It seems strange to remove your wakeup event from the list when a specific suspend blocker is acquired when any suspend blocker will prevent that wakeup event from being added to the list in the first place.

...

Quoted 3 lines

I don't think there is a need to tie the fds to anything else. If you poll the fds on the last suspend unblock call, you should get the same behaviour.

You are quite right; there is no need to associate suspend blockers with wakeup sources.  The power manager merely needs to poll all wakeup sources whenever no suspend blockers are active.  I put those associations in the proposal because of the line of reasoning that led up to it, but they aren't necessary.

Quoted 3 lines

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Correct; the power manager would need to know whenever a wakeup-capable device file was opened or closed.

Quoted 8 lines
Quoted 7 lines

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake.  Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources.  At those points it could remove wakeup sources that have timed out.

Quoted 5 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

Quoted 5 lines

If the app activates a suspend blocker before reading the event, this doesn't matter.  If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event.  This is equally true with wakelocks.

It is not the same. Using a wakelock with a timeout only has a problem if the app did not get a change to run and block suspend before the timeout expires. With the timeout values we use there is only a problem if the system is already unresponsive. If the driver does not block suspend but instead a power manager calls select or poll on a file descriptor while the app does a blocking read, the power manager can easily miss the event and suspend before the app blocks suspend.

Quoted 34 lines
Quoted 3 lines

Also,
existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Now you've put your finger on the key.  The main difference between my scheme and the original wakelock scheme is that programs have to inform the power manager whenever they open or close a wakeup-capable device file.  With everything implemented inside the kernel this isn't necessary, because obviously a kernel driver already knows when its device file is opened or closed.

As I said before, this additional complication in userspace is the price paid for keeping stuff out of the kernel.  If you had implemented wakelocks this way originally, you would not have needed to patch the vanilla kernel and this entire stormy discussion would never have occurred.  (But of course you couldn't have used this for the original implementation of wakelocks, because back then the hardware couldn't achieve the lowest power states from idle.)

Quoted 10 lines
Quoted 2 lines

Obviously this proposal would complicate your userspace.  Not enormously, since most of the work is confined to the power manager,

No, the main problem it that it is not confined to the power manager. The power manager does not have a list of file descriptors to monitor, so we have to modify all code that handles wakeup events. This includes vendor supplied code that we don't have the source for, but, on some platforms at least, this code relies on kernel wakelocks with a timeout and could at first be handled the same way we would have to handle existing apps reading from a socket.

Look, I never said this scheme was _better_ than wakelocks.  I merely said that it could be used without significant modifications to the kernel.

Quoted 7 lines
Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

I'm not sure what you mean by dynamic power management here (frequency of suspends?), but auto suspend is already in use on x86 desktops and laptops. Suspend blockers can fix the race with some wakeup events there.

Quoted 20 lines
Quoted 3 lines

Your solution is not immediately useful since depends on removing all periodic kernel timers and adding support to stopping the monotonic clock for set of processes that are frozen.

The monotonic clock is indeed an issue.

Periodic kernel timers... I don't know about them.  Has anyone tried to measure them?  There are excellent reasons for trimming them when the system goes into low-power idle, independent of Android.  This sounds like the kind of thing Arjan might have worked on.

Quoted 3 lines

Your solution forces the user space interface to be more complicated, and it creates a new user space power manager that has to start before any process that handle wakeup events.

That's right.

Alan Stern

Signature · 1 line
Arve Hjønnevåg
#305 lore raw
In reply to Arve Hjønnevåg
Quoted 12 lines · Arve Hjønnevåg
Quoted 7 lines

I think this is where you misunderstood.  There is no "report wakeup event" as such.  All that happens is that data becomes available to be read from the input device file.  However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Yes this is not what I though you were suggesting. I thought you were trying to make sure the power manager sees all wakeup events. If you are only listening for wakeup events while no suspend blockers are active, why latch them?

...

Quoted 9 lines

If you only poll the fd after the last user-space suspend blocker is released, why do you care when the kernel wakelock could have been released? It seem the only thing it saves you is an extra poll call when two wakeup events happen at the same time and one of them is fully processed and unblocks suspend before the other event handler blocks suspend. It seems strange to remove your wakeup event from the list when a specific suspend blocker is acquired when any suspend blocker will prevent that wakeup event from being added to the list in the first place.

...

Quoted 3 lines

I don't think there is a need to tie the fds to anything else. If you poll the fds on the last suspend unblock call, you should get the same behaviour.

You are quite right; there is no need to associate suspend blockers with wakeup sources. The power manager merely needs to poll all wakeup sources whenever no suspend blockers are active. I put those associations in the proposal because of the line of reasoning that led up to it, but they aren't necessary.

Quoted 3 lines

All input events that can wake the system are handled by one user-space suspend blocker. Input devices come and go so we would need to add and remove the fds dynamically.

Correct; the power manager would need to know whenever a wakeup-capable device file was opened or closed.

Quoted 8 lines
Quoted 7 lines

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake.  Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources.  At those points it could remove wakeup sources that have timed out.

Quoted 5 lines

For that to work the wakeup events would have to be reported to the power manager in a reliable way in the first place. Passing the file descriptor that the app uses to the power manager does not work for this, since the app could read the event while the power manager was not in the poll call and the power manager would never see it.

If the app activates a suspend blocker before reading the event, this doesn't matter. If the app doesn't activate a suspend blocker then it risks being suspended after it has read the event but before it has handled the event. This is equally true with wakelocks.

Quoted 3 lines

Also,
existing apps don't pass their file descriptors to the power manager, so it has the get the event from somewhere else.

Now you've put your finger on the key. The main difference between my scheme and the original wakelock scheme is that programs have to inform the power manager whenever they open or close a wakeup-capable device file. With everything implemented inside the kernel this isn't necessary, because obviously a kernel driver already knows when its device file is opened or closed.

As I said before, this additional complication in userspace is the price paid for keeping stuff out of the kernel. If you had implemented wakelocks this way originally, you would not have needed to patch the vanilla kernel and this entire stormy discussion would never have occurred. (But of course you couldn't have used this for the original implementation of wakelocks, because back then the hardware couldn't achieve the lowest power states from idle.)

Quoted 10 lines
Quoted 2 lines

Obviously this proposal would complicate your userspace.  Not enormously, since most of the work is confined to the power manager,

No, the main problem it that it is not confined to the power manager. The power manager does not have a list of file descriptors to monitor, so we have to modify all code that handles wakeup events. This includes vendor supplied code that we don't have the source for, but, on some platforms at least, this code relies on kernel wakelocks with a timeout and could at first be handled the same way we would have to handle existing apps reading from a socket.

Look, I never said this scheme was _better_ than wakelocks. I merely said that it could be used without significant modifications to the kernel.

Quoted 3 lines

The suspend blocker approach is more generally useful since it supports hardware where suspend is needed. Why this argument is being ignored is very puzzling.

Probably because people doesn't envision system suspend being used for dynamic power management on that kind of hardware.

Quoted 3 lines

Your solution is not immediately useful since depends on removing all periodic kernel timers and adding support to stopping the monotonic clock for set of processes that are frozen.

The monotonic clock is indeed an issue.

Periodic kernel timers... I don't know about them. Has anyone tried to measure them? There are excellent reasons for trimming them when the system goes into low-power idle, independent of Android. This sounds like the kind of thing Arjan might have worked on.

Quoted 3 lines

Your solution forces the user space interface to be more complicated, and it creates a new user space power manager that has to start before any process that handle wakeup events.

That's right.

Alan Stern

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

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps.  Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

Quoted 3 lines

If you want to ensure that more than one process see the event it has to be two steps, but it does not affect the race I was trying to describe.

Are you sure about that? If two processes call poll() for the same file descriptor, don't both calls return when data becomes available? But agreed, it doesn't matter -- especially since I only need one process (the power manager) to see the event.

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it.  The API you're referring to is simply the function that activates a suspend blocker.  It does prevent task freezing, but you shouldn't say it prevents freezing for event type A.  More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active.  Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A

I think this is where you misunderstood. There is no "report wakeup event" as such. All that happens is that data becomes available to be read from the input device file. However the power manager process isn't polling the device file at this point (because a suspend blocker is active), so it doesn't realize that the source has become active again.

Quoted 13 lines
Quoted 6 lines
Quoted 1 line

- queue event for delivery to user-space

Same as above.

Quoted 2 lines

User space continues:
- Read events

Sorry, I missed the unblock task freezing step here.

Quoted 4 lines
Quoted 3 lines

- Wait for more events

Result: Task are not frozen again.

Quoted 7 lines
Quoted 3 lines

Because the suspend blocker was never deactivated.  The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Yes, but with the sequence of events above task will not be frozen again even if the wake-lock/suspend-blocker/task-freezing-preventer is released.

Yes they will. When the suspend blocker is deactivated, the power manager process will realize that there are no active suspend blockers and it will think there are no active sources. Thus it will freeze processes as usual.

Quoted 15 lines
Quoted 15 lines

Here's how my scheme is meant to work:

       Wakeup event for input device A occurs.

       A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

       The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

       Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

Quoted 7 lines
Quoted 4 lines

       When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources.  But it doesn't freeze userspace yet, because now a suspend blocker is active.

If another event happens at this point don't you put A back on the list? If so, it never gets removed.

No, you don't put A back on the list. Sources get put on the list only when the information returned by poll() indicates they have data available. The power manager doesn't poll while suspend blockers are active.

Quoted 20 lines
Quoted 19 lines

       The other process consumes events from A and does other stuff.  Maybe more input data arrives while this is happening and the process reads it.  Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

       When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers.  Therefore it freezes userspace and does a big poll() on all possible sources.  (If there are still events on the input device queue, the poll() returns immediately.)

       Rinse and repeat.

I don't see any dangerous races there.  The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

Quoted 8 lines
Quoted 5 lines

There is no race.  The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

If the driver making data available to be read triggers a wakeup event in the power manager process

It doesn't. Only return from a poll() causes the power manager process to think a wakeup event has occurred.

Quoted 4 lines

that has to be cleared by the process
reading the events, then you have a race. Since the power manager is selecting/polling on the same file descriptor, I don't see what you gain from linking the wakeup events to suspend blockers.

What I gain is the ability to know when an in-kernel wakelock _could_ have been released, without actually implementing in-kernel wakelocks.

With real in-kernel wakelocks, the wakelock is released when the input queue becomes empty. There's no way for the power manager process to know exactly when that happens without modifying the kernel. However we can use the activation of the corresponding userspace suspend blocker as a proxy. It's nearly as good, and it gets the job done.

If you prefer, an interface could be added whereby a user process tells the power manager explicitly that it's going to read data from an input device, instead of relying on implicit notification through suspend blocker activation. I don't know whether this would be simpler or more complex; it depends on the design of your userspace.

Quoted 4 lines

If you break
this link it think can work, but it does require us to modify all code that reads wakeup events from the kernel to register the file descriptors they get events from.

Yes. I don't know how your user code is structured; if there is a fixed correspondence between file descriptors and suspend blockers (the same wakeup events are always handled by the same suspend blockers) then this will be a simple change -- the file descriptor can be registered when the suspend blocker is created.

If the correspondence is more dynamic (different suspend blockers used for the same wakeup device at different times, or multiple wakeup devices handled by one suspend blocker) then the required changes will be more complicated. Not tremendously more.

Quoted 2 lines

It would also require adding
poll/select support to android alarm driver,

Yes. Is this a platform-specific driver? (I assume so, since you called it the "android alarm driver".) Then poll/select support can be added without provoking a lot of objections from legions of kernel developers.

Quoted 3 lines

and any driver that
currently uses a wakelock with a timeout would need to notify the user space power manager instead.

Hmm. This is symptomatic of a deficiency in the original wakelock implementation -- those timeouts always were arbitrary.

The power manager would indeed have to know about wakeup devices that don't need to _keep_ the system awake. Here's one way to cope: During those times when no suspend blockers are active but the PM process thinks a wakeup source is active, the PM process could poll every few seconds to update its list of active sources. At those points it could remove wakeup sources that have timed out.

Obviously this proposal would complicate your userspace. Not enormously, since most of the work is confined to the power manager, but somewhat. That's the price to be paid for leaving the kernel essentially untouched. Consider the amount of resistance your wakelock/suspend-blocker patches have already received; you'll have to decide which approach will work out better in the end.

Alan Stern

#307 lore raw
In reply to Arve Hjønnevåg
Quoted 3 lines · Arve Hjønnevåg

The patch that modifies evdev (posted in this patchset) uses an ioctl to enable the suspend blocker. Not all input devices are used for wakeup events and those don't need to block suspend.

But you do have a 1-1 correspondence, right? That is, the input devices that are used for wakeup events are exactly the ones that block suspend?

Quoted 5 lines

If you read an event that occurred after you blocked the task freezing, then tasks will never get frozen again (until more events occur). I think my original description was less confusing, but it seems you got completely distracted by my use of block and unblock suspend when referring to the user space api.

I still find your wording a little confusing. Task freezing can be prevented (a more accurate term than "blocked") by two kinds of things:
a suspend blocker or an "active" wakeup source. I'm not sure which kind you mean here.

Quoted 3 lines

It has an indirect connection. You report a wakeup event when it occurs, but clear it when user space calls an api before reading the event. So:

Yes, that's right.

Quoted 3 lines

Wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

That's not really two distinct steps. Queuing the event for delivery to userspace involves waking up any tasks that are waiting to read the device file; that action (calling wake_up_all() or whatever the driver does) is how the event gets reported.

Quoted 2 lines

User space wakes up:
- Calls api to block task freezing for event type A

Again, that's a confusing way of putting it. The API you're referring to is simply the function that activates a suspend blocker. It does prevent task freezing, but you shouldn't say it prevents freezing for event type A. More like the other way around: In addition to preventing freezing, the function tells the power manager that event type A should no longer be considered active. Thus, in a sense it _stops_ event type A from preventing freezing.

Quoted 3 lines

Another wakeup event occurs, and the driver:
- report wakeup event type A
- queue event for delivery to user-space

Same as above.

Quoted 5 lines

User space continues:
- Read events
- Wait for more events

Result: Task are not frozen again.

Because the suspend blocker was never deactivated. The same thing happens with wakelocks: If a task activates a wakelock and never deactivates it, the system won't go into opportunistic suspend again.

Here's how my scheme is meant to work:

Wakeup event for input device A occurs.

A's driver adds an entry to the input device queue and (if the queue was empty) does wake_up_all() on the device file's wait_queue.

The PM process returns from poll() and sees that device file A is now readable, so it adds A to its list of active sources and unfreezes userspace.

Some other process sees that device file A is now readable, so it activates a suspend blocker and reads events from A.

When the PM process receives the request to activate the suspend blocker, it removes A from its list of active sources. But it doesn't freeze userspace yet, because now a suspend blocker is active.

The other process consumes events from A and does other stuff. Maybe more input data arrives while this is happening and the process reads it. Eventually the process decides to deactivate the suspend blocker, perhaps when no more data is available from the device file, perhaps not.

When the PM process receives the request to deactivate the suspend blocker, it sees that now there are no active sources and no active suspend blockers. Therefore it freezes userspace and does a big poll() on all possible sources. (If there are still events on the input device queue, the poll() returns immediately.)

Rinse and repeat.

I don't see any dangerous races there. The scheme can be made a little more efficient by having the PM process do another poll() (with 0 timeout) just before freezing userspace; if the result indicates that a source is active then the freezing and unfreezing can be skipped.

The big assumption here is that a user process never consumes wakeup events without first activating a suspend blocker. This seems like a reasonable assumption, but we can work around it if necessary.

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel.  However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

Then the source id need to be passed from the kernel to user-space.

A source ID is a file descriptor. File descriptors are passed from the kernel to userspace whenever a file is opened; I can't deny it. And they are passed back to the kernel as part of the read() and poll() system calls. Is that what you mean?

Quoted 4 lines

No, that is not the unclear part. What is unclear to me is where the source IDs come from. Are they static and hardcoded in the driver and user-space, or are they passed between the driver and user-space client?

They are not static; they are file descriptors. I guess this should have been made more clear originally, but this is still pretty new to me too.

Quoted 2 lines

I don't understand how you are planning to ensure that the driver and user-space code that consumes the real event use the same source id.

How can it be otherwise? The userspace code consumes the event by reading from the device file. In order to do so, it has to use the same file descriptor it received when it opened the device file originally.

Quoted 3 lines

The biggest problem I have with it though is that you have created a new race condition between reporting that a wakeup event has occurred and processing of the real event.

There is no race. The driver reports an event has occurred by making the data available to be read from the device file, and the event is processed by reading it from the device file (or at least, that's the first step in processing the event).

There's one other thing worth mentioning. All along I've been talking about a power manager process that coordinates all these activities. In theory there's no reason that process couldn't be implemented as a kernel thread. This would improve efficiency by reducing the number of context switches, and it would change IPC calls into plain system calls.

If you did implement it that way, it could be done as a standalone kernel module, totally noninvasive. It would not need to be part of the vanilla kernel and nobody would object to it.

Alan Stern

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

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle.  But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

No, you have a different problem. If you open an input device and issue the ioctl to enable the suspend blocker that blocks while the

Um, the suspend blocker that is active while the queue is nonempty is an in-kernel suspend blocker, right? Not a userspace suspend blocker. Hence it doesn't have to be enabled by an ioctl. Or is this some part of the whole wakelock design that hasn't yet been posted? As far as I know, you intended the in-kernel suspend blocker to be enabled whenever the input device file is open.

Quoted 2 lines

queue is not empty then don't read the event, that is a bug that is easy to fix.

I assume you mean "you open an input device but then fail to read from it". When that happens the device's driver will activate its in-kernel suspend blocker, and since the input queue will never become empty, the suspend blocker will never be deactivated. Yes, that's a bug.

Quoted 3 lines

What you have is a race condition. If you read an event that occurred after you blocked the task freezing tasks will never get frozen again (until more events occur).

Sorry, I can't parse that sentence. Could you rephrase it more grammatically?

It seems to say: "If you read an event that occurred after [something], then tasks won't get frozen again until more events occur". Which doesn't make sense, firstly because in my scheme reading events has no direct connection with freezing or unfreezing tasks, and secondly because the occurrence of events doesn't cause tasks to be frozen -- just the opposite: occurrence of events _prevents_ tasks from being frozen.

Quoted 3 lines

We have multiple input devices and one thread reading from them. Do all input devices that can generate wakeup events share a wakeup source?

Basically, a wakeup source is a file descriptor that in your scheme, some user process would read from in order to clear an in-kernel wakelock. Thus, if each of your input devices activates an in-kernel wakelock that is cleared when a user process reads the device, then the file descriptors for these input devices would each be considered a wakeup source.

Quoted 2 lines

It seems you would need a way to pass the wakeup source id to use from user space to the driver and for this to work

No, nothing needs to be passed from userspace to the kernel. However the source ID (or a set of source IDs) does need to be passed to the power manager process, probably when the suspend blocker is created.

[On rereading this, I realized it might not have been clear that in my scheme, suspend blockers have no in-kernel component. They are implemented entirely by IPC between the process owning the suspend blocker and the power manager process. Would it be less confusing if I called them something else?]

Quoted 3 lines

(ignoring the race if
you allow multiple alarms per file) which seems like more work than using a suspend blocker.

It's not very much more: just one additional argument to the routine that creates a suspend blocker.

I get the impression that you don't fully understand how my scheme is meant to work. Would some additional explanation or examples help?

Alan Stern

#309 lore raw
In reply to Arve Hjønnevåg
Quoted 10 lines · Arve Hjønnevåg
Quoted 10 lines

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources.  (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Here's how you can do it.  Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

Quoted 6 lines
Quoted 4 lines

The power-manager process should keep a list of "active" wakeup sources.  A source gets removed from the list when an associated suspend blocker is activated.

How do you do this safely? If you remove the active wakeup only when

"remove the active wakeup" isn't a good way of expressing this. You remove the wakeup source from the power manager's list of active sources. This is just manipulation of a data structure internal to the power manager; it doesn't affect the actual source.

Quoted 3 lines

activating the suspend blocker, you will never unblock suspend if another wakeup event happens after user-space blocked suspend but before user-space read the events.

I'm not sure what you mean. In this scheme userspace doesn't ever block suspends. Instead the power manager freezes and unfreezes all the other processes. And the system never suspends, it simply goes idle for prolonged periods of time... with all processes frozen except the power manager, and it sitting inside a poll() system call.

It's true that under some exceptional circumstances the system would never remove a wakeup source from the "active" list and then would never go idle. But exactly the same problem exists with wakelocks, if the kernel activates a wakelock and there's no user process reading the corresponding event queue.

Quoted 4 lines

Also, I'm not sure we can easily associate a wakeup event with a user space suspend blocker. For instance when an alarm triggers it is sometimes because of a user-space alarm and sometimes because an in-kernel alarm.

That's okay. The association is optional, and not all suspend blockers will have an associated wakeup source. (However, each wakeup source that needs to percolate up into userspace -- i.e., that isn't handled internally by the kernel -- should have at least one associated suspend blocker.) The purpose of these associations is to make explicit the "handoff" in your original scheme, whereby a source would cause the kernel to activate a wakelock until some user process activated its own and then cleared the kernel's wakelock. In your scheme, the connection between the userspace wakelock and the wakeup source is implicit; in my scheme it is explicit.

For example, a process that uses a suspend blocker in order to read keystrokes would obviously associate its suspend blocker with the keypad-matrix wakeup source.

Or take your example of an alarm. To make it work in my scheme, each user alarm would have to be implemented as a poll-able file descriptor. Processes reading the descriptor would block until the alarm expires. (I don't know of any driver that provides this sort of timer interface, but it would be easy to write one. You could think of it as applying Unix's "Everything is a file" philosophy to alarms.) Each of these descriptors would then be a wakeup source, included among the sources that the power manager polls for, and a suspend blocker could be associated with it.

Alan Stern

#310 lore raw
In reply to Alan Stern

2010/6/6 Alan Stern <[email protected]>:

Quoted 28 lines · Alan Stern
Quoted 12 lines
Quoted 5 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way.  Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event.  When the event occurs, it must then activate a suspend blocker.

Quoted 8 lines

Better yet, make it more fine-grained.  Instead of trusted apps, have trusted threads.  Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

In fact it's possible to do this with only minimal changes to the userspace, providing you can specify all your possible hardware wakeup sources.  (On the Android this list probably isn't very large -- I imagine it includes the keypad, the radio link(s), the RTC, and maybe a few switches, buttons, or other things.)

Quoted 8 lines

Here's how you can do it.  Extend the userspace suspend-blocker API, so that each suspend blocker can optionally have an associated wakeup source.

The power-manager process should keep a list of "active" wakeup sources.  A source gets removed from the list when an associated suspend blocker is activated.

How do you do this safely? If you remove the active wakeup only when activating the suspend blocker, you will never unblock suspend if another wakeup event happens after user-space blocked suspend but before user-space read the events.

Also, I'm not sure we can easily associate a wakeup event with a user space suspend blocker. For instance when an alarm triggers it is sometimes because of a user-space alarm and sometimes because an in-kernel alarm.

Quoted 19 lines

When the "active" list is empty and no suspend blockers are activated, the power manager freezes ALL other processes, trusted and untrusted alike.  It then does a big poll() on all the wakeup sources.  When the poll() returns, its output is used to repopulate the "active" list and processes are unfrozen.

(You can also include some error detection: If a source remains on the "active" list for too long then something has gone wrong.)

To do all this you don't even need to use cgroups.  The existing PM implementation allows a user process to freeze everything but itself; that's how swsusp and related programs work.

This is still a big-hammer sort of approach, but it doesn't require any kernel changes.

Alan Stern

Signature · 1 line
Arve Hjønnevåg
#311 lore raw
In reply to Alan Stern

2010/6/5 Alan Stern <[email protected]>:

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

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes. Without annotating the drivers to block the cgroup freezing in the same places as we now block suspend, it also prevents processes in the cgroup that we freeze from directly consuming wakup events.

Quoted 5 lines

The driver annotations don't need to block the cgroup freezing.  They just need to keep the system running long enough to awaken a thread that will handle the wakeup event.  (See below.)  A pm-qos constraint is good enough for this.

I'm not sure what you mean by this, either you need to annotate the drivers or you don't.

Quoted 11 lines
Quoted 4 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way.  Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event.  When the event occurs, it must then activate a suspend blocker.

This breaks existing apps. It effectively requires that a process that use suspend blocker do no work that does not block suspend.

Quoted 4 lines

Better yet, make it more fine-grained.  Instead of trusted apps, have trusted threads.  Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

This would create a minefield of possible deadlocks. You now have to make sure that your trusted threads do not share any locks with your untrusted threads. For instance you cannot safely call into the heap while any threads in your process are frozen.

Quoted 11 lines

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

Quoted 5 lines

And, it
does not solve the problem for systems that enters lower power states from suspend than it can from idle. The last point my not be relevant to android anymore, but desktop systems already have auto suspend and it would be preferable to have a race free kernel api for this.

Quoted 4 lines

This is an entirely different matter from the rest of the discussion. It would be better to consider this separately after Android's current problems have been addressed.

Yes there has not been much discussion about this, but I don't understand why not. Automatic suspend is used outside Android, and it has the same race conditions that suspend blockers fix.

Signature · 1 line
Arve Hjønnevåg
#312 lore raw
In reply to Alan Stern

2010/6/5 Alan Stern <[email protected]>:

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

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes. Without annotating the drivers to block the cgroup freezing in the same places as we now block suspend, it also prevents processes in the cgroup that we freeze from directly consuming wakup events.

Quoted 5 lines

The driver annotations don't need to block the cgroup freezing.  They just need to keep the system running long enough to awaken a thread that will handle the wakeup event.  (See below.)  A pm-qos constraint is good enough for this.

I'm not sure what you mean by this, either you need to annotate the drivers or you don't.

Quoted 11 lines
Quoted 4 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way.  Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event.  When the event occurs, it must then activate a suspend blocker.

This breaks existing apps. It effectively requires that a process that use suspend blocker do no work that does not block suspend.

Quoted 4 lines

Better yet, make it more fine-grained.  Instead of trusted apps, have trusted threads.  Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

This would create a minefield of possible deadlocks. You now have to make sure that your trusted threads do not share any locks with your untrusted threads. For instance you cannot safely call into the heap while any threads in your process are frozen.

Quoted 11 lines

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

Quoted 5 lines

And, it
does not solve the problem for systems that enters lower power states from suspend than it can from idle. The last point my not be relevant to android anymore, but desktop systems already have auto suspend and it would be preferable to have a race free kernel api for this.

Quoted 4 lines

This is an entirely different matter from the rest of the discussion. It would be better to consider this separately after Android's current problems have been addressed.

Yes there has not been much discussion about this, but I don't understand why not. Automatic suspend is used outside Android, and it has the same race conditions that suspend blockers fix.

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

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes. Without annotating the drivers to block the cgroup freezing in the same places as we now block suspend, it also prevents processes in the cgroup that we freeze from directly consuming wakup events.

The driver annotations don't need to block the cgroup freezing. They just need to keep the system running long enough to awaken a thread that will handle the wakeup event. (See below.) A pm-qos constraint is good enough for this.

Quoted 4 lines

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption.

You can solve this problem if you restructure your "trusted" apps in the right way. Require a trusted app to guarantee that whenever it doesn't hold any suspend blockers, it will do nothing but wait (in a poll() system call for example) for a wakeup event. When the event occurs, it must then activate a suspend blocker.

Better yet, make it more fine-grained. Instead of trusted apps, have trusted threads. Freeze the untrusted threads along with everything else, and require the trusted threads to satisfy this guarantee.

In this way, while the system is idle no user timers will get renewed. Kernel timers are another matter, but we should be able to handle them. There's nothing Android-specific about wanting to reduce kernel timer wakeups while in a low-power mode.

Quoted 5 lines

And, it
does not solve the problem for systems that enters lower power states from suspend than it can from idle. The last point my not be relevant to android anymore, but desktop systems already have auto suspend and it would be preferable to have a race free kernel api for this.

This is an entirely different matter from the rest of the discussion. It would be better to consider this separately after Android's current problems have been addressed.

Alan Stern

#314 lore raw
In reply to Arve Hjønnevåg
Quoted 47 lines · Arve Hjønnevåg

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

Quoted 38 lines · Arve Hjønnevåg
Quoted 37 lines

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

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

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 7 lines
Quoted 4 lines

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Basically, it involves two mechanisms, detection of wakeup events occuring right before suspend is started

Quoted 6 lines

This sounds like the timeout approach which I thought you did not like.

Quoted 3 lines

and aborting suspend if wakeup events occur
in the middle of it.

Aborting suspend is easy, but when do you allow suspend again?

I would recommend you to wait for the patches and then comment. :-)

Quoted 25 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 8 lines

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

Quoted 8 lines

It will be able to do that if it causes the frozen part of user space to be thawed.

I think you have this problem already, though, because you use full system suspend and all of your apps are frozen by it. So, to handle the situation you describe above, you need to carry out full system resume that will thaw the tasks for you. I don't see any fundamental difference betwee the two cases.

Quoted 4 lines

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes.

Why does it have to have _any_ power advantage? It's totally sufficient if it gives you approximately the same power savings. IOW, it doesn't have to be _better_ if it's acceptable to the kernel people at large.

The rest of your objections have been addressed by Alan, so I'm not going to repeat his arguments.

Rafael

#315 lore raw
In reply to Arve Hjønnevåg
Quoted 47 lines · Arve Hjønnevåg

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

Quoted 38 lines · Arve Hjønnevåg
Quoted 37 lines

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

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

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 7 lines
Quoted 4 lines

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Basically, it involves two mechanisms, detection of wakeup events occuring right before suspend is started

Quoted 6 lines

This sounds like the timeout approach which I thought you did not like.

Quoted 3 lines

and aborting suspend if wakeup events occur
in the middle of it.

Aborting suspend is easy, but when do you allow suspend again?

I would recommend you to wait for the patches and then comment. :-)

Quoted 25 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 8 lines

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

Quoted 8 lines

It will be able to do that if it causes the frozen part of user space to be thawed.

I think you have this problem already, though, because you use full system suspend and all of your apps are frozen by it. So, to handle the situation you describe above, you need to carry out full system resume that will thaw the tasks for you. I don't see any fundamental difference betwee the two cases.

Quoted 4 lines

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes.

Why does it have to have _any_ power advantage? It's totally sufficient if it gives you approximately the same power savings. IOW, it doesn't have to be _better_ if it's acceptable to the kernel people at large.

The rest of your objections have been addressed by Alan, so I'm not going to repeat his arguments.

Rafael

#316 lore raw
In reply to Rafael J. Wysocki

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

Quoted 38 lines · Arve Hjønnevåg
Quoted 37 lines

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

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

2010/6/4 Matt Helsley <[email protected]>:

Quoted 19 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 5 lines

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 7 lines
Quoted 4 lines

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Basically, it involves two mechanisms, detection of wakeup events occuring right before suspend is started

This sounds like the timeout approach which I thought you did not like.

Quoted 3 lines

and aborting suspend if wakeup events occur
in the middle of it.

Aborting suspend is easy, but when do you allow suspend again?

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 8 lines

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

Quoted 8 lines

It will be able to do that if it causes the frozen part of user space to be thawed.

I think you have this problem already, though, because you use full system suspend and all of your apps are frozen by it.  So, to handle the situation you describe above, you need to carry out full system resume that will thaw the tasks for you.  I don't see any fundamental difference betwee the two cases.

Yes, we can keep all our user space suspend blockers and thaw the frozen cgroup when any suspend blocker is held, but this would eliminate any power advantage that freezing a cgroup has over using suspend to freeze all processes. Without annotating the drivers to block the cgroup freezing in the same places as we now block suspend, it also prevents processes in the cgroup that we freeze from directly consuming wakup events.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

From what you're saying it follows that you're not really willing to accept any solution different to your suspend blockers.  Is that really the case?

I don't think that is a fair way to put it. We need to support our user-space framework and I have not seen an alternative solution that clearly will work (other than replacing suspend_blockers with pm_qos constraints that do the same thing).

Then think again of the approach I proposed and explain to me why it won't work, because I haven't seen any convincing argument on that yet.

If you are referring to the approach that we don't use suspend but freeze a cgroup instead, this only solves the problem of bad apps. It does not help pause timers in trusted user space code and in the kernel, so it does not lower our average power consumption. And, it does not solve the problem for systems that enters lower power states from suspend than it can from idle. The last point my not be relevant to android anymore, but desktop systems already have auto suspend and it would be preferable to have a race free kernel api for this.

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

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

Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines

2010/6/4 Matt Helsley <[email protected]>:

Quoted 24 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 8 lines
Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

Quoted 4 lines

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Basically, it involves two mechanisms, detection of wakeup events occuring right before suspend is started and aborting suspend if wakeup events occur in the middle of it.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

Quoted 8 lines

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

It will be able to do that if it causes the frozen part of user space to be thawed.

I think you have this problem already, though, because you use full system suspend and all of your apps are frozen by it. So, to handle the situation you describe above, you need to carry out full system resume that will thaw the tasks for you. I don't see any fundamental difference betwee the two cases.

Quoted 7 lines
Quoted 3 lines

From what you're saying it follows that you're not really willing to accept any solution different to your suspend blockers. Is that really the case?

I don't think that is a fair way to put it. We need to support our user-space framework and I have not seen an alternative solution that clearly will work (other than replacing suspend_blockers with pm_qos constraints that do the same thing).

Then think again of the approach I proposed and explain to me why it won't work, because I haven't seen any convincing argument on that yet.

Rafael

#318 lore raw
In reply to Rafael J. Wysocki

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

Quoted 27 lines · Arve Hjønnevåg
Quoted 26 lines

2010/6/4 Matt Helsley <[email protected]>:

Quoted 24 lines · Arve Hjønnevåg
Quoted 2 lines · Thomas Gleixner
Quoted 1 line · Rafael J. Wysocki

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

Quoted 8 lines
Quoted 3 lines

I'm not aware of any bug with combining both, but we cannot use suspend at all without suspend blockers in the kernel (since wakeup events may be ignored)

The more I think of it, the more it appears to me that the problem of lost wakeup events can actually be solved without suspend blockers. I'll send a bunch of patches to address this issue, probably tomorrow.

I know of two ways to prevent lost wakeup events. Reset a timeout every time you receive a wakeup event or prevents suspend until you know the event has been fully processed. Does your solution fall onto one of these two categories, or do you have a third way?

Quoted 7 lines
Quoted 3 lines

and I don't know how we can safely freeze
cgroups without funneling all potential wakeup events through a process that never gets frozen.

If your untrusted apps get called by the trusted ones, they aren't really untrusted in the first place.

That is not a correct statement. A trusted apps can call into an untrusted app, it just has to validate the response and handle not getting a response at all. There are also different levels of trust. I may have trusted an app to provide a contact pictures, but not trusted it to block suspend. When the phone rings the app will be called to provide the picture for the incoming call dialog, but if it is frozen at this point the more trusted app that handles the incoming phone call will not be able to get the picture.

Quoted 3 lines

From what you're saying it follows that you're not really willing to accept any solution different to your suspend blockers.  Is that really the case?

I don't think that is a fair way to put it. We need to support our user-space framework and I have not seen an alternative solution that clearly will work (other than replacing suspend_blockers with pm_qos constraints that do the same thing).

Signature · 1 line
Arve Hjønnevåg
#319 lore raw
In reply to Arve Hjønnevåg
Quoted 2 lines · Arve Hjønnevåg
Quoted 1 line · Thomas Gleixner

On Sat, 5 Jun 2010, Rafael J. Wysocki wrote:

<snip>

Quoted 8 lines
Quoted 7 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 4 lines

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Perhaps I'm misunderstanding, but suspend and the cgroup freezer interoperate well today -- you don't have to choose one or the other. If you've discovered otherwise I'd consider it a bug and would like to hear more about it.

<snip>

Quoted 2 lines

it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing).

I don't see why that would be a problem. The cgroup freezer works independently of the suspend freezer -- even with suspend blockers. So my hunch is this is really the same as the next problem you refer to:

Quoted 3 lines

The biggest hurdle is how
to handle dependencies between processes that gets frozen and processes that don't get frozen.

I'm not sure it covers everything you want, but it should be possible to identify some of those so long as you know which process you're communicating with.

A trusted app can look up the freezer cgroup of a target app in /proc, then look at the cgroup's freezer.state file. If it's FREEZING or FROZEN then you've very likely got a "bad" dependency.

For example, say a trusted app plans on doing a blocking read() to fetch the output of an untrusted app via a pipe. Assuming we know the untrusted app's pid we could then check the dependency and determine that we're likely to block because the untrusted app's freezer cgroup is FREEZING or FROZEN. (certain to block if we see FROZEN)

That said, it involves quite a few system calls compared to a simple read() from the pipe. So my guess is it would be a debugging tool at best -- not something you always have enabled.

It may even be possible to make an lsof-like debugging tool to do that from outside both apps.

Cheers,
-Matt Helsley

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

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

Can you please answer the following question:

What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Sorry, no. I'm perfectly willing to make progress on that, as long as we walk on a sane ground. But abusing the kernel for fixing basic engineering problems in the user space side of affairs is completely out of discussion.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I wonder what people think.  Is this realistic and if so, would it be difficult to implement?

I think it's realistic and not overly complicated to implement.

The kernel support can be easily implemented on most arm hardware, I don't know if it can work on most existing x86 hardware. It does not

It does not matter. Even Intel folks told you more than once, that x86 hardware is going to be fixed pretty soon. Hint: that's crucial to their business ....

Quoted 5 lines

give us the same power savings as suspend with existing software, but it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing). The biggest hurdle is how to handle dependencies between processes that gets frozen and processes that don't get frozen.

See above.

Thanks,

tglx

#321 lore raw

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 22 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 16 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 8 lines
Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Quoted 10 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Quoted 6 lines

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 8 lines

Sorry, no. I'm perfectly willing to make progress on that, as long as we walk on a sane ground. But abusing the kernel for fixing basic engineering problems in the user space side of affairs is completely out of discussion.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

I wonder what people think.  Is this realistic and if so, would it be difficult to implement?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I think it's realistic and not overly complicated to implement.

The kernel support can be easily implemented on most arm hardware, I don't know if it can work on most existing x86 hardware. It does not

It does not matter. Even Intel folks told you more than once, that x86

How does it not matter. Are dropping support for existing x86 hardware once the new hardware comes out?

Quoted 14 lines

hardware is going to be fixed pretty soon. Hint: that's crucial to their business ....

Quoted 5 lines

give us the same power savings as suspend with existing software, but it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing). The biggest hurdle is how to handle dependencies between processes that gets frozen and processes that don't get frozen.

See above.

Thanks,

       tglx

Signature · 1 line
Arve Hjønnevåg
#322 lore raw
In reply to Thomas Gleixner

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 22 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 16 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 8 lines
Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Quoted 10 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Quoted 6 lines

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 8 lines

Sorry, no. I'm perfectly willing to make progress on that, as long as we walk on a sane ground. But abusing the kernel for fixing basic engineering problems in the user space side of affairs is completely out of discussion.

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

I wonder what people think.  Is this realistic and if so, would it be difficult to implement?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I think it's realistic and not overly complicated to implement.

The kernel support can be easily implemented on most arm hardware, I don't know if it can work on most existing x86 hardware. It does not

It does not matter. Even Intel folks told you more than once, that x86

How does it not matter. Are dropping support for existing x86 hardware once the new hardware comes out?

Quoted 14 lines

hardware is going to be fixed pretty soon. Hint: that's crucial to their business ....

Quoted 5 lines

give us the same power savings as suspend with existing software, but it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing). The biggest hurdle is how to handle dependencies between processes that gets frozen and processes that don't get frozen.

See above.

Thanks,

       tglx

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#323 lore raw
Quoted 28 lines · Arve Hjønnevåg

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 27 lines

Arve,

Quoted 22 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Quoted 7 lines
Quoted 3 lines

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Quoted 21 lines
Quoted 10 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Quoted 6 lines

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

See above.

Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Thanks,

tglx

#324 lore raw

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 30 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

Quoted 9 lines
Quoted 3 lines

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

Quoted 32 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

Quoted 42 lines
Quoted 22 lines
Quoted 11 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Quoted 6 lines

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

See above.

Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

Signature · 1 line
Arve Hjønnevåg
#325 lore raw
In reply to Thomas Gleixner

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 30 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

Quoted 9 lines
Quoted 3 lines

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

Quoted 32 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

Quoted 42 lines
Quoted 22 lines
Quoted 11 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Quoted 6 lines

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

See above.

Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#326 lore raw
Quoted 10 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 9 lines
Quoted 7 lines · Arve Hjønnevåg
Quoted 3 lines

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Quoted 8 lines
Quoted 5 lines

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

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

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 7 lines
Quoted 3 lines

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 5 lines
Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

framework selects A because it is in the foreground

if (A is frozen)
unfreeze(A)

deliver_event_to(A)

It's that simple.

If your framework cannot deal with that simple problem then you have a much more serious problem already.

Thanks,

tglx

#327 lore raw

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 14 lines
Quoted 7 lines · Arve Hjønnevåg
Quoted 3 lines

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

Quoted 7 lines
Quoted 2 lines

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

Whether you claimed it or not, this is the only case where using cgroups would have a significant power saving over what we get with suspend. The trusted app is idle and the untrusted app is frozen, so we enter a low power mode from idle.

Quoted 5 lines

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

If the task that is blocking suspend is using the cpu anyway, then the bad app does not increase the power consumption nearly as much as if the task that blocked suspend is idle.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 8 lines
Quoted 3 lines

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Quoted 55 lines
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 5 lines
Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

Quoted 9 lines

     framework selects A because it is in the foreground

     if (A is frozen)
        unfreeze(A)

     deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

Quoted 7 lines

If your framework cannot deal with that simple problem then you have a much more serious problem already.

Thanks,

       tglx

Signature · 1 line
Arve Hjønnevåg
#328 lore raw
In reply to Thomas Gleixner

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 14 lines
Quoted 7 lines · Arve Hjønnevåg
Quoted 3 lines

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

Quoted 7 lines
Quoted 2 lines

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

Whether you claimed it or not, this is the only case where using cgroups would have a significant power saving over what we get with suspend. The trusted app is idle and the untrusted app is frozen, so we enter a low power mode from idle.

Quoted 5 lines

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

If the task that is blocking suspend is using the cpu anyway, then the bad app does not increase the power consumption nearly as much as if the task that blocked suspend is idle.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 8 lines
Quoted 3 lines

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Quoted 55 lines
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 5 lines
Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

Quoted 9 lines

     framework selects A because it is in the foreground

     if (A is frozen)
        unfreeze(A)

     deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

Quoted 7 lines

If your framework cannot deal with that simple problem then you have a much more serious problem already.

Thanks,

       tglx

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#329 lore raw
Quoted 4 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

...

Quoted 9 lines
Quoted 9 lines

So taking your example:

Event happens and gets delivered to the framework

framework selects A because it is in the foreground

if (A is frozen)
unfreeze(A)

Quoted 8 lines
Quoted 4 lines

deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

Well, the freezing of the "untrusted" part of user space needs to be triggered somehow in the first place. Whatever mechanism is used for that, there should be a way to tell it to not to freeze the "untrusted" part of user space for a while. Yes, it is similar to wakelocks, but I think it can be implemented entirely in user space.

So, in general, the "trusted" app that needs an "untrusted" one to handle stuff will take a "freeze lock" to prevent the power manager from freezing the "untrusted" part of user space (that will also cause it to thaw these tasks if they are frozen at the moment) and will release the "freeze lock" when it's done with its job. You can use timeouts and whatever you like with that and the kernel doesn't have to participate in that (except for carrying out the low-level freezing and thawing of the "untrusted" tasks at the power manager's request).

Rafael

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

...

Quoted 9 lines
Quoted 9 lines

So taking your example:

Event happens and gets delivered to the framework

framework selects A because it is in the foreground

if (A is frozen)
unfreeze(A)

Quoted 8 lines
Quoted 4 lines

deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

Well, the freezing of the "untrusted" part of user space needs to be triggered somehow in the first place. Whatever mechanism is used for that, there should be a way to tell it to not to freeze the "untrusted" part of user space for a while. Yes, it is similar to wakelocks, but I think it can be implemented entirely in user space.

So, in general, the "trusted" app that needs an "untrusted" one to handle stuff will take a "freeze lock" to prevent the power manager from freezing the "untrusted" part of user space (that will also cause it to thaw these tasks if they are frozen at the moment) and will release the "freeze lock" when it's done with its job. You can use timeouts and whatever you like with that and the kernel doesn't have to participate in that (except for carrying out the low-level freezing and thawing of the "untrusted" tasks at the power manager's request).

Rafael

#331 lore raw
In reply to Arve Hjønnevåg
Quoted 17 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 14 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

Quoted 8 lines
Quoted 4 lines

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

If you do not have a clearly defined user space framework, then we talk about a completely random conglomeration of applications which need to be brought into submission by some global brute force approach.

I'm tired of this, really. You just use terminlology as it fits to defend the complete design failure of android. But you fail to trick me :)

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

We need to know that, otherwise we turn in circles forever.

Thanks,

tglx

#332 lore raw

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 7 lines
Quoted 3 lines

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

Quoted 6 lines
Quoted 3 lines

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

You said you were going to fix the framework. I did know if you were talking about the cgroup framework, or the android user-space frameworks. I don't think either has knowledge about all shared resources.

Quoted 6 lines

If you do not have a clearly defined user space framework, then we talk about a completely random conglomeration of applications which need to be brought into submission by some global brute force approach.

Quoted 8 lines

I'm tired of this, really. You just use terminlology as it fits to defend the complete design failure of android. But you fail to trick me :)

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

Quoted 5 lines

We need to know that, otherwise we turn in circles forever.

Thanks,

       tglx

Signature · 1 line
Arve Hjønnevåg
#333 lore raw
In reply to Thomas Gleixner

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 7 lines
Quoted 3 lines

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

Quoted 6 lines
Quoted 3 lines

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

You said you were going to fix the framework. I did know if you were talking about the cgroup framework, or the android user-space frameworks. I don't think either has knowledge about all shared resources.

Quoted 6 lines

If you do not have a clearly defined user space framework, then we talk about a completely random conglomeration of applications which need to be brought into submission by some global brute force approach.

Quoted 8 lines

I'm tired of this, really. You just use terminlology as it fits to defend the complete design failure of android. But you fail to trick me :)

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

Quoted 5 lines

We need to know that, otherwise we turn in circles forever.

Thanks,

       tglx

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#334 lore raw
Quoted 28 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 27 lines · Arve Hjønnevåg
Quoted 25 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 12 lines · Arve Hjønnevåg
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 8 lines
Quoted 3 lines

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Quoted 7 lines
Quoted 2 lines

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

You said you were going to fix the framework. I did know if you were talking about the cgroup framework, or the android user-space frameworks. I don't think either has knowledge about all shared resources.

The cgroup freezer makes sure that there are no in kernel resources blocked. Of course the user space side has to do the same and it's not rocket science.

Quoted 10 lines
Quoted 10 lines

If you do not have a clearly defined user space framework, then we talk about a completely random conglomeration of applications which need to be brought into submission by some global brute force approach.

I'm tired of this, really. You just use terminlology as it fits to defend the complete design failure of android. But you fail to trick me :)

Quoted 6 lines
Quoted 4 lines

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some

Sigh. That's the main reason why this discussion goes nowhere.

How in heavens sake can we make a decision whether suspend blockers are the right and only way to go, when the people

Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

#335 lore raw
Quoted 1 line · Thomas Gleixner

On Sat, 5 Jun 2010, Arve Hjønnevåg wrote:

<snip>

Quoted 3 lines
Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

If you want to wake up cgroup-frozen tasks for these fds perhaps your framework can fcnt(fd, F_SETOWN, <p[g]id>) to send SIGIO to a userspace-suspend-blocker thread/process/process group. When IO comes in, the suspend blocker is signalled which then unfreezes the cgroup of the frozen untrusted task. SIGIO works on pipes, fifos, sockets, ttys, and ptys -- many of which are precisely the kinds of things that would connect [trusted and untrusted] apps. Notably absent (last I checked): inotify fds, signalfd, timerfd, eventfd, filesystem fds and likely more.

Incidentally, this is just to show that it's not impossible to implement "wakeups" for cgroup-frozen tasks in userspace.

Cheers,
-Matt Helsley

#336 lore raw
Quoted 11 lines · Matt Helsley
Quoted 1 line · Thomas Gleixner

On Sat, 5 Jun 2010, Arve Hjønnevåg wrote:

<snip>

Quoted 3 lines
Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

If you want to wake up cgroup-frozen tasks for these fds perhaps your framework can fcnt(fd, F_SETOWN, <p[g]id>) to send SIGIO to a

How does the framework get all the fds that are used by the apps for wakeup events?

Quoted 13 lines

userspace-suspend-blocker thread/process/process group. When IO comes in, the suspend blocker is signalled which then unfreezes the cgroup of the frozen untrusted task. SIGIO works on pipes, fifos, sockets, ttys, and ptys -- many of which are precisely the kinds of things that would connect [trusted and untrusted] apps. Notably absent (last I checked): inotify fds, signalfd, timerfd, eventfd, filesystem fds and likely more.

Incidentally, this is just to show that it's not impossible to implement "wakeups" for cgroup-frozen tasks in userspace.

Cheers,
       -Matt Helsley

Signature · 1 line
Arve Hjønnevåg
#337 lore raw
In reply to Matt Helsley
Quoted 11 lines · Matt Helsley
Quoted 1 line · Thomas Gleixner

On Sat, 5 Jun 2010, Arve Hjønnevåg wrote:

<snip>

Quoted 3 lines
Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

If you want to wake up cgroup-frozen tasks for these fds perhaps your framework can fcnt(fd, F_SETOWN, <p[g]id>) to send SIGIO to a

How does the framework get all the fds that are used by the apps for wakeup events?

Quoted 13 lines

userspace-suspend-blocker thread/process/process group. When IO comes in, the suspend blocker is signalled which then unfreezes the cgroup of the frozen untrusted task. SIGIO works on pipes, fifos, sockets, ttys, and ptys -- many of which are precisely the kinds of things that would connect [trusted and untrusted] apps. Notably absent (last I checked): inotify fds, signalfd, timerfd, eventfd, filesystem fds and likely more.

Incidentally, this is just to show that it's not impossible to implement "wakeups" for cgroup-frozen tasks in userspace.

Cheers,
       -Matt Helsley

Signature · 1 line
Arve Hjønnevåg
#338 lore raw
In reply to Thomas Gleixner
Quoted 1 line · Thomas Gleixner

On Sat, 5 Jun 2010, Arve Hjønnevåg wrote:

<snip>

Quoted 3 lines
Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

If you want to wake up cgroup-frozen tasks for these fds perhaps your framework can fcnt(fd, F_SETOWN, <p[g]id>) to send SIGIO to a userspace-suspend-blocker thread/process/process group. When IO comes in, the suspend blocker is signalled which then unfreezes the cgroup of the frozen untrusted task. SIGIO works on pipes, fifos, sockets, ttys, and ptys -- many of which are precisely the kinds of things that would connect [trusted and untrusted] apps. Notably absent (last I checked): inotify fds, signalfd, timerfd, eventfd, filesystem fds and likely more.

Incidentally, this is just to show that it's not impossible to implement "wakeups" for cgroup-frozen tasks in userspace.

Cheers,
-Matt Helsley

#339 lore raw
In reply to Thomas Gleixner

2010/6/6 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 14 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

Quoted 8 lines
Quoted 4 lines

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

Quoted 9 lines
Quoted 4 lines

You said you were going to fix the framework. I did know if you were talking about the cgroup framework, or the android user-space frameworks. I don't think either has knowledge about all shared resources.

The cgroup freezer makes sure that there are no in kernel resources blocked. Of course the user space side has to do the same and it's not rocket science.

It is much easier to make sure there are no kernel resources held than that there are no resources held in user-space. The kernel threads have to return to a safe location before they get frozen, where user threads are just frozen wherever they are.

Signature · 1 line
Arve Hjønnevåg
#340 lore raw
In reply to Thomas Gleixner

2010/6/6 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 14 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

Quoted 8 lines
Quoted 4 lines

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

Quoted 9 lines
Quoted 4 lines

You said you were going to fix the framework. I did know if you were talking about the cgroup framework, or the android user-space frameworks. I don't think either has knowledge about all shared resources.

The cgroup freezer makes sure that there are no in kernel resources blocked. Of course the user space side has to do the same and it's not rocket science.

It is much easier to make sure there are no kernel resources held than that there are no resources held in user-space. The kernel threads have to return to a safe location before they get frozen, where user threads are just frozen wherever they are.

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 5 lines

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some

Sigh, thats the whole reason why this discussion goes nowhere.

How in heavens sake should we be able to decide whether suspend blockers are the right and only thing which solves a problem, when the folks advocating suspend blockers are not able to explain the problem in the first place ?

Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

Yes, we know that already, but that's a completely useless information as it does not describe the full constraints and dependencies.

Lemme summarize:

Android needs suspend blockers, because it works, but cannot explain why it works and why it only works that way.

A brilliant argument to merge them - NOT.

Thanks,

tglx

#342 lore raw

2010/6/6 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 5 lines

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some

Sigh, thats the whole reason why this discussion goes nowhere.

Please keep in mind that we also have third party applications and that it is not acceptable to break them. So even if I was able to tell you everything our framework does, you still need to make sure your solution does not break existing apps.

Quoted 12 lines

How in heavens sake should we be able to decide whether suspend blockers are the right and only thing which solves a problem, when the folks advocating suspend blockers are not able to explain the problem in the first place ?

Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

Yes, we know that already, but that's a completely useless information as it does not describe the full constraints and dependencies.

Quoted 7 lines

Lemme summarize:

 Android needs suspend blockers, because it works, but cannot explain why it works and why it only works that way.

A brilliant argument to merge them - NOT.

Your solution changes the programming model in a way that suspend does not. Linux allow processes to communicate with each other, and if you freeze individual processes this breaks. For the android framework code a lack of a timely response from an application is treated as an error, and the user is notified that the application is misbehaving. It may be possible to change the framework to make sure that no processes are frozen while it is waiting for a response, but this is a major change and applications that receive wakeup events directly from the kernel will still be broken.

Signature · 1 line
Arve Hjønnevåg
#343 lore raw
In reply to Thomas Gleixner

2010/6/6 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 5 lines

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some

Sigh, thats the whole reason why this discussion goes nowhere.

Please keep in mind that we also have third party applications and that it is not acceptable to break them. So even if I was able to tell you everything our framework does, you still need to make sure your solution does not break existing apps.

Quoted 12 lines

How in heavens sake should we be able to decide whether suspend blockers are the right and only thing which solves a problem, when the folks advocating suspend blockers are not able to explain the problem in the first place ?

Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

Yes, we know that already, but that's a completely useless information as it does not describe the full constraints and dependencies.

Quoted 7 lines

Lemme summarize:

 Android needs suspend blockers, because it works, but cannot explain why it works and why it only works that way.

A brilliant argument to merge them - NOT.

Your solution changes the programming model in a way that suspend does not. Linux allow processes to communicate with each other, and if you freeze individual processes this breaks. For the android framework code a lack of a timely response from an application is treated as an error, and the user is notified that the application is misbehaving. It may be possible to change the framework to make sure that no processes are frozen while it is waiting for a response, but this is a major change and applications that receive wakeup events directly from the kernel will still be broken.

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 5 lines

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

I don't think I can, since I only know small parts of it. I know some

Sigh, thats the whole reason why this discussion goes nowhere.

How in heavens sake should we be able to decide whether suspend blockers are the right and only thing which solves a problem, when the folks advocating suspend blockers are not able to explain the problem in the first place ?

Quoted 3 lines

events like input event go though a single thread in our system process, while other events like network packets (which are also wakeup events) goes directly to the app.

Yes, we know that already, but that's a completely useless information as it does not describe the full constraints and dependencies.

Lemme summarize:

Android needs suspend blockers, because it works, but cannot explain why it works and why it only works that way.

A brilliant argument to merge them - NOT.

Thanks,

tglx

#345 lore raw
In reply to Arve Hjønnevåg
Quoted 17 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 16 lines · Arve Hjønnevåg
Quoted 14 lines
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

Quoted 8 lines
Quoted 4 lines

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

I'm not sure which framework you are talking about here, but I don't think there is a single framework that knows about all shared resources.

Damn, it's not me talking about "our framework", you are mentioning when it fits your needs.

If you do not have a clearly defined user space framework, then we talk about a completely random conglomeration of applications which need to be brought into submission by some global brute force approach.

I'm tired of this, really. You just use terminlology as it fits to defend the complete design failure of android. But you fail to trick me :)

Can you please explain in a consistent way how the application stack and the underlying framework (which exists according to android docs) is handling events and how the separation of trust level works ?

We need to know that, otherwise we turn in circles forever.

Thanks,

tglx

#346 lore raw
In reply to Arve Hjønnevåg
Quoted 10 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 8 lines
Quoted 4 lines

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

Whether you claimed it or not, this is the only case where using cgroups would have a significant power saving over what we get with suspend. The trusted app is idle and the untrusted app is frozen, so we enter a low power mode from idle.

Nothing else was what I said and depending on the usage pattern this can be significant. Just you converted a perfectly sensible technical argument into a quibble about BUGs in applicatins which are not confinable by defintion.

Quoted 8 lines
Quoted 5 lines

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

If the task that is blocking suspend is using the cpu anyway, then the bad app does not increase the power consumption nearly as much as if the task that blocked suspend is idle.

That's utter bullshit. If the app missed to release the supsend blocker then your crappy "while(1);" app is killing you in no time, while the same frozen crappy "while(1);" does no harm at all.

Thanks,

tglx

#347 lore raw

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 8 lines
Quoted 4 lines

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

Whether you claimed it or not, this is the only case where using cgroups would have a significant power saving over what we get with suspend. The trusted app is idle and the untrusted app is frozen, so we enter a low power mode from idle.

Nothing else was what I said and depending on the usage pattern this can be significant. Just you converted a perfectly sensible technical argument into a quibble about BUGs in applicatins which are not confinable by defintion.

Quoted 5 lines
Quoted 5 lines

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

Quoted 8 lines
Quoted 3 lines

If the task that is blocking suspend is using the cpu anyway, then the bad app does not increase the power consumption nearly as much as if the task that blocked suspend is idle.

That's utter bullshit. If the app missed to release the supsend blocker then your crappy "while(1);" app is killing you in no time, while the same frozen crappy "while(1);" does no harm at all.

This is the bug I described above. If the app that blocked suspend did not release the suspend blocker and went idle, then another while(1) app will drain the battery. If the app that blocked suspend only blocked suspend while it needs to run (which is the typical reason to block suspend) then the system is not idle anyway and the impact of the while(1) app is much less severe.

Signature · 1 line
Arve Hjønnevåg
#348 lore raw
In reply to Thomas Gleixner

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 8 lines
Quoted 4 lines

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

Whether you claimed it or not, this is the only case where using cgroups would have a significant power saving over what we get with suspend. The trusted app is idle and the untrusted app is frozen, so we enter a low power mode from idle.

Nothing else was what I said and depending on the usage pattern this can be significant. Just you converted a perfectly sensible technical argument into a quibble about BUGs in applicatins which are not confinable by defintion.

Quoted 5 lines
Quoted 5 lines

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

Quoted 8 lines
Quoted 3 lines

If the task that is blocking suspend is using the cpu anyway, then the bad app does not increase the power consumption nearly as much as if the task that blocked suspend is idle.

That's utter bullshit. If the app missed to release the supsend blocker then your crappy "while(1);" app is killing you in no time, while the same frozen crappy "while(1);" does no harm at all.

This is the bug I described above. If the app that blocked suspend did not release the suspend blocker and went idle, then another while(1) app will drain the battery. If the app that blocked suspend only blocked suspend while it needs to run (which is the typical reason to block suspend) then the system is not idle anyway and the impact of the while(1) app is much less severe.

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 8 lines
Quoted 4 lines

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

Whether you claimed it or not, this is the only case where using cgroups would have a significant power saving over what we get with suspend. The trusted app is idle and the untrusted app is frozen, so we enter a low power mode from idle.

Nothing else was what I said and depending on the usage pattern this can be significant. Just you converted a perfectly sensible technical argument into a quibble about BUGs in applicatins which are not confinable by defintion.

Quoted 8 lines
Quoted 5 lines

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

If the task that is blocking suspend is using the cpu anyway, then the bad app does not increase the power consumption nearly as much as if the task that blocked suspend is idle.

That's utter bullshit. If the app missed to release the supsend blocker then your crappy "while(1);" app is killing you in no time, while the same frozen crappy "while(1);" does no harm at all.

Thanks,

tglx

#350 lore raw
In reply to Arve Hjønnevåg
Quoted 47 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

     framework selects A because it is in the foreground

     if (A is frozen)
        unfreeze(A)

Quoted 8 lines
Quoted 4 lines

     deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

The framework decides when to freeze the app in the first place (as your framework does now when it decides to suspend)

So it knows whether the app is frozen or not.

So it knows damend well whether it processed the event or not.

Thanks,

tglx

#351 lore raw

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

     framework selects A because it is in the foreground

     if (A is frozen)
        unfreeze(A)

Quoted 8 lines
Quoted 4 lines

     deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

Quoted 7 lines

The framework decides when to freeze the app in the first place (as your framework does now when it decides to suspend)

    So it knows whether the app is frozen or not.

    So it knows damend well whether it processed the event or not.

Our user-space code is not single-threaded. So just because an app was not frozen when you checked does not mean it will remain unfrozen. We can use the same user-space wakelock api we have now to prevent freezing apps instead of preventing suspend, but we loose any advantage we get from freezing just a subset of processes this way.

Signature · 1 line
Arve Hjønnevåg
#352 lore raw
In reply to Thomas Gleixner

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

     framework selects A because it is in the foreground

     if (A is frozen)
        unfreeze(A)

Quoted 8 lines
Quoted 4 lines

     deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

Quoted 7 lines

The framework decides when to freeze the app in the first place (as your framework does now when it decides to suspend)

    So it knows whether the app is frozen or not.

    So it knows damend well whether it processed the event or not.

Our user-space code is not single-threaded. So just because an app was not frozen when you checked does not mean it will remain unfrozen. We can use the same user-space wakelock api we have now to prevent freezing apps instead of preventing suspend, but we loose any advantage we get from freezing just a subset of processes this way.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#353 lore raw
Quoted 11 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

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

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

The framework decides when to freeze the app in the first place (as your framework does now when it decides to suspend)

    So it knows whether the app is frozen or not.

Quoted 8 lines
Quoted 2 lines

    So it knows damend well whether it processed the event or not.

Our user-space code is not single-threaded. So just because an app was not frozen when you checked does not mean it will remain unfrozen. We can use the same user-space wakelock api we have now to prevent freezing apps instead of preventing suspend, but we loose any advantage we get from freezing just a subset of processes this way.

Errm. That does not matter whether its single threaded or not. And right, you have to prevent that it gets frozen while you are calling into it.

But that does not change the fact that you can do finer grained power control even in the case when suspend is impossible because a background application has work to finish and does that without requiring interaction with the frozen part.

That's what I pointed out in the first place and you just argue in circles why it is impossible to do so.

Let me recapitulate:

Full on state: No difference because everything runs
Full suspend state: No difference because everything is down

Screen off, background work active:

Suspend blocker held by the active background work lets other applications which are unrelated consume CPU cycles and power.

versus

Frozen apps restrict the CPU cycles and power consumption to the background work (if there are no interactions with frozen tasks) and therefor save more power than the on/off approach.

If your user space stack cannot be distangled that way, then it's a problem of your user space stack and not changing the fact, that a well designedd system allows you to do that.

Any objections ?

Thanks,

tglx

#354 lore raw
In reply to Arve Hjønnevåg
Quoted 11 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

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

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

The framework decides when to freeze the app in the first place (as your framework does now when it decides to suspend)

    So it knows whether the app is frozen or not.

Quoted 8 lines
Quoted 2 lines

    So it knows damend well whether it processed the event or not.

Our user-space code is not single-threaded. So just because an app was not frozen when you checked does not mean it will remain unfrozen. We can use the same user-space wakelock api we have now to prevent freezing apps instead of preventing suspend, but we loose any advantage we get from freezing just a subset of processes this way.

Errm. That does not matter whether its single threaded or not. And right, you have to prevent that it gets frozen while you are calling into it.

But that does not change the fact that you can do finer grained power control even in the case when suspend is impossible because a background application has work to finish and does that without requiring interaction with the frozen part.

That's what I pointed out in the first place and you just argue in circles why it is impossible to do so.

Let me recapitulate:

Full on state: No difference because everything runs
Full suspend state: No difference because everything is down

Screen off, background work active:

Suspend blocker held by the active background work lets other applications which are unrelated consume CPU cycles and power.

versus

Frozen apps restrict the CPU cycles and power consumption to the background work (if there are no interactions with frozen tasks) and therefor save more power than the on/off approach.

If your user space stack cannot be distangled that way, then it's a problem of your user space stack and not changing the fact, that a well designedd system allows you to do that.

Any objections ?

Thanks,

tglx

#355 lore raw
In reply to Arve Hjønnevåg
Quoted 47 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

     framework selects A because it is in the foreground

     if (A is frozen)
        unfreeze(A)

Quoted 8 lines
Quoted 4 lines

     deliver_event_to(A)

It's that simple.

That is too simple. You also have to prevent A from being frozen while it is processing the event or the result would be the same as if it was frozen beforehand.

The framework decides when to freeze the app in the first place (as your framework does now when it decides to suspend)

So it knows whether the app is frozen or not.

So it knows damend well whether it processed the event or not.

Thanks,

tglx

#356 lore raw
In reply to Arve Hjønnevåg
Quoted 10 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 9 lines
Quoted 7 lines · Arve Hjønnevåg
Quoted 3 lines

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Quoted 8 lines
Quoted 5 lines

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

What you are describing is a problem which is not solvable either way. If you take the lock and do not release it you're not going to suspend. I never claimed that any other mechanism resolves this.

But this is not related to the fact that freezing crap while running a sane background task is going to save you power vs. an approach where running a sane background task allows crap to consume power unconfined until it is done.

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

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 7 lines
Quoted 3 lines

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

I'm going to fix the framework which puts the group into freeze state w/o making sure that there is no held shared resource. Come on it's not rocket science.

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 5 lines
Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

It's not about a central process, it goes through your framework, which should be able to deal with it. If not, it's a design failure which needs to be fixed at the place where the failure happened.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Quoted 6 lines

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Quoted 7 lines

You are claiming that trusted code should not have any dependencies on untrusted code. I gave you a visible example of such a dependency and want you to tell me how you can avoid this dependency. Since you are claiming that our user-space framework is fundamentally broken if it has to wait for untrusted code, I don't think it is unreasonable for you to answer this. Or do you think it is valid to communicate with untrusted code when the screen is on but not when it is off.

It does not matter whether the screen is off or not. If you need to call into that untrusted app from your trusted app and you know about the might be frozen state then you can deal with it.

So taking your example:

Event happens and gets delivered to the framework

framework selects A because it is in the foreground

if (A is frozen)
unfreeze(A)

deliver_event_to(A)

It's that simple.

If your framework cannot deal with that simple problem then you have a much more serious problem already.

Thanks,

tglx

#357 lore raw
In reply to Arve Hjønnevåg
Quoted 55 lines · Arve Hjønnevåg

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 30 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

Quoted 9 lines
Quoted 3 lines

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 7 lines
Quoted 3 lines

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

That depends a good deal on what you mean by holding a resource.

Generally, however, if your "trusted" processes depend on the processes you don't trust, then either the former should not be trusted, or the latter should be trusted.

Quoted 32 lines
Quoted 32 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 5 lines
Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

Well, yeah.

Arve, we're still learning you have some more requirements we had no idea about before and such that _only_ the suspend blockers (or wakelocks) framework is suitable to satisfy them. I don't realistically think we can make any progress this way.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

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

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Which is not the same as "the dependencies are such that they can't be taken into account in any way other than by using wakelocks (or suspend blockers)".

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

Can you please answer the following question:

What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right? So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway. So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

Quoted 5 lines
Quoted 2 lines

So which unfixable problem are you describing with the above example ?

You are claiming that trusted code should not have any dependencies on untrusted code.

Not "any". It shouldn't have dependencies that make a difference between "trusted" and "untrusted".

Think of security, for example. A root-owned process surely can exchange data with processes owned by non-root users, but it shouldn't blindly accept any data these processes give it.

Your wakelock-holding application is a counterpart of the root-owned process above. It can exchange data with processes that don't take wakelocks, but not in such a way that would prevent them from taking wakelocks if necessary (or from dropping wakelocks if no longer needed from their point of view).

If this condition is satisfied, then I claim you won't have any problems with freezing the "untrusted" apps upfront. If this condition is not satisfied, in turn, your framework already doesn't work.

Rafael

#358 lore raw

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

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 30 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

Quoted 9 lines
Quoted 3 lines

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 6 lines
Quoted 3 lines

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

That depends a good deal on what you mean by holding a resource.

I'm not sure why that matters. Any resource held by a frozen process could cause problems whether it is something like being the current foreground app or a mutex in shared memory.

Quoted 4 lines

Generally, however, if your "trusted" processes depend on the processes you don't trust, then either the former should not be trusted, or the latter should be trusted.

There are different levels of trust. Trusted processes often need to wait for an untrusted process to release a resource for the untrusted process to behave correctly, but the trusted process can revoke the resource if the untrusted process does not comply in time.

Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Quoted 5 lines
Quoted 1 line

Cross app calls do not go through a central process.

Well, yeah.

Arve, we're still learning you have some more requirements we had no idea

What new requirement are you talking about. Did you assume all our user-space ipc calls went though a single process?

Quoted 29 lines

about before and such that _only_ the suspend blockers (or wakelocks) framework is suitable to satisfy them.  I don't realistically think we can make any progress this way.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

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

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Which is not the same as "the dependencies are such that they can't be taken into account in any way other than by using wakelocks (or suspend blockers)".

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

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right?  So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Not if you mean when we write to /sys/power/state. Processes are not frozen until the last suspend blocker is released.

Quoted 8 lines

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway.  So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

I don't think what you said here is correct. If a wakeup event happens all processed are unfrozen since the driver blocks suspend. The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

Quoted 30 lines
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

Quoted 5 lines
Quoted 2 lines

So which unfixable problem are you describing with the above example ?

You are claiming that trusted code should not have any dependencies on untrusted code.

Not "any".  It shouldn't have dependencies that make a difference between "trusted" and "untrusted".

Think of security, for example.  A root-owned process surely can exchange data with processes owned by non-root users, but it shouldn't blindly accept any data these processes give it.

Quoted 8 lines

Your wakelock-holding application is a counterpart of the root-owned process above.  It can exchange data with processes that don't take wakelocks, but not in such a way that would prevent them from taking wakelocks if necessary (or from dropping wakelocks if no longer needed from their point of view).

If this condition is satisfied, then I claim you won't have any problems with freezing the "untrusted" apps upfront.  If this condition is not satisfied, in turn, your framework already doesn't work.

The problem is that properly working untrusted apps may get treated as non-working apps and killed because they were frozen and did not respond. Also this is not invisible to the user as the system usually gives the app several seconds to respond.

Signature · 1 line
Arve Hjønnevåg
#359 lore raw
Quoted 4 lines · Arve Hjønnevåg

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

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

...

Quoted 5 lines
Quoted 2 lines

Arve, we're still learning you have some more requirements we had no idea

What new requirement are you talking about. Did you assume all our user-space ipc calls went though a single process?

No, but I didn't assume that your wakelock-holding processes depend on the other processes in a way that might prevent them from acquiring or dropping a wakelock.

...

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right? So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Not if you mean when we write to /sys/power/state. Processes are not frozen until the last suspend blocker is released.

That doesn't matter. In the opportunistic mode you don't need to write into /sys/power/state to start suspend, this is done by the kernel automatically as soon as the last wakelock has been released (at least this is my assumption about how this works). Now, at this point the processes that don't use wakelocks can't really prevent themselves from being frozen and only the wakelocks users can do that. So, if a wakelock user depends on a process that doesn't use wakelocks in such a way that (because of that dependence) it can't acquire its wakelock while processes are being frozen, things don't work as they are supposed to.

Quoted 10 lines
Quoted 7 lines

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway. So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

I don't think what you said here is correct. If a wakeup event happens all processed are unfrozen since the driver blocks suspend.

This only means that the theoretical failure you gave as an example doesn't happen in practice. No problem, then. :-)

Quoted 3 lines

The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

And how is this different from an approach with cgroup freezing? Apps that use wakelock within the current framework would use "freeze locks" to prevent the "untrusted" part of user space from being frozen or to thaw it. Where's the problem, then?

Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#360 lore raw

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

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

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

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

...

Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Arve, we're still learning you have some more requirements we had no idea

What new requirement are you talking about. Did you assume all our user-space ipc calls went though a single process?

No, but I didn't assume that your wakelock-holding processes depend on the other processes in a way that might prevent them from acquiring or dropping a wakelock.

It does not prevent it from acquiring a wakelock (assuming the already held wakelock does not have a timeout), but it could delay it and cause an error dialog to pop up stating that the fozen app is misbehaving.

Quoted 13 lines

...

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right?  So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Not if you mean when we write to /sys/power/state. Processes are not frozen until the last suspend blocker is released.

Quoted 10 lines

That doesn't matter.  In the opportunistic mode you don't need to write into /sys/power/state to start suspend, this is done by the kernel automatically as soon as the last wakelock has been released (at least this is my assumption about how this works).  Now, at this point the processes that don't use wakelocks can't really prevent themselves from being frozen and only the wakelocks users can do that.  So, if a wakelock user depends on a process that doesn't use wakelocks in such a way that (because of that dependence) it can't acquire its wakelock while processes are being frozen, things don't work as they are supposed to.

You seem to forget that we use overlapping wakelocks. A process that need to acquire a wakelock does so before the driver it talks to releases its wakelock. At this point no processes are frozen.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway.  So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

Quoted 6 lines
Quoted 2 lines

I don't think what you said here is correct. If a wakeup event happens all processed are unfrozen since the driver blocks suspend.

This only means that the theoretical failure you gave as an example doesn't happen in practice.  No problem, then. :-)

If individual processes are frozen, we run into problems that we cannot run into if we freeze and thaw all processes.

Quoted 9 lines
Quoted 3 lines

The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

And how is this different from an approach with cgroup freezing?  Apps that use wakelock within the current framework would use "freeze locks" to prevent the "untrusted" part of user space from being frozen or to thaw it.  Where's the problem, then?

They will not be able to get wakeup events directly from the kernel. If the kernel does not thaw processes when a wakeup event happens, the app may never get to the point where it grabs its wakelock.

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

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

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

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

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

...

Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Arve, we're still learning you have some more requirements we had no idea

What new requirement are you talking about. Did you assume all our user-space ipc calls went though a single process?

No, but I didn't assume that your wakelock-holding processes depend on the other processes in a way that might prevent them from acquiring or dropping a wakelock.

It does not prevent it from acquiring a wakelock (assuming the already held wakelock does not have a timeout), but it could delay it and cause an error dialog to pop up stating that the fozen app is misbehaving.

Quoted 13 lines

...

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right?  So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Not if you mean when we write to /sys/power/state. Processes are not frozen until the last suspend blocker is released.

Quoted 10 lines

That doesn't matter.  In the opportunistic mode you don't need to write into /sys/power/state to start suspend, this is done by the kernel automatically as soon as the last wakelock has been released (at least this is my assumption about how this works).  Now, at this point the processes that don't use wakelocks can't really prevent themselves from being frozen and only the wakelocks users can do that.  So, if a wakelock user depends on a process that doesn't use wakelocks in such a way that (because of that dependence) it can't acquire its wakelock while processes are being frozen, things don't work as they are supposed to.

You seem to forget that we use overlapping wakelocks. A process that need to acquire a wakelock does so before the driver it talks to releases its wakelock. At this point no processes are frozen.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway.  So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

Quoted 6 lines
Quoted 2 lines

I don't think what you said here is correct. If a wakeup event happens all processed are unfrozen since the driver blocks suspend.

This only means that the theoretical failure you gave as an example doesn't happen in practice.  No problem, then. :-)

If individual processes are frozen, we run into problems that we cannot run into if we freeze and thaw all processes.

Quoted 9 lines
Quoted 3 lines

The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

And how is this different from an approach with cgroup freezing?  Apps that use wakelock within the current framework would use "freeze locks" to prevent the "untrusted" part of user space from being frozen or to thaw it.  Where's the problem, then?

They will not be able to get wakeup events directly from the kernel. If the kernel does not thaw processes when a wakeup event happens, the app may never get to the point where it grabs its wakelock.

Signature · 5 lines
Arve Hjønnevåg
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#362 lore raw
Quoted 2 lines · Arve Hjønnevåg

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

Quoted 1 line · Arve Hjønnevåg

...

Quoted 2 lines

If individual processes are frozen, we run into problems that we cannot run into if we freeze and thaw all processes.

Not individual processes, but the processes that don't use wakelocks in the Android world all together. And of course the approach has to be different, because it's a different design, but I don't think there are any fundamental issues you can't solve within this approach.

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

And how is this different from an approach with cgroup freezing? Apps that use wakelock within the current framework would use "freeze locks" to prevent the "untrusted" part of user space from being frozen or to thaw it. Where's the problem, then?

Quoted 3 lines

They will not be able to get wakeup events directly from the kernel. If the kernel does not thaw processes when a wakeup event happens, the app may never get to the point where it grabs its wakelock.

The apps that use "freeze locks" (or wakelocks) are never frozen, so I don't think this would be a problem.

Rafael

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

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

Quoted 1 line · Arve Hjønnevåg

...

Quoted 2 lines

If individual processes are frozen, we run into problems that we cannot run into if we freeze and thaw all processes.

Not individual processes, but the processes that don't use wakelocks in the Android world all together. And of course the approach has to be different, because it's a different design, but I don't think there are any fundamental issues you can't solve within this approach.

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

And how is this different from an approach with cgroup freezing? Apps that use wakelock within the current framework would use "freeze locks" to prevent the "untrusted" part of user space from being frozen or to thaw it. Where's the problem, then?

Quoted 3 lines

They will not be able to get wakeup events directly from the kernel. If the kernel does not thaw processes when a wakeup event happens, the app may never get to the point where it grabs its wakelock.

The apps that use "freeze locks" (or wakelocks) are never frozen, so I don't think this would be a problem.

Rafael

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

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

Quoted 3 lines · Arve Hjønnevåg
Quoted 2 lines

2010/6/5 Thomas Gleixner <[email protected]>:

Quoted 1 line

B1;2005;0cOn Fri, 4 Jun 2010, Arve Hjønnevåg wrote:

...

Quoted 5 lines
Quoted 2 lines

Arve, we're still learning you have some more requirements we had no idea

What new requirement are you talking about. Did you assume all our user-space ipc calls went though a single process?

No, but I didn't assume that your wakelock-holding processes depend on the other processes in a way that might prevent them from acquiring or dropping a wakelock.

...

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right? So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Not if you mean when we write to /sys/power/state. Processes are not frozen until the last suspend blocker is released.

That doesn't matter. In the opportunistic mode you don't need to write into /sys/power/state to start suspend, this is done by the kernel automatically as soon as the last wakelock has been released (at least this is my assumption about how this works). Now, at this point the processes that don't use wakelocks can't really prevent themselves from being frozen and only the wakelocks users can do that. So, if a wakelock user depends on a process that doesn't use wakelocks in such a way that (because of that dependence) it can't acquire its wakelock while processes are being frozen, things don't work as they are supposed to.

Quoted 10 lines
Quoted 7 lines

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway. So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

I don't think what you said here is correct. If a wakeup event happens all processed are unfrozen since the driver blocks suspend.

This only means that the theoretical failure you gave as an example doesn't happen in practice. No problem, then. :-)

Quoted 3 lines

The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

And how is this different from an approach with cgroup freezing? Apps that use wakelock within the current framework would use "freeze locks" to prevent the "untrusted" part of user space from being frozen or to thaw it. Where's the problem, then?

Rafael

#365 lore raw
In reply to Rafael J. Wysocki

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

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 30 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

Quoted 9 lines
Quoted 3 lines

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 6 lines
Quoted 3 lines

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

That depends a good deal on what you mean by holding a resource.

I'm not sure why that matters. Any resource held by a frozen process could cause problems whether it is something like being the current foreground app or a mutex in shared memory.

Quoted 4 lines

Generally, however, if your "trusted" processes depend on the processes you don't trust, then either the former should not be trusted, or the latter should be trusted.

There are different levels of trust. Trusted processes often need to wait for an untrusted process to release a resource for the untrusted process to behave correctly, but the trusted process can revoke the resource if the untrusted process does not comply in time.

Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Quoted 5 lines
Quoted 1 line

Cross app calls do not go through a central process.

Well, yeah.

Arve, we're still learning you have some more requirements we had no idea

What new requirement are you talking about. Did you assume all our user-space ipc calls went though a single process?

Quoted 29 lines

about before and such that _only_ the suspend blockers (or wakelocks) framework is suitable to satisfy them.  I don't realistically think we can make any progress this way.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

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

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Which is not the same as "the dependencies are such that they can't be taken into account in any way other than by using wakelocks (or suspend blockers)".

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

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right?  So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Not if you mean when we write to /sys/power/state. Processes are not frozen until the last suspend blocker is released.

Quoted 8 lines

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway.  So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

I don't think what you said here is correct. If a wakeup event happens all processed are unfrozen since the driver blocks suspend. The app that reads this event blocks suspend before reading it. If it was busy talking to a less trusted app when the event happened it still works since all apps are running at this point.

Quoted 30 lines
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

Quoted 5 lines
Quoted 2 lines

So which unfixable problem are you describing with the above example ?

You are claiming that trusted code should not have any dependencies on untrusted code.

Not "any".  It shouldn't have dependencies that make a difference between "trusted" and "untrusted".

Think of security, for example.  A root-owned process surely can exchange data with processes owned by non-root users, but it shouldn't blindly accept any data these processes give it.

Quoted 8 lines

Your wakelock-holding application is a counterpart of the root-owned process above.  It can exchange data with processes that don't take wakelocks, but not in such a way that would prevent them from taking wakelocks if necessary (or from dropping wakelocks if no longer needed from their point of view).

If this condition is satisfied, then I claim you won't have any problems with freezing the "untrusted" apps upfront.  If this condition is not satisfied, in turn, your framework already doesn't work.

The problem is that properly working untrusted apps may get treated as non-working apps and killed because they were frozen and did not respond. Also this is not invisible to the user as the system usually gives the app several seconds to respond.

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

2010/6/5 Thomas Gleixner <[email protected]>:

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

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 30 lines

Arve,

Quoted 18 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Quoted 4 lines

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

Quoted 9 lines
Quoted 3 lines

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

It is not unrelated if the trusted app has stopped working but still blocks suspend. The battery drains when you combine them.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Quoted 7 lines
Quoted 3 lines

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

I don't think is is straight forward. If the a process in the frozen group holds a resource that a process in the unfrozen group needs, how do deal with that?

That depends a good deal on what you mean by holding a resource.

Generally, however, if your "trusted" processes depend on the processes you don't trust, then either the former should not be trusted, or the latter should be trusted.

Quoted 32 lines
Quoted 32 lines
Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Quoted 5 lines
Quoted 3 lines

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Cross app calls do not go through a central process.

Well, yeah.

Arve, we're still learning you have some more requirements we had no idea about before and such that _only_ the suspend blockers (or wakelocks) framework is suitable to satisfy them. I don't realistically think we can make any progress this way.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

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

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Which is not the same as "the dependencies are such that they can't be taken into account in any way other than by using wakelocks (or suspend blockers)".

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

Can you please answer the following question:

What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

When Android starts opportunistic suspend, all applications are frozen, "trusted" as well as "untrusted", right? So, after they are all frozen, none of them can do anything to prevent suspend from happening, right?

Now, in my proposed approach the "untrusted" apps are frozen exactly at the point Android would start opportunistic suspend and they wouldn't be able to do anything about that anyway. So if one of your "trusted" apps depends on the "untrusted" ones in a way that you describe, you alread have a bug (the "trusted" app cannot prevent automatic suspend from happening even if it wants, because it depends on an "untrusted" app that has just been frozen).

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

Quoted 5 lines
Quoted 2 lines

So which unfixable problem are you describing with the above example ?

You are claiming that trusted code should not have any dependencies on untrusted code.

Not "any". It shouldn't have dependencies that make a difference between "trusted" and "untrusted".

Think of security, for example. A root-owned process surely can exchange data with processes owned by non-root users, but it shouldn't blindly accept any data these processes give it.

Your wakelock-holding application is a counterpart of the root-owned process above. It can exchange data with processes that don't take wakelocks, but not in such a way that would prevent them from taking wakelocks if necessary (or from dropping wakelocks if no longer needed from their point of view).

If this condition is satisfied, then I claim you won't have any problems with freezing the "untrusted" apps upfront. If this condition is not satisfied, in turn, your framework already doesn't work.

Rafael

#367 lore raw
In reply to Arve Hjønnevåg
Quoted 28 lines · Arve Hjønnevåg

2010/6/4 Thomas Gleixner <[email protected]>:

Quoted 27 lines

Arve,

Quoted 22 lines · Arve Hjønnevåg
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Quoted 7 lines
Quoted 3 lines

Why is it a BUG in the trusted app, when I initiate a download and put the phone down ?

It is not, but we have had bugs where a trusted app does not unblock suspend after some failure case where it is no longer making any progress.

Well, that's simply an application bug which sucks battery with or without suspend blockers. So it's unrelated to the freezing of untrusted apps while a trusted app still works in the background before allowing the machine to suspend.

Quoted 6 lines
Quoted 4 lines

That download might take a minute or two, but that's not an justification for the crapplication to run unconfined and prevent lower power states.

I agree, but this is not a simple problem to solve.

Not with suspend blockers, but with cgroup confinement of crap, it's straight forward.

Quoted 19 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 7 lines

Sorry, that's really the worst argument I saw in this whole discussion.

You're basically saying, that you have no idea what your user space stack is doing and you do not care at all as long as your suspend blocker scheme makes things work somehow.

Quoted 6 lines

Yes I don't know everything our user-space stack is doing, but I do know that it makes many calls between processes (and in both directions). As far as I know it uses timeouts when calling into untrusted code, so a misbehaving application will cause an error dialog to pop up asking if the user if it should wait longer or terminate the application.

Sigh, the more I learn about the details of android and it's violation of all sane engineering principles the more I understand why you invented a huge nail to push through all layers in order to bring the system into idle at all. And yes, you need a sledge hammer to drive that big nail through everything, so you are using the right tool.

Seriously, the cross app call goes through your framework, which already knows, that the untrusted part is frozen. So it can deal nicely with it in any way you want including unfreezing.

Quoted 21 lines
Quoted 10 lines

Up to that point, I really tried hard to step back from my initial "OMG, promoting crap is a nono" reaction and work with you on a sensible technical solution to confine crap and make it aligned with other efforts in this area.

So now, after I spent a reasonable amount of time (as you did) to understand what your requirements are, you come up with another restriction which is so outside of any level of sanity, that I'm at the point of giving up and just going into NAK mode.

I don't think this is a new restriction. Both Brian and I have mentioned that we have a lot of dependencies between processes.

Quoted 6 lines

Can you please answer the following question:

   What is the point of having the distinction of "trusted" and "untrusted" when you have no way to prevent "trusted" code calling "into "untrusted" code ?

Quoted 4 lines

Trusted code that calls into untrusted code has to deal with the untrusted code not responding, but we only want to pop up a message that the application is not responding if it is misbehaving, not just because it was frozen though no fault of its own.

See above.

Quoted 5 lines
Quoted 4 lines

That's violating any sense of abstraction and layering and makes it entirely clear that the only way you can deal with your own design failure is a big hammer which you need to force into the kernel.

Quoted 7 lines

How can it be fixed? The user presses the back button, the framework determines that app A is in the foreground and send the key to app A, app A decides that it it does not have anything internal to go back to and tells the framework to switch back to the previous app. If the user presses the back key again, the framework does not know which app this key should go to until app A has finished processing the first key press.

Errm, what has this to do with frozen apps? If your system is handling input events then there are no frozen apps and even if they are frozen your framework can unfreeze them _before_ talking to them.

So which unfixable problem are you describing with the above example ?

Thanks,

tglx

#368 lore raw
In reply to Thomas Gleixner
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Rafael J. Wysocki

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

Quoted 7 lines

There is an additional benefit to this approach:

    In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

Yes this can happen. It is usually only a big problem when you combine an (trusted) application that has a bug that blocks suspend forever with an application that wakes up too often for us to enter low power idle modes.

Quoted 6 lines

    With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Yes this would be better, but I want it in addition to suspend, not instead of it. It is also unclear if our user-space code could easily make use of it since our trusted code calls into untrusted code.

Quoted 4 lines
Quoted 4 lines

(2) Allow the cpuidle framework to put CPUs into low-power states after the "trusted" apps (ie. the ones that use suspend blockers in the Android world) have gone idle.

As far as I know this is what we already have on hardware that supports it.

Quoted 3 lines
Quoted 3 lines

(3) Teach the cpuidle framework to schedule runtime suspend of I/O devices before idling the last CPU (*).

I don't think we need this for android phones. We already put I/O devices in low power modes when they are not in use.

Quoted 7 lines
Quoted 7 lines

(4) Design a mechanism to resume the I/O devices suspended in (3) so that they are not powered up unnecessarily (that's going to be difficult as far as I can see).

This way, in principle, we should be able to save (at least almost) as much energy as the opportunistic suspend currently used by Android, provided that things will be capable of staying idle for extended periods of time.

The main reason we use suspend is that the system does not stay idle for extened periods of time. If this gets fixed, and our if user-space framework can deal with a subset of processes being frozen (this is a big if) this solution may work, but it does not help us today.

Quoted 10 lines
Quoted 7 lines

(*) That may require per-device PM QoS requirements to be used, in which case devices may even be suspended earlier if the PM QoS requirements of all of their users are met.

I wonder what people think.  Is this realistic and if so, would it be difficult to implement?

I think it's realistic and not overly complicated to implement.

The kernel support can be easily implemented on most arm hardware, I don't know if it can work on most existing x86 hardware. It does not give us the same power savings as suspend with existing software, but it can handle bad apps better (assuming you don't combine opportunistic suspend and cgroup freezing). The biggest hurdle is how to handle dependencies between processes that gets frozen and processes that don't get frozen.

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

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

There is an additional benefit to this approach:

In the current android world a background task (e.g. download initiated before the screensaver kicked in) prevents the suspend, but that also means that the crapplications can still suck power completely unconfined.

With the cgroup freezer you can "suspend" them right away and just keep the trusted background task(s) alive which allows us to go into deeper idle states instead of letting the crapplications run unconfined until the download finished and the suspend blocker goes away.

Quoted 15 lines

(2) Allow the cpuidle framework to put CPUs into low-power states after the "trusted" apps (ie. the ones that use suspend blockers in the Android world) have gone idle.

(3) Teach the cpuidle framework to schedule runtime suspend of I/O devices before idling the last CPU (*).

(4) Design a mechanism to resume the I/O devices suspended in (3) so that they are not powered up unnecessarily (that's going to be difficult as far as I can see).

This way, in principle, we should be able to save (at least almost) as much energy as the opportunistic suspend currently used by Android, provided that things will be capable of staying idle for extended periods of time.

Quoted 6 lines

(*) That may require per-device PM QoS requirements to be used, in which case
devices may even be suspended earlier if the PM QoS requirements of all of their users are met.

I wonder what people think. Is this realistic and if so, would it be difficult to implement?

I think it's realistic and not overly complicated to implement.

Thanks,

tglx

#370 lore raw
In reply to Peter Zijlstra
Quoted 30 lines · Peter Zijlstra
Quoted 3 lines · Ingo Molnar

Btw., i'd like to summarize the scheduler based suspend scheme proposed by Thomas Gleixner, Peter Zijlstra and myself. I found no good summary of it in the big thread, and there are also new elements of the proposal:

Just to clarify, my proposition doesn't go much further than treating 'suspend' as a genuine idle state (on suitable hardware, which x86 isn't).

Quoted 6 lines

- Create a 'deep idle' mode that suspends. This, if all constraints are met, is triggered by the scheduler automatically: just like the other idle modes are triggered currently. This approach fixes the wakeup races because an incoming wakeup event will set need_resched() and abort the suspend.

Right, so 'suspend' as idle seems (at least on UP/arm) a very sensible idea. On SMP current suspend hot-unplugs all but the boot cpu, I'm not sure we need to do that, since if the system is genuinely idle, what races are there?

And if its not idle...

Quoted 3 lines

( This mode can even use the existing suspend code to bring stuff down,
therefore it also solves the pending timer problem and works even on PC style x86. )

You cannot solve the pending timer issue from idle, unless you allow idle to stop clock_monotonic, which would change idle semantics, and that is not something I can say is a good idea.

Quoted 8 lines

You want all idle states to have the same semantics, otherwise things just get way too confusing.

Quoted 3 lines

- Solve crappy app confinement via the scheduler:

A first proposal was to use the existing cgroup mechanism,

I still believe containment is a cgroup problem.

I kind of agree here, so I'd like to focus a bit on that.

Here's my idea in the very general terms:

(1) Use the cgroup freezer to "suspend" the "untrusted" apps (ie. the ones that don't use suspend blockers aka wakelocks in the Android world) at the point Android would normally start opportunistic suspend.

(2) Allow the cpuidle framework to put CPUs into low-power states after the "trusted" apps (ie. the ones that use suspend blockers in the Android world) have gone idle.

(3) Teach the cpuidle framework to schedule runtime suspend of I/O devices before idling the last CPU (*).

(4) Design a mechanism to resume the I/O devices suspended in (3) so that they are not powered up unnecessarily (that's going to be difficult as far as I can see).

This way, in principle, we should be able to save (at least almost) as much energy as the opportunistic suspend currently used by Android, provided that things will be capable of staying idle for extended periods of time.

(*) That may require per-device PM QoS requirements to be used, in which case
devices may even be suspended earlier if the PM QoS requirements of all of their users are met.

I wonder what people think. Is this realistic and if so, would it be difficult to implement?

Rafael

#371 lore raw
In reply to a message not in the archive
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · * [email protected] <[email protected]> wrote:

[...] Not only has the source code been made available, but hundreds of engineering hours have been made trying to accomodate the demands of LKML --- and LKML has said no to suspend blockers/wakelocks.

Quoted 6 lines

I dont think you are being fair here, at all.

Firstly, the suspend-blockers feature is not being rejected (fixing and extending suspend is a worthwile goal), it's just that various different schemes have been proposed by the people who'll eventually have to maintain that code down the line.

Btw., i'd like to summarize the scheduler based suspend scheme proposed by Thomas Gleixner, Peter Zijlstra and myself. I found no good summary of it in the big thread, and there are also new elements of the proposal:

- Create a 'deep idle' mode that suspends. This, if all constraints are met, is triggered by the scheduler automatically: just like the other idle modes are triggered currently. This approach fixes the wakeup races because an incoming wakeup event will set need_resched() and abort the suspend.

( This mode can even use the existing suspend code to bring stuff down,
therefore it also solves the pending timer problem and works even on PC style x86. )

- Introduce a 'minimum wakeup latency' task attribute (task->latency), settable via a scheduler syscall. This is an ABI that influences the kernel how idle the system can go. (i.e. the equivalent of suspend blockers, just not binary and not system-wide.)

- Solve crappy app confinement via the scheduler:

A first proposal was to use the existing cgroup mechanism, but we found a different and probably more elegant solution:

We can slightly extend the scheduler and introduce another per task 'minimum latency other tasks are allowed to run' scheduling attribute (task->exclude_latency) - set via a scheduler syscall as well. (only settable by privileged tasks - such as the screensaver.)

This allows a task to 'exclude' other tasks that dont have low-latency requirements. Crappy apps would have a large latency value, so they'd be idled out when a privileged task sets the exclusion level low enough.

In the case of Android, this would for example be used by the screensaver to introduce different levels of runnability/idling.

[ Note that this scheme would also be useful in a completely different
scenario, for real-time tasks as well: it would allow extreme-RT tasks to quiescence all lower prio tasks in a controlled manner. (even if the RT task is sleeping) ]

- Controlled auto-suspend: drivers (such as input) could on wakeup automatically set the 'minimum wakeup latency' value of wakee tasks to a lower value. This automatically prevents another auto-suspend in the near
future: up to the point the wakee task increases its latency (via the scheduler syscall) again and allows suspend again.

This means there will be no surprise suspends for a task that may take a bit longer than usual to finish its work. [ Detail: this would only be done for tasks that have a non-default (non-infinity) task->latency value - to prevent the input driver from lowering latency values (and preventing future suspends) just because some unaware apps are running and using input drivers. ]

All in one, this scheme allows everything without exception that suspend-blockers allows and supports all the important usecases:

- allows agressive auto-idling

- has no wakeup races

- allows crappy-app confinement and other finegrained suspend control

- it should be pretty easy to adopt by Android as well, as it goes along similar principles of kernel automatisms combined with user-space controlled task and system attributes.

It's straightforward to adapt and it is also more generic, more clean and more flexible than suspend-blockers.

Please mention any remaining technical issues that may still be are unaddressed.

Thanks,

Ingo