Suspend block api (version 8)
Subsystems (6)
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Neil Brown2010/6/2 Neil Brown <[email protected]>:
Quoted 38 lines
Quoted 35 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 33 lines · Neil Brown
Quoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
Quoted 6 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Some wakeup events like the an incoming phone may be handled by a vendor supplied daemon that I do not have the source code for. And, no I'm not open to a change that would require all wakeup events to go to a single process.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
Not all wakeup events are broadcast like input events so they cannot be read by both daemons. Not that this really matters, since reading the event from the suspend daemon does not mean that it has been delivered to and processed by the other daemon.
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
- The event handling daemon giving the suspend-daemon's pid as
F_OWNER, and using poll/select to get the events itself.I don't like the idea of using signals for this. Without the hack Alan Stern suggested, you will temporarily block suspend if the wakeup event happened before the suspend daemon thread made it to the kernel, but abort suspend if it happened right after.
Quoted 9 lines
I'm not sure why that difference matters. But I'm also not sure that it is true.
When any wakeup event happen, a signal will be delivered to the suspend daemon.
This will interrupt a pending suspend request, or a sleep, or whatever else the daemon is doing.
It can then go back to waiting for a good time to suspend, and then try to suspend again.
This is inferior to the solution that is in the android kernel and the suspend blocker patchset. Both suspend as soon as possible and do not require signal handlers that modify the argument to your kernel call.
Quoted 12 lines
Quoted 9 lines
Quoted 7 lines
When 'mem' is written to
/sys/power/state,suspend_preparewaits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and triggerkill_fasync.And what happens if you are not waiting when this happens?
I'm not sure I understand the question. Could you explain it please?
If the thread is not already in the kernel how does your signal handler abort suspend.
Quoted 15 lines
Either the initial event happens late enough to abort/resume the suspend, or the signal happens early enough to abort the suspend, or alert the daemon not to do a suspend. Either way we don't get stuck in suspend.
Quoted 9 lines
Quoted 3 lines
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
Waiting after a wake event is the same as
suspend_block_timeout. This is useful when passing events through layers of code that does no block suspend, but we should strive to avoid it. Other people had much stronger objections to this, which is why it is not included in the last suspend blocker patchset.
Quoted 9 lines
Absolutely agree. The idea of of waiting was just a simple way to present code that actually could work. There are doubtlessly better ways and I assume they have been implemented in the suspend-blocker code.
We just need some way to wait for the suspend-block count to reach zero, with some confidence that this amount of time is limited.(though to be honest ... the incredible simplicity of waiting a little while is very compelling.... :-))
Sure, but forcing that as the only way to prevent suspend is taking to too far.
Quoted 9 lines
Quoted 4 lines
It also does not work for drivers that need to block suspend for more than a few seconds. For instance the gpio keypad matrix driver needs to block suspend while keys are pressed so it can scan the keypad.
I cannot imagine why it would take multiple seconds to scan a keypad. Can you explain that?
Do you mean while keys are held pressed?
Yes.
Quoted 2 lines
Maybe you don't get a wake-up event
on key-release?
We should.
Quoted 3 lines
In that case your user-space daemon could block suspend while there are any pressed keys.... confused.
The user-space daemon should not need to know which keys are in a matrix. We also have other drivers that need to block suspend. For instance, some devices need to block suspend while connected to a USB host.
Quoted 6 lines
Thanks for the review,
NeilBrown
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Neil Brown2010/6/2 Neil Brown <[email protected]>:
Quoted 38 lines
Quoted 35 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 33 lines · Neil Brown
Quoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
Quoted 6 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Some wakeup events like the an incoming phone may be handled by a vendor supplied daemon that I do not have the source code for. And, no I'm not open to a change that would require all wakeup events to go to a single process.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
Not all wakeup events are broadcast like input events so they cannot be read by both daemons. Not that this really matters, since reading the event from the suspend daemon does not mean that it has been delivered to and processed by the other daemon.
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
- The event handling daemon giving the suspend-daemon's pid as
F_OWNER, and using poll/select to get the events itself.I don't like the idea of using signals for this. Without the hack Alan Stern suggested, you will temporarily block suspend if the wakeup event happened before the suspend daemon thread made it to the kernel, but abort suspend if it happened right after.
Quoted 9 lines
I'm not sure why that difference matters. But I'm also not sure that it is true.
When any wakeup event happen, a signal will be delivered to the suspend daemon.
This will interrupt a pending suspend request, or a sleep, or whatever else the daemon is doing.
It can then go back to waiting for a good time to suspend, and then try to suspend again.
This is inferior to the solution that is in the android kernel and the suspend blocker patchset. Both suspend as soon as possible and do not require signal handlers that modify the argument to your kernel call.
Quoted 12 lines
Quoted 9 lines
Quoted 7 lines
When 'mem' is written to
/sys/power/state,suspend_preparewaits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and triggerkill_fasync.And what happens if you are not waiting when this happens?
I'm not sure I understand the question. Could you explain it please?
If the thread is not already in the kernel how does your signal handler abort suspend.
Quoted 15 lines
Either the initial event happens late enough to abort/resume the suspend, or the signal happens early enough to abort the suspend, or alert the daemon not to do a suspend. Either way we don't get stuck in suspend.
Quoted 9 lines
Quoted 3 lines
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
Waiting after a wake event is the same as
suspend_block_timeout. This is useful when passing events through layers of code that does no block suspend, but we should strive to avoid it. Other people had much stronger objections to this, which is why it is not included in the last suspend blocker patchset.
Quoted 9 lines
Absolutely agree. The idea of of waiting was just a simple way to present code that actually could work. There are doubtlessly better ways and I assume they have been implemented in the suspend-blocker code.
We just need some way to wait for the suspend-block count to reach zero, with some confidence that this amount of time is limited.(though to be honest ... the incredible simplicity of waiting a little while is very compelling.... :-))
Sure, but forcing that as the only way to prevent suspend is taking to too far.
Quoted 9 lines
Quoted 4 lines
It also does not work for drivers that need to block suspend for more than a few seconds. For instance the gpio keypad matrix driver needs to block suspend while keys are pressed so it can scan the keypad.
I cannot imagine why it would take multiple seconds to scan a keypad. Can you explain that?
Do you mean while keys are held pressed?
Yes.
Quoted 2 lines
Maybe you don't get a wake-up event
on key-release?
We should.
Quoted 3 lines
In that case your user-space daemon could block suspend while there are any pressed keys.... confused.
The user-space daemon should not need to know which keys are in a matrix. We also have other drivers that need to block suspend. For instance, some devices need to block suspend while connected to a USB host.
Quoted 6 lines
Thanks for the review,
NeilBrown
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
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 10 lines · Arve Hjønnevåg
2010/6/2 Neil Brown <[email protected]>:
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
That's not the goal at all. We want a solution which is acceptable for android and OTOH does not get into the way of other approaches.
The main problem I have is that suspend blockers are only addressing one particular problem space of power management.
We have more requirements than that, e.g. an active device transfer requires to prevent the idle code to select a deep power state due to latency requirements.
So we then have to implement two mechanisms in the relevant drivers:
1) telling the idle code to limit latency
2) telling the suspend code not to suspend
My main interest is to limit it to one mechanism, which is QoS based and let idle and suspend make the appropriate decisions based on that information.
Thanks,
tglx
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
2010/6/2 Thomas Gleixner <[email protected]>:
Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines
2010/6/2 Neil Brown <[email protected]>:
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
Quoted 6 lines
Quoted 2 lines
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
That's not the goal at all. We want a solution which is acceptable for android and OTOH does not get into the way of other approaches.
I don't actually think the suspend blocker patchset get in the way of anything else.
Quoted 11 lines
The main problem I have is that suspend blockers are only addressing one particular problem space of power management.
We have more requirements than that, e.g. an active device transfer requires to prevent the idle code to select a deep power state due to latency requirements.
So we then have to implement two mechanisms in the relevant drivers:
1) telling the idle code to limit latency
2) telling the suspend code not to suspend
And 3) telling the idle code to not enter low power modes that disrupt active interrupts or clocks.
Our wakelock code handles 2 and 3, but I removed support for 3 on request since you can hack it by specifying a latency value that you know the low power mode cannot support.
Quoted 5 lines
My main interest is to limit it to one mechanism, which is QoS based and let idle and suspend make the appropriate decisions based on that information.
We can use one mechanism for this, but we still have to specify both. To me this is just another naming argument and not a good reason to not merge the suspend blocker code. You have to modify the same drivers if you call suspend_block() as if you call pm_qos_update_requirement(don't suspend). We have to specify when it is not safe to suspend independent of when it is not safe to enter low power idle modes so unless you want to have a bitmap of constraints you don't save any calls. And, if we later get a constraint framework that supports everything, we can switch to it then and we will then already have some drivers annotated.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 32 lines · Arve Hjønnevåg
2010/6/2 Thomas Gleixner <[email protected]>:
Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines
2010/6/2 Neil Brown <[email protected]>:
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
Quoted 6 lines
Quoted 2 lines
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
That's not the goal at all. We want a solution which is acceptable for android and OTOH does not get into the way of other approaches.
I don't actually think the suspend blocker patchset get in the way of anything else.
Quoted 11 lines
The main problem I have is that suspend blockers are only addressing one particular problem space of power management.
We have more requirements than that, e.g. an active device transfer requires to prevent the idle code to select a deep power state due to latency requirements.
So we then have to implement two mechanisms in the relevant drivers:
1) telling the idle code to limit latency
2) telling the suspend code not to suspend
Quoted 6 lines
And 3) telling the idle code to not enter low power modes that disrupt active interrupts or clocks.
Our wakelock code handles 2 and 3, but I removed support for 3 on request since you can hack it by specifying a latency value that you know the low power mode cannot support.
You are mixing concepts.
clock domains and power domains are a separate issue which are already handled by the run time power management code and the clock framework.
The interrupt latency is a QoS requirement and has nothing to do with power domains and clock domains simply because I can go deeper w/o violating the clock and power domain constraints when the latency allows it.
Quoted 8 lines
Quoted 4 lines
My main interest is to limit it to one mechanism, which is QoS based and let idle and suspend make the appropriate decisions based on that information.
We can use one mechanism for this, but we still have to specify both. To me this is just another naming argument and not a good reason to not merge the suspend blocker code. You have to modify the same
The main objection against suspend blocker is the user space interface / ABI issue, not the driver code which we can fix in no time. But we cannot fix it once it is glued into a user space interface.
I don't care about adding two empty static inlines into a header file, which allows to merge the android drivers, but I care much about giving a guaranteed behaviour to user space.
Thanks,
tglx
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 32 lines · Arve Hjønnevåg
2010/6/2 Thomas Gleixner <[email protected]>:
Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines
2010/6/2 Neil Brown <[email protected]>:
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
Quoted 6 lines
Quoted 2 lines
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
That's not the goal at all. We want a solution which is acceptable for android and OTOH does not get into the way of other approaches.
I don't actually think the suspend blocker patchset get in the way of anything else.
Quoted 11 lines
The main problem I have is that suspend blockers are only addressing one particular problem space of power management.
We have more requirements than that, e.g. an active device transfer requires to prevent the idle code to select a deep power state due to latency requirements.
So we then have to implement two mechanisms in the relevant drivers:
1) telling the idle code to limit latency
2) telling the suspend code not to suspend
Quoted 6 lines
And 3) telling the idle code to not enter low power modes that disrupt active interrupts or clocks.
Our wakelock code handles 2 and 3, but I removed support for 3 on request since you can hack it by specifying a latency value that you know the low power mode cannot support.
You are mixing concepts.
clock domains and power domains are a separate issue which are already handled by the run time power management code and the clock framework.
The interrupt latency is a QoS requirement and has nothing to do with power domains and clock domains simply because I can go deeper w/o violating the clock and power domain constraints when the latency allows it.
Quoted 8 lines
Quoted 4 lines
My main interest is to limit it to one mechanism, which is QoS based and let idle and suspend make the appropriate decisions based on that information.
We can use one mechanism for this, but we still have to specify both. To me this is just another naming argument and not a good reason to not merge the suspend blocker code. You have to modify the same
The main objection against suspend blocker is the user space interface / ABI issue, not the driver code which we can fix in no time. But we cannot fix it once it is glued into a user space interface.
I don't care about adding two empty static inlines into a header file, which allows to merge the android drivers, but I care much about giving a guaranteed behaviour to user space.
Thanks,
tglx
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Thomas Gleixner2010/6/2 Thomas Gleixner <[email protected]>:
Quoted 9 lines · Arve Hjønnevåg
Quoted 8 lines
2010/6/2 Neil Brown <[email protected]>:
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
Quoted 6 lines
Quoted 2 lines
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
That's not the goal at all. We want a solution which is acceptable for android and OTOH does not get into the way of other approaches.
I don't actually think the suspend blocker patchset get in the way of anything else.
Quoted 11 lines
The main problem I have is that suspend blockers are only addressing one particular problem space of power management.
We have more requirements than that, e.g. an active device transfer requires to prevent the idle code to select a deep power state due to latency requirements.
So we then have to implement two mechanisms in the relevant drivers:
1) telling the idle code to limit latency
2) telling the suspend code not to suspend
And 3) telling the idle code to not enter low power modes that disrupt active interrupts or clocks.
Our wakelock code handles 2 and 3, but I removed support for 3 on request since you can hack it by specifying a latency value that you know the low power mode cannot support.
Quoted 5 lines
My main interest is to limit it to one mechanism, which is QoS based and let idle and suspend make the appropriate decisions based on that information.
We can use one mechanism for this, but we still have to specify both. To me this is just another naming argument and not a good reason to not merge the suspend blocker code. You have to modify the same drivers if you call suspend_block() as if you call pm_qos_update_requirement(don't suspend). We have to specify when it is not safe to suspend independent of when it is not safe to enter low power idle modes so unless you want to have a bitmap of constraints you don't save any calls. And, if we later get a constraint framework that supports everything, we can switch to it then and we will then already have some drivers annotated.
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 10 lines · Arve Hjønnevåg
2010/6/2 Neil Brown <[email protected]>:
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
That's not the goal at all. We want a solution which is acceptable for android and OTOH does not get into the way of other approaches.
The main problem I have is that suspend blockers are only addressing one particular problem space of power management.
We have more requirements than that, e.g. an active device transfer requires to prevent the idle code to select a deep power state due to latency requirements.
So we then have to implement two mechanisms in the relevant drivers:
1) telling the idle code to limit latency
2) telling the suspend code not to suspend
My main interest is to limit it to one mechanism, which is QoS based and let idle and suspend make the appropriate decisions based on that information.
Thanks,
tglx
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 46 lines · On Wed, 2 Jun 2010 02:12:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
2010/6/2 Neil Brown <[email protected]>:
Quoted 38 lines
Quoted 35 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 33 lines · Neil Brown
Quoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake eventsQuoted 6 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Quoted 4 lines
Some wakeup events like the an incoming phone may be handled by a vendor supplied daemon that I do not have the source code for. And, no I'm not open to a change that would require all wakeup events to go to a single process.
Ahh.. Well I have no answer for the "I must support a closed-source app" card that has not been heard 1000 times already.
My proposal doesn't require all wakeup events to go through one single process - it was just one of (at least) 3 options.
Quoted 40 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
Not all wakeup events are broadcast like input events so they cannot be read by both daemons. Not that this really matters, since reading the event from the suspend daemon does not mean that it has been delivered to and processed by the other daemon.
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
- The event handling daemon giving the suspend-daemon's pid as
F_OWNER, and using poll/select to get the events itself.I don't like the idea of using signals for this. Without the hack Alan Stern suggested, you will temporarily block suspend if the wakeup event happened before the suspend daemon thread made it to the kernel, but abort suspend if it happened right after.
Quoted 9 lines
I'm not sure why that difference matters. But I'm also not sure that it is true.
When any wakeup event happen, a signal will be delivered to the suspend daemon.
This will interrupt a pending suspend request, or a sleep, or whatever else the daemon is doing.
It can then go back to waiting for a good time to suspend, and then try to suspend again.
Quoted 4 lines
This is inferior to the solution that is in the android kernel and the suspend blocker patchset. Both suspend as soon as possible and do not require signal handlers that modify the argument to your kernel call.
The solution in the android kernel and the suspend blocker patchset both share one fairly fatal flaw - they are not being accepted upstream. I am trying to find a minimal suitable solution that does not share that flaw.
I do not know yet if it does or not, but as it is fixing a real (design) bug, I feel it has some chance. Of course if it doesn't meet your need, then that becomes irrelevant....
And there is no requirement to modify any arguments in any signal handlers.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
When 'mem' is written to
/sys/power/state,suspend_preparewaits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and triggerkill_fasync.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And what happens if you are not waiting when this happens?
I'm not sure I understand the question. Could you explain it please?
If the thread is not already in the kernel how does your signal handler abort suspend.
setjmp / longjmp. This is the time-honoured method for allowing a signal to break the flow of a program and re-start somewhere else.
Quoted 45 lines
Quoted 16 lines
Either the initial event happens late enough to abort/resume the suspend, or the signal happens early enough to abort the suspend, or alert the daemon not to do a suspend. Either way we don't get stuck in suspend.
Quoted 9 lines
Quoted 3 lines
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
Waiting after a wake event is the same as
suspend_block_timeout. This is useful when passing events through layers of code that does no block suspend, but we should strive to avoid it. Other people had much stronger objections to this, which is why it is not included in the last suspend blocker patchset.Quoted 9 lines
Absolutely agree. The idea of of waiting was just a simple way to present code that actually could work. There are doubtlessly better ways and I assume they have been implemented in the suspend-blocker code.
We just need some way to wait for the suspend-block count to reach zero, with some confidence that this amount of time is limited.(though to be honest ... the incredible simplicity of waiting a little while is very compelling.... :-))
Sure, but forcing that as the only way to prevent suspend is taking to too far.
Quoted 9 lines
Quoted 4 lines
It also does not work for drivers that need to block suspend for more than a few seconds. For instance the gpio keypad matrix driver needs to block suspend while keys are pressed so it can scan the keypad.
I cannot imagine why it would take multiple seconds to scan a keypad. Can you explain that?
Do you mean while keys are held pressed?
Yes.
Quoted 2 lines
Maybe you don't get a wake-up event
on key-release?We should.
Quoted 8 lines
Quoted 3 lines
In that case your user-space daemon could block suspend while there are any pressed keys.... confused.
The user-space daemon should not need to know which keys are in a matrix. We also have other drivers that need to block suspend. For instance, some devices need to block suspend while connected to a USB host.
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
You could get those drivers to return EBUSY from PM_SUSPEND_PREPARE (which would need to be a configurable option), but then I guess you have no way to wait for the device to become non-busy.
If user-space really cannot tell if the driver is busy or not, then I would suggest that the driver is fairly poorly designed.
It would seem then that a user-space requested suspend is not sufficient for your needs even if we remove the race window, as you have drivers that want to avoid suspend indefinitely, and that "need to avoid suspend" status is not visible from user-space.
It is a pity that this extra requirement was not clear from your introduction to the "Opportunistic suspend support" patch.
If that be the case, I'll stop bothering you with suggestions that can never work.
Thanks for your time,
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 46 lines · On Wed, 2 Jun 2010 02:12:10 -0700 Arve Hjønnevåg <[email protected]> wrote:
2010/6/2 Neil Brown <[email protected]>:
Quoted 38 lines
Quoted 35 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 33 lines · Neil Brown
Quoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake eventsQuoted 6 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Quoted 4 lines
Some wakeup events like the an incoming phone may be handled by a vendor supplied daemon that I do not have the source code for. And, no I'm not open to a change that would require all wakeup events to go to a single process.
Ahh.. Well I have no answer for the "I must support a closed-source app" card that has not been heard 1000 times already.
My proposal doesn't require all wakeup events to go through one single process - it was just one of (at least) 3 options.
Quoted 40 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
Not all wakeup events are broadcast like input events so they cannot be read by both daemons. Not that this really matters, since reading the event from the suspend daemon does not mean that it has been delivered to and processed by the other daemon.
Quoted 6 lines
There would still need to be some sort of communication between the the suspend daemon on any event daemon to ensure that the events had been processed. This could be very light weight interaction. The point though is that with this patch it becomes possible to avoid races. Possible is better than impossible.
We already have a solution. I don't think rejecting our solution but merging a worse solution should be the goal.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
- The event handling daemon giving the suspend-daemon's pid as
F_OWNER, and using poll/select to get the events itself.I don't like the idea of using signals for this. Without the hack Alan Stern suggested, you will temporarily block suspend if the wakeup event happened before the suspend daemon thread made it to the kernel, but abort suspend if it happened right after.
Quoted 9 lines
I'm not sure why that difference matters. But I'm also not sure that it is true.
When any wakeup event happen, a signal will be delivered to the suspend daemon.
This will interrupt a pending suspend request, or a sleep, or whatever else the daemon is doing.
It can then go back to waiting for a good time to suspend, and then try to suspend again.
Quoted 4 lines
This is inferior to the solution that is in the android kernel and the suspend blocker patchset. Both suspend as soon as possible and do not require signal handlers that modify the argument to your kernel call.
The solution in the android kernel and the suspend blocker patchset both share one fairly fatal flaw - they are not being accepted upstream. I am trying to find a minimal suitable solution that does not share that flaw.
I do not know yet if it does or not, but as it is fixing a real (design) bug, I feel it has some chance. Of course if it doesn't meet your need, then that becomes irrelevant....
And there is no requirement to modify any arguments in any signal handlers.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
When 'mem' is written to
/sys/power/state,suspend_preparewaits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and triggerkill_fasync.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And what happens if you are not waiting when this happens?
I'm not sure I understand the question. Could you explain it please?
If the thread is not already in the kernel how does your signal handler abort suspend.
setjmp / longjmp. This is the time-honoured method for allowing a signal to break the flow of a program and re-start somewhere else.
Quoted 45 lines
Quoted 16 lines
Either the initial event happens late enough to abort/resume the suspend, or the signal happens early enough to abort the suspend, or alert the daemon not to do a suspend. Either way we don't get stuck in suspend.
Quoted 9 lines
Quoted 3 lines
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
Waiting after a wake event is the same as
suspend_block_timeout. This is useful when passing events through layers of code that does no block suspend, but we should strive to avoid it. Other people had much stronger objections to this, which is why it is not included in the last suspend blocker patchset.Quoted 9 lines
Absolutely agree. The idea of of waiting was just a simple way to present code that actually could work. There are doubtlessly better ways and I assume they have been implemented in the suspend-blocker code.
We just need some way to wait for the suspend-block count to reach zero, with some confidence that this amount of time is limited.(though to be honest ... the incredible simplicity of waiting a little while is very compelling.... :-))
Sure, but forcing that as the only way to prevent suspend is taking to too far.
Quoted 9 lines
Quoted 4 lines
It also does not work for drivers that need to block suspend for more than a few seconds. For instance the gpio keypad matrix driver needs to block suspend while keys are pressed so it can scan the keypad.
I cannot imagine why it would take multiple seconds to scan a keypad. Can you explain that?
Do you mean while keys are held pressed?
Yes.
Quoted 2 lines
Maybe you don't get a wake-up event
on key-release?We should.
Quoted 8 lines
Quoted 3 lines
In that case your user-space daemon could block suspend while there are any pressed keys.... confused.
The user-space daemon should not need to know which keys are in a matrix. We also have other drivers that need to block suspend. For instance, some devices need to block suspend while connected to a USB host.
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
You could get those drivers to return EBUSY from PM_SUSPEND_PREPARE (which would need to be a configurable option), but then I guess you have no way to wait for the device to become non-busy.
If user-space really cannot tell if the driver is busy or not, then I would suggest that the driver is fairly poorly designed.
It would seem then that a user-space requested suspend is not sufficient for your needs even if we remove the race window, as you have drivers that want to avoid suspend indefinitely, and that "need to avoid suspend" status is not visible from user-space.
It is a pity that this extra requirement was not clear from your introduction to the "Opportunistic suspend support" patch.
If that be the case, I'll stop bothering you with suggestions that can never work.
Thanks for your time,
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
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Or if you get in an upper layer, the knowledge that the subsystem has about it's requirements to function properly. Why would you separate it out?
If all your drivers specify their needed requirements, the pm-core (or idle) has the maximum flexibility to implement any strategy and is guaranteed a stable system as long as it honours the given requirements. (That's the theory, of course.)
Quoted 7 lines
You could get those drivers to return EBUSY from
PM_SUSPEND_PREPARE(which would need to be a configurable option), but then I guess you have no way to wait for the device to become non-busy.If user-space really cannot tell if the driver is busy or not, then I would suggest that the driver is fairly poorly designed.
In general, userspace has no business knowing if the driver is busy or not. It would need intimate knowledge about the driver to determine if it is busy or not. That is what the kernel is all about, to hide that knowledge from userspace and masking it with a one-fits-all-API.
Quoted 5 lines
It would seem then that a user-space requested suspend is not sufficient for your needs even if we remove the race window, as you have drivers that want to avoid suspend indefinitely, and that "need to avoid suspend" status is not visible from user-space.
Well, but the kernel-solution and the userspace solution should be pretty independent. The tricky part here seems to be to have a kernel-userspace-boundary that doesn't require a specific kernel implementation and works.
Could someone perhaps make a recap on what are the problems with the API? I have no clear eye (experience?) for that (or so it seems).
Quoted 2 lines
It is a pity that this extra requirement was not clear from your introduction to the "Opportunistic suspend support" patch.
I think that the main problem was that _all_ the requirements were not communicated well. That caused everybody to think that their solution would be a better fit. You are not alone.
Quoted 4 lines
If that be the case, I'll stop bothering you with suggestions that can never work.
Thanks for your time,
NeilBrown
Don't be frustrated. What should Arve be? :)
Cheers,
Flo
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Or if you get in an upper layer, the knowledge that the subsystem has about it's requirements to function properly. Why would you separate it out?
If all your drivers specify their needed requirements, the pm-core (or idle) has the maximum flexibility to implement any strategy and is guaranteed a stable system as long as it honours the given requirements. (That's the theory, of course.)
Quoted 7 lines
You could get those drivers to return EBUSY from
PM_SUSPEND_PREPARE(which would need to be a configurable option), but then I guess you have no way to wait for the device to become non-busy.If user-space really cannot tell if the driver is busy or not, then I would suggest that the driver is fairly poorly designed.
In general, userspace has no business knowing if the driver is busy or not. It would need intimate knowledge about the driver to determine if it is busy or not. That is what the kernel is all about, to hide that knowledge from userspace and masking it with a one-fits-all-API.
Quoted 5 lines
It would seem then that a user-space requested suspend is not sufficient for your needs even if we remove the race window, as you have drivers that want to avoid suspend indefinitely, and that "need to avoid suspend" status is not visible from user-space.
Well, but the kernel-solution and the userspace solution should be pretty independent. The tricky part here seems to be to have a kernel-userspace-boundary that doesn't require a specific kernel implementation and works.
Could someone perhaps make a recap on what are the problems with the API? I have no clear eye (experience?) for that (or so it seems).
Quoted 2 lines
It is a pity that this extra requirement was not clear from your introduction to the "Opportunistic suspend support" patch.
I think that the main problem was that _all_ the requirements were not communicated well. That caused everybody to think that their solution would be a better fit. You are not alone.
Quoted 4 lines
If that be the case, I'll stop bothering you with suggestions that can never work.
Thanks for your time,
NeilBrown
Don't be frustrated. What should Arve be? :)
Cheers,
Flo
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 2 lines · On Wed, 2 Jun 2010 21:05:21 +0200 Florian Mickler <[email protected]> wrote:
Could someone perhaps make a recap on what are the problems with the API? I have no clear eye (experience?) for that (or so it seems).
Good interface design is an acquired taste. And it isn't always easy to explain satisfactorily. But let me try to explain what I see.
A key aspect of a good interface is unity, and sometimes uniformity. For example, the file descriptor is a key element to the unity of the Unix (and hence Posix and Linux) interface. "everything is a file" and even when it isn't, everything is accessed via a file descriptor. This is one of the reasons that signals cause so much problem when programming in Unix - they aren't files, don't have file descriptors and don't look them at all. That is why signalfd was created, to try to tie signals back in to the 'file descriptor' model.
So unity is important. Adding new concepts is best done as an extension of an existing concept. That means that all the infrastructure, not only code and design but also developer understanding, can be leveraged to help get the new concept *right* first time. It also means that using the new concept is easier to learn.
So the problem with the wake-locks / suspend-blockers (and I've actually come to like the first name much more) is that it introduces a new concept without properly leveraging existing concepts.
The new concept is opportunistic suspend, though maybe a better name would be automatic suspend - not sure.
There appear to be two ways you can get opportunistic suspend leveraging already-existing concepts.
One is to leverage the current "power/state = mem" architecture and just let userspace choose the opportune moment. The user-space daemon that chooses this moment would need full information about states of various things to do this, but sysfs is good at providing full information about what is in the kernel, and there are dozens of ways for user-space processes to communicate their state to each other. So this is all doable today without introducing new design concepts.
Except there is a race between suspending and new events, so we just need to fix the race. Hence my patch.
The other is to leverage the more general power management infrastructure. We can already detect when the processor won't be needed for a while, and put it into a low-power state. We can already put devices to sleep when they aren't being used. We can just generalise this so that we can detect when all devices are either unused, or capable of supporting an S3 transition, and detect when the next timer interrupt is far enough in the future that S3 latency wont be a problem - set the rtc alarm to match the next timer and go to S3. All completely transparent. (I admit I'm not entirely sure what the qos that is being discussed brings us, but I assume it is better quality rather than correctness).
So there are at least two different ways that opportunistic suspend could be integrated into existing infrastructure with virtually no change of interface and no new concepts - just refining or extending existing concepts.
Yet the approach used and preferred by android is to create something substantially new. Yes, it does use the existing suspend infrastructure, but in a very new and different way. Suspend is now initiated by the kernel, but in a completely different way to the ways that the kernel already initiates power saving. So we have two infrastructures for essentially one task. Looked at the other way, it moves the initiation of suspend from user-space into the kernel, and then allows user-space to tell the kernel not to suspend. That to me is very ugly.
In general, the kernel should provide information to user-space, and provide services to user-space, and user-space should use that information to decide what services to request. This is the essence the "policy lives in user-space" maxim.
The Android code has user-space giving information to the kernel, so the kernel can make a policy decision. This approach is generally less flexible and is best avoided.
Just as a bit of background, let's think about some of the areas in the kernel where the kernel does make policy decisions based on user-space input.
- the scheduler - based on 'nice' setting it decided who should run when
- the VM - based on read-ahead settings, madvise/fadvise, recent-use heuristics, it tries to decide what to keep in memory and what to swap out.
I think those are the main ones. There are other smaller fish like the choice of IO scheduler and various ways to tune network connections.
But the two big ones are perfect examples of subsystems that have proven very hard to get *right*, and have been substantially re-written more than once. In each case, the difficulty wasn't how to perform the work, it was the choice of what work to perform. It probably also involved getting different sorts of information about the current state.
That perspective leaves me very sceptical of any design that involves making policy decisions in the kernel. It is too easy to get wrong, then too hard to change.
Admittedly the power subsystem does seem to make policy decisions in the kernel, via the various governors. Though I don't know much about how these work, it seems significant that there is a pluggable infrastructure with multiple governors, and one of them leaves the decisions to user-space.
So that is what I see as wrong with the android API : it doesn't bring unity by simply leveraging existing infrastructure, and it makes policy decisions in the kernel.
Quoted 8 lines
Quoted 3 lines
It is a pity that this extra requirement was not clear from your introduction to the "Opportunistic suspend support" patch.
I think that the main problem was that _all_ the requirements were not communicated well. That caused everybody to think that their solution would be a better fit. You are not alone.
Quoted 7 lines
Quoted 4 lines
If that be the case, I'll stop bothering you with suggestions that can never work.
Thanks for your time,
NeilBrownDon't be frustrated. What should Arve be? :)
Sometimes appearing frustrated can elicit a different style of response to appearing polite and constructive... can be helpful.
And yes: I fully understand that Arve would be frustrated. There seems to be a big disconnect in perceptions of what problem is trying to be solved, and thus disconnects in what the solution should look like, and I suspect that would be very frustrating all around.
NeilBrown
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Florian MicklerQuoted 2 lines · On Wed, 2 Jun 2010 21:05:21 +0200 Florian Mickler <[email protected]> wrote:
Could someone perhaps make a recap on what are the problems with the API? I have no clear eye (experience?) for that (or so it seems).
Good interface design is an acquired taste. And it isn't always easy to explain satisfactorily. But let me try to explain what I see.
A key aspect of a good interface is unity, and sometimes uniformity. For example, the file descriptor is a key element to the unity of the Unix (and hence Posix and Linux) interface. "everything is a file" and even when it isn't, everything is accessed via a file descriptor. This is one of the reasons that signals cause so much problem when programming in Unix - they aren't files, don't have file descriptors and don't look them at all. That is why signalfd was created, to try to tie signals back in to the 'file descriptor' model.
So unity is important. Adding new concepts is best done as an extension of an existing concept. That means that all the infrastructure, not only code and design but also developer understanding, can be leveraged to help get the new concept *right* first time. It also means that using the new concept is easier to learn.
So the problem with the wake-locks / suspend-blockers (and I've actually come to like the first name much more) is that it introduces a new concept without properly leveraging existing concepts.
The new concept is opportunistic suspend, though maybe a better name would be automatic suspend - not sure.
There appear to be two ways you can get opportunistic suspend leveraging already-existing concepts.
One is to leverage the current "power/state = mem" architecture and just let userspace choose the opportune moment. The user-space daemon that chooses this moment would need full information about states of various things to do this, but sysfs is good at providing full information about what is in the kernel, and there are dozens of ways for user-space processes to communicate their state to each other. So this is all doable today without introducing new design concepts.
Except there is a race between suspending and new events, so we just need to fix the race. Hence my patch.
The other is to leverage the more general power management infrastructure. We can already detect when the processor won't be needed for a while, and put it into a low-power state. We can already put devices to sleep when they aren't being used. We can just generalise this so that we can detect when all devices are either unused, or capable of supporting an S3 transition, and detect when the next timer interrupt is far enough in the future that S3 latency wont be a problem - set the rtc alarm to match the next timer and go to S3. All completely transparent. (I admit I'm not entirely sure what the qos that is being discussed brings us, but I assume it is better quality rather than correctness).
So there are at least two different ways that opportunistic suspend could be integrated into existing infrastructure with virtually no change of interface and no new concepts - just refining or extending existing concepts.
Yet the approach used and preferred by android is to create something substantially new. Yes, it does use the existing suspend infrastructure, but in a very new and different way. Suspend is now initiated by the kernel, but in a completely different way to the ways that the kernel already initiates power saving. So we have two infrastructures for essentially one task. Looked at the other way, it moves the initiation of suspend from user-space into the kernel, and then allows user-space to tell the kernel not to suspend. That to me is very ugly.
In general, the kernel should provide information to user-space, and provide services to user-space, and user-space should use that information to decide what services to request. This is the essence the "policy lives in user-space" maxim.
The Android code has user-space giving information to the kernel, so the kernel can make a policy decision. This approach is generally less flexible and is best avoided.
Just as a bit of background, let's think about some of the areas in the kernel where the kernel does make policy decisions based on user-space input.
- the scheduler - based on 'nice' setting it decided who should run when
- the VM - based on read-ahead settings, madvise/fadvise, recent-use heuristics, it tries to decide what to keep in memory and what to swap out.
I think those are the main ones. There are other smaller fish like the choice of IO scheduler and various ways to tune network connections.
But the two big ones are perfect examples of subsystems that have proven very hard to get *right*, and have been substantially re-written more than once. In each case, the difficulty wasn't how to perform the work, it was the choice of what work to perform. It probably also involved getting different sorts of information about the current state.
That perspective leaves me very sceptical of any design that involves making policy decisions in the kernel. It is too easy to get wrong, then too hard to change.
Admittedly the power subsystem does seem to make policy decisions in the kernel, via the various governors. Though I don't know much about how these work, it seems significant that there is a pluggable infrastructure with multiple governors, and one of them leaves the decisions to user-space.
So that is what I see as wrong with the android API : it doesn't bring unity by simply leveraging existing infrastructure, and it makes policy decisions in the kernel.
Quoted 8 lines
Quoted 3 lines
It is a pity that this extra requirement was not clear from your introduction to the "Opportunistic suspend support" patch.
I think that the main problem was that _all_ the requirements were not communicated well. That caused everybody to think that their solution would be a better fit. You are not alone.
Quoted 7 lines
Quoted 4 lines
If that be the case, I'll stop bothering you with suggestions that can never work.
Thanks for your time,
NeilBrownDon't be frustrated. What should Arve be? :)
Sometimes appearing frustrated can elicit a different style of response to appearing polite and constructive... can be helpful.
And yes: I fully understand that Arve would be frustrated. There seems to be a big disconnect in perceptions of what problem is trying to be solved, and thus disconnects in what the solution should look like, and I suspect that would be very frustrating all around.
NeilBrown
Dmitry Torokhov
maintainerRe: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Florian MicklerQuoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the gpio_matrix driver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressed KEY_SUSPEND or KEY_POWER it cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
Signature · 1 line
Dmitry
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 10 lines · On Wed, 2 Jun 2010 16:32:44 -0700 Dmitry Torokhov <[email protected]>…
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 9 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
I can't follow the gpio_matrix_driver example, but your point is obviously true.
A device should never register a constraint because of the data it handles. That belongs into userspace. Or wherever the data is consumed.
I'm obviously not trying to say that a network driver should block suspend while I'm on facebook. Or unblock when visiting m$.com. That would be absurd.
But, there are of course places in the kernel, where some kernel code listens to data. For example the packet-filtering. Or sysrq-keys. But I don't know how that relates to suspend_blockers now... ?
Mind if I rephrase the quote?
From: "Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices."
To: "It fits, when the requirement is a direct consequence of the intimate knowledge the driver has about the driven devices."
Cheers,
Flo
p.s.: tsss.... language... what a broken concept. And yet we have to work with it.
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Dmitry TorokhovQuoted 10 lines · On Wed, 2 Jun 2010 16:32:44 -0700 Dmitry Torokhov <[email protected]>…
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 9 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
I can't follow the gpio_matrix_driver example, but your point is obviously true.
A device should never register a constraint because of the data it handles. That belongs into userspace. Or wherever the data is consumed.
I'm obviously not trying to say that a network driver should block suspend while I'm on facebook. Or unblock when visiting m$.com. That would be absurd.
But, there are of course places in the kernel, where some kernel code listens to data. For example the packet-filtering. Or sysrq-keys. But I don't know how that relates to suspend_blockers now... ?
Mind if I rephrase the quote?
From: "Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices."
To: "It fits, when the requirement is a direct consequence of the intimate knowledge the driver has about the driven devices."
Cheers,
Flo
p.s.: tsss.... language... what a broken concept. And yet we have to work with it.
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Dmitry TorokhovQuoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
If we just suspend while the keypad scan is active, a second press of KEY_POWER would not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 21 lines · On Wed, 2 Jun 2010 19:44:59 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
Quoted 13 lines
If we just suspend while the keypad scan is active, a second press of
KEY_POWERwould not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Thanks for the detailed explanation. That helps a lot.
I see that if follows that performing a suspend while keys are pressed would not be good, and keys could be pressed for arbitrarily long periods. It does not follow that the keypad driver should therefore explicitly disable suspend. It could simply inform user-space that the keypad is in the alternate scan mode, so user-space can choose not to enter suspend in at that time (i.e. policy in user-space).
I can see also how one might want to express this behaviour as a PM_QOS constraint (now that I have read a bit about PM_QOS), but I cannot see that you would need to. As the keypad driver is polling during this mode, it would presumably set a timer that would fire in the near future, and the very existence of this timer (with a duration shorter than the S3 latency) would be enough to ensure S3 wasn't automatically entered by PM.
At most you might use set_timer_slack to give a slightly higher upper bound to the timeout.
So if we take the suspend-from-idle approach, this driver needs no annotation, and if we take the 'fix the suspend/wake-event race' then this driver needs no special treatment - just enough to close the race, and some user-space policy support.
i.e. it doesn't seem to be a special case.
NeilBrown
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 21 lines · On Wed, 2 Jun 2010 19:44:59 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
Quoted 13 lines
If we just suspend while the keypad scan is active, a second press of
KEY_POWERwould not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Thanks for the detailed explanation. That helps a lot.
I see that if follows that performing a suspend while keys are pressed would not be good, and keys could be pressed for arbitrarily long periods. It does not follow that the keypad driver should therefore explicitly disable suspend. It could simply inform user-space that the keypad is in the alternate scan mode, so user-space can choose not to enter suspend in at that time (i.e. policy in user-space).
I can see also how one might want to express this behaviour as a PM_QOS constraint (now that I have read a bit about PM_QOS), but I cannot see that you would need to. As the keypad driver is polling during this mode, it would presumably set a timer that would fire in the near future, and the very existence of this timer (with a duration shorter than the S3 latency) would be enough to ensure S3 wasn't automatically entered by PM.
At most you might use set_timer_slack to give a slightly higher upper bound to the timeout.
So if we take the suspend-from-idle approach, this driver needs no annotation, and if we take the 'fix the suspend/wake-event race' then this driver needs no special treatment - just enough to close the race, and some user-space policy support.
i.e. it doesn't seem to be a special case.
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Dmitry Torokhov
maintainerRe: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 21 lines · Arve Hjønnevåg
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
Quoted 12 lines
If we just suspend while the keypad scan is active, a second press of
KEY_POWERwould not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Would that be still the case if you reprogram the device as wakeup source while suspending?
Anyway, it does not really matter. Your case (current suspend blockers) would delay putting device to sleep till you release all the keys, including KEY_POWER. If you delegate the decision to userspace it would have an _option_ of putting the device to sleep earlier, however in both cases user has to release all keys before the device can be resumed.
Signature · 1 line
Dmitry
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
2010/6/4 Dmitry Torokhov <[email protected]>:
Quoted 35 lines · Arve Hjønnevåg
Quoted 21 lines
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.Quoted 12 lines
If we just suspend while the keypad scan is active, a second press of
KEY_POWERwould not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Quoted 2 lines
Would that be still the case if you reprogram the device as wakeup source while suspending?
It depends on what part you are referring to. It is impossible to detect some keys presses if you suspend while a key is held down. That key will connect one output to one input. If the interrupt is edge triggered you can just turn all the outputs back on (and clear the interrupt that this will generate) and suspend, but no additional key presses on keys connected to the same input will cause an interrupt until all those keys have been released first or a key connected to another input is pressed. If the interrupt is level triggered (and fixed polarity) you cannot do this. You must either disable the input interrupt or the output. This means that you if the user releases the key and press it again, you cannot wakeup on this key. You can also not wake up on any other keys connected to the disables input or output. So you have some choice in what events you loose, but there will always be some key press sequence that will not work if you suspend but will work if you prevent suspend in the middle.
Quoted 6 lines
Anyway, it does not really matter. Your case (current suspend blockers) would delay putting device to sleep till you release all the keys, including
KEY_POWER. If you delegate the decision to userspace it would have an _option_ of putting the device to sleep earlier, however in both cases user has to release all keys before the device can be resumed.
We deliver all keys to user space so that is has the option of reacting to them. Yes if we did not do this user space would have the option of suspending while keys are pressed, but it would need detailed knowledge about the driver to make this decision (will the driver loose key events if we suspend, which keys can be lost, does the condition clear automatically when all the keys are released or do we need another wakeup event to get out of it).
Signature · 1 line
Arve Hjønnevåg
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Dmitry Torokhov2010/6/4 Dmitry Torokhov <[email protected]>:
Quoted 35 lines · Arve Hjønnevåg
Quoted 21 lines
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.Quoted 12 lines
If we just suspend while the keypad scan is active, a second press of
KEY_POWERwould not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Quoted 2 lines
Would that be still the case if you reprogram the device as wakeup source while suspending?
It depends on what part you are referring to. It is impossible to detect some keys presses if you suspend while a key is held down. That key will connect one output to one input. If the interrupt is edge triggered you can just turn all the outputs back on (and clear the interrupt that this will generate) and suspend, but no additional key presses on keys connected to the same input will cause an interrupt until all those keys have been released first or a key connected to another input is pressed. If the interrupt is level triggered (and fixed polarity) you cannot do this. You must either disable the input interrupt or the output. This means that you if the user releases the key and press it again, you cannot wakeup on this key. You can also not wake up on any other keys connected to the disables input or output. So you have some choice in what events you loose, but there will always be some key press sequence that will not work if you suspend but will work if you prevent suspend in the middle.
Quoted 6 lines
Anyway, it does not really matter. Your case (current suspend blockers) would delay putting device to sleep till you release all the keys, including
KEY_POWER. If you delegate the decision to userspace it would have an _option_ of putting the device to sleep earlier, however in both cases user has to release all keys before the device can be resumed.
We deliver all keys to user space so that is has the option of reacting to them. Yes if we did not do this user space would have the option of suspending while keys are pressed, but it would need detailed knowledge about the driver to make this decision (will the driver loose key events if we suspend, which keys can be lost, does the condition clear automatically when all the keys are released or do we need another wakeup event to get out of it).
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Arve HjønnevågQuoted 21 lines · Arve Hjønnevåg
Quoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
Quoted 12 lines
If we just suspend while the keypad scan is active, a second press of
KEY_POWERwould not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Would that be still the case if you reprogram the device as wakeup source while suspending?
Anyway, it does not really matter. Your case (current suspend blockers) would delay putting device to sleep till you release all the keys, including KEY_POWER. If you delegate the decision to userspace it would have an _option_ of putting the device to sleep earlier, however in both cases user has to release all keys before the device can be resumed.
Signature · 1 line
Dmitry
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Dmitry TorokhovQuoted 10 lines · Dmitry Torokhov
Quoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
Quoted 8 lines
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the
gpio_matrixdriver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressedKEY_SUSPENDorKEY_POWERit cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
If we just suspend while the keypad scan is active, a second press of KEY_POWER would not be able wake the device up. The gpio keypad matrix driver has two operating modes. No keys are pressed: all the outputs are active so a key press will generate an interrupt in one of the inputs. Keys are pressed: Activate a single output at a time so we can determine which keys are pressed. The second mode is entered when the driver gets an interrupt in the first mode. The first mode is entered if the scan detected that no keys are pressed. The driver could be modified to stop the scan on suspend and forcibly put the device back in no-keys-pressed state, but pressing additional keys connected to the same input can no longer generate any events (the input does not change).
Signature · 1 line
Arve Hjønnevåg
Dmitry Torokhov
maintainerRe: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Florian MicklerQuoted 8 lines · Florian Mickler
Quoted 3 lines · On Wed, 2 Jun 2010 21:02:24 +1000 Neil Brown <[email protected]> wrote:
And this decision (to block suspend) really needs to be made in the driver, not in userspace?
Well, it fits. The requirement is a direct consequence of the intimate knowledge the driver has about the driven devices.
That is not really true. A driver does have intimate knowledge of the device, however it does not necessarily have an idea about the data read from the device. Consider the gpio_matrix driver: Arve says that it has to continue scanning matrix once first interrupt arrvies. But it really depends on what key has been pressed - if user pressed KEY_SUSPEND or KEY_POWER it cmight be better if we did not wait for key release but initiated the action right away. The decision on how system reacts to a key press does not belong to the driver but really to userspace.
Signature · 1 line
Dmitry
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 7 lines · Neil Brown
Quoted 5 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 4 lines
The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
Quoted 5 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
Brian
Re: [linux-pm] [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 14 lines · Brian Swetland
Quoted 7 lines · Neil Brown
Quoted 5 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 4 lines
The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake eventsQuoted 5 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Quoted 5 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
Quoted 8 lines
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
I'm not sure its a step in any direction, but I do understand the avoidance of having to rework a lot of code.
--mgross
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 10 lines · mark gross
Quoted 6 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
For "high level" framework/application level wakelocks, yes, but lower level components beneath the java api layer use the kernel interface directly.
Brian
Re: [linux-pm] [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to mark grossQuoted 10 lines · mark gross
Quoted 6 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
For "high level" framework/application level wakelocks, yes, but lower level components beneath the java api layer use the kernel interface directly.
Brian
Re: [linux-pm] [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 8 lines · Brian Swetland
Quoted 7 lines · mark gross
Quoted 6 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Quoted 8 lines
Quoted 3 lines
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
For "high level" framework/application level wakelocks, yes, but lower level components beneath the java api layer use the kernel interface directly.
Oh. I thought everything went through hardware/libhardware_legacy/power/power.c
who else is hitting /sys/power/* in the android user mode then?
I'll have to go hunting for them I guess.
--mgross
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 13 lines · mark gross
Quoted 12 lines · Brian Swetland
Quoted 10 lines · mark gross
Quoted 6 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
Quoted 7 lines
Quoted 4 lines
For "high level" framework/application level wakelocks, yes, but lower level components beneath the java api layer use the kernel interface directly.
Oh. I thought everything went through
hardware/libhardware_legacy/power/power.c
who else is hitting/sys/power/*in the android user mode then?
I believe everything does -- that's the thin wrapper around the kernel interface (which will have to change slightly to meet the suspend_blocker device/fd vs wakelock proc/sys interface, etc), which is used by the powermanager service, the RIL, and any other low level code. At the App/Service level, wakelocks are provided by a java level API that is a remote interface to the powermanager.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [linux-pm] [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to mark grossQuoted 13 lines · mark gross
Quoted 12 lines · Brian Swetland
Quoted 10 lines · mark gross
Quoted 6 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
Quoted 7 lines
Quoted 4 lines
For "high level" framework/application level wakelocks, yes, but lower level components beneath the java api layer use the kernel interface directly.
Oh. I thought everything went through
hardware/libhardware_legacy/power/power.c
who else is hitting/sys/power/*in the android user mode then?
I believe everything does -- that's the thin wrapper around the kernel interface (which will have to change slightly to meet the suspend_blocker device/fd vs wakelock proc/sys interface, etc), which is used by the powermanager service, the RIL, and any other low level code. At the App/Service level, wakelocks are provided by a java level API that is a remote interface to the powermanager.
Brian
--
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
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Brian SwetlandQuoted 8 lines · Brian Swetland
Quoted 7 lines · mark gross
Quoted 6 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Quoted 8 lines
Quoted 3 lines
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
For "high level" framework/application level wakelocks, yes, but lower level components beneath the java api layer use the kernel interface directly.
Oh. I thought everything went through hardware/libhardware_legacy/power/power.c
who else is hitting /sys/power/* in the android user mode then?
I'll have to go hunting for them I guess.
--mgross
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Brian SwetlandQuoted 14 lines · Brian Swetland
Quoted 7 lines · Neil Brown
Quoted 5 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 4 lines
The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake eventsQuoted 5 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Quoted 5 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Um doesn't the android framework bottleneck the user mode lock processing through the powermanager and any wake up event processing eventually has to grab a lock through this bottleneck anyway?
Quoted 8 lines
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
I'm not sure its a step in any direction, but I do understand the avoidance of having to rework a lot of code.
--mgross
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Brian SwetlandQuoted 14 lines · On Wed, 2 Jun 2010 11:05:18 -0700 Brian Swetland <[email protected]> wrote:
Quoted 7 lines · Neil Brown
Quoted 5 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 4 lines
The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake eventsQuoted 5 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Quoted 5 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Just to be clear: I'm not suggesting all wake-events need to go through one process. That was just one example of how the interface I proposed could be used. There were two other examples.
However one process would need to know about any wakeup event that happens. I don't think that needs to be a significant bottleneck, but I don't really know enough about all the requirement to try devising a demonstration.
Quoted 8 lines
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
I guess it becomes an question of economics for you then. Does the cost of whatever user-space changes are required exceed the value of using an upstream kernel? Both the cost and the value would be very hard to estimate in advance. I don't envy you the decision...
NeilBrown
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Brian SwetlandQuoted 14 lines · On Wed, 2 Jun 2010 11:05:18 -0700 Brian Swetland <[email protected]> wrote:
Quoted 7 lines · Neil Brown
Quoted 5 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 4 lines
The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake eventsQuoted 5 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
Quoted 5 lines
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
Just to be clear: I'm not suggesting all wake-events need to go through one process. That was just one example of how the interface I proposed could be used. There were two other examples.
However one process would need to know about any wakeup event that happens. I don't think that needs to be a significant bottleneck, but I don't really know enough about all the requirement to try devising a demonstration.
Quoted 8 lines
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
I guess it becomes an question of economics for you then. Does the cost of whatever user-space changes are required exceed the value of using an upstream kernel? Both the cost and the value would be very hard to estimate in advance. I don't envy you the decision...
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
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 9 lines · Neil Brown
Quoted 8 lines
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
Quoted 4 lines
I guess it becomes an question of economics for you then. Does the cost of whatever user-space changes are required exceed the value of using an upstream kernel? Both the cost and the value would be very hard to estimate in advance. I don't envy you the decision...
Well, at this point we've invested more engineering hours in the various rewrites of this (single) patchset and discussion around it than we have spent on rebasing our trees on roughly every other mainline release since 2.6.16 or so, across five years of Android development. We think there's some good value to be had (all the usual reasons) by heading upstream, so we're still discussing these patches and exploring alternatives, but yes, from one way of looking at it, it'd certainly be cheaper to just keep maintaining our own trees.
Brian
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 5 lines · Brian Swetland
Quoted 4 lines
I guess it becomes an question of economics for you then. Does the cost of whatever user-space changes are required exceed the value of using an upstream kernel? Both the cost and the value would be very hard to estimate in advance. I don't envy you the decision...
Quoted 9 lines
Well, at this point we've invested more engineering hours in the various rewrites of this (single) patchset and discussion around it than we have spent on rebasing our trees on roughly every other mainline release since 2.6.16 or so, across five years of Android development. We think there's some good value to be had (all the usual reasons) by heading upstream, so we're still discussing these patches and exploring alternatives, but yes, from one way of looking at it, it'd certainly be cheaper to just keep maintaining our own trees.
And let's be blunt. If in the future the Android team (which I'm not a member of) decides that they have invested more engineering time than they can justify from a business perspective, the next time someone starts whining on a blog, or on Slashdot, or at a conference, about how "OMG! Google is forking the kernel!!!", or "Google is making the lives of device driver writers for the embedded world difficult", it will now be possible from a political point of view to point and the hundreds, if not thousands, of e-mail messages of LKML developers wanting to redesign this effort and saying "Nyet! Nyet! Nyet!" to the original patchset, to point out that Google has a made an effort, and gone far beyond what is required by the GPL. 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.
Realistically, a company makes decisions about whether to pursue engineering efforts based on business plans, and this is true whether the company is Red Hat, or Novell, or IBM, or Google. One of the cost/benefits can be things that aren't easily measured such as public relations. But past a certain point, it may be that the right answer is to make a single public appeal to Linus, and if he says no, or if he ignores the pull request, then the company at hand can say, "We've done the best that we could, but the Linux developer community, and Linus specifically, has refused our patch". And yes, it's all about PR, but let's not kid ourselves --- the GPL and bad PR can't be used as blackmail to force a company to invest arbitrarily unlimited amounts of engineering effort just to satisfy the mandarins of the LKML and/or Linus.
And if people want to call this a fork, Linus has in the past said that sometimes forks are healthy, and necessary, and we can see how things play out in the marketplace.
Disclosure: I work at Google, but I'm not at all involved in the Android development team, and it's not at all my call when Brian and his team should make a decision that they've invested more time/energy than can be justified to their management --- heck, they even roll up to an completely different VP than I do. :-)
- Ted
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Brian SwetlandQuoted 5 lines · Brian Swetland
Quoted 4 lines
I guess it becomes an question of economics for you then. Does the cost of whatever user-space changes are required exceed the value of using an upstream kernel? Both the cost and the value would be very hard to estimate in advance. I don't envy you the decision...
Quoted 9 lines
Well, at this point we've invested more engineering hours in the various rewrites of this (single) patchset and discussion around it than we have spent on rebasing our trees on roughly every other mainline release since 2.6.16 or so, across five years of Android development. We think there's some good value to be had (all the usual reasons) by heading upstream, so we're still discussing these patches and exploring alternatives, but yes, from one way of looking at it, it'd certainly be cheaper to just keep maintaining our own trees.
And let's be blunt. If in the future the Android team (which I'm not a member of) decides that they have invested more engineering time than they can justify from a business perspective, the next time someone starts whining on a blog, or on Slashdot, or at a conference, about how "OMG! Google is forking the kernel!!!", or "Google is making the lives of device driver writers for the embedded world difficult", it will now be possible from a political point of view to point and the hundreds, if not thousands, of e-mail messages of LKML developers wanting to redesign this effort and saying "Nyet! Nyet! Nyet!" to the original patchset, to point out that Google has a made an effort, and gone far beyond what is required by the GPL. 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.
Realistically, a company makes decisions about whether to pursue engineering efforts based on business plans, and this is true whether the company is Red Hat, or Novell, or IBM, or Google. One of the cost/benefits can be things that aren't easily measured such as public relations. But past a certain point, it may be that the right answer is to make a single public appeal to Linus, and if he says no, or if he ignores the pull request, then the company at hand can say, "We've done the best that we could, but the Linux developer community, and Linus specifically, has refused our patch". And yes, it's all about PR, but let's not kid ourselves --- the GPL and bad PR can't be used as blackmail to force a company to invest arbitrarily unlimited amounts of engineering effort just to satisfy the mandarins of the LKML and/or Linus.
And if people want to call this a fork, Linus has in the past said that sometimes forks are healthy, and necessary, and we can see how things play out in the marketplace.
Disclosure: I work at Google, but I'm not at all involved in the Android development team, and it's not at all my call when Brian and his team should make a decision that they've invested more time/energy than can be justified to their management --- heck, they even roll up to an completely different VP than I do. :-)
- Ted
--
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
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 6 lines · On Thu, 2010-06-03 at 10:21 -0400, [email protected] wrote:
And let's be blunt. If in the future the Android team (which I'm not a member of) decides that they have invested more engineering time than they can justify from a business perspective, the next time someone starts whining on a blog, or on Slashdot, or at a conference, about how "OMG! Google is forking the kernel!!!", or "Google is making the lives of device driver writers for the embedded world
Quoted 8 lines
difficult", it will now be possible from a political point of view to point and the hundreds, if not thousands, of e-mail messages of LKML developers wanting to redesign this effort and saying "Nyet! Nyet! Nyet!" to the original patchset, to point out that Google has a made an effort, and gone far beyond what is required by the GPL. 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.
In the spirit of being blunt, so what?
We say no for good technical reasons. Also when did it become sensible to push features after they were shipped?
It never works to develop stuff like this out-of-tree and then push for inclusion. You always get to rewrite (at least 3 times).
If Google indeed decides it doesn't want to play upstream, then sad. But I don't see how we would be unjust in complaining about it.
There is more to our community than the letter of the GPL, and you should know that. So I really don't see the point of your argument (was there one besides the management gibberish?).
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to [email protected]Quoted 6 lines · On Thu, 2010-06-03 at 10:21 -0400, [email protected] wrote:
And let's be blunt. If in the future the Android team (which I'm not a member of) decides that they have invested more engineering time than they can justify from a business perspective, the next time someone starts whining on a blog, or on Slashdot, or at a conference, about how "OMG! Google is forking the kernel!!!", or "Google is making the lives of device driver writers for the embedded world
Quoted 8 lines
difficult", it will now be possible from a political point of view to point and the hundreds, if not thousands, of e-mail messages of LKML developers wanting to redesign this effort and saying "Nyet! Nyet! Nyet!" to the original patchset, to point out that Google has a made an effort, and gone far beyond what is required by the GPL. 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.
In the spirit of being blunt, so what?
We say no for good technical reasons. Also when did it become sensible to push features after they were shipped?
It never works to develop stuff like this out-of-tree and then push for inclusion. You always get to rewrite (at least 3 times).
If Google indeed decides it doesn't want to play upstream, then sad. But I don't see how we would be unjust in complaining about it.
There is more to our community than the letter of the GPL, and you should know that. So I really don't see the point of your argument (was there one besides the management gibberish?).
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 9 lines · Neil Brown
Quoted 8 lines
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
Quoted 4 lines
I guess it becomes an question of economics for you then. Does the cost of whatever user-space changes are required exceed the value of using an upstream kernel? Both the cost and the value would be very hard to estimate in advance. I don't envy you the decision...
Well, at this point we've invested more engineering hours in the various rewrites of this (single) patchset and discussion around it than we have spent on rebasing our trees on roughly every other mainline release since 2.6.16 or so, across five years of Android development. We think there's some good value to be had (all the usual reasons) by heading upstream, so we're still discussing these patches and exploring alternatives, but yes, from one way of looking at it, it'd certainly be cheaper to just keep maintaining our own trees.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 7 lines · Neil Brown
Quoted 5 lines · On Wed, 2 Jun 2010 00:05:14 -0700 Arve Hjønnevåg <[email protected]> wrote:
Quoted 4 lines
The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
Quoted 5 lines
Quoted 1 line
Wake up events are not all processed by one daemon.
Not with your current user-space code, no. Are you saying that you are not open to any significant change in the Android user-space code? That would make the situation a lot harder to resolve.
There are many wakeup events possible in a typical system -- keypresses or other input events, network traffic, telephony events, media events (fill audio buffer, fill video decoder buffer, etc), and I think requiring that all wakeup event processing bottleneck through a single userspace process is non-optimal here.
The current suspend-blocker proposal already involves userspace changes (it's different than our existing wakelock interface), and we're certainly not opposed to any/all userspace changes on principle, but on the other hand we're not interested in significant reworks of userspace unless they actually improve the situation somehow. I think bottlenecking events through a central daemon would represent a step backwards.
Brian
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 54 lines · Neil Brown
Quoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
- The event handling daemon giving the suspend-daemon's pid asF_OWNER, and using poll/select to get the events itself.When 'mem' is written to
/sys/power/state,suspend_preparewaits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and triggerkill_fasync.
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
If more precise timing is needed and achievable, that can be added later. It would be an entirely internal change and would not affect the API further. Some of the code developed for suspend-blockers might be a starting point for this.Drivers should call
pm_suspend_delay()whenever a wake-event occurs. This simply records the time so that the suspend process knows if there is in fact any need to wait at all.
Quoted 7 lines
The delay to wait after the last
pm_suspend_delay()is limited to 10 seconds and can be set by kernel parameter suspend_block_delay=number-of-milliseconds It defaults to 2 jiffies (which is possibly too short).- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?
In theory wakeup events can also happen after wait_for_blockers() has returned 0 and I guess we should rollback the suspend in such cases.
Rafael
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
Quoted 8 lines · On Wed, 2 Jun 2010 22:41:14 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines · Neil Brown
- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?In theory wakeup events can also happen after
wait_for_blockers()has returned 0 and I guess we should rollback the suspend in such cases.
I naively assumed this was already the case, but on a slightly closer look at the code it seems not.
Presumably there is some point deep in the suspend code, probably after the call to sysdev_suspend, where interrupts are disabled and we are about to actually suspend. At that point a simple "is a roll-back required" test could abort the suspend.
Then any driver that handles wake-up events, if it gets and event that (would normally cause a wakeup) PM_SUSPEND_PREPARE and PM_POST_SUSPEND, could set the "roll-back is required" flag.
??
NeilBrown
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
In reply to Rafael J. WysockiQuoted 8 lines · On Wed, 2 Jun 2010 22:41:14 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines · Neil Brown
- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?In theory wakeup events can also happen after
wait_for_blockers()has returned 0 and I guess we should rollback the suspend in such cases.
I naively assumed this was already the case, but on a slightly closer look at the code it seems not.
Presumably there is some point deep in the suspend code, probably after the call to sysdev_suspend, where interrupts are disabled and we are about to actually suspend. At that point a simple "is a roll-back required" test could abort the suspend.
Then any driver that handles wake-up events, if it gets and event that (would normally cause a wakeup) PM_SUSPEND_PREPARE and PM_POST_SUSPEND, could set the "roll-back is required" flag.
??
NeilBrown
Re: [PATCH] - race-free suspend. Was: Re: [linux-pm] [PATCH 0/8] Suspend block api (version 8)
Quoted 12 lines · Neil Brown
Quoted 8 lines · On Wed, 2 Jun 2010 22:41:14 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines · Neil Brown
- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?In theory wakeup events can also happen after
wait_for_blockers()has returned 0 and I guess we should rollback the suspend in such cases.
Quoted 7 lines
I naively assumed this was already the case, but on a slightly closer look at the code it seems not.
Presumably there is some point deep in the suspend code, probably after the call to
sysdev_suspend, where interrupts are disabled and we are about to actually suspend. At that point a simple "is a roll-back required" test could abort the suspend.
Yes.
Quoted 3 lines
Then any driver that handles wake-up events, if it gets and event that (would normally cause a wakeup)
PM_SUSPEND_PREPAREandPM_POST_SUSPEND, could set the "roll-back is required" flag.
That's my idea, but instead of setting a flag, I'd use a counter increased every time there is a wakeup event. Then, the core suspend core code would store a pre-suspend value of the counter and compare it with the current value after all wakeup event sources had been set. If they were different, the suspend would be aborted.
Rafael
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 12 lines · Neil Brown
Quoted 8 lines · On Wed, 2 Jun 2010 22:41:14 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 3 lines · Neil Brown
- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?In theory wakeup events can also happen after
wait_for_blockers()has returned 0 and I guess we should rollback the suspend in such cases.
Quoted 7 lines
I naively assumed this was already the case, but on a slightly closer look at the code it seems not.
Presumably there is some point deep in the suspend code, probably after the call to
sysdev_suspend, where interrupts are disabled and we are about to actually suspend. At that point a simple "is a roll-back required" test could abort the suspend.
Yes.
Quoted 3 lines
Then any driver that handles wake-up events, if it gets and event that (would normally cause a wakeup)
PM_SUSPEND_PREPAREandPM_POST_SUSPEND, could set the "roll-back is required" flag.
That's my idea, but instead of setting a flag, I'd use a counter increased every time there is a wakeup event. Then, the core suspend core code would store a pre-suspend value of the counter and compare it with the current value after all wakeup event sources had been set. If they were different, the suspend would be aborted.
Rafael
Re: [PATCH] - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Neil BrownQuoted 54 lines · Neil Brown
Quoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).The user-space suspend daemon avoids losing wake-events by using
fcntl(F_OWNER)to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
- The event handling daemon giving the suspend-daemon's pid asF_OWNER, and using poll/select to get the events itself.When 'mem' is written to
/sys/power/state,suspend_preparewaits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and triggerkill_fasync.
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
If more precise timing is needed and achievable, that can be added later. It would be an entirely internal change and would not affect the API further. Some of the code developed for suspend-blockers might be a starting point for this.Drivers should call
pm_suspend_delay()whenever a wake-event occurs. This simply records the time so that the suspend process knows if there is in fact any need to wait at all.
Quoted 7 lines
The delay to wait after the last
pm_suspend_delay()is limited to 10 seconds and can be set by kernel parameter suspend_block_delay=number-of-milliseconds It defaults to 2 jiffies (which is possibly too short).- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?
In theory wakeup events can also happen after wait_for_blockers() has returned 0 and I guess we should rollback the suspend in such cases.
Rafael
PATCH 1/1 - race-free suspend. Was: Re: [PATCH 0/8] Suspend block api (version 8)
In reply to Thomas GleixnerQuoted 7 lines · On Tue, 1 Jun 2010 12:50:01 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 6 lines · Neil Brown
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...
Quoted 8 lines
Quoted 2 lines
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If we can fix it, yes we definitely should do and not work around it.
Thanks,
tglx
OK.
Here is my suggestion.
While I think this patch would actually work, and hope the ugly aspects are reasonably balanced by the simplicity, I present it primarily as a base for improvement.
The important part is to present how drivers and user-space can co-operate to avoid losing wake-events. The details of what happens in the kernel are certainly up for discussion (as is everything else really of course).
The user-space suspend daemon avoids losing wake-events by using fcntl(F_OWNER) to ensure it gets a signal whenever any important wake-event is ready to be read by user-space. This may involve:
- the one daemon processing all wake events
- Both the suspend daemon and the main event handling daemon opening any given device that delivers wake events (this should work with input events ... unless grabbing is needed)
- The event handling daemon giving the suspend-daemon's pid as F_OWNER, and using poll/select to get the events itself.
When 'mem' is written to /sys/power/state, suspend_prepare waits in an interruptible wait until any wake-event that might have been initiated before the suspend was request, has had a chance to be queued for user-space and trigger kill_fasync.
Currently this wait is a configurable time after the last wake-event was initiated. This is hackish, but simple and probably adequate.
If more precise timing is needed and achievable, that can be added later. It would be an entirely internal change and would not affect the API further. Some of the code developed for suspend-blockers might be a starting point for this.
Drivers should call pm_suspend_delay() whenever a wake-event occurs. This simply records the time so that the suspend process knows if there is in fact any need to wait at all.
The delay to wait after the last pm_suspend_delay() is limited to 10 seconds and can be set by kernel parameter suspend_block_delay=number-of-milliseconds It defaults to 2 jiffies (which is possibly too short).
- Would this fix the "bug"??
- and address the issues that suspend-blockers was created to address?
- or are the requirements on user-space too onerous?
Thanks,
NeilBrown
include/linux/suspend.h +2 -0
@@ -142,11 +142,13 @@ extern void arch_suspend_disable_irqs(void);extern void arch_suspend_enable_irqs (void );extern int pm_suspend (suspend_state_t state); +extern void pm_suspend_delay (void );#else /* !CONFIG_SUSPEND */ #define suspend_valid_only_mem NULLstatic inline void suspend_set_ops (struct platform_suspend_ops *ops) {}static inline int pm_suspend (suspend_state_t state) {return -ENOSYS ; } +static inlint void pm_suspend_delay(void) {}#endif /* !CONFIG_SUSPEND */ /* struct pbe is used for creating lists of pages that should be restored
kernel/power/suspend.c +67 -0
79 lines not on this page · raw message
Quoted 15 lines · On Tue, 1 Jun 2010 03:49:37 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 14 lines · Neil Brown
And if you are right that the race window cannot be closed, then the whole suspend-blocker infrastructure is pointless as the purpose of it is simply to close that window. If it really does not and cannot work, then it would be best to reject it for that reason rather than for less concrete aesthetic arguments.
But presumably it does work in practice on Android hardware so ..... confused.Having just seen the email from Thomas, maybe you mean that it cannot be closed on devices using ACPI, but can on other devices. I can sort-of imagine how that would be the case (I tried reading an ACPI spec once - my hat is of to those of you who understand it).
That shouldn't prevent us from closing the race window on "sane" hardware that allows it. This would, I think, be sufficient for Android's needs.
Quoted 4 lines
Quoted 2 lines
I'm hoping we can get agreement on:
- there is a race with suspendThat's a matter of how you define "suspend".
I define "suspend" as
echo mem > /sys/power/state
Quoted 11 lines
If "suspend" is another deep idle state and the hardware is sane, there is no race at all - assumed that the driver/platform developer got it right. It's not rocket science to transition from "normal" irq delivery to wakeup based delivery raceless (except for PC style x86 hardware of today)
If "suspend" is the thing we are used to via
/sys/power/statethen the race will persist forever except for the suspend blocker workaround, which we can express in QoS terms as well w/o adding another suspend related user space API.
I'm not interested in adding another user-space API if it can possibly be avoided, and I think it can. But that is a later step in the process.
I think you have acknowledged that there is a race with suspend - thanks. Next step was "can it be closed".
You seem to suggest that it can, but you describe it as a "work around" rather than a "bug fix"...
Do you agree that the race is a "bug", and therefore it is appropriate to "fix" it assuming an acceptable fix can be found (which I think it can)?
If you agree that it is appropriate for try to fix this bug, then the next step would be to get the Android devs to agree that a fix could - in principle - address the need for which they created suspend-blockers.
Arve: can you confirm that?
Then, with a clear and agreed goal, we can look at possible fixes.
Thanks,
NeilBrown
Quoted 4 lines
Thanks,
tglx
Quoted 16 lines · Neil Brown
Quoted 12 lines
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Quoted 6 lines
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
You're barking up the wrong tree. If I understand correctly, Rafael is saying that there's a race involving events which are not _wakeup_ events. If a non-wakeup event arrives shortly before a suspend, it can have its normal effect. If it arrives while a suspend is in progress, its delivery may be delayed until the system resumes. And if it arrives after the system is fully suspended, it may never be noticed at all.
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
Or maybe I'm misunderstanding also, and Rafael is saying that there's a race involving events whose meaning changes depending on whether or not the system is asleep. This is obviously true and clearly unavoidable.
Quoted 6 lines
And if you are right that the race window cannot be closed, then the whole suspend-blocker infrastructure is pointless as the purpose of it is simply to close that window. If it really does not and cannot work, then it would be best to reject it for that reason rather than for less concrete aesthetic arguments.
But presumably it does work in practice on Android hardware so ..... confused.
The point you're missing is that Android works with regard to wakeup events. It doesn't necessarily always receive non-wakeup events (although I don't know how Android classifies events -- maybe everything is a wakeup event for them).
Alan Stern
Quoted 16 lines · Neil Brown
Quoted 12 lines
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Quoted 6 lines
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
You're barking up the wrong tree. If I understand correctly, Rafael is saying that there's a race involving events which are not _wakeup_ events. If a non-wakeup event arrives shortly before a suspend, it can have its normal effect. If it arrives while a suspend is in progress, its delivery may be delayed until the system resumes. And if it arrives after the system is fully suspended, it may never be noticed at all.
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
Or maybe I'm misunderstanding also, and Rafael is saying that there's a race involving events whose meaning changes depending on whether or not the system is asleep. This is obviously true and clearly unavoidable.
Quoted 6 lines
And if you are right that the race window cannot be closed, then the whole suspend-blocker infrastructure is pointless as the purpose of it is simply to close that window. If it really does not and cannot work, then it would be best to reject it for that reason rather than for less concrete aesthetic arguments.
But presumably it does work in practice on Android hardware so ..... confused.
The point you're missing is that Android works with regard to wakeup events. It doesn't necessarily always receive non-wakeup events (although I don't know how Android classifies events -- maybe everything is a wakeup event for them).
Alan Stern
Quoted 25 lines · On Mon, 31 May 2010 22:10:00 -0400 (EDT) Alan Stern…
Quoted 16 lines · Neil Brown
Quoted 12 lines
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Quoted 6 lines
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
Quoted 7 lines
You're barking up the wrong tree. If I understand correctly, Rafael is saying that there's a race involving events which are not _wakeup_ events. If a non-wakeup event arrives shortly before a suspend, it can have its normal effect. If it arrives while a suspend is in progress, its delivery may be delayed until the system resumes. And if it arrives after the system is fully suspended, it may never be noticed at all.
I am only thinking of wakeup event. (And I am only thinking of suspend as initiated by writing 'mem' to /sys/power/state.)
I agree that non-wakeup events can easily be delayed by suspend, and this is by design and no-one wants it to change.
Quoted 6 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
Quoted 13 lines
Or maybe I'm misunderstanding also, and Rafael is saying that there's a race involving events whose meaning changes depending on whether or not the system is asleep. This is obviously true and clearly unavoidable.
Quoted 6 lines
And if you are right that the race window cannot be closed, then the whole suspend-blocker infrastructure is pointless as the purpose of it is simply to close that window. If it really does not and cannot work, then it would be best to reject it for that reason rather than for less concrete aesthetic arguments.
But presumably it does work in practice on Android hardware so ..... confused.
Quoted 5 lines
The point you're missing is that Android works with regard to wakeup events. It doesn't necessarily always receive non-wakeup events (although I don't know how Android classifies events -- maybe everything is a wakeup event for them).
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event
So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" event
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
Thanks,
NeilBrown
Quoted 11 lines · Neil Brown
Quoted 5 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
That wasn't what I meant. An important requirement is that a wakeup event received after the device has been suspended, but before the system suspend is complete, should cause the system suspend to abort. This is one of the things suspend blockers were meant to help with. In theory it should already work correctly -- but it doesn't. That's a real bug.
The other things you're talking about aren't really bugs. That is, they are things which the kernel _ought_ to do but it wasn't _intended_ to do. They are misfeatures: failures of design, not failures of execution.
Quoted 4 lines
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
This is a matter of semantics and it is highly debatable.
Quoted 2 lines
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
Yes.
Quoted 5 lines
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" event
None of those things can cause the system to wake up after it is suspended. Indeed, they can't happen at all if the CPU isn't running (unless the GSM processor runs autonomously -- let's ignore such details). Hence it makes little sense to call them "wakeup" events.
Quoted 8 lines
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
That's not entirely clear. Yes, for Android's use case that's what you want. But in other situations maybe you don't. Consider the example of someone who closes the lid of their laptop and throws it in a backpack. The computer should suspend immediately; it shouldn't be delayed by these "virtual wakeup" events.
Alan Stern
Quoted 58 lines · Alan Stern
Quoted 11 lines · Neil Brown
Quoted 5 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
That wasn't what I meant. An important requirement is that a wakeup event received after the device has been suspended, but before the system suspend is complete, should cause the system suspend to abort. This is one of the things suspend blockers were meant to help with. In theory it should already work correctly -- but it doesn't. That's a real bug.
The other things you're talking about aren't really bugs. That is, they are things which the kernel _ought_ to do but it wasn't _intended_ to do. They are misfeatures: failures of design, not failures of execution.
Quoted 4 lines
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
This is a matter of semantics and it is highly debatable.
Quoted 2 lines
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
Yes.
Quoted 5 lines
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" eventNone of those things can cause the system to wake up after it is suspended. Indeed, they can't happen at all if the CPU isn't running (unless the GSM processor runs autonomously -- let's ignore such details). Hence it makes little sense to call them "wakeup" events.
Quoted 8 lines
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
Quoted 5 lines
That's not entirely clear. Yes, for Android's use case that's what you want. But in other situations maybe you don't. Consider the example of someone who closes the lid of their laptop and throws it in a backpack. The computer should suspend immediately; it shouldn't be delayed by these "virtual wakeup" events.
BTW, this is an important point. We've already had some bug reports regarding such unwanted wakeup events.
Rafael
Quoted 58 lines · Alan Stern
Quoted 11 lines · Neil Brown
Quoted 5 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
That wasn't what I meant. An important requirement is that a wakeup event received after the device has been suspended, but before the system suspend is complete, should cause the system suspend to abort. This is one of the things suspend blockers were meant to help with. In theory it should already work correctly -- but it doesn't. That's a real bug.
The other things you're talking about aren't really bugs. That is, they are things which the kernel _ought_ to do but it wasn't _intended_ to do. They are misfeatures: failures of design, not failures of execution.
Quoted 4 lines
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
This is a matter of semantics and it is highly debatable.
Quoted 2 lines
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
Yes.
Quoted 5 lines
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" eventNone of those things can cause the system to wake up after it is suspended. Indeed, they can't happen at all if the CPU isn't running (unless the GSM processor runs autonomously -- let's ignore such details). Hence it makes little sense to call them "wakeup" events.
Quoted 8 lines
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
Quoted 5 lines
That's not entirely clear. Yes, for Android's use case that's what you want. But in other situations maybe you don't. Consider the example of someone who closes the lid of their laptop and throws it in a backpack. The computer should suspend immediately; it shouldn't be delayed by these "virtual wakeup" events.
BTW, this is an important point. We've already had some bug reports regarding such unwanted wakeup events.
Rafael
Quoted 21 lines · On Tue, 1 Jun 2010 10:47:49 -0400 (EDT) Alan Stern <[email protected]>…
Quoted 11 lines · Neil Brown
Quoted 5 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
That wasn't what I meant. An important requirement is that a wakeup event received after the device has been suspended, but before the system suspend is complete, should cause the system suspend to abort. This is one of the things suspend blockers were meant to help with. In theory it should already work correctly -- but it doesn't. That's a real bug.
Quoted 4 lines
The other things you're talking about aren't really bugs. That is, they are things which the kernel _ought_ to do but it wasn't _intended_ to do. They are misfeatures: failures of design, not failures of execution.
A fairly subtle distinction, but I can accept it. We are working with a design failure.
But when a design failure results in a feature not being usable in a race-free way, I would still call that failure of design a bug - a bug in the design.
Quoted 19 lines
Quoted 5 lines
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
This is a matter of semantics and it is highly debatable.
Quoted 2 lines
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
Yes.
Quoted 5 lines
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" event
Quoted 5 lines
None of those things can cause the system to wake up after it is suspended. Indeed, they can't happen at all if the CPU isn't running (unless the GSM processor runs autonomously -- let's ignore such details). Hence it makes little sense to call them "wakeup" events.
I think we are seeing this very differently. In my mind these are in one sense all the same event, just represented in different ways.
One of the reasons that we have an OS is to support levels of abstraction. A disk drives stores sectors, but I want to store files
A monitor displays pixels, but I want to display text
A network sends packets, but I want to send Email.
The OS (including but not only the kernel) handles the conversion. It is still my Email that is going out over the network even though the network card has no concept of 'email'.
Similarly the event of importance above in the notification that a TXT has arrived.
At the lowest level, it appears as 'data-ready' on a UART. At the highest level is it sound-waves in the air. But it is the same event. And the role of the OS is to allow me to treat it all as one event - one abstract concept.
Obviously the involvement of the kernel ends when the event reaches or crosses the boundary to user-space, and user-space must be responsible for taking it to the boundary to meat-space.
But the kernel needs to ensure that this holistic wake-up event can be handled without racing with a suspend request.
If you just protect the lowest level representation of the event, but don't allow the higher level representations to be protected, then it is a bit like a filesystem that requires you to send SCSI commands to the disk drive if you want to be sure your data is safe.
Quoted 9 lines
Quoted 8 lines
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
Quoted 5 lines
That's not entirely clear. Yes, for Android's use case that's what you want. But in other situations maybe you don't. Consider the example of someone who closes the lid of their laptop and throws it in a backpack. The computer should suspend immediately; it shouldn't be delayed by these "virtual wakeup" events.
Completely agree. Old behaviour must remain unchanged, new behaviour must be explicitly requested.
At each level, it must be explicitly stated that an event is to be treated like a wake-up event. I believe that is already the case in drivers - they need to explicitly configure the interrupt to cause a wake-from-suspend.
I've considered several possibilities for how user-space could explicitly say that events are wake-event. My current favourite is to use fcntl(F_SETOWN) to request a signal be sent to the process that is initiating the suspend when the relevant events are ready to be consumed by user-space. This would work for events that come through the input system (button press) or through the network, or rtc alarm events. I suspect all potential wake-events could be made to use this scheme, but I don't have an exhausting list at present.
So a suspend request waits just long enough to close any race, checks if there are signals pending, and proceeds with the suspend if there aren't. The "just long enough" is a little tricky to measure, though the in-kernel part of suspend-blockers presumably can be used to get that right.
If the suspending process hasn't requested the delivery of these signals, the suspend will possibly pause to make sure that any events-in-transit in the kernel have reached their in-kernel destination (milliseconds at most) and then proceed with the suspend as normal.
So yes, there are different use cases and we should support all of them, both "I shut the lid and my laptop really stays asleep" and "I never miss a TXT because my phone went to sleep at a bad time". The process that initiates the suspend has a role in choosing what can wake it up.
Thanks,
NeilBrown
Quoted 21 lines · On Tue, 1 Jun 2010 10:47:49 -0400 (EDT) Alan Stern <[email protected]>…
Quoted 11 lines · Neil Brown
Quoted 5 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
That wasn't what I meant. An important requirement is that a wakeup event received after the device has been suspended, but before the system suspend is complete, should cause the system suspend to abort. This is one of the things suspend blockers were meant to help with. In theory it should already work correctly -- but it doesn't. That's a real bug.
Quoted 4 lines
The other things you're talking about aren't really bugs. That is, they are things which the kernel _ought_ to do but it wasn't _intended_ to do. They are misfeatures: failures of design, not failures of execution.
A fairly subtle distinction, but I can accept it. We are working with a design failure.
But when a design failure results in a feature not being usable in a race-free way, I would still call that failure of design a bug - a bug in the design.
Quoted 19 lines
Quoted 5 lines
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
This is a matter of semantics and it is highly debatable.
Quoted 2 lines
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
Yes.
Quoted 5 lines
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" event
Quoted 5 lines
None of those things can cause the system to wake up after it is suspended. Indeed, they can't happen at all if the CPU isn't running (unless the GSM processor runs autonomously -- let's ignore such details). Hence it makes little sense to call them "wakeup" events.
I think we are seeing this very differently. In my mind these are in one sense all the same event, just represented in different ways.
One of the reasons that we have an OS is to support levels of abstraction. A disk drives stores sectors, but I want to store files
A monitor displays pixels, but I want to display text
A network sends packets, but I want to send Email.
The OS (including but not only the kernel) handles the conversion. It is still my Email that is going out over the network even though the network card has no concept of 'email'.
Similarly the event of importance above in the notification that a TXT has arrived.
At the lowest level, it appears as 'data-ready' on a UART. At the highest level is it sound-waves in the air. But it is the same event. And the role of the OS is to allow me to treat it all as one event - one abstract concept.
Obviously the involvement of the kernel ends when the event reaches or crosses the boundary to user-space, and user-space must be responsible for taking it to the boundary to meat-space.
But the kernel needs to ensure that this holistic wake-up event can be handled without racing with a suspend request.
If you just protect the lowest level representation of the event, but don't allow the higher level representations to be protected, then it is a bit like a filesystem that requires you to send SCSI commands to the disk drive if you want to be sure your data is safe.
Quoted 9 lines
Quoted 8 lines
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
Quoted 5 lines
That's not entirely clear. Yes, for Android's use case that's what you want. But in other situations maybe you don't. Consider the example of someone who closes the lid of their laptop and throws it in a backpack. The computer should suspend immediately; it shouldn't be delayed by these "virtual wakeup" events.
Completely agree. Old behaviour must remain unchanged, new behaviour must be explicitly requested.
At each level, it must be explicitly stated that an event is to be treated like a wake-up event. I believe that is already the case in drivers - they need to explicitly configure the interrupt to cause a wake-from-suspend.
I've considered several possibilities for how user-space could explicitly say that events are wake-event. My current favourite is to use fcntl(F_SETOWN) to request a signal be sent to the process that is initiating the suspend when the relevant events are ready to be consumed by user-space. This would work for events that come through the input system (button press) or through the network, or rtc alarm events. I suspect all potential wake-events could be made to use this scheme, but I don't have an exhausting list at present.
So a suspend request waits just long enough to close any race, checks if there are signals pending, and proceeds with the suspend if there aren't. The "just long enough" is a little tricky to measure, though the in-kernel part of suspend-blockers presumably can be used to get that right.
If the suspending process hasn't requested the delivery of these signals, the suspend will possibly pause to make sure that any events-in-transit in the kernel have reached their in-kernel destination (milliseconds at most) and then proceed with the suspend as normal.
So yes, there are different use cases and we should support all of them, both "I shut the lid and my laptop really stays asleep" and "I never miss a TXT because my phone went to sleep at a bad time". The process that initiates the suspend has a role in choosing what can wake it up.
Thanks,
NeilBrown
Quoted 2 lines · Neil Brown
On Tue, 1 Jun 2010 10:47:49 -0400 (EDT)
Alan Stern <[email protected]> wrote:
...
Quoted 4 lines
So yes, there are different use cases and we should support all of them, both "I shut the lid and my laptop really stays asleep" and "I never miss a TXT because my phone went to sleep at a bad time". The process that initiates the suspend has a role in choosing what can wake it up.
You'd need to add some all new infrastructure for that, because right now only hardware wakeup signals are regarded as (system) wakeup events (they are either interrupts or things like PCI PMEs, possibly translated to some platform signals like GPIOs or something).
I think I know how to prevent these hardware wakeup events from being lost (such that the entire suspend will be aborted if one of them happens during suspend), but for the handling of more generally defined wakeup events we'd need to provide user space with information on what wakeup events are available and how to enable and disable them, among other things.
Rafael
Quoted 2 lines · Neil Brown
On Tue, 1 Jun 2010 10:47:49 -0400 (EDT)
Alan Stern <[email protected]> wrote:
...
Quoted 4 lines
So yes, there are different use cases and we should support all of them, both "I shut the lid and my laptop really stays asleep" and "I never miss a TXT because my phone went to sleep at a bad time". The process that initiates the suspend has a role in choosing what can wake it up.
You'd need to add some all new infrastructure for that, because right now only hardware wakeup signals are regarded as (system) wakeup events (they are either interrupts or things like PCI PMEs, possibly translated to some platform signals like GPIOs or something).
I think I know how to prevent these hardware wakeup events from being lost (such that the entire suspend will be aborted if one of them happens during suspend), but for the handling of more generally defined wakeup events we'd need to provide user space with information on what wakeup events are available and how to enable and disable them, among other things.
Rafael
Quoted 11 lines · Neil Brown
Quoted 5 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
That wasn't what I meant. An important requirement is that a wakeup event received after the device has been suspended, but before the system suspend is complete, should cause the system suspend to abort. This is one of the things suspend blockers were meant to help with. In theory it should already work correctly -- but it doesn't. That's a real bug.
The other things you're talking about aren't really bugs. That is, they are things which the kernel _ought_ to do but it wasn't _intended_ to do. They are misfeatures: failures of design, not failures of execution.
Quoted 4 lines
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
This is a matter of semantics and it is highly debatable.
Quoted 2 lines
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
Yes.
Quoted 5 lines
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" event
None of those things can cause the system to wake up after it is suspended. Indeed, they can't happen at all if the CPU isn't running (unless the GSM processor runs autonomously -- let's ignore such details). Hence it makes little sense to call them "wakeup" events.
Quoted 8 lines
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
That's not entirely clear. Yes, for Android's use case that's what you want. But in other situations maybe you don't. Consider the example of someone who closes the lid of their laptop and throws it in a backpack. The computer should suspend immediately; it shouldn't be delayed by these "virtual wakeup" events.
Alan Stern
Quoted 25 lines · On Mon, 31 May 2010 22:10:00 -0400 (EDT) Alan Stern…
Quoted 16 lines · Neil Brown
Quoted 12 lines
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Quoted 6 lines
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
Quoted 7 lines
You're barking up the wrong tree. If I understand correctly, Rafael is saying that there's a race involving events which are not _wakeup_ events. If a non-wakeup event arrives shortly before a suspend, it can have its normal effect. If it arrives while a suspend is in progress, its delivery may be delayed until the system resumes. And if it arrives after the system is fully suspended, it may never be noticed at all.
I am only thinking of wakeup event. (And I am only thinking of suspend as initiated by writing 'mem' to /sys/power/state.)
I agree that non-wakeup events can easily be delayed by suspend, and this is by design and no-one wants it to change.
Quoted 6 lines
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
This is exactly the issue. Linux doesn't get this right. A wakeup that is processed by the driver just before suspend may not get all the way out to it's final destination (possibly in meat-space) until after some other event wakes the device. It is not possible to guarantee full delivery of a wakeup event with Linux in its current state. This is a bug.
Quoted 13 lines
Or maybe I'm misunderstanding also, and Rafael is saying that there's a race involving events whose meaning changes depending on whether or not the system is asleep. This is obviously true and clearly unavoidable.
Quoted 6 lines
And if you are right that the race window cannot be closed, then the whole suspend-blocker infrastructure is pointless as the purpose of it is simply to close that window. If it really does not and cannot work, then it would be best to reject it for that reason rather than for less concrete aesthetic arguments.
But presumably it does work in practice on Android hardware so ..... confused.
Quoted 5 lines
The point you're missing is that Android works with regard to wakeup events. It doesn't necessarily always receive non-wakeup events (although I don't know how Android classifies events -- maybe everything is a wakeup event for them).
I don't think I'm missing that. Wakeup events are the only events of interest. But wakeup events are more than just low-level hardware events. They are also the virtual events that are a direct consequence of the original hardware event.
A UART asserts 'data ready' which is routed to an IO interrupt line that wakes the device. This is a wakeup event.
So are the bits that appear on the data line which represent the data So are the characters that appear on the serial port
So is the "here is a message from the GSM processor" event
So is the "there is a new TXT message" event
So is the "'beep beep beep' out the speaker" event
All these events are wakeup events, and should abort or instant-resume the system. Currently only the first can be guaranteed to do this (... and maybe the second, depending on the details of the implementation). suspend-blocks effectively pass a lock from one event to the next to ensure that all of these event block the suspend. There are various other ways to achieve the same thing, and I think it can be done with no significant change to the API. But some how we need to allow all of these events to be linked wake-up events, not just the first one.
Thanks,
NeilBrown
Quoted 39 lines · Alan Stern
Quoted 16 lines · Neil Brown
Quoted 12 lines
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Quoted 6 lines
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
You're barking up the wrong tree. If I understand correctly, Rafael is saying that there's a race involving events which are not _wakeup_ events. If a non-wakeup event arrives shortly before a suspend, it can have its normal effect. If it arrives while a suspend is in progress, its delivery may be delayed until the system resumes. And if it arrives after the system is fully suspended, it may never be noticed at all.
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
Quoted 4 lines
Or maybe I'm misunderstanding also, and Rafael is saying that there's a race involving events whose meaning changes depending on whether or not the system is asleep. This is obviously true and clearly unavoidable.
In fact I was referring to both in different places. That's why what I said wasn't too clear, sorry about that.
Rafael
Quoted 39 lines · Alan Stern
Quoted 16 lines · Neil Brown
Quoted 12 lines
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Quoted 6 lines
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
You're barking up the wrong tree. If I understand correctly, Rafael is saying that there's a race involving events which are not _wakeup_ events. If a non-wakeup event arrives shortly before a suspend, it can have its normal effect. If it arrives while a suspend is in progress, its delivery may be delayed until the system resumes. And if it arrives after the system is fully suspended, it may never be noticed at all.
With wakeup events the problem isn't so bad. Wakeup events are always noticed, and if the system is designed properly they will either abort a suspend-in-progress or else cause the system to resume as soon as the suspend is complete. (Linux is not yet properly designed in this sense.)
Quoted 4 lines
Or maybe I'm misunderstanding also, and Rafael is saying that there's a race involving events whose meaning changes depending on whether or not the system is asleep. This is obviously true and clearly unavoidable.
In fact I was referring to both in different places. That's why what I said wasn't too clear, sorry about that.
Rafael
Quoted 24 lines · On Tue, 1 Jun 2010 02:32:20 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 10 lines · Neil Brown
I want to be able to turn my freerunner upside-down by which I tell it (via the accelerometers) that I am done and want it to turn off. If a TXT message comes in just then, I don't want it to suspend, I want it to make an alert noise.
I can put code in to ignore the accelerometer if a txt has just recently come in, but if the TXT arrives just as the write to/sys/power/statestarts, the UART interrupt handler could have completed before it has thePRE_SUSPENDmethod called. So the suspend will complete and the wakeup from the UART will have been "lost" in that the event didn't get all the way to its
destination: my ear.As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the
PRE_SUSPENDthing won't really solve the entire problem while increasing complexity.Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.
Quoted 3 lines
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
Well you are the expert so I assume you are right, but I would really like to understand why this is.
I guess that if the event was delivered as an edge-triggered interrupt which the interrupt controller couldn't latch, then it might get lost. Is that what happens?
But if the event comes in as a level-triggered (or latched) interrupt, then the driver simply chooses not to acknowledge the interrupt after PRE_SUSPEND until RESUME. Then any suspend would immediately be woken. Maybe the window for ignoring interrupt would have to be a bit smaller than that, but it should be a well defined window that can be locked.
Why cannot we carry this sort of guarantee all the way up to user-space and beyond? Am I completely misunderstanding the hardware?
And if you are right that the race window cannot be closed, then the whole suspend-blocker infrastructure is pointless as the purpose of it is simply to close that window. If it really does not and cannot work, then it would be best to reject it for that reason rather than for less concrete aesthetic arguments.
But presumably it does work in practice on Android hardware so ..... confused.
Having just seen the email from Thomas, maybe you mean that it cannot be closed on devices using ACPI, but can on other devices. I can sort-of imagine how that would be the case (I tried reading an ACPI spec once - my hat is of to those of you who understand it).
That shouldn't prevent us from closing the race window on "sane" hardware that allows it. This would, I think, be sufficient for Android's needs.
I'm hoping we can get agreement on:
- there is a race with suspend
- it can be closed on the sort of hardware that is typically used in the mobile space
- closing it would address the need which lead to the suspend-block proposal.
If we have agreement on that, we can move on to
- should we close the race? (hopefully "yes" because bugs should be fixed).
- how should we close the race? (lots of room for exploration there).
Thanks,
NeilBrown
Quoted 46 lines · Neil Brown
Quoted 43 lines · On Tue, 1 Jun 2010 00:05:19 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 41 lines · Neil Brown
Quoted 26 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Quoted 7 lines
Fair enough. Let's agree on a non ambigous terminology then:
forced:
suspend which you enforce via user interaction, which also implies that you risk losing wakeups depending on the hardware properties
Reasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.
Quoted 5 lines
Quoted 1 line
Define "losing", please.
I did. See next line in my original.
"... by which I mean that they will not be seen until some other event effects a wake-up".
OK, sorry.
Quoted 11 lines
By "seen" I mean "a user-space process has had a chance
to react to the event, including having the opportunity to abort the suspend (or ensure an immediate wake-up)".
Another way of saying it might be that the event - as an abstract concept - does not reach it's final destination promptly. This "final destination" may be well outside the kernel.Quoted 4 lines
Currently, we simply don't regard hardware signals occuring _during_ the suspend operation itself as wakeups (unless they are wakeup interrupts to be precise, because these _are_ taken into account by our current code).
Quoted 8 lines
Quoted 6 lines
The reason is that the meaning of given event may be _different_ at run time and after the system has been suspended. For example, consider a power button on a PC box. If it's pressed at run time, it usually means "power off the system" to the kernel. After the system has been suspended, however, it means "wake up". So, you have to switch from one interpretation of the event to the other and that's not an atomic operaition (to put it lightly).
Yes, a suspend-toggle switch is inherently racy.
For this reason we generally have to assume that some events occuring during suspend will only be seen by user space after resume. Now, since we make such an assumption anyway, there's a little point working around some races related to it while leaving the others as they are (that wouldn't improve things all that much).
Quoted 4 lines
It is only wake-up sources that are not inherently racy that are interesting. e.g. a serial line from a GSM device which reports "You have an SMS message". I want to be able to turn my freerunner upside-down by which I tell it (via the accelerometers) that I am done and want it to turn off. If a TXT message
Quoted 8 lines
comes in just then, I don't want it to suspend, I want it to make an alert noise.
I can put code in to ignore the accelerometer if a txt has just recently come in, but if the TXT arrives just as the write to/sys/power/statestarts, the UART interrupt handler could have completed before it has thePRE_SUSPENDmethod called. So the suspend will complete and the wakeup from the UART will have been "lost" in that the event didn't get all the way to its
destination: my ear.
As I said before, we generally can't prevent such things from happening, because even if we handle the particular race described above, it still is possible that the event will be "lost" if it arrives just a bit later (eg. during a suspend-toggle switch). So the PRE_SUSPEND thing won't really solve the entire problem while increasing complexity.
Quoted 5 lines
My freerunner has a single core so without
CONFIG_PREEMPTit may be that there is no actual race-window - maybe thePRE_SUSPENDswill all run before asoft_irqthread has a chance to finish handling of the interrupt (my knowledge of these details is limits). But on a muilti-core device I think there would definitely be a race-window.
Yes, there always will be a race window. The only thing we can do is to narrow it, but we cannot really close it (at least not on a PC, but I'm not really sure it can be closed at all).
If you really want _all_ events to be delivered timely, the only way to go is to avoid using suspend (and use the idle framework for power management).
Thanks,
Rafael
Quoted 64 lines · Rafael J. Wysocki
Quoted 33 lines · Neil Brown
Quoted 30 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Fair enough. Let's agree on a non ambigous terminology then:
forced:
Quoted 8 lines
Quoted 3 lines
suspend which you enforce via user interaction, which also implies that you risk losing wakeups depending on the hardware properties
Reasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.Define "losing", please.
Currently, we simply don't regard hardware signals occuring _during_ the suspend operation itself as wakeups (unless they are wakeup interrupts to be precise, because these _are_ taken into account by our current code).
The reason is that the meaning of given event may be _different_ at run time and after the system has been suspended. For example, consider a power button on a PC box. If it's pressed at run time, it usually means "power off the system" to the kernel. After the system has been suspended, however, it means "wake up". So, you have to switch from one interpretation of the event to the other and that's not an atomic operaition (to put it lightly).
Quoted 8 lines
Even with ideal hardware events can be lost - by which I mean that they will not be seen until some other event effects a wake-up.
e.g. the interrupt which signals the event happens immediately before the suspend is requested (or maybe at the same time as), but the process which needs to handle the event doesn't get a chance to see it before the suspend procedure freezes that process, and even if it did it would have no way to abort the suspend.
Quoted 9 lines
Quoted 3 lines
So I submit that the current implementation doesn't match your description of "forced", is therefore buggy, and that if it were fixed, that would be sufficient to meet the immediate needs of android.
I don't really think it may be fixed with respect to every possible kind of hardware. On platforms where I/O interrupts are wakeup events it should work right now. On other platforms it may be impossible to overcome hardware limitations.
There is no reason you cannot make the rtc alarms work reliably on x86 hardware. Even if you may loose key events while suspending I think it is still valuable to have reliable alarms. I gave an example earlier why reliable alarms are useful (dvr application).
Signature · 1 line
Arve Hjønnevåg
Quoted 69 lines · Arve Hjønnevåg
Quoted 68 lines · Rafael J. Wysocki
Quoted 33 lines · Neil Brown
Quoted 30 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Fair enough. Let's agree on a non ambigous terminology then:
forced:
Quoted 8 lines
Quoted 3 lines
suspend which you enforce via user interaction, which
also implies that you risk losing wakeups depending on the hardware propertiesReasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.Define "losing", please.
Currently, we simply don't regard hardware signals occuring _during_ the suspend operation itself as wakeups (unless they are wakeup interrupts to be precise, because these _are_ taken into account by our current code).
The reason is that the meaning of given event may be _different_ at run time and after the system has been suspended. For example, consider a power button on a PC box. If it's pressed at run time, it usually means "power off the system" to the kernel. After the system has been suspended, however, it means "wake up". So, you have to switch from one interpretation of the event to the other and that's not an atomic operaition (to put it lightly).
Quoted 11 lines
Even with ideal hardware events can be lost - by which I mean that they will not be seen until some other event effects a wake-up.
e.g. the interrupt which signals the event happens immediately before the suspend is requested (or maybe at the same time as), but the process which needs to handle the event doesn't get a chance to see it before the suspend procedure freezes that process, and even if it did it would have no way to abort the suspend.So I submit that the current implementation doesn't match your description of "forced", is therefore buggy, and that if it were fixed, that would be sufficient to meet the immediate needs of android.
Quoted 8 lines
Quoted 5 lines
I don't really think it may be fixed with respect to every possible kind of hardware. On platforms where I/O interrupts are wakeup events it should work right now. On other platforms it may be impossible to overcome hardware limitations.
There is no reason you cannot make the rtc alarms work reliably on x86 hardware.
They usually work, but not in 100% of cases.
Generally, "x86 hardware" is a broad category, where modern ones have much more interesting capabilities than the older.
Quoted 2 lines
Even if you may loose key events while suspending I think it is still valuable to have reliable alarms.
I don't think anyone will argue with that. :-)
Rafael
Quoted 69 lines · Arve Hjønnevåg
Quoted 68 lines · Rafael J. Wysocki
Quoted 33 lines · Neil Brown
Quoted 30 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Fair enough. Let's agree on a non ambigous terminology then:
forced:
Quoted 8 lines
Quoted 3 lines
suspend which you enforce via user interaction, which
also implies that you risk losing wakeups depending on the hardware propertiesReasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.Define "losing", please.
Currently, we simply don't regard hardware signals occuring _during_ the suspend operation itself as wakeups (unless they are wakeup interrupts to be precise, because these _are_ taken into account by our current code).
The reason is that the meaning of given event may be _different_ at run time and after the system has been suspended. For example, consider a power button on a PC box. If it's pressed at run time, it usually means "power off the system" to the kernel. After the system has been suspended, however, it means "wake up". So, you have to switch from one interpretation of the event to the other and that's not an atomic operaition (to put it lightly).
Quoted 11 lines
Even with ideal hardware events can be lost - by which I mean that they will not be seen until some other event effects a wake-up.
e.g. the interrupt which signals the event happens immediately before the suspend is requested (or maybe at the same time as), but the process which needs to handle the event doesn't get a chance to see it before the suspend procedure freezes that process, and even if it did it would have no way to abort the suspend.So I submit that the current implementation doesn't match your description of "forced", is therefore buggy, and that if it were fixed, that would be sufficient to meet the immediate needs of android.
Quoted 8 lines
Quoted 5 lines
I don't really think it may be fixed with respect to every possible kind of hardware. On platforms where I/O interrupts are wakeup events it should work right now. On other platforms it may be impossible to overcome hardware limitations.
There is no reason you cannot make the rtc alarms work reliably on x86 hardware.
They usually work, but not in 100% of cases.
Generally, "x86 hardware" is a broad category, where modern ones have much more interesting capabilities than the older.
Quoted 2 lines
Even if you may loose key events while suspending I think it is still valuable to have reliable alarms.
I don't think anyone will argue with that. :-)
Rafael
Quoted 64 lines · Rafael J. Wysocki
Quoted 33 lines · Neil Brown
Quoted 30 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Fair enough. Let's agree on a non ambigous terminology then:
forced:
Quoted 8 lines
Quoted 3 lines
suspend which you enforce via user interaction, which also implies that you risk losing wakeups depending on the hardware properties
Reasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.Define "losing", please.
Currently, we simply don't regard hardware signals occuring _during_ the suspend operation itself as wakeups (unless they are wakeup interrupts to be precise, because these _are_ taken into account by our current code).
The reason is that the meaning of given event may be _different_ at run time and after the system has been suspended. For example, consider a power button on a PC box. If it's pressed at run time, it usually means "power off the system" to the kernel. After the system has been suspended, however, it means "wake up". So, you have to switch from one interpretation of the event to the other and that's not an atomic operaition (to put it lightly).
Quoted 8 lines
Even with ideal hardware events can be lost - by which I mean that they will not be seen until some other event effects a wake-up.
e.g. the interrupt which signals the event happens immediately before the suspend is requested (or maybe at the same time as), but the process which needs to handle the event doesn't get a chance to see it before the suspend procedure freezes that process, and even if it did it would have no way to abort the suspend.
Quoted 9 lines
Quoted 3 lines
So I submit that the current implementation doesn't match your description of "forced", is therefore buggy, and that if it were fixed, that would be sufficient to meet the immediate needs of android.
I don't really think it may be fixed with respect to every possible kind of hardware. On platforms where I/O interrupts are wakeup events it should work right now. On other platforms it may be impossible to overcome hardware limitations.
There is no reason you cannot make the rtc alarms work reliably on x86 hardware. Even if you may loose key events while suspending I think it is still valuable to have reliable alarms. I gave an example earlier why reliable alarms are useful (dvr application).
Signature · 1 line
Arve Hjønnevåg
Quoted 33 lines · Neil Brown
Quoted 30 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Fair enough. Let's agree on a non ambigous terminology then:
forced:
Quoted 8 lines
Quoted 3 lines
suspend which you enforce via user interaction, which also implies that you risk losing wakeups depending on the hardware properties
Reasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.
Define "losing", please.
Currently, we simply don't regard hardware signals occuring _during_ the suspend operation itself as wakeups (unless they are wakeup interrupts to be precise, because these _are_ taken into account by our current code).
The reason is that the meaning of given event may be _different_ at run time and after the system has been suspended. For example, consider a power button on a PC box. If it's pressed at run time, it usually means "power off the system" to the kernel. After the system has been suspended, however, it means "wake up". So, you have to switch from one interpretation of the event to the other and that's not an atomic operaition (to put it lightly).
Quoted 11 lines
Even with ideal hardware events can be lost - by which I mean that they will not be seen until some other event effects a wake-up.
e.g. the interrupt which signals the event happens immediately before the suspend is requested (or maybe at the same time as), but the process which needs to handle the event doesn't get a chance to see it before the suspend procedure freezes that process, and even if it did it would have no way to abort the suspend.So I submit that the current implementation doesn't match your description of "forced", is therefore buggy, and that if it were fixed, that would be sufficient to meet the immediate needs of android.
I don't really think it may be fixed with respect to every possible kind of hardware. On platforms where I/O interrupts are wakeup events it should work right now. On other platforms it may be impossible to overcome hardware limitations.
Thanks,
Rafael
Quoted 26 lines · On Thu, 27 May 2010 23:40:29 +0200 (CEST) Thomas Gleixner <[email protected]>…
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Quoted 7 lines
Fair enough. Let's agree on a non ambigous terminology then:
forced:
suspend which you enforce via user interaction, which also implies that you risk losing wakeups depending on the hardware properties
Reasonable definition I think. However the current implementation doesn't exactly match it.
With the current implementation you risk losing wakeups *independent* of the hardware properties.
Even with ideal hardware events can be lost - by which I mean that they will not be seen until some other event effects a wake-up.
e.g. the interrupt which signals the event happens immediately before the suspend is requested (or maybe at the same time as), but the process which needs to handle the event doesn't get a chance to see it before the suspend procedure freezes that process, and even if it did it would have no way to abort the suspend.
So I submit that the current implementation doesn't match your description of "forced", is therefore buggy, and that if it were fixed, that would be sufficient to meet the immediate needs of android.
NeilBrown
Quoted 15 lines
opportunistic:
suspend driven from the idle context, which guarantees to not lose wakeups. Provided only when the hardware does provide the necessary capabilities.
Thanks,
tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Thomas Gleixner
Quoted 13 lines · Alan Stern
Quoted 10 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Fair enough. Let's agree on a non ambigous terminology then:
forced:
suspend which you enforce via user interaction, which also implies that you risk losing wakeups depending on the hardware properties
opportunistic:
suspend driven from the idle context, which guarantees to not lose wakeups. Provided only when the hardware does provide the necessary capabilities.
Thanks,
tglx
Quoted 11 lines · Thomas Gleixner
Quoted 9 lines · Alan Stern
Quoted 7 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Well, what about when I want the machine to suspend _regardless_ of whether or not it's idle at the moment? That actually happens quite often to me. :-)
Quoted 4 lines
Quoted 1 line
attention to latencies or other requirements.
s2disk is a totally different beast as it shuts down the box into the complete power off state.
I don't see much difference between that and ACPI S3 other than the memory contents are preserved in S3. It also is complete power off state - except for memory refresh and wakeup sources (which also may be active in S4).
Rafael
Quoted 9 lines · Alan Stern
Quoted 7 lines · Felipe Balbi
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
Quoted 6 lines
Quoted 3 lines
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Does this mean you believe "echo mem >/sys/power/state" is bad and should be removed? Or "echo disk >/sys/power/state"? They pay no
mem should be replaced by an idle suspend to ram mechanism
Quoted 1 line
attention to latencies or other requirements.
s2disk is a totally different beast as it shuts down the box into the complete power off state.
Thanks,
tglx
Quoted 5 lines · ext Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
I disagree here. I believe expressing that as QoS is much better. Let the kernel decide which power state is better as long as I can say I need 100us IRQ latency or 100ms wakeup latency.
Signature · 3 lines
balbi DefectiveByDesign.org
Quoted 5 lines · Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
Only if they only block. You get into trouble when the in kernel un-block opperation triggers an implicit suspend.
Quoted 7 lines
Opportunistic suspends are okay.
The proposed userspace API is too Android-specific.
More kernel mechanisms are needed for expressing processes' latency requirements.
True.
--mgross
Quoted 36 lines
The last one is obviously a longer-term issue, so let's ignore it for now. That leaves as the only point of contention the userspace suspend-blocker API.
The proposal I made a couple of days ago removes this API and leaves the other things (i.e., the in-kernel suspend blockers and opportunistic suspend) intact. In place of the userspace kernel-blocker API, Android would have to implement a power manager process that would essentially juggle all the latency requirements in userspace.
Communication between the power manager process and the kernel would be limited to adding a new "opportunistic" entry to
/sys/power/state-- something which could well be useful in its own right. Even if this API turns out not to be good, it's simple enough that it could be removed pretty easily.This answers Alan Cox's (and other's) desire not to implement a questionable or special-purpose API. And it also answers Thomas's desire to make scheduling decisions based on latency requirements (although the answer is simply to punt all these decisions out of the kernel and into userspace -- which is reasonable for now since the alternative would require a long-term kernel development effort).
Indeed, having a power manager thread may well turn out to be a useful thing -- but even if it doesn't, this scheme minimizes the damage while still allowing the Android platform to use a vanilla kernel with only limited modifications to their userspace.
Alan Stern
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Quoted 5 lines · Alan Stern
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
Only if they only block. You get into trouble when the in kernel un-block opperation triggers an implicit suspend.
Quoted 7 lines
Opportunistic suspends are okay.
The proposed userspace API is too Android-specific.
More kernel mechanisms are needed for expressing processes' latency requirements.
True.
--mgross
Quoted 36 lines
The last one is obviously a longer-term issue, so let's ignore it for now. That leaves as the only point of contention the userspace suspend-blocker API.
The proposal I made a couple of days ago removes this API and leaves the other things (i.e., the in-kernel suspend blockers and opportunistic suspend) intact. In place of the userspace kernel-blocker API, Android would have to implement a power manager process that would essentially juggle all the latency requirements in userspace.
Communication between the power manager process and the kernel would be limited to adding a new "opportunistic" entry to
/sys/power/state-- something which could well be useful in its own right. Even if this API turns out not to be good, it's simple enough that it could be removed pretty easily.This answers Alan Cox's (and other's) desire not to implement a questionable or special-purpose API. And it also answers Thomas's desire to make scheduling decisions based on latency requirements (although the answer is simply to punt all these decisions out of the kernel and into userspace -- which is reasonable for now since the alternative would require a long-term kernel development effort).
Indeed, having a power manager thread may well turn out to be a useful thing -- but even if it doesn't, this scheme minimizes the damage while still allowing the Android platform to use a vanilla kernel with only limited modifications to their userspace.
Alan Stern
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
If people don't mind, here is a greatly simplified summary of the comments and objections I have seen so far on this thread:
The in-kernel suspend blocker implementation is okay, even beneficial.
Opportunistic suspends are okay.
The proposed userspace API is too Android-specific.
More kernel mechanisms are needed for expressing processes' latency requirements.
The last one is obviously a longer-term issue, so let's ignore it for now. That leaves as the only point of contention the userspace suspend-blocker API.
The proposal I made a couple of days ago removes this API and leaves the other things (i.e., the in-kernel suspend blockers and opportunistic suspend) intact. In place of the userspace kernel-blocker API, Android would have to implement a power manager process that would essentially juggle all the latency requirements in userspace.
Communication between the power manager process and the kernel would be limited to adding a new "opportunistic" entry to /sys/power/state -- something which could well be useful in its own right. Even if this API turns out not to be good, it's simple enough that it could be removed pretty easily.
This answers Alan Cox's (and other's) desire not to implement a questionable or special-purpose API. And it also answers Thomas's desire to make scheduling decisions based on latency requirements (although the answer is simply to punt all these decisions out of the kernel and into userspace -- which is reasonable for now since the alternative would require a long-term kernel development effort).
Indeed, having a power manager thread may well turn out to be a useful thing -- but even if it doesn't, this scheme minimizes the damage while still allowing the Android platform to use a vanilla kernel with only limited modifications to their userspace.
Alan Stern
Quoted 11 lines · Alan Cox
- Supporting Android needs well good
- Opportunistic suspend good
- Manner in which interface is expressed to userspace bad
- Latency constraint interface would be better
- Your existing behaviour can be implemented by a simplistic use of a latency constraint interface
- We can fix a pile of other directly connected things at the same time
- Implementation internals I care far less about because we can fix those later
- Suspend is just a power state
Quoted 1 line
How does that fit your model and vision ?
I don't entirely see how this works. In order to deal with poorly written applications, it's necessary to (optionally, based on some policy) ignore them when it comes to the scheduler. The problem is how to implement the optional nature of this in a race-free manner. This is obviously a pathological case, but imagine an application that does something along the following lines:
int input = open ("/dev/input", O_RDONLY|O_NONBLOCK); char foo;
while (1) {
suspend_block();
if (read(input, &foo, 1) > 0) {
(do something)
suspend_unblock();
} else {
suspend_unblock();
(draw bouncing cows and clouds and tractor beams briefly)
}
}Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag one way which indicates to the scheduler that tasks in TASK_RUNNING should be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted to TASK_INTERRUPTIBLE or something.
Except that doesn't work. If the session goes idle in the middle of the app drawing a frame, we'll stop the process and the task will never call read(). So the user hits a key, we wake up, nothing shifts from TASK_INTERRUPTIBLE into TASK_RUNNING, the key never gets read, we go back to sleep. The event never gets delivered.
Now let's try this in the Android world. The user hits a key and the system wakes up. The input layer takes a suspend block. The application now draws all the cows it wants to, takes its own suspend block and reads the input device. This empties the queue and the kernel-level suspend block is released. The application then processes the event before releasing the suspend block. The event has been delivered and handled.
You can't express that with resource limits or QoS constraints. If you want to deal with this kind of situation then, as far as I can tell, you need either suspend blockers or something so close to them that it makes no difference.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 21 lines · Matthew Garrett
I don't entirely see how this works. In order to deal with poorly written applications, it's necessary to (optionally, based on some policy) ignore them when it comes to the scheduler. The problem is how to implement the optional nature of this in a race-free manner. This is obviously a pathological case, but imagine an application that does something along the following lines:
int input = open ("
/dev/input", O_RDONLY|O_NONBLOCK); char foo;while (1) { suspend_block(); if (read(input, &foo, 1) > 0) { (do something) suspend_unblock(); } else { suspend_unblock(); (draw bouncing cows and clouds and tractor beams briefly) } }
Quoted 8 lines
Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.
What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!
Quoted 21 lines · Matthew Garrett
I don't entirely see how this works. In order to deal with poorly written applications, it's necessary to (optionally, based on some policy) ignore them when it comes to the scheduler. The problem is how to implement the optional nature of this in a race-free manner. This is obviously a pathological case, but imagine an application that does something along the following lines:
int input = open ("
/dev/input", O_RDONLY|O_NONBLOCK); char foo;while (1) { suspend_block(); if (read(input, &foo, 1) > 0) { (do something) suspend_unblock(); } else { suspend_unblock(); (draw bouncing cows and clouds and tractor beams briefly) } }
Quoted 8 lines
Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.
What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines · Matthew Garrett
one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!
Well, primarily that it's possible to design an implementation where it *doesn't* prevent your phone froms sleeping, but also because a given application may justifiably be preventing your phone from sleeping for a short while. What threshold do you use to determine the difference?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines · Matthew Garrett
one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!
Well, primarily that it's possible to design an implementation where it *doesn't* prevent your phone froms sleeping, but also because a given application may justifiably be preventing your phone from sleeping for a short while. What threshold do you use to determine the difference?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Matthew Garrett
one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.
Quoted 7 lines
Quoted 2 lines
What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!Well, primarily that it's possible to design an implementation where it *doesn't* prevent your phone froms sleeping, but also because a given application may justifiably be preventing your phone from sleeping for a short while. What threshold do you use to determine the difference?
Whatever you want, why would the kernel care?
You can create a whole resource management layer in userspace, with different privilidge/trust levels. Trusted apps may wake more than untrusted apps. Who cares.
The thing is, you can easily detect what keeps your cpu from idling. What you do about it a pure userspace solution.
You can use the QoS stuff to give hints, like don't wake me more than 5 times a minute, if with those hints an app still doesn't meet whatever criteria are suitable for the current mode, yell at it. Or adjust its QoS parameters for it.
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Matthew Garrett
one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.
Quoted 7 lines
Quoted 2 lines
What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!Well, primarily that it's possible to design an implementation where it *doesn't* prevent your phone froms sleeping, but also because a given application may justifiably be preventing your phone from sleeping for a short while. What threshold do you use to determine the difference?
Whatever you want, why would the kernel care?
You can create a whole resource management layer in userspace, with different privilidge/trust levels. Trusted apps may wake more than untrusted apps. Who cares.
The thing is, you can easily detect what keeps your cpu from idling. What you do about it a pure userspace solution.
You can use the QoS stuff to give hints, like don't wake me more than 5 times a minute, if with those hints an app still doesn't meet whatever criteria are suitable for the current mode, yell at it. Or adjust its QoS parameters for it.
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Quoted 25 lines · Peter Zijlstra
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Matthew Garrett
one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.Quoted 7 lines
Quoted 2 lines
What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!Well, primarily that it's possible to design an implementation where it *doesn't* prevent your phone froms sleeping, but also because a given application may justifiably be preventing your phone from sleeping for a short while. What threshold do you use to determine the difference?
Whatever you want, why would the kernel care?
You can create a whole resource management layer in userspace, with different privilidge/trust levels. Trusted apps may wake more than untrusted apps. Who cares.
The thing is, you can easily detect what keeps your cpu from idling. What you do about it a pure userspace solution.
Quoted 7 lines
You can use the QoS stuff to give hints, like don't wake me more than 5 times a minute, if with those hints an app still doesn't meet whatever criteria are suitable for the current mode, yell at it. Or adjust its QoS parameters for it.
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
Quoted 25 lines · Peter Zijlstra
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Matthew Garrett
one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.Quoted 7 lines
Quoted 2 lines
What's wrong with simply making the phone beep loudly and displaying:
bouncing cows is preventing your phone from sleeping!Well, primarily that it's possible to design an implementation where it *doesn't* prevent your phone froms sleeping, but also because a given application may justifiably be preventing your phone from sleeping for a short while. What threshold do you use to determine the difference?
Whatever you want, why would the kernel care?
You can create a whole resource management layer in userspace, with different privilidge/trust levels. Trusted apps may wake more than untrusted apps. Who cares.
The thing is, you can easily detect what keeps your cpu from idling. What you do about it a pure userspace solution.
Quoted 7 lines
You can use the QoS stuff to give hints, like don't wake me more than 5 times a minute, if with those hints an app still doesn't meet whatever criteria are suitable for the current mode, yell at it. Or adjust its QoS parameters for it.
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
Quoted 5 lines
Quoted 2 lines
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
That isn't helpful. But if you feel like that I suggest you run with your memory management protection disabled, it's really on there to deal with crap code and its giving the wrong incentives. Come to think of it you might want to remove your seatbelts and any safety catches or airbags
- it only encourages carelessness.
The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
Arguing that you don't need to do this isn't useful. Android has demonstrated a need to do this. RT has a need to do some of this. Virtualisation wants elements of this etc.
The question is how you do it right.
Quoted 12 lines · Alan Cox
Quoted 5 lines
Quoted 2 lines
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
That isn't helpful. But if you feel like that I suggest you run with your memory management protection disabled, it's really on there to deal with crap code and its giving the wrong incentives. Come to think of it you might want to remove your seatbelts and any safety catches or airbags
- it only encourages carelessness.
Quoted 7 lines
The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
Arguing that you don't need to do this isn't useful. Android has demonstrated a need to do this. RT has a need to do some of this. Virtualisation wants elements of this etc.
Sure, I fully agree with the task and per device QoS stuff. I'm just saying that its good to inform the user that some app is severely mis-behaving.
Quoted 12 lines · Alan Cox
Quoted 5 lines
Quoted 2 lines
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
That isn't helpful. But if you feel like that I suggest you run with your memory management protection disabled, it's really on there to deal with crap code and its giving the wrong incentives. Come to think of it you might want to remove your seatbelts and any safety catches or airbags
- it only encourages carelessness.
Quoted 7 lines
The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
Arguing that you don't need to do this isn't useful. Android has demonstrated a need to do this. RT has a need to do some of this. Virtualisation wants elements of this etc.
Sure, I fully agree with the task and per device QoS stuff. I'm just saying that its good to inform the user that some app is severely mis-behaving.
Quoted 3 lines · On Thu, 27 May 2010 16:10:54 +0100 Alan Cox <[email protected]> wrote:
The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
And the thing is, even a well written app can be a 'crapplication' depending on the context and mood of the user.
cheers,
Flo
Quoted 3 lines · On Thu, 27 May 2010 16:10:54 +0100 Alan Cox <[email protected]> wrote:
The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
And the thing is, even a well written app can be a 'crapplication' depending on the context and mood of the user.
cheers,
Flo
Quoted 16 lines · Alan Cox
Quoted 5 lines
Quoted 2 lines
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
That isn't helpful. But if you feel like that I suggest you run with your memory management protection disabled, it's really on there to deal with crap code and its giving the wrong incentives. Come to think of it you might want to remove your seatbelts and any safety catches or airbags
- it only encourages carelessness.The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
Quoted 5 lines
Arguing that you don't need to do this isn't useful. Android has demonstrated a need to do this. RT has a need to do some of this. Virtualisation wants elements of this etc.
The question is how you do it right.
I violently agree, thanks Alan!
Rafael
Quoted 16 lines · Alan Cox
Quoted 5 lines
Quoted 2 lines
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
That isn't helpful. But if you feel like that I suggest you run with your memory management protection disabled, it's really on there to deal with crap code and its giving the wrong incentives. Come to think of it you might want to remove your seatbelts and any safety catches or airbags
- it only encourages carelessness.The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
Quoted 5 lines
Arguing that you don't need to do this isn't useful. Android has demonstrated a need to do this. RT has a need to do some of this. Virtualisation wants elements of this etc.
The question is how you do it right.
I violently agree, thanks Alan!
Rafael
Quoted 5 lines
Quoted 2 lines
Heck, for all I care, simply SIGKILL the thing and report it once the user starts looking at his screen again.
Provide incentive for Joe Clicker to improve his app, instead of cope with the shit he created.
That isn't helpful. But if you feel like that I suggest you run with your memory management protection disabled, it's really on there to deal with crap code and its giving the wrong incentives. Come to think of it you might want to remove your seatbelts and any safety catches or airbags
- it only encourages carelessness.
The reality is you need a sane, generic, race free way to express your requirements (eg for hard RT) and ditto for constraining the expression (for 'crapplications')
Arguing that you don't need to do this isn't useful. Android has demonstrated a need to do this. RT has a need to do some of this. Virtualisation wants elements of this etc.
The question is how you do it right.
Quoted 4 lines
Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag
I would hope not, because I'd rather prefer my app that used the screen to get the chance to save important data on what it was doing irrespective of the screen blank: "I have an elegant proof for this problem but my battery has gone flat"
(and I imagine we can play that examples game forever given Ashby's law)
Quoted 1 line
You can't express that with resource limits or QoS constraints.
I don't see why not. You just have to think about the problem from the right end. Start from "normality is well behaved applications" and progress to "but I can constrain bogus ones".
So what are the resource constraints/QoS constraints for your example:
[Simplistically]
1. App says 'I want to wakeup from events for me within 1 second' (Because I like drawing cows at about that rate)
2. App open driver for buttons
3. App opens driver for screen
Driver for buttons goes 'humm, well I can trigger wakeup from all power states so I need no restrictions'. Screen will vary by device a lot.
(I'll come back to the screen a bit more in a moment)
So lets consider the same binary
App runs on OLPC like h/w
The pm code goes 'well I can suspend/resume in a second thats cool' The screen code goes 'Hey I've got OLPC like video so thats ok' The button driver can wake the system from suspend and queue an event
App runs on Android like h/w
The pm code goes 'well I can suspend/resume in a second thats cool' The screen code goes 'Gee the screen goes blank if I go below level X' so
I'll set a limit
The button driver can wake the system from suspend and queue an event
App runs on Android like h/w but not trusted
The pm code goes 'well tough, you can't do that, I'll refuse you'
(Maybe user space wrapped by Android with a 'Cows wants to eat your phone alive [Refuse] [This Time Only] [Always] UI User hits refuse and Android duly assigns the code no guarantee and a hard limit of no guarantee.
The screen code goes 'tough'
The button driver can wake the system etc
Cows will get suspended for longer than one second whether it likes it or not
App runs on a desktop PC
The pm code goes 'well I can't do suspend/resume in 1 second, but I can do C6'
The screen goes 'I need C6'
The button driver goes 'I need C6'
Same app in each case and a lot less syscalls. No pathalogical cases either - with suspend blockers you can get emergent synchronization patterns between applications where each app rarely blocks suspends but together their timings fall such that they never allow it. How do you propose to even detect that ?
Ok now the screen
If I write to an X server and the server doesn't wish to talk to me it ignores the stream and I block. This has been the case since the 1980s.
What is the problem here - your device driver for the display can block tasks it doesn't want to use the display.
Quoted 2 lines · Alan Cox
What is the problem here - your device driver for the display can block tasks it doesn't want to use the display.
Very well put again.
I bet the next example is a proglet that does: while(1); without device interaction :-).
Quoted 2 lines · Alan Cox
What is the problem here - your device driver for the display can block tasks it doesn't want to use the display.
Very well put again.
I bet the next example is a proglet that does: while(1); without device interaction :-).
Quoted 9 lines · Alan Cox
Quoted 4 lines
Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag
I would hope not, because I'd rather prefer my app that used the screen to get the chance to save important data on what it was doing irrespective of the screen blank: "I have an elegant proof for this problem but my battery has gone flat"
Perhaps set after callbacks are made. But given that the approach doesn't work anyway...
Quoted 2 lines
What is the problem here - your device driver for the display can block tasks it doesn't want to use the display.
It's still racy. Going back to my example without any of the suspend blocking code, but using a network socket rather than an input device:
int input = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))
while (1) {
if (read(input, &foo, 1) > 0) {
(do something)
} else {
(draw bouncing cows and clouds and tractor beams briefly)
}
}A network packet arrives while we're drawing. Before we finish drawing, the policy timeout expires and the screen turns off. The app's drawing is blocked and so never gets to the point of reading the socket. The wakeup event has been lost.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines · On Thu, 27 May 2010 17:07:14 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 5 lines · Alan Cox
Quoted 4 lines
Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag
Quoted 7 lines
Quoted 4 lines
I would hope not, because I'd rather prefer my app that used the screen to get the chance to save important data on what it was doing irrespective of the screen blank: "I have an elegant proof for this problem but my battery has gone flat"
Perhaps set after callbacks are made. But given that the approach doesn't work anyway...
Which approach doesn't work, and why ?
Quoted 18 lines
Quoted 2 lines
What is the problem here - your device driver for the display can block tasks it doesn't want to use the display.
It's still racy. Going back to my example without any of the suspend blocking code, but using a network socket rather than an input device:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))while (1) { if (read(input, &foo, 1) > 0) { (do something) } else { (draw bouncing cows and clouds and tractor beams briefly) } }
Quoted 2 lines
A network packet arrives while we're drawing. Before we finish drawing, the policy timeout expires and the screen turns off.
Which is correct for a badly behaved application. You said you wanted to constrain it. You've done so. Now I am not sure why such a "timeout" would expire in the example as the task is clearly busy when drawing, or is talking to someone else who is in turn busy. Someone somewhere is actually drawing be it a driver or app code.
For a well behaved application you are drawing so you are running drawing stuff so why would you suspend. The app has said it has a latency constraint that suspend cannot meet, or has a device open that cannot meet the constraints in suspend.
You also have the socket open so you can meaningfully extract resource constraint information from that fact.
See it's not the read() that matters, it's the connect and the close.
If your policy for a well behaved application is 'thou shalt not suspend in a way that breaks its networking' then for a well behaving app once I connect the socket we cannot suspend that app until such point as the app closes the socket. At any other point we will break the connection. Whether that is desirable is a policy question and you get to pick how much you choose to trust an app and how you interpret the information in your cpufreq and suspend drivers.
If you have wake-on-lan then the network stack might be smarter and choose to express itself as
'the constraint is C6 unless the input queue is empty in which
case suspend is ok as I have WoL and my network routing is such that I can prove that interface will be used'
In truth I doubt much hardware can make such an inference but some phones probably can. On the other hand for /dev/input/foo you can make the inference very nicely thank you.
Again wake on lan information does not belong in the application !
Quoted 6 lines · Alan Cox
Quoted 2 lines · On Thu, 27 May 2010 17:07:14 +0100 Matthew Garrett <[email protected]> wrote:
Perhaps set after callbacks are made. But given that the approach doesn't work anyway...
Which approach doesn't work, and why ?
Sorry, using cgroups and scheduler tricks as a race-free replacement for opportunistic suspend.
Quoted 15 lines
Quoted 15 lines
It's still racy. Going back to my example without any of the suspend blocking code, but using a network socket rather than an input device:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))while (1) { if (read(input, &foo, 1) > 0) { (do something) } else { (draw bouncing cows and clouds and tractor beams briefly) } }
Quoted 8 lines
Quoted 2 lines
A network packet arrives while we're drawing. Before we finish drawing, the policy timeout expires and the screen turns off.
Which is correct for a badly behaved application. You said you wanted to constrain it. You've done so. Now I am not sure why such a "timeout" would expire in the example as the task is clearly busy when drawing, or is talking to someone else who is in turn busy. Someone somewhere is actually drawing be it a driver or app code.
The timeout would be at the userspace platform level. If I haven't touched the app for 30 seconds (and if the app hasn't taken any form of suspend block), the screen should turn off. In the current Android implementation that will then (in the absence of any kernel-level suspend blockers) result in the system transitioning into a fully suspended state.
Quoted 4 lines
For a well behaved application you are drawing so you are running drawing stuff so why would you suspend. The app has said it has a latency constraint that suspend cannot meet, or has a device open that cannot meet the constraints in suspend.
Not at all. The fact that the application hasn't taken any sort of suspend block means that the application has indicated that it's happy with no longer being scheduled when the screen is shut off, *providing there's no wakeup event to be processed*.
Quoted 5 lines
You also have the socket open so you can meaningfully extract resource constraint information from that fact.
See it's not the
read()that matters, it's the connect and the close.
Quoted 7 lines
If your policy for a well behaved application is 'thou shalt not suspend in a way that breaks its networking' then for a well behaving app once I connect the socket we cannot suspend that app until such point as the app closes the socket. At any other point we will break the connection. Whether that is desirable is a policy question and you get to pick how much you choose to trust an app and how you interpret the information in your cpufreq and suspend drivers.
Again, that's not the desired outcome. The desired outcome is that when the screen shuts off, the application no longer gets scheduled until a network packet arrives. The difference between these scenarios is large.
Quoted 6 lines
If you have wake-on-lan then the network stack might be smarter and choose to express itself as
'the constraint is C6 unless the input queue is empty in which
case suspend is ok as I have WoL and my network routing is such that I can prove that interface will be used'
This is still racy. Going back to this:
int input = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))
while (1) {
if (read(input, &foo, 1) > 0) {
(do something)
} else {
* SUSPEND OCCURS HERE *
(draw bouncing cows and clouds and tractor beams briefly)
}
}A wakeup event now arrives. We use kernel level suspend blockers to prevent the system from going back to sleep until userspace has read the packet. The application finishes drawing its cows, reads the packet (thus releasing the kernel-level suspend block) and them immediately reaches the end of its timeslice. At this point the application has not had an opportunity to indicate in any way whether or not the packet has altered its constraints in any way. What stops us from immediately suspending again?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 1 line
network packet arrives. The difference between these scenarios is large.
Your application seems to change desired outcome every email. Sorry but you need to explicitly explain and define a policy in full that we can test ideas against. Otherwise this is useless.
Quoted 13 lines
Quoted 6 lines
If you have wake-on-lan then the network stack might be smarter and choose to express itself as
'the constraint is C6 unless the input queue is empty in which
case suspend is ok as I have WoL and my network routing is such that I can prove that interface will be used'This is still racy. Going back to this:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))
Quoted 5 lines
while (1) {
if (read(input, &foo, 1) > 0) {
(do something)
} else {
* SUSPEND OCCURS HERE *Fine but then the packet will arrive and we will wake back up process the packet and wake the task. See suspend is just like a deep sleep. If we went to sleep there and the packet arrival doesn't rewake the box the driver was buggy.
Quoted 4 lines
reaches the end of its timeslice. At this point the application has not had an opportunity to indicate in any way whether or not the packet has altered its constraints in any way. What stops us from immediately suspending again?
If my app level constraint before the packet is 'don't suspend' then my constraint on receipt is 'don't suspend' so I won't suspend. If my constraint is then lowered and I suspend I will suspend *after* the lowering.
If my constraint is tightened then the decision to tighten is run under the previous constraint. Which is fine, because if I have a case where I must tighten my constraint within the tight constraint time I've screwed up my app and need to fix it.
In reality almost all your userspace is going to look like 'trusted app' or 'untrusted app' in droidthink and won't be transitioning in user space (but may well be adding/losing kernel constraints)
This is good because it's another thing app authors don't have to care about. It's good because apps can be run trusted/untrusted without recompiling.
Alan
Quoted 12 lines · Alan Cox
Quoted 11 lines
This is still racy. Going back to this:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))while (1) { if (read(input, &foo, 1) > 0) { (do something) } else { * SUSPEND OCCURS HERE *
Quoted 4 lines
Fine but then the packet will arrive and we will wake back up process the packet and wake the task. See suspend is just like a deep sleep. If we went to sleep there and the packet arrival doesn't rewake the box the driver was buggy.
Yes, there's no problem so far. The question is how you guarantee that the application has had the opportunity to handle the packet.
Quoted 9 lines
Quoted 4 lines
reaches the end of its timeslice. At this point the application has not had an opportunity to indicate in any way whether or not the packet has altered its constraints in any way. What stops us from immediately suspending again?
If my app level constraint before the packet is 'don't suspend' then my constraint on receipt is 'don't suspend' so I won't suspend. If my constraint is then lowered and I suspend I will suspend *after* the lowering.
If the app level constraint before the packet was "don't suspend", we wouldn't have suspended. Here's a description of the desired behaviour of the application as you requested:
The application is a network monitoring app that renders server state via animated bouncing cows. The desired behaviour is that the application will cease to be scheduled if the session becomes idle (where idle is defined as the system having received no user input for 30 seconds) but that push notifications from the server still be received in order to allow the application to present the user with critical alerts.
Under Android:
User puts down phone. 30 seconds later the screen turns off and releases the last user-level suspend block. The phone enters suspend and the application is suspended. A network packet is received, causing the network driver to take a suspend block. The application finishes the frame it was drawing, takes its own suspend block and reads the network packet. In doing so the network driver releases its suspend block, but since userspace is holding one the phone stays awake. The application then handles the event as necessary, releases its suspend block and the phone goes to sleep again.
I don't see how this behaviour can be emulated in your model.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines
Yes, there's no problem so far. The question is how you guarantee that the application has had the opportunity to handle the packet.
Because the application has said that it wants QoS guarantees. It wants to know that if the events it can receive occur it will wake up within the timescale.
So it receives the event. It's now running, not idle so we won't suspend it.
At some point in time it will become idle again _or_ the CPU limit will get it.
If the app is not trusted then we might suspend it before it handles the packet. That is fine, it's not trusted and we will do that when we decide its in the system interest to suspend it anyway.
You still don't lose the event because on resume the task will do its processing.
Quoted 7 lines
The application is a network monitoring app that renders server state via animated bouncing cows. The desired behaviour is that the application will cease to be scheduled if the session becomes idle (where idle is defined as the system having received no user input for 30 seconds) but that push notifications from the server still be received in order to allow the application to present the user with critical alerts.
This is a bit confusing - does the screen come back on for such events, what constraints is the server operating under ? How does your code look
- it's hard to imagine the examples you've given as being workable given they would block on network packet wait when a critical event occurs. Are you using poll or threads or what ?
Quoted 12 lines
Under Android:
User puts down phone. 30 seconds later the screen turns off and releases the last user-level suspend block. The phone enters suspend and the application is suspended. A network packet is received, causing the network driver to take a suspend block. The application finishes the frame it was drawing, takes its own suspend block and reads the network packet. In doing so the network driver releases its suspend block, but since userspace is holding one the phone stays awake. The application then handles the event as necessary, releases its suspend block and the phone goes to sleep again.
Quoted 1 line
I don't see how this behaviour can be emulated in your model.
User puts down phone. 30 seconds later the X server decides to turn the screen off and closes the device. This probalby releases the constraint held via the display driver not to suspend. Any further draw requests will block.
System looks at the other tasks and sees they are idle and can sink to a low power state. Cows is either blocked on a packet receive or could even be blocked on writing to the display (or both if its a realistic example and using poll)
Everyone is idle, we can sleep
The kernel looks at the constraints it has
- must not sink to a state below which network receive of packets fails
- must not sink below a state where whatever is needed for the critical alert code etc to do its stuff
- must not sink to a state which takes more than [constraint] seconds to get back out of
It picks 'opportunistic suspend'
It goes to sleep
A packet arrives
It wakes the hardware
We are busy, we do not wish to suspend
It processes the packet
It wakes the user app
It starts processing the packet
[We are busy, we do not wish to suspend]
Presumably your display server listens to waking back up and decides to re-activate the screen (your example is unclear and implies it carries on processing the extra frame in the dark which seems a bit silly ?
I still don't see a problem.
I think your problem arises because you start from the basis that forcing suspend is special. As Thomas has said there are working implementations where suspend is an idle mode.
The moment you discard that specific notion everything works, as it does today on other embedded platforms.
Now what do you do if the app is burning too much processor time. That's a QoS question too. We've got cpu limits, we've got SIGXCPU, we don't have "cpu per second" type limits but that isn't hard to do either.
Stop transitioning Run->Forced Suspend. If you've got stuff stuck running then deal with it by constraining it to go idle or by blowing it out of the water. PM will then do the rest.
Quoted 8 lines · Alan Cox
Quoted 7 lines
The application is a network monitoring app that renders server state via animated bouncing cows. The desired behaviour is that the application will cease to be scheduled if the session becomes idle (where idle is defined as the system having received no user input for 30 seconds) but that push notifications from the server still be received in order to allow the application to present the user with critical alerts.
Quoted 5 lines
This is a bit confusing - does the screen come back on for such events, what constraints is the server operating under ? How does your code look
- it's hard to imagine the examples you've given as being workable given they would block on network packet wait when a critical event occurs. Are you using poll or threads or what ?
It's code that's broadly identical to what I posted. The screen will come on if the event is critical, won't otherwise.
Quoted 19 lines
Quoted 12 lines
Under Android:
User puts down phone. 30 seconds later the screen turns off and releases the last user-level suspend block. The phone enters suspend and the application is suspended. A network packet is received, causing the network driver to take a suspend block. The application finishes the frame it was drawing, takes its own suspend block and reads the network packet. In doing so the network driver releases its suspend block, but since userspace is holding one the phone stays awake. The application then handles the event as necessary, releases its suspend block and the phone goes to sleep again.
Quoted 1 line
I don't see how this behaviour can be emulated in your model.
User puts down phone. 30 seconds later the X server decides to turn the screen off and closes the device. This probalby releases the constraint held via the display driver not to suspend. Any further draw requests will block.
Quoted 4 lines
System looks at the other tasks and sees they are idle and can sink to a low power state. Cows is either blocked on a packet receive or could even be blocked on writing to the display (or both if its a realistic example and using poll)
Even if it's using poll, it could block purely on the display if X turns the screen off between poll() waking and the write being made.
Quoted 11 lines
The kernel looks at the constraints it has
- must not sink to a state below which network receive of packets fails
- must not sink below a state where whatever is needed for the critical alert code etc to do its stuff
- must not sink to a state which takes more than [constraint] seconds to get back out ofIt picks 'opportunistic suspend'
It goes to sleep
Quoted 6 lines
A packet arrives
It wakes the hardware
We are busy, we do not wish to suspend
It processes the packet
It wakes the user app
It starts processing the packet
If it's blocked on the write then it only starts processing the packet again if the screen wakes up. You need to power up every piece of hardware that an application's blocked on, just in case they need to complete that read or write in order to get back to the event loop where they have the opportunity to read the network packet.
So, yes, I think this can work in that case. But it doesn't work in others - you won't idle applications that aren't accessing hardware drivers.
As an aside, I think this is a good idea in any case since a fringe benefit is the removal of the requirement to use the process freezer in suspend to RAM...
Quoted 3 lines
Stop transitioning
Run->ForcedSuspend. If you've got stuff stuck running then deal with it by constraining it to go idle or by blowing it out of the water. PM will then do the rest.
The problem is determining how to constrain it to go idle, where "idle" is defined as "Doesn't wake up until a wakeup event is received". It's acceptable for something to use as much CPU as it wants when the user is actively interacting with the device, but in most cases processes shouldn't be permitted to use any CPU when the session is idle. The question is how to implement something that allows a CPU-guzzling application to be idled without impairing its ability to process wakeup events.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Alan Cox
Quoted 7 lines
The application is a network monitoring app that renders server state via animated bouncing cows. The desired behaviour is that the application will cease to be scheduled if the session becomes idle (where idle is defined as the system having received no user input for 30 seconds) but that push notifications from the server still be received in order to allow the application to present the user with critical alerts.
Quoted 5 lines
This is a bit confusing - does the screen come back on for such events, what constraints is the server operating under ? How does your code look
- it's hard to imagine the examples you've given as being workable given they would block on network packet wait when a critical event occurs. Are you using poll or threads or what ?
It's code that's broadly identical to what I posted. The screen will come on if the event is critical, won't otherwise.
Quoted 19 lines
Quoted 12 lines
Under Android:
User puts down phone. 30 seconds later the screen turns off and releases the last user-level suspend block. The phone enters suspend and the application is suspended. A network packet is received, causing the network driver to take a suspend block. The application finishes the frame it was drawing, takes its own suspend block and reads the network packet. In doing so the network driver releases its suspend block, but since userspace is holding one the phone stays awake. The application then handles the event as necessary, releases its suspend block and the phone goes to sleep again.
Quoted 1 line
I don't see how this behaviour can be emulated in your model.
User puts down phone. 30 seconds later the X server decides to turn the screen off and closes the device. This probalby releases the constraint held via the display driver not to suspend. Any further draw requests will block.
Quoted 4 lines
System looks at the other tasks and sees they are idle and can sink to a low power state. Cows is either blocked on a packet receive or could even be blocked on writing to the display (or both if its a realistic example and using poll)
Even if it's using poll, it could block purely on the display if X turns the screen off between poll() waking and the write being made.
Quoted 11 lines
The kernel looks at the constraints it has
- must not sink to a state below which network receive of packets fails
- must not sink below a state where whatever is needed for the critical alert code etc to do its stuff
- must not sink to a state which takes more than [constraint] seconds to get back out ofIt picks 'opportunistic suspend'
It goes to sleep
Quoted 6 lines
A packet arrives
It wakes the hardware
We are busy, we do not wish to suspend
It processes the packet
It wakes the user app
It starts processing the packet
If it's blocked on the write then it only starts processing the packet again if the screen wakes up. You need to power up every piece of hardware that an application's blocked on, just in case they need to complete that read or write in order to get back to the event loop where they have the opportunity to read the network packet.
So, yes, I think this can work in that case. But it doesn't work in others - you won't idle applications that aren't accessing hardware drivers.
As an aside, I think this is a good idea in any case since a fringe benefit is the removal of the requirement to use the process freezer in suspend to RAM...
Quoted 3 lines
Stop transitioning
Run->ForcedSuspend. If you've got stuff stuck running then deal with it by constraining it to go idle or by blowing it out of the water. PM will then do the rest.
The problem is determining how to constrain it to go idle, where "idle" is defined as "Doesn't wake up until a wakeup event is received". It's acceptable for something to use as much CPU as it wants when the user is actively interacting with the device, but in most cases processes shouldn't be permitted to use any CPU when the session is idle. The question is how to implement something that allows a CPU-guzzling application to be idled without impairing its ability to process wakeup events.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 10 lines
The problem is determining how to constrain it to go idle, where "idle" is defined as "Doesn't wake up until a wakeup event is received". It's acceptable for something to use as much CPU as it wants when the user is actively interacting with the device, but in most cases processes shouldn't be permitted to use any CPU when the session is idle. The question is how to implement something that allows a CPU-guzzling application to be idled without impairing its ability to process wakeup events.
From your literal description:
setpriority. signal, process groups.
kill(-desktopgroup, SIGSTOP); kill(-desktopgroup, SIGCONT); kill(pid_i_am_crit_eventing, SIGCONT);
or SIGTSTP might be friendlier as a well behaved smart app can catch it, fire it into the event loop and elegantly save and sleep.
Some window managers played with doing setpriority for focussed windows. OLPC the same thing for OOM targets via /proc/oom_adj
The scheduler can happily do this, the power management will also recognize STOPPED processes as no impediment to suspend.
Quoted 2 lines · Alan Cox
The scheduler can happily do this, the power management will also recognize STOPPED processes as no impediment to suspend.
But wakeup events won't be delivered to STOPped processes, and there's also the race of an application being in the middle of handling a wakeup event when you send it the signal.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines · Alan Cox
The scheduler can happily do this, the power management will also recognize STOPPED processes as no impediment to suspend.
But wakeup events won't be delivered to STOPped processes, and there's also the race of an application being in the middle of handling a wakeup event when you send it the signal.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines · On Thu, 27 May 2010 20:29:26 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 2 lines · Alan Cox
The scheduler can happily do this, the power management will also recognize STOPPED processes as no impediment to suspend.
But wakeup events won't be delivered to STOPped processes, and there's
Try the following
cat <pipe
kill -STOP catpid
echo "wombats are cool" > pipe
kill -CONT catpid
it will echo "wombats are cool"
The event was not lost.
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()
Quoted 9 lines · Alan Cox
Quoted 1 line · On Thu, 27 May 2010 20:29:26 +0100 Matthew Garrett <[email protected]> wrote:
But wakeup events won't be delivered to STOPped processes, and there's
Try the following
cat <pipe
kill -STOP catpid
Quoted 6 lines
echo "wombats are cool" > pipe
kill -CONT catpidit will echo "wombats are cool"
The event was not lost.
Not lost, but not delivered. So you need your policy agent to send SIGCONT when you receive any wakeup event, which either means proxying all your network traffic through your policy agent or having some mechanism for alerting the policy agent whenever you leave the deep idle state.
Quoted 4 lines
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()
Doesn't help - I may be hit by the signal between the poll() unblocking and me having the opportunity to call sigmask().
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Alan Cox
Quoted 1 line · On Thu, 27 May 2010 20:29:26 +0100 Matthew Garrett <[email protected]> wrote:
But wakeup events won't be delivered to STOPped processes, and there's
Try the following
cat <pipe
kill -STOP catpid
Quoted 6 lines
echo "wombats are cool" > pipe
kill -CONT catpidit will echo "wombats are cool"
The event was not lost.
Not lost, but not delivered. So you need your policy agent to send SIGCONT when you receive any wakeup event, which either means proxying all your network traffic through your policy agent or having some mechanism for alerting the policy agent whenever you leave the deep idle state.
Quoted 4 lines
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()
Doesn't help - I may be hit by the signal between the poll() unblocking and me having the opportunity to call sigmask().
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines
Quoted 1 line
The event was not lost.
Not lost, but not delivered. So you need your policy agent to send
it will be delivered next time the process wakes. It's not lost.
Quoted 4 lines
SIGCONT when you receive any wakeup event, which either means proxying all your network traffic through your policy agent or having some mechanism for alerting the policy agent whenever you leave the deep idle state.
You didn't mention that requirement last time.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()Doesn't help - I may be hit by the signal between the
poll()unblocking and me having the opportunity to callsigmask().
ppoll(). This is all existing solved stuff.
Alan
Quoted 10 lines · Alan Cox
Quoted 1 line
Not lost, but not delivered. So you need your policy agent to send
it will be delivered next time the process wakes. It's not lost.
Quoted 4 lines
SIGCONT when you receive any wakeup event, which either means proxying all your network traffic through your policy agent or having some mechanism for alerting the policy agent whenever you leave the deep idle state.
You didn't mention that requirement last time.
I thought it was pretty obvious that wakeup events had to actually be delivered to the applications that are listening for them.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()Doesn't help - I may be hit by the signal between the
poll()unblocking and me having the opportunity to callsigmask().
ppoll(). This is all existing solved stuff.
Isn't that the inverse of what we want? The application should default to being SIGSTOPpable except in the case of it being in the process of having a specific event delivered.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 4 lines
Quoted 2 lines
Doesn't help - I may be hit by the signal between the
poll()unblocking and me having the opportunity to callsigmask().
ppoll(). This is all existing solved stuff.Isn't that the inverse of what we want? The application should default to being SIGSTOPpable except in the case of it being in the process of having a specific event delivered.
Would it help to divide the application into two processes, one of which receives events and the other does the drawing?
Alan Stern
Quoted 2 lines · Alan Stern
Would it help to divide the application into two processes, one of which receives events and the other does the drawing?
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Alan Stern
Would it help to divide the application into two processes, one of which receives events and the other does the drawing?
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Thank you for confirming that the so-called "feature" is just there to make apps work in some area that are crappy anyways - and God knows in which other areas they are crappy too.
SCNR,
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Quoted 7 lines · Bernd Petrovitsch
Quoted 2 lines · Matthew Garrett
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Thank you for confirming that the so-called "feature" is just there to make apps work in some area that are crappy anyways - and God knows in which other areas they are crappy too.
Kind of like memory protection, really. Or preemptive multitasking. Or many things that the kernel does to prevent badly written applications from interfering with other applications or the user's experience.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Bernd Petrovitsch
Quoted 2 lines · Matthew Garrett
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Thank you for confirming that the so-called "feature" is just there to make apps work in some area that are crappy anyways - and God knows in which other areas they are crappy too.
Kind of like memory protection, really. Or preemptive multitasking. Or many things that the kernel does to prevent badly written applications from interfering with other applications or the user's experience.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Matthew Garrett
Quoted 4 lines · Bernd Petrovitsch
Quoted 2 lines · Matthew Garrett
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Quoted 7 lines
Quoted 3 lines
Thank you for confirming that the so-called "feature" is just there to make apps work in some area that are crappy anyways - and God knows in which other areas they are crappy too.
Kind of like memory protection, really. Or preemptive multitasking. Or many things that the kernel does to prevent badly written applications from interfering with other applications or the user's experience.
With the main difference that their semantics and API is defined by the lower layer so that the lower layer can make useful - for the multitasking part - scheduling decisions.
There were other forms of multitasking before preemptive multitasking - coroutines (e.g. in Win-3.x quite late in IT history) and the like. So why not simply skip one step in evolution and go more directly to a useful solution?
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Quoted 5 lines · Matthew Garrett
Quoted 4 lines · Bernd Petrovitsch
Quoted 2 lines · Matthew Garrett
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Quoted 7 lines
Quoted 3 lines
Thank you for confirming that the so-called "feature" is just there to make apps work in some area that are crappy anyways - and God knows in which other areas they are crappy too.
Kind of like memory protection, really. Or preemptive multitasking. Or many things that the kernel does to prevent badly written applications from interfering with other applications or the user's experience.
With the main difference that their semantics and API is defined by the lower layer so that the lower layer can make useful - for the multitasking part - scheduling decisions.
There were other forms of multitasking before preemptive multitasking - coroutines (e.g. in Win-3.x quite late in IT history) and the like. So why not simply skip one step in evolution and go more directly to a useful solution?
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Quoted 7 lines · Matthew Garrett
Quoted 2 lines · Alan Stern
Would it help to divide the application into two processes, one of which receives events and the other does the drawing?
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Thank you for confirming that the so-called "feature" is just there to make apps work in some area that are crappy anyways - and God knows in which other areas they are crappy too.
SCNR,
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : [email protected] LUGA : http://www.luga.at
Quoted 2 lines · Alan Stern
Would it help to divide the application into two processes, one of which receives events and the other does the drawing?
At the point where you're rewriting the application you can just make it adhere to our current behavioural standards anyway.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 4 lines
Quoted 2 lines
Doesn't help - I may be hit by the signal between the
poll()unblocking and me having the opportunity to callsigmask().
ppoll(). This is all existing solved stuff.Isn't that the inverse of what we want? The application should default to being SIGSTOPpable except in the case of it being in the process of having a specific event delivered.
Would it help to divide the application into two processes, one of which receives events and the other does the drawing?
Alan Stern
Quoted 10 lines · Alan Cox
Quoted 1 line
Not lost, but not delivered. So you need your policy agent to send
it will be delivered next time the process wakes. It's not lost.
Quoted 4 lines
SIGCONT when you receive any wakeup event, which either means proxying all your network traffic through your policy agent or having some mechanism for alerting the policy agent whenever you leave the deep idle state.
You didn't mention that requirement last time.
I thought it was pretty obvious that wakeup events had to actually be delivered to the applications that are listening for them.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()Doesn't help - I may be hit by the signal between the
poll()unblocking and me having the opportunity to callsigmask().
ppoll(). This is all existing solved stuff.
Isn't that the inverse of what we want? The application should default to being SIGSTOPpable except in the case of it being in the process of having a specific event delivered.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines
Quoted 1 line
The event was not lost.
Not lost, but not delivered. So you need your policy agent to send
it will be delivered next time the process wakes. It's not lost.
Quoted 4 lines
SIGCONT when you receive any wakeup event, which either means proxying all your network traffic through your policy agent or having some mechanism for alerting the policy agent whenever you leave the deep idle state.
You didn't mention that requirement last time.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()Doesn't help - I may be hit by the signal between the
poll()unblocking and me having the opportunity to callsigmask().
ppoll(). This is all existing solved stuff.
Alan
Quoted 6 lines · On Thu, 27 May 2010 20:29:26 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 2 lines · Alan Cox
The scheduler can happily do this, the power management will also recognize STOPPED processes as no impediment to suspend.
But wakeup events won't be delivered to STOPped processes, and there's
Try the following
cat <pipe
kill -STOP catpid
echo "wombats are cool" > pipe
kill -CONT catpid
it will echo "wombats are cool"
The event was not lost.
Quoted 2 lines
also the race of an application being in the middle of handling a wakeup event when you send it the signal.
sigmask()
Quoted 10 lines
The problem is determining how to constrain it to go idle, where "idle" is defined as "Doesn't wake up until a wakeup event is received". It's acceptable for something to use as much CPU as it wants when the user is actively interacting with the device, but in most cases processes shouldn't be permitted to use any CPU when the session is idle. The question is how to implement something that allows a CPU-guzzling application to be idled without impairing its ability to process wakeup events.
From your literal description:
setpriority. signal, process groups.
kill(-desktopgroup, SIGSTOP); kill(-desktopgroup, SIGCONT); kill(pid_i_am_crit_eventing, SIGCONT);
or SIGTSTP might be friendlier as a well behaved smart app can catch it, fire it into the event loop and elegantly save and sleep.
Some window managers played with doing setpriority for focussed windows. OLPC the same thing for OOM targets via /proc/oom_adj
The scheduler can happily do this, the power management will also recognize STOPPED processes as no impediment to suspend.
Quoted 2 lines · Matthew Garrett
Even if it's using poll, it could block purely on the display if X turns the screen off between
poll()waking and the write being made.
That's what fcntl(fd, F_SETFL, O_NONBLOCK) is for.
Quoted 2 lines · Matthew Garrett
Even if it's using poll, it could block purely on the display if X turns the screen off between
poll()waking and the write being made.
That's what fcntl(fd, F_SETFL, O_NONBLOCK) is for.
Quoted 2 lines
Yes, there's no problem so far. The question is how you guarantee that the application has had the opportunity to handle the packet.
Because the application has said that it wants QoS guarantees. It wants to know that if the events it can receive occur it will wake up within the timescale.
So it receives the event. It's now running, not idle so we won't suspend it.
At some point in time it will become idle again _or_ the CPU limit will get it.
If the app is not trusted then we might suspend it before it handles the packet. That is fine, it's not trusted and we will do that when we decide its in the system interest to suspend it anyway.
You still don't lose the event because on resume the task will do its processing.
Quoted 7 lines
The application is a network monitoring app that renders server state via animated bouncing cows. The desired behaviour is that the application will cease to be scheduled if the session becomes idle (where idle is defined as the system having received no user input for 30 seconds) but that push notifications from the server still be received in order to allow the application to present the user with critical alerts.
This is a bit confusing - does the screen come back on for such events, what constraints is the server operating under ? How does your code look
- it's hard to imagine the examples you've given as being workable given they would block on network packet wait when a critical event occurs. Are you using poll or threads or what ?
Quoted 12 lines
Under Android:
User puts down phone. 30 seconds later the screen turns off and releases the last user-level suspend block. The phone enters suspend and the application is suspended. A network packet is received, causing the network driver to take a suspend block. The application finishes the frame it was drawing, takes its own suspend block and reads the network packet. In doing so the network driver releases its suspend block, but since userspace is holding one the phone stays awake. The application then handles the event as necessary, releases its suspend block and the phone goes to sleep again.
Quoted 1 line
I don't see how this behaviour can be emulated in your model.
User puts down phone. 30 seconds later the X server decides to turn the screen off and closes the device. This probalby releases the constraint held via the display driver not to suspend. Any further draw requests will block.
System looks at the other tasks and sees they are idle and can sink to a low power state. Cows is either blocked on a packet receive or could even be blocked on writing to the display (or both if its a realistic example and using poll)
Everyone is idle, we can sleep
The kernel looks at the constraints it has
- must not sink to a state below which network receive of packets fails
- must not sink below a state where whatever is needed for the critical alert code etc to do its stuff
- must not sink to a state which takes more than [constraint] seconds to get back out of
It picks 'opportunistic suspend'
It goes to sleep
A packet arrives
It wakes the hardware
We are busy, we do not wish to suspend
It processes the packet
It wakes the user app
It starts processing the packet
[We are busy, we do not wish to suspend]
Presumably your display server listens to waking back up and decides to re-activate the screen (your example is unclear and implies it carries on processing the extra frame in the dark which seems a bit silly ?
I still don't see a problem.
I think your problem arises because you start from the basis that forcing suspend is special. As Thomas has said there are working implementations where suspend is an idle mode.
The moment you discard that specific notion everything works, as it does today on other embedded platforms.
Now what do you do if the app is burning too much processor time. That's a QoS question too. We've got cpu limits, we've got SIGXCPU, we don't have "cpu per second" type limits but that isn't hard to do either.
Stop transitioning Run->Forced Suspend. If you've got stuff stuck running then deal with it by constraining it to go idle or by blowing it out of the water. PM will then do the rest.
Quoted 12 lines · Alan Cox
Quoted 11 lines
This is still racy. Going back to this:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))while (1) { if (read(input, &foo, 1) > 0) { (do something) } else { * SUSPEND OCCURS HERE *
Quoted 4 lines
Fine but then the packet will arrive and we will wake back up process the packet and wake the task. See suspend is just like a deep sleep. If we went to sleep there and the packet arrival doesn't rewake the box the driver was buggy.
Yes, there's no problem so far. The question is how you guarantee that the application has had the opportunity to handle the packet.
Quoted 9 lines
Quoted 4 lines
reaches the end of its timeslice. At this point the application has not had an opportunity to indicate in any way whether or not the packet has altered its constraints in any way. What stops us from immediately suspending again?
If my app level constraint before the packet is 'don't suspend' then my constraint on receipt is 'don't suspend' so I won't suspend. If my constraint is then lowered and I suspend I will suspend *after* the lowering.
If the app level constraint before the packet was "don't suspend", we wouldn't have suspended. Here's a description of the desired behaviour of the application as you requested:
The application is a network monitoring app that renders server state via animated bouncing cows. The desired behaviour is that the application will cease to be scheduled if the session becomes idle (where idle is defined as the system having received no user input for 30 seconds) but that push notifications from the server still be received in order to allow the application to present the user with critical alerts.
Under Android:
User puts down phone. 30 seconds later the screen turns off and releases the last user-level suspend block. The phone enters suspend and the application is suspended. A network packet is received, causing the network driver to take a suspend block. The application finishes the frame it was drawing, takes its own suspend block and reads the network packet. In doing so the network driver releases its suspend block, but since userspace is holding one the phone stays awake. The application then handles the event as necessary, releases its suspend block and the phone goes to sleep again.
I don't see how this behaviour can be emulated in your model.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 1 line
network packet arrives. The difference between these scenarios is large.
Your application seems to change desired outcome every email. Sorry but you need to explicitly explain and define a policy in full that we can test ideas against. Otherwise this is useless.
Quoted 13 lines
Quoted 6 lines
If you have wake-on-lan then the network stack might be smarter and choose to express itself as
'the constraint is C6 unless the input queue is empty in which
case suspend is ok as I have WoL and my network routing is such that I can prove that interface will be used'This is still racy. Going back to this:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))
Quoted 5 lines
while (1) {
if (read(input, &foo, 1) > 0) {
(do something)
} else {
* SUSPEND OCCURS HERE *Fine but then the packet will arrive and we will wake back up process the packet and wake the task. See suspend is just like a deep sleep. If we went to sleep there and the packet arrival doesn't rewake the box the driver was buggy.
Quoted 4 lines
reaches the end of its timeslice. At this point the application has not had an opportunity to indicate in any way whether or not the packet has altered its constraints in any way. What stops us from immediately suspending again?
If my app level constraint before the packet is 'don't suspend' then my constraint on receipt is 'don't suspend' so I won't suspend. If my constraint is then lowered and I suspend I will suspend *after* the lowering.
If my constraint is tightened then the decision to tighten is run under the previous constraint. Which is fine, because if I have a case where I must tighten my constraint within the tight constraint time I've screwed up my app and need to fix it.
In reality almost all your userspace is going to look like 'trusted app' or 'untrusted app' in droidthink and won't be transitioning in user space (but may well be adding/losing kernel constraints)
This is good because it's another thing app authors don't have to care about. It's good because apps can be run trusted/untrusted without recompiling.
Alan
Quoted 6 lines · Alan Cox
Quoted 2 lines · On Thu, 27 May 2010 17:07:14 +0100 Matthew Garrett <[email protected]> wrote:
Perhaps set after callbacks are made. But given that the approach doesn't work anyway...
Which approach doesn't work, and why ?
Sorry, using cgroups and scheduler tricks as a race-free replacement for opportunistic suspend.
Quoted 15 lines
Quoted 15 lines
It's still racy. Going back to my example without any of the suspend blocking code, but using a network socket rather than an input device:
int input =
socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))while (1) { if (read(input, &foo, 1) > 0) { (do something) } else { (draw bouncing cows and clouds and tractor beams briefly) } }
Quoted 8 lines
Quoted 2 lines
A network packet arrives while we're drawing. Before we finish drawing, the policy timeout expires and the screen turns off.
Which is correct for a badly behaved application. You said you wanted to constrain it. You've done so. Now I am not sure why such a "timeout" would expire in the example as the task is clearly busy when drawing, or is talking to someone else who is in turn busy. Someone somewhere is actually drawing be it a driver or app code.
The timeout would be at the userspace platform level. If I haven't touched the app for 30 seconds (and if the app hasn't taken any form of suspend block), the screen should turn off. In the current Android implementation that will then (in the absence of any kernel-level suspend blockers) result in the system transitioning into a fully suspended state.
Quoted 4 lines
For a well behaved application you are drawing so you are running drawing stuff so why would you suspend. The app has said it has a latency constraint that suspend cannot meet, or has a device open that cannot meet the constraints in suspend.
Not at all. The fact that the application hasn't taken any sort of suspend block means that the application has indicated that it's happy with no longer being scheduled when the screen is shut off, *providing there's no wakeup event to be processed*.
Quoted 5 lines
You also have the socket open so you can meaningfully extract resource constraint information from that fact.
See it's not the
read()that matters, it's the connect and the close.
Quoted 7 lines
If your policy for a well behaved application is 'thou shalt not suspend in a way that breaks its networking' then for a well behaving app once I connect the socket we cannot suspend that app until such point as the app closes the socket. At any other point we will break the connection. Whether that is desirable is a policy question and you get to pick how much you choose to trust an app and how you interpret the information in your cpufreq and suspend drivers.
Again, that's not the desired outcome. The desired outcome is that when the screen shuts off, the application no longer gets scheduled until a network packet arrives. The difference between these scenarios is large.
Quoted 6 lines
If you have wake-on-lan then the network stack might be smarter and choose to express itself as
'the constraint is C6 unless the input queue is empty in which
case suspend is ok as I have WoL and my network routing is such that I can prove that interface will be used'
This is still racy. Going back to this:
int input = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))
while (1) {
if (read(input, &foo, 1) > 0) {
(do something)
} else {
* SUSPEND OCCURS HERE *
(draw bouncing cows and clouds and tractor beams briefly)
}
}A wakeup event now arrives. We use kernel level suspend blockers to prevent the system from going back to sleep until userspace has read the packet. The application finishes drawing its cows, reads the packet (thus releasing the kernel-level suspend block) and them immediately reaches the end of its timeslice. At this point the application has not had an opportunity to indicate in any way whether or not the packet has altered its constraints in any way. What stops us from immediately suspending again?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Alan Cox
Quoted 4 lines
Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag
I would hope not, because I'd rather prefer my app that used the screen to get the chance to save important data on what it was doing irrespective of the screen blank: "I have an elegant proof for this problem but my battery has gone flat"
Perhaps set after callbacks are made. But given that the approach doesn't work anyway...
Quoted 2 lines
What is the problem here - your device driver for the display can block tasks it doesn't want to use the display.
It's still racy. Going back to my example without any of the suspend blocking code, but using a network socket rather than an input device:
int input = socket(AF_INET, SOCK_STREAM|SOCK_NONBLOCK, 0); char foo;
struct sockaddr addr;
connect (input, &addr, sizeof(addr))
while (1) {
if (read(input, &foo, 1) > 0) {
(do something)
} else {
(draw bouncing cows and clouds and tractor beams briefly)
}
}A network packet arrives while we're drawing. Before we finish drawing, the policy timeout expires and the screen turns off. The app's drawing is blocked and so never gets to the point of reading the socket. The wakeup event has been lost.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 51 lines · Matthew Garrett
Quoted 11 lines · Alan Cox
- Supporting Android needs well good
- Opportunistic suspend good
- Manner in which interface is expressed to userspace bad
- Latency constraint interface would be better
- Your existing behaviour can be implemented by a simplistic use of a latency constraint interface
- We can fix a pile of other directly connected things at the same time
- Implementation internals I care far less about because we can fix those later
- Suspend is just a power stateQuoted 1 line
How does that fit your model and vision ?
I don't entirely see how this works. In order to deal with poorly written applications, it's necessary to (optionally, based on some policy) ignore them when it comes to the scheduler. The problem is how to implement the optional nature of this in a race-free manner. This is obviously a pathological case, but imagine an application that does something along the following lines:
int input = open ("
/dev/input", O_RDONLY|O_NONBLOCK); char foo;while (1) { suspend_block(); if (read(input, &foo, 1) > 0) { (do something) suspend_unblock(); } else { suspend_unblock(); (draw bouncing cows and clouds and tractor beams briefly) } }Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.Except that doesn't work. If the session goes idle in the middle of the app drawing a frame, we'll stop the process and the task will never call
read(). So the user hits a key, we wake up, nothing shifts fromTASK_INTERRUPTIBLEintoTASK_RUNNING, the key never gets read, we go back to sleep. The event never gets delivered.
Quoted 7 lines
Now let's try this in the Android world. The user hits a key and the system wakes up. The input layer takes a suspend block. The application now draws all the cows it wants to, takes its own suspend block and reads the input device. This empties the queue and the kernel-level suspend block is released. The application then processes the event before releasing the suspend block. The event has been delivered and handled.
Thanks for providing this example:
1) It proves that suspend blockers are solely designed to encourage people to code crap.
2) It exposes the main conceptual problem of the approach:
The input layer in the kernel magically takes a suspend blocker and releases it in an equally magic way just to allow the crappy application to reach the point where it takes it's own suspend blocker and can react on the user input.
And you need to do that, because the user applications suspend blocker magic is racy as hell. To work around that you sprinkle your suspend blocker magic all over the kernel instead of telling people how to solve the problem correctly.
And what are you achieving with this versus power saving ?
Exaclty _NOTHING_ !
Simply because you move the cow drawing CPU time from the point where the device wants to go into suspend to the point where the user hits a key again. You even delay the reaction of your app to the user input by the time it needs to finish drawing cows.
So you need to come up with a way better example why you need your blockers than with this prove of misconception.
Quoted 4 lines
You can't express that with resource limits or QoS constraints. If you want to deal with this kind of situation then, as far as I can tell, you need either suspend blockers or something so close to them that it makes no difference.
Wrong. If your application is interactive then you set the QoS requirement once to interactive and be done.
So the correct point to make a power state decision is when the app waits for a key press. At this point the kernel can take several pathes:
1) Keep the system alive because the input device is in active state and a key press is expected
2) Go into supsend because the input device is deactivated after the screen lock kicked in.
This behaves exactly the same way in terms of power consumption as your blocker example just without all the mess you are trying to create.
And it allows the kernel to use intermediate power saving methods (between idle and suspend) which might be available on some hardware.
Thanks,
tglx
Quoted 51 lines · Matthew Garrett
Quoted 11 lines · Alan Cox
- Supporting Android needs well good
- Opportunistic suspend good
- Manner in which interface is expressed to userspace bad
- Latency constraint interface would be better
- Your existing behaviour can be implemented by a simplistic use of a latency constraint interface
- We can fix a pile of other directly connected things at the same time
- Implementation internals I care far less about because we can fix those later
- Suspend is just a power stateQuoted 1 line
How does that fit your model and vision ?
I don't entirely see how this works. In order to deal with poorly written applications, it's necessary to (optionally, based on some policy) ignore them when it comes to the scheduler. The problem is how to implement the optional nature of this in a race-free manner. This is obviously a pathological case, but imagine an application that does something along the following lines:
int input = open ("
/dev/input", O_RDONLY|O_NONBLOCK); char foo;while (1) { suspend_block(); if (read(input, &foo, 1) > 0) { (do something) suspend_unblock(); } else { suspend_unblock(); (draw bouncing cows and clouds and tractor beams briefly) } }Now, if the user is playing this game, you want it to be scheduled. If the user has put down their phone and the screen lock has kicked in, you don't want it to be scheduled. So we could imagine some sort of cgroup that contains untrusted tasks - when the session is active we set a flag one way which indicates to the scheduler that tasks in
TASK_RUNNINGshould be scheduled, and when the session is idle we set the flag the other way and all processes in that cgroup get shifted toTASK_INTERRUPTIBLEor something.Except that doesn't work. If the session goes idle in the middle of the app drawing a frame, we'll stop the process and the task will never call
read(). So the user hits a key, we wake up, nothing shifts fromTASK_INTERRUPTIBLEintoTASK_RUNNING, the key never gets read, we go back to sleep. The event never gets delivered.
Quoted 7 lines
Now let's try this in the Android world. The user hits a key and the system wakes up. The input layer takes a suspend block. The application now draws all the cows it wants to, takes its own suspend block and reads the input device. This empties the queue and the kernel-level suspend block is released. The application then processes the event before releasing the suspend block. The event has been delivered and handled.
Thanks for providing this example:
1) It proves that suspend blockers are solely designed to encourage people to code crap.
2) It exposes the main conceptual problem of the approach:
The input layer in the kernel magically takes a suspend blocker and releases it in an equally magic way just to allow the crappy application to reach the point where it takes it's own suspend blocker and can react on the user input.
And you need to do that, because the user applications suspend blocker magic is racy as hell. To work around that you sprinkle your suspend blocker magic all over the kernel instead of telling people how to solve the problem correctly.
And what are you achieving with this versus power saving ?
Exaclty _NOTHING_ !
Simply because you move the cow drawing CPU time from the point where the device wants to go into suspend to the point where the user hits a key again. You even delay the reaction of your app to the user input by the time it needs to finish drawing cows.
So you need to come up with a way better example why you need your blockers than with this prove of misconception.
Quoted 4 lines
You can't express that with resource limits or QoS constraints. If you want to deal with this kind of situation then, as far as I can tell, you need either suspend blockers or something so close to them that it makes no difference.
Wrong. If your application is interactive then you set the QoS requirement once to interactive and be done.
So the correct point to make a power state decision is when the app waits for a key press. At this point the kernel can take several pathes:
1) Keep the system alive because the input device is in active state and a key press is expected
2) Go into supsend because the input device is deactivated after the screen lock kicked in.
This behaves exactly the same way in terms of power consumption as your blocker example just without all the mess you are trying to create.
And it allows the kernel to use intermediate power saving methods (between idle and suspend) which might be available on some hardware.
Thanks,
tglx
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Matthew Garrett
Now let's try this in the Android world. The user hits a key and the system wakes up. The input layer takes a suspend block. The application now draws all the cows it wants to, takes its own suspend block and reads the input device. This empties the queue and the kernel-level suspend block is released. The application then processes the event before releasing the suspend block. The event has been delivered and handled.
Quoted 4 lines
Thanks for providing this example:
1) It proves that suspend blockers are solely designed to encourage people to code crap.
No. Suspend blockers are designed to ensure that suspend isn't racy with respect to wakeup events. The bit that mitigates badly written applications is the bit where the scheduler doesn't run any more.
If you're happy with a single badly written application being able to cripple your power management story, you don't need opportunistic suspend. But you still have complications when it comes to deciding to enter suspend at the same time as you receive a wakeup event.
Quoted 4 lines
And you need to do that, because the user applications suspend blocker magic is racy as hell. To work around that you sprinkle your suspend blocker magic all over the kernel instead of telling people how to solve the problem correctly.
What /is/ the correct way to solve this problem when entering explicit suspend states? How do you guarantee that an event has been delivered to userspace before transitioning into suspend? Now, this is a less interesting problem if you're not using opportunistic suspend, but it's still a problem.
Quoted 4 lines
Simply because you move the cow drawing CPU time from the point where the device wants to go into suspend to the point where the user hits a key again. You even delay the reaction of your app to the user input by the time it needs to finish drawing cows.
It's how application mainloops tend to work.
Quoted 12 lines
Quoted 4 lines
You can't express that with resource limits or QoS constraints. If you want to deal with this kind of situation then, as far as I can tell, you need either suspend blockers or something so close to them that it makes no difference.
Wrong. If your application is interactive then you set the QoS requirement once to interactive and be done.
So the correct point to make a power state decision is when the app waits for a key press. At this point the kernel can take several pathes:
Quoted 5 lines
1) Keep the system alive because the input device is in active state and a key press is expected
2) Go into supsend because the input device is deactivated after the screen lock kicked in.
That's no good. If the input device has been deactivated, how does the wakeup event get delivered to the application?
Quoted 3 lines
This behaves exactly the same way in terms of power consumption as your blocker example just without all the mess you are trying to create.
And means that wakeup events don't get delivered. That's a shortcoming.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines
No. Suspend blockers are designed to ensure that suspend isn't racy with respect to wakeup events. The bit that mitigates badly written applications is the bit where the scheduler doesn't run any more.
How does having applications taking blockers fix that - it makes it worse. They are now blocking the kernel doing the right job.
Quoted 2 lines
If you're happy with a single badly written application being able to cripple your power management story, you don't need opportunistic
And taking a suspend blocker isn't "crippling your power management" ???
Quoted 5 lines
What /is/ the correct way to solve this problem when entering explicit suspend states? How do you guarantee that an event has been delivered to userspace before transitioning into suspend? Now, this is a less interesting problem if you're not using opportunistic suspend, but it's still a problem.
The same way as we deal with low power states on other non PC devices ?
Quoted 2 lines
That's no good. If the input device has been deactivated, how does the wakeup event get delivered to the application?
If the input device is letting itself get de-activated in a way that can lose events the input device driver is buggy. It's nobody elses business how it does the its job, and certainly *not* the applications.
That's a kernel internal issue.
You know the resource constraint exists because the driver knows it is open
Your QoS guarantees tell you what you desired latency of response at the point you can become ready is.
That's all your need to do it right.
In kernel yes your device driver probably does need to say things like 'Don't go below C6 for a moment' just as a high speed serial port might want to say 'Nothing over 10mS please'
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
So you need
Userspace -> QoS guarantee expression, implied resource
expression via device use. *NO* knowledge of device or platform in the application
Kernel space
Drivers -> Explicit guarantee expression not bound to
tasks. Driver encapsulates the variety in the device hardware and expresses it in a uniform manner to the idling/suspend logic
CPU Freq -> Encapsulates the variety in the CPU and core
power functionality of devices, makes policy based upon the uniform express from the drivers and tasks
All the autonomy is now in the right places, and we have requisite variety to actually manage the situation.
Alan
Quoted 4 lines · Alan Cox
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines · Alan Cox
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Alan Cox
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
Quoted 6 lines
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Opportunistic suspend is just a deep idle state, nothing else. If the overall QoS requirements allow to enter that deep idle state then the kernel goes there. Same decision as for all other idle states. You don't need any user space blocker for this decision, just sensible QoS information.
Stop thinking about suspend as a special mechanism. It's not - except for s2disk, which is an entirely different beast.
Thanks,
tglx
Quoted 9 lines · Thomas Gleixner
Quoted 6 lines · Matthew Garrett
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Quoted 2 lines
Stop thinking about suspend as a special mechanism. It's not - except for s2disk, which is an entirely different beast.
On PCs, suspend has more in common with s2disk than it does C states.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Matthew Garrett
Quoted 8 lines · Thomas Gleixner
Quoted 6 lines · Matthew Garrett
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Quoted 4 lines
Quoted 1 line
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Quoted 8 lines
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
Because you may then block them in such a way that they never handle an event that should wake them.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Quoted 8 lines
Quoted 5 lines
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
Because you may then block them in such a way that they never handle an event that should wake them.
*blink*, do explain?
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
Pretty much the same for everything else, input events, WoL etc..
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Quoted 8 lines
Quoted 5 lines
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
Because you may then block them in such a way that they never handle an event that should wake them.
*blink*, do explain?
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
Pretty much the same for everything else, input events, WoL etc..
Quoted 5 lines · Peter Zijlstra
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Peter Zijlstra
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Why would you care about the screen for a network event?
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Matthew Garrett
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
Quoted 11 lines · Peter Zijlstra
Quoted 5 lines · Matthew Garrett
Quoted 1 line · Peter Zijlstra
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Matthew Garrett
Quoted 1 line · Peter Zijlstra
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Quoted 7 lines
Quoted 4 lines
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Since we're talking about a purely idle driven power saving, we wait until the cpu is idle.
Note that it doesn't need to broadcast this, it could opt to reply with that message on the first drawing attempt after it goes away and block on the second.
Quoted 4 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
Quoted 2 lines · Peter Zijlstra
Then that's an application bug right there, isn't it?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Since we're talking about a purely idle driven power saving, we wait until the cpu is idle.
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 3 lines
Note that it doesn't need to broadcast this, it could opt to reply with that message on the first drawing attempt after it goes away and block on the second.
That's more interesting, but you're changing semantics quite heavily at this point.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Quoted 6 lines
Quoted 3 lines
Note that it doesn't need to broadcast this, it could opt to reply with that message on the first drawing attempt after it goes away and block on the second.
That's more interesting, but you're changing semantics quite heavily at this point.
So?
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events. So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 5 lines
Quoted 2 lines
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events.
It will, when it gets unblocked from whatever thing it got stuck on.
Quoted 2 lines
So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
Uhm, how again is blocking a badly behaved app causing harm to the well behaved one?
The well behaved one didn't get blocked and still happily waiting (on its own accord, in sys_poll() or something) for something to happen, if it would get an event it'd be placed on the runqueue and do its thing.
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 5 lines
Quoted 2 lines
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events.
It will, when it gets unblocked from whatever thing it got stuck on.
Quoted 2 lines
So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
Uhm, how again is blocking a badly behaved app causing harm to the well behaved one?
The well behaved one didn't get blocked and still happily waiting (on its own accord, in sys_poll() or something) for something to happen, if it would get an event it'd be placed on the runqueue and do its thing.
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events.
It will, when it gets unblocked from whatever thing it got stuck on.
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines · Matthew Garrett
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Its blocked because its a buggy app, who cares about misbehaviour in a buggy app?
If it were a proper app it wouldn't have gotten blocked and would've been able to receive the network packet.
I thought we'd already been over this?
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Its blocked because its a buggy app, who cares about misbehaviour in a buggy app?
So why bother blocking? Just kill the app and tell the user. If you want to support suboptimal apps then blocking isn't sufficient. If you don't want to then blocking isn't necessary.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Its blocked because its a buggy app, who cares about misbehaviour in a buggy app?
So why bother blocking? Just kill the app and tell the user. If you want to support suboptimal apps then blocking isn't sufficient. If you don't want to then blocking isn't necessary.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 2 lines · Matthew Garrett
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Its blocked because its a buggy app, who cares about misbehaviour in a buggy app?
If it were a proper app it wouldn't have gotten blocked and would've been able to receive the network packet.
I thought we'd already been over this?
Quoted 12 lines · On Thu, 27 May 2010 19:17:58 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Matthew Garrett
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events.
It will, when it gets unblocked from whatever thing it got stuck on.
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Thats a stupid argument. If you write broken code then it doesn't work. You know if I do
ls < unopenedfifo
it blocks too.
There is a difference between dealing with apps that overconsume resources and arbitarily broken code (which your suspend blocker case doesn't fix either but makes worse).
Can we stick to sane stuff ?
Quoted 12 lines · On Thu, 27 May 2010 19:17:58 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Matthew Garrett
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events.
It will, when it gets unblocked from whatever thing it got stuck on.
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Thats a stupid argument. If you write broken code then it doesn't work. You know if I do
ls < unopenedfifo
it blocks too.
There is a difference between dealing with apps that overconsume resources and arbitarily broken code (which your suspend blocker case doesn't fix either but makes worse).
Can we stick to sane stuff ?
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events.
It will, when it gets unblocked from whatever thing it got stuck on.
It's blocked on the screen being turned off. It's supposed to be reading a network packet. How does it ever get to reading the network packet?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · On Thu, 27 May 2010 18:59:20 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 7 lines
Quoted 2 lines
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events. So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
I don't see how you put the first two sentences together and get the final one.
When you beat up badly behaved apps that doesn't penalise well behaved ones.
Forcing "well behaved apps" to make hundreds of extra calls to a complex blocker interface that also requires tons of kernel code and requires the application know platform policy and be recompiled if it changes - now that is punishing well behaved apps.
A well behaved app should just work using standard existing APIs because that is how all the standard current well behaved apps are written [1].
Alan
--
[1] I'm dying to see the suspend blocker patch for evolution ;)
Quoted 7 lines · Alan Cox
Quoted 4 lines · On Thu, 27 May 2010 18:59:20 +0100 Matthew Garrett <[email protected]> wrote:
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events. So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
Quoted 5 lines
I don't see how you put the first two sentences together and get the final one.
When you beat up badly behaved apps that doesn't penalise well behaved ones.
If you're going to block an app on drawing then you either need to reenable drawing on wakeup or you need to have an interface for alerting the app to the fact that drawing is about to block and it should get back to its event loop. The first is suboptimal, the second penalises well behaved apps.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Alan Cox
Quoted 4 lines · On Thu, 27 May 2010 18:59:20 +0100 Matthew Garrett <[email protected]> wrote:
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events. So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
Quoted 5 lines
I don't see how you put the first two sentences together and get the final one.
When you beat up badly behaved apps that doesn't penalise well behaved ones.
If you're going to block an app on drawing then you either need to reenable drawing on wakeup or you need to have an interface for alerting the app to the fact that drawing is about to block and it should get back to its event loop. The first is suboptimal, the second penalises well behaved apps.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Ok. So the existing badly-behaved application ignores your request and then gets blocked. And now it no longer responds to wakeup events. So you penalise well-behaved applications without providing any benefits to badly-behaved ones.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 3 lines · Matthew Garrett
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Correct, a well behaved app would have. I thought we all agreed that well behaved apps weren't the problem?
Quoted 6 lines
Quoted 3 lines
Note that it doesn't need to broadcast this, it could opt to reply with that message on the first drawing attempt after it goes away and block on the second.
That's more interesting, but you're changing semantics quite heavily at this point.
So?
Quoted 4 lines · Peter Zijlstra
Quoted 3 lines · Matthew Garrett
Quoted 2 lines · Peter Zijlstra
Then that's an application bug right there, isn't it?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Since we're talking about a purely idle driven power saving, we wait until the cpu is idle.
If that's what you're aiming for then you don't need to block applications on hardware access because they should all already have idled themselves.
Quoted 3 lines
Note that it doesn't need to broadcast this, it could opt to reply with that message on the first drawing attempt after it goes away and block on the second.
That's more interesting, but you're changing semantics quite heavily at this point.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Matthew Garrett
Quoted 1 line · Peter Zijlstra
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Quoted 7 lines
Quoted 4 lines
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Very realistic scenario on a mobile phone.
Quoted 5 lines · Thomas Gleixner
Quoted 2 lines · Matthew Garrett
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Very realistic scenario on a mobile phone.
If the aim is to produce a solution that isn't special-cased to specific devices, thinking about how long an application may take to respond is entirely relevant.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Thomas Gleixner
Quoted 2 lines · Matthew Garrett
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Very realistic scenario on a mobile phone.
If the aim is to produce a solution that isn't special-cased to specific devices, thinking about how long an application may take to respond is entirely relevant.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Matthew Garrett
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Matthew Garrett
Quoted 1 line · Peter Zijlstra
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Quoted 7 lines
Quoted 4 lines
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Very realistic scenario on a mobile phone.
Quoted 11 lines · Peter Zijlstra
Quoted 5 lines · Matthew Garrett
Quoted 1 line · Peter Zijlstra
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
How long do you wait for applications to respond that they've stopped drawing? What if the application is heavily in swap at the time?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Matthew Garrett
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Then that's an application bug right there, isn't it?
If should have listened to the window server telling its clients it was going to go away. Drawing after you get that is your own damn fault ;-)
Quoted 5 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Why would you care about the screen for a network event?
Because the application that needs to handle the network packet is currently blocked trying to draw something to the screen.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 10 lines · Matthew Garrett
Quoted 5 lines · Peter Zijlstra
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Why would you care about the screen for a network event?
Quoted 10 lines · On Thu, 27 May 2010 18:25:10 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 5 lines · Peter Zijlstra
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Well on my laptop today it works like this
A WoL packet arrives
The CPU resumes
Depp process, chipset and laptop BIOS magic happens
The kernel gets called
The kernel lets interested people know a resume occurred
The X server sees this
X reconfigures the display
X redraws the display (either by sending everyone expose events or by keeping the bits, not sure how it works this week as it has changed over time)
My desktop re-appears
Alan
Quoted 5 lines · Alan Cox
Quoted 2 lines · On Thu, 27 May 2010 18:25:10 +0100 Matthew Garrett <[email protected]> wrote:
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Quoted 7 lines
Well on my laptop today it works like this
A WoL packet arrives
The CPU resumes
Depp process, chipset and laptop BIOS magic happens The kernel gets called
The kernel lets interested people know a resume occurred
No it doesn't. The kernel continues executing anything that was on the runqueue before the scheduler stopped. If you're using idle-based suspend then there's nothing on the runqueue - the application that should be scheduled because of the event is blocked on writing to the screen.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · On Thu, 27 May 2010 22:36:35 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 7 lines · Alan Cox
Quoted 2 lines · On Thu, 27 May 2010 18:25:10 +0100 Matthew Garrett <[email protected]> wrote:
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Well on my laptop today it works like this
Quoted 7 lines
Quoted 5 lines
A WoL packet arrives
The CPU resumes
Depp process, chipset and laptop BIOS magic happens The kernel gets called
The kernel lets interested people know a resume occurredNo it doesn't. The kernel continues executing anything that was on the
Would you like to come and watch my laptop resume ? With printk's if you want. You appear at this point to be arguing that bumble bees can't fly, while watching one.
Quoted 4 lines
runqueue before the scheduler stopped. If you're using idle-based suspend then there's nothing on the runqueue - the application that should be scheduled because of the event is blocked on writing to the screen.
IFF its your bogus example
IFF you don't have any task waiting for resume notifications (ie its not
X)
So take the PC desktop case and for simplicity sake lets assume the X application in question has either filled the socket (unlikely) or is mid query request so blocked on the socket.
The important line then is
'The kernel lets interested people know a resume occurred'
Interesting people includes X
X therefore ends up on the runqueue
X gets the display back in order
X completes processing the outstanding X request and replies The application continues
If I was blocked on say serial output then the resume is going to wake the serial driver, which will transmit the queue, which will wake the app.
Alan
Quoted 7 lines · Alan Cox
Quoted 1 line · On Thu, 27 May 2010 22:36:35 +0100 Matthew Garrett <[email protected]> wrote:
No it doesn't. The kernel continues executing anything that was on the
Would you like to come and watch my laptop resume ? With printk's if you want. You appear at this point to be arguing that bumble bees can't fly, while watching one.
The kernel performs no explicit notification to userspace. With legacy graphics setups you'll get a VT switch, but X is entirely unaware that that's due to suspend and that's going away in any case. On a typical setup it's not even the kernel that does the VT switch to and from X - that's handled by a script that happens to be on the runqueue. So yeah, things kind of work as you suggest right now - but only by accident, not design. What you're describing requires a new interface to inform interested bits of userspace whenever you transition from your deep idle state into a less deep one.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 1 line
The kernel performs no explicit notification to userspace. With legacy
For a PC ACPI using type device /proc/acpi/events which wakes acpid which wakes gnome-power-manager which wakes half the universe
Do we need a better more generic version of the events files - maybe but thats a rather different kettle of fish to suspend blockers.
Alan
Quoted 4 lines · Alan Cox
Quoted 1 line
The kernel performs no explicit notification to userspace. With legacy
For a PC ACPI using type device
/proc/acpi/eventswhich wakes acpid which wakes gnome-power-manager which wakes half the universe
No, there's no explicit /proc/acpi/event notification on resume.
Quoted 2 lines
Do we need a better more generic version of the events files - maybe but thats a rather different kettle of fish to suspend blockers.
It's a requirement for any reasonable alternative approach.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines · Alan Cox
Quoted 1 line
The kernel performs no explicit notification to userspace. With legacy
For a PC ACPI using type device
/proc/acpi/eventswhich wakes acpid which wakes gnome-power-manager which wakes half the universe
No, there's no explicit /proc/acpi/event notification on resume.
Quoted 2 lines
Do we need a better more generic version of the events files - maybe but thats a rather different kettle of fish to suspend blockers.
It's a requirement for any reasonable alternative approach.
Signature · 1 line
Matthew Garrett | [email protected]
Matthew:
Remind me why the idle/QOS power management approach won't work here.
If the difficulty is untrusted apps preventing the system from being idle, why not assign them to QoS(NONE) as Thomas suggested?
If the difficulty is that some untrusted apps need to receive wakeup events, why not just decree that this is not allowed? It seems reasonable that if you can't trust a program then you shouldn't allow it to wake up the system.
If the difficulty is that some trusted apps need to do CPU-burning things like drawing bouncing cows in the background, why not break these apps into two processes or threads? One can be trusted and receive all the wakeup events, and the other can be untrusted and draw all the cows it likes. We're only talking about trusted apps, most of which would be controlled by Google, so the conversion shouldn't be too hard.
If the difficulty is that ACPI-based systems can't use idle/QOS PM effectively... well, so be it. We don't have to solve every problem in the world right away, and just now we're mainly concerned about helping the Android people.
Alan Stern
Matthew:
Remind me why the idle/QOS power management approach won't work here.
If the difficulty is untrusted apps preventing the system from being idle, why not assign them to QoS(NONE) as Thomas suggested?
If the difficulty is that some untrusted apps need to receive wakeup events, why not just decree that this is not allowed? It seems reasonable that if you can't trust a program then you shouldn't allow it to wake up the system.
If the difficulty is that some trusted apps need to do CPU-burning things like drawing bouncing cows in the background, why not break these apps into two processes or threads? One can be trusted and receive all the wakeup events, and the other can be untrusted and draw all the cows it likes. We're only talking about trusted apps, most of which would be controlled by Google, so the conversion shouldn't be too hard.
If the difficulty is that ACPI-based systems can't use idle/QOS PM effectively... well, so be it. We don't have to solve every problem in the world right away, and just now we're mainly concerned about helping the Android people.
Alan Stern
Quoted 1 line
The kernel performs no explicit notification to userspace. With legacy
For a PC ACPI using type device /proc/acpi/events which wakes acpid which wakes gnome-power-manager which wakes half the universe
Do we need a better more generic version of the events files - maybe but thats a rather different kettle of fish to suspend blockers.
Alan
Quoted 7 lines · Alan Cox
Quoted 1 line · On Thu, 27 May 2010 22:36:35 +0100 Matthew Garrett <[email protected]> wrote:
No it doesn't. The kernel continues executing anything that was on the
Would you like to come and watch my laptop resume ? With printk's if you want. You appear at this point to be arguing that bumble bees can't fly, while watching one.
The kernel performs no explicit notification to userspace. With legacy graphics setups you'll get a VT switch, but X is entirely unaware that that's due to suspend and that's going away in any case. On a typical setup it's not even the kernel that does the VT switch to and from X - that's handled by a script that happens to be on the runqueue. So yeah, things kind of work as you suggest right now - but only by accident, not design. What you're describing requires a new interface to inform interested bits of userspace whenever you transition from your deep idle state into a less deep one.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · On Thu, 27 May 2010 22:36:35 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 7 lines · Alan Cox
Quoted 2 lines · On Thu, 27 May 2010 18:25:10 +0100 Matthew Garrett <[email protected]> wrote:
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Well on my laptop today it works like this
Quoted 7 lines
Quoted 5 lines
A WoL packet arrives
The CPU resumes
Depp process, chipset and laptop BIOS magic happens The kernel gets called
The kernel lets interested people know a resume occurredNo it doesn't. The kernel continues executing anything that was on the
Would you like to come and watch my laptop resume ? With printk's if you want. You appear at this point to be arguing that bumble bees can't fly, while watching one.
Quoted 4 lines
runqueue before the scheduler stopped. If you're using idle-based suspend then there's nothing on the runqueue - the application that should be scheduled because of the event is blocked on writing to the screen.
IFF its your bogus example
IFF you don't have any task waiting for resume notifications (ie its not
X)
So take the PC desktop case and for simplicity sake lets assume the X application in question has either filled the socket (unlikely) or is mid query request so blocked on the socket.
The important line then is
'The kernel lets interested people know a resume occurred'
Interesting people includes X
X therefore ends up on the runqueue
X gets the display back in order
X completes processing the outstanding X request and replies The application continues
If I was blocked on say serial output then the resume is going to wake the serial driver, which will transmit the queue, which will wake the app.
Alan
Quoted 5 lines · Alan Cox
Quoted 2 lines · On Thu, 27 May 2010 18:25:10 +0100 Matthew Garrett <[email protected]> wrote:
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Quoted 7 lines
Well on my laptop today it works like this
A WoL packet arrives
The CPU resumes
Depp process, chipset and laptop BIOS magic happens The kernel gets called
The kernel lets interested people know a resume occurred
No it doesn't. The kernel continues executing anything that was on the runqueue before the scheduler stopped. If you're using idle-based suspend then there's nothing on the runqueue - the application that should be scheduled because of the event is blocked on writing to the screen.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Peter Zijlstra
Suppose X (or whatever windowing system) will block all clients that try to draw when you switch off your screen.
How would we not wake them when we do turn the screen back on and start servicing the pending requests again?
How (and why) does the WoL (which may be *any* packet, not just a magic one) turn the screen back on?
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines · Matthew Garrett
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Quoted 8 lines
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
Because you may then block them in such a way that they never handle an event that should wake them.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Thomas Gleixner
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Quoted 8 lines
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle. That used to be the case on Android. Arve has said that it isn't necessarily true any more, but that's the way their software is set up.
Alan Stern
Quoted 2 lines · Alan Stern
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle.
Sounds like something that's fixable, doesn't it?
Quoted 3 lines
That used to be
the case on Android. Arve has said that it isn't necessarily true any more, but that's the way their software is set up.
Who cares about their current software? We're arguing about sensible interfaces for the technical problem posed.
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Alan Stern
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle.
Sounds like something that's fixable, doesn't it?
The fix would probably have to involve rewriting the ACPI spec.
Rafael
Quoted 9 lines · On Thu, 27 May 2010 23:36:26 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Alan Stern
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle.
Sounds like something that's fixable, doesn't it?
The fix would probably have to involve rewriting the ACPI spec.
We are on about the fourth version of ACPI already. ACPI evolves and improves and extends. It's not an impossibility to sort that out if everyone in the x86 OS world starts thinking 'How come their ARM platform can do this'
We are also on at least the second suspend/resume model in Linux. The first was 'isn't this APM stuff neat', the second is heavily oriented around ACPI ideas. And we already have SoC people moving into the third model and making it work on non-x6 ('suspend is not special').
I've not poked at the current desktop stuff enough to see if the gnome-power-manager and friends handle pushing the suspend button with dbus notifiers to apps. I guess it does.
Alan
Quoted 9 lines · On Thu, 27 May 2010 23:36:26 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Alan Stern
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle.
Sounds like something that's fixable, doesn't it?
The fix would probably have to involve rewriting the ACPI spec.
We are on about the fourth version of ACPI already. ACPI evolves and improves and extends. It's not an impossibility to sort that out if everyone in the x86 OS world starts thinking 'How come their ARM platform can do this'
We are also on at least the second suspend/resume model in Linux. The first was 'isn't this APM stuff neat', the second is heavily oriented around ACPI ideas. And we already have SoC people moving into the third model and making it work on non-x6 ('suspend is not special').
I've not poked at the current desktop stuff enough to see if the gnome-power-manager and friends handle pushing the suspend button with dbus notifiers to apps. I guess it does.
Alan
Quoted 6 lines · Peter Zijlstra
Quoted 2 lines · Alan Stern
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle.
Sounds like something that's fixable, doesn't it?
The fix would probably have to involve rewriting the ACPI spec.
Rafael
Quoted 2 lines · Alan Stern
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle.
Sounds like something that's fixable, doesn't it?
Quoted 3 lines
That used to be
the case on Android. Arve has said that it isn't necessarily true any more, but that's the way their software is set up.
Who cares about their current software? We're arguing about sensible interfaces for the technical problem posed.
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Matthew Garrett
Quoted 1 line · Thomas Gleixner
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Quoted 8 lines
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
On some platforms (like those with ACPI), deeper power-savings are available by using forced suspend than by using idle. That used to be the case on Android. Arve has said that it isn't necessarily true any more, but that's the way their software is set up.
Alan Stern
Quoted 9 lines · Matthew Garrett
Quoted 8 lines · Thomas Gleixner
Quoted 6 lines · Matthew Garrett
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Quoted 4 lines
Quoted 1 line
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
I think Alan and Thomas but certainly I am saying is that you can get to the same state without suspend.
Either you suspend (forcefully don't schedule stuff), or you end up blocking all tasks on QoS/resource limits and end up with an idle system that goes into a deep idle state (aka suspend).
So why isn't blocking every task on a QoS/resource good enough for you?
Quoted 4 lines
Quoted 1 line
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Nothing gets scheduled in a deep idle state either - its idle. We leave the idle state to schedule anything.
I believe the constraint is
- Do not auto-enter a state for which you cannot maintain the devices in use "properly".
On a current PC that generally means 'not suspend', on a lot of embedded boards (including Android phones) it includes an opportunistic 'suspend' and also several states half way between the PC deepest idles and suspend.
Quoted 4 lines
Quoted 2 lines
Stop thinking about suspend as a special mechanism. It's not - except for s2disk, which is an entirely different beast.
On PCs, suspend has more in common with s2disk than it does C states.
Todays PCs are a special case. More to the point I don't think anyone is expected opportunistic suspend to be useful on _todays_ x86 systems.
Even on todays PCs your assumption is questionable for virtual machines where a VM suspend is a lot faster and rather useful.
Alan
Quoted 7 lines · Alan Cox
Quoted 4 lines
Quoted 1 line
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Nothing gets scheduled in a deep idle state either - its idle. We leave the idle state to schedule anything.
Certainly, if you can force the system to be idle then you don't need opportunistic suspend. But you haven't shown how to do that without it being racey.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Alan Cox
Quoted 4 lines
Quoted 1 line
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Nothing gets scheduled in a deep idle state either - its idle. We leave the idle state to schedule anything.
Certainly, if you can force the system to be idle then you don't need opportunistic suspend. But you haven't shown how to do that without it being racey.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines
Quoted 1 line
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Nothing gets scheduled in a deep idle state either - its idle. We leave the idle state to schedule anything.
I believe the constraint is
- Do not auto-enter a state for which you cannot maintain the devices in use "properly".
On a current PC that generally means 'not suspend', on a lot of embedded boards (including Android phones) it includes an opportunistic 'suspend' and also several states half way between the PC deepest idles and suspend.
Quoted 4 lines
Quoted 2 lines
Stop thinking about suspend as a special mechanism. It's not - except for s2disk, which is an entirely different beast.
On PCs, suspend has more in common with s2disk than it does C states.
Todays PCs are a special case. More to the point I don't think anyone is expected opportunistic suspend to be useful on _todays_ x86 systems.
Even on todays PCs your assumption is questionable for virtual machines where a VM suspend is a lot faster and rather useful.
Alan
Quoted 9 lines · Thomas Gleixner
Quoted 6 lines · Matthew Garrett
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Opportunistic suspend is just a deep idle state, nothing else.
No. The useful property of opportunistic suspend is that nothing gets scheduled. That's fundamentally different to a deep idle state.
Quoted 2 lines
Stop thinking about suspend as a special mechanism. It's not - except for s2disk, which is an entirely different beast.
On PCs, suspend has more in common with s2disk than it does C states.
Signature · 1 line
Matthew Garrett | [email protected]
Hi,
Quoted 5 lines · ext Thomas Gleixner
Opportunistic suspend is just a deep idle state, nothing else. If the overall QoS requirements allow to enter that deep idle state then the kernel goes there. Same decision as for all other idle states. You don't need any user space blocker for this decision, just sensible QoS information.
agree completely with you. Adding virtual differences between power states is a bad idea and causes unnecessary complication to the system. If we have a generic way of describing desired latencies (irq, wakeup, throughput, whatever), then the kernel should decide what's the best power state for the current situation.
Signature · 3 lines
balbi DefectiveByDesign.org
Hi,
Quoted 5 lines · ext Thomas Gleixner
Opportunistic suspend is just a deep idle state, nothing else. If the overall QoS requirements allow to enter that deep idle state then the kernel goes there. Same decision as for all other idle states. You don't need any user space blocker for this decision, just sensible QoS information.
agree completely with you. Adding virtual differences between power states is a bad idea and causes unnecessary complication to the system. If we have a generic way of describing desired latencies (irq, wakeup, throughput, whatever), then the kernel should decide what's the best power state for the current situation.
Signature · 3 lines
balbi DefectiveByDesign.org
Quoted 7 lines · Matthew Garrett
Quoted 4 lines · Alan Cox
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
Quoted 6 lines
Sure, if you're not using opportunistic suspend then I don't think there's any real need for the userspace side of this. The question is how to implement something with the useful properties of opportunistic suspend without without implementing something pretty much equivalent to the userspace suspend blockers. I've sent another mail expressing why I don't think your proposed QoS style behaviour provides that.
Opportunistic suspend is just a deep idle state, nothing else. If the overall QoS requirements allow to enter that deep idle state then the kernel goes there. Same decision as for all other idle states. You don't need any user space blocker for this decision, just sensible QoS information.
Stop thinking about suspend as a special mechanism. It's not - except for s2disk, which is an entirely different beast.
Thanks,
tglx
Quoted 10 lines · Alan Cox
That's all your need to do it right.
In kernel yes your device driver probably does need to say things like 'Don't go below C6 for a moment' just as a high speed serial port might want to say 'Nothing over 10mS please'
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
I'm not opposed, but yes it needs to be expressed in quantifiable terms, i.e. wakeup latency. That's just contributing to the global QoS state of affairs even if it is not tied to a particular task.
And that allows the driver to be intelligent about it. The serial port at 9600 has definitely different requirements than at 115200.
But that's quite a different concept than the big hammer approach of the blockers.
Thanks,
tglx
Quoted 10 lines · Alan Cox
That's all your need to do it right.
In kernel yes your device driver probably does need to say things like 'Don't go below C6 for a moment' just as a high speed serial port might want to say 'Nothing over 10mS please'
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
I'm not opposed, but yes it needs to be expressed in quantifiable terms, i.e. wakeup latency. That's just contributing to the global QoS state of affairs even if it is not tied to a particular task.
And that allows the driver to be intelligent about it. The serial port at 9600 has definitely different requirements than at 115200.
But that's quite a different concept than the big hammer approach of the blockers.
Thanks,
tglx
Quoted 5 lines · Alan Cox
So you need
Userspace -> QoS guarantee expression, implied resource
expression via device use. *NO* knowledge of device or platform in the application
I have a pile of use cases where I want to turn off "implied resource expression via device use." There are two orthogonal variables to consider:
1. I'm drawing cows on the screen (or asking another process to do so on my behalf).
2. I care whether anyone can actually see the cows, and I'm willing (or not) to burn power to make them visible.
Quite often, I'm drawing cows but I don't care about cow visibility, so I would tell PM to turn the display off when the PM framework is looking for ways to conserve power; however, if the animated cow is part of an alarm clock application, then I want the display on, powering it up if was previously turned off.
A real-world example of this is a backup process on a file server. I'd like to tell the kernel that the backup process's CPU usage and disk I/O is *not* implied resource expression, and if there's no other processes using the CPU or disks, the kernel can just power down the drives or idle the CPU on a whim. The backup process can hang until some other process comes along to wake the drives and CPU up again, and then the backups will run during the idle time while the drive is waiting for new requests from other processes. Obviously if the backup process is trying to write dirty pages to a powered-down drive there will be problems (memory starvation and lost data come to mind), so I'd make sure I don't do that.
I'd also like to change my mind about these sorts of things on the fly, without requiring hooks in the backup process itself. I'm thinking of a syscall with PID, FD, mode bits (read/write? iowait/runnable?), and policy (whether usage implies expression).
I can express mostly the same things if "policy" was "maximum latency," but not all. Consider how you'd have to specify latencies to get hard disks that spin down when idle, spin up immediately if read requests are issued, but wait several minutes to spin up if write requests are issued. I can't specify that with a single latency value since it would result in either unacceptably large latencies in some cases, or the disks would never spin down. I'd need a matrix with drive power states as rows and read/write operations as columns, either per process or per file descriptor. Also something in user-space needs to know about the approximate value for hard disk spin-up times in order to set their PM QoS constraints high enough to be useful but also low enough to be useful.
Well, maybe the last problem can be resolved by specifying QoS constraints in bands. You'd have a QOS_OTHER band that applies to processes that haven't specified a constraint, and a QOS_EXPLICIT band that applies to those that have, and you'd be able to change all the QOS_OTHER processes at once.
Quoted 5 lines · Alan Cox
So you need
Userspace -> QoS guarantee expression, implied resource
expression via device use. *NO* knowledge of device or platform in the application
I have a pile of use cases where I want to turn off "implied resource expression via device use." There are two orthogonal variables to consider:
1. I'm drawing cows on the screen (or asking another process to do so on my behalf).
2. I care whether anyone can actually see the cows, and I'm willing (or not) to burn power to make them visible.
Quite often, I'm drawing cows but I don't care about cow visibility, so I would tell PM to turn the display off when the PM framework is looking for ways to conserve power; however, if the animated cow is part of an alarm clock application, then I want the display on, powering it up if was previously turned off.
A real-world example of this is a backup process on a file server. I'd like to tell the kernel that the backup process's CPU usage and disk I/O is *not* implied resource expression, and if there's no other processes using the CPU or disks, the kernel can just power down the drives or idle the CPU on a whim. The backup process can hang until some other process comes along to wake the drives and CPU up again, and then the backups will run during the idle time while the drive is waiting for new requests from other processes. Obviously if the backup process is trying to write dirty pages to a powered-down drive there will be problems (memory starvation and lost data come to mind), so I'd make sure I don't do that.
I'd also like to change my mind about these sorts of things on the fly, without requiring hooks in the backup process itself. I'm thinking of a syscall with PID, FD, mode bits (read/write? iowait/runnable?), and policy (whether usage implies expression).
I can express mostly the same things if "policy" was "maximum latency," but not all. Consider how you'd have to specify latencies to get hard disks that spin down when idle, spin up immediately if read requests are issued, but wait several minutes to spin up if write requests are issued. I can't specify that with a single latency value since it would result in either unacceptably large latencies in some cases, or the disks would never spin down. I'd need a matrix with drive power states as rows and read/write operations as columns, either per process or per file descriptor. Also something in user-space needs to know about the approximate value for hard disk spin-up times in order to set their PM QoS constraints high enough to be useful but also low enough to be useful.
Well, maybe the last problem can be resolved by specifying QoS constraints in bands. You'd have a QOS_OTHER band that applies to processes that haven't specified a constraint, and a QOS_EXPLICIT band that applies to those that have, and you'd be able to change all the QOS_OTHER processes at once.
Quoted 3 lines
No. Suspend blockers are designed to ensure that suspend isn't racy with respect to wakeup events. The bit that mitigates badly written applications is the bit where the scheduler doesn't run any more.
How does having applications taking blockers fix that - it makes it worse. They are now blocking the kernel doing the right job.
Quoted 2 lines
If you're happy with a single badly written application being able to cripple your power management story, you don't need opportunistic
And taking a suspend blocker isn't "crippling your power management" ???
Quoted 5 lines
What /is/ the correct way to solve this problem when entering explicit suspend states? How do you guarantee that an event has been delivered to userspace before transitioning into suspend? Now, this is a less interesting problem if you're not using opportunistic suspend, but it's still a problem.
The same way as we deal with low power states on other non PC devices ?
Quoted 2 lines
That's no good. If the input device has been deactivated, how does the wakeup event get delivered to the application?
If the input device is letting itself get de-activated in a way that can lose events the input device driver is buggy. It's nobody elses business how it does the its job, and certainly *not* the applications.
That's a kernel internal issue.
You know the resource constraint exists because the driver knows it is open
Your QoS guarantees tell you what you desired latency of response at the point you can become ready is.
That's all your need to do it right.
In kernel yes your device driver probably does need to say things like 'Don't go below C6 for a moment' just as a high speed serial port might want to say 'Nothing over 10mS please'
I can't speak for Thomas, but I'm certainly not arguing that you don't need something that looks more like the blocker side of the logic *in kernel*, because there is stuff that you want to express which isn't tied to the task.
So you need
Userspace -> QoS guarantee expression, implied resource
expression via device use. *NO* knowledge of device or platform in the application
Kernel space
Drivers -> Explicit guarantee expression not bound to
tasks. Driver encapsulates the variety in the device hardware and expresses it in a uniform manner to the idling/suspend logic
CPU Freq -> Encapsulates the variety in the CPU and core
power functionality of devices, makes policy based upon the uniform express from the drivers and tasks
All the autonomy is now in the right places, and we have requisite variety to actually manage the situation.
Alan
Quoted 15 lines · Matthew Garrett
Quoted 9 lines · Thomas Gleixner
Quoted 7 lines · Matthew Garrett
Now let's try this in the Android world. The user hits a key and the system wakes up. The input layer takes a suspend block. The application now draws all the cows it wants to, takes its own suspend block and reads the input device. This empties the queue and the kernel-level suspend block is released. The application then processes the event before releasing the suspend block. The event has been delivered and handled.
Quoted 4 lines
Thanks for providing this example:
1) It proves that suspend blockers are solely designed to encourage people to code crap.
Quoted 8 lines
No. Suspend blockers are designed to ensure that suspend isn't racy with respect to wakeup events. The bit that mitigates badly written applications is the bit where the scheduler doesn't run any more.
If you're happy with a single badly written application being able to cripple your power management story, you don't need opportunistic suspend. But you still have complications when it comes to deciding to enter suspend at the same time as you receive a wakeup event.
Wrong. Setting the QoS requirements of the badly written app to any latency will allow the kernel to suspend even if the crappy app is active.
And again. I'm opposing the general chant that fixing crappy applications in the kernel is a good thing. It's the worst decision we could make.
Quoted 10 lines
Quoted 4 lines
And you need to do that, because the user applications suspend blocker magic is racy as hell. To work around that you sprinkle your suspend blocker magic all over the kernel instead of telling people how to solve the problem correctly.
What /is/ the correct way to solve this problem when entering explicit suspend states? How do you guarantee that an event has been delivered to userspace before transitioning into suspend? Now, this is a less interesting problem if you're not using opportunistic suspend, but it's still a problem.
Holy crap. If an event happens _before_ we go into an idle state - and I see suspend as an deeper idle state - then we do not go there at all.
The whole notion of treating suspend to RAM any different than a plain idle C-State is wrong. It's not different at all. You just use a different mechanism which has longer takedown and wakeup latencies and requires to shut down stuff and setup extra wakeup sources.
And there is the whole problem. Switching from normal event delivery to those special wakeup sources. That needs to be engineered in any case carefuly and it does not matter whether you add suspend blockers or not.
Quoted 6 lines
Quoted 4 lines
Simply because you move the cow drawing CPU time from the point where the device wants to go into suspend to the point where the user hits a key again. You even delay the reaction of your app to the user input by the time it needs to finish drawing cows.
It's how application mainloops tend to work.
So what's the f*cking point ? You draw exactly the same amount of power and still you are claiming that it's better or what ?
Quoted 18 lines
Quoted 12 lines
Quoted 4 lines
You can't express that with resource limits or QoS constraints. If you want to deal with this kind of situation then, as far as I can tell, you need either suspend blockers or something so close to them that it makes no difference.
Wrong. If your application is interactive then you set the QoS requirement once to interactive and be done.
So the correct point to make a power state decision is when the app waits for a key press. At this point the kernel can take several pathes:
Quoted 5 lines
1) Keep the system alive because the input device is in active state and a key press is expected
2) Go into supsend because the input device is deactivated after the screen lock kicked in.
Quoted 8 lines
That's no good. If the input device has been deactivated, how does the wakeup event get delivered to the application?
Quoted 3 lines
This behaves exactly the same way in terms of power consumption as your blocker example just without all the mess you are trying to create.
And means that wakeup events don't get delivered. That's a shortcoming.
That's utter nonsense. If we have a problem with missed wakeups then it needs to be fixed and not papered over with suspend blocker magic.
I'm starting to get really grumpy about the chant that suspend blockers are the only way to fix missed wakeups. That might be the only way you can think of with your pink android glasses on, but again this is not rocket science even if it does not fit into the current way the kernel handles the whole suspend mechanism.
So if we really sit back and look at suspend as another idle state, then we have first off the same requirements for entering it as we have for any other idle state:
No running tasks (and we can solve the don't care task problem nicely with QoS)
Aside of that we need to bring devices into a quiescent state and setup the wakeup sources. That switch over needs to be done with and without suspend blockers in a careful way for each SoC implementation.
If the interrupt happens _BEFORE_ we switch over to the quiescent state, then we need to backout. If it happens after the switch then it goes into the nirwana if the suspend wakeup has not been set up correctly. If we have it setup correctly then we go into suspend just to come back immediately. There is nothing you can do about that with suspend blockers.
So if the interrupt comes in before we switch then we have that information already today. We might not make use of it or just in a racy way, but that does not warrant to work around that problem with a big hammer approach.
You can try to lull me into cozy suspend blocker acceptance as long as you want, but you better spend your time on either giving a coherent explanation why suspend blockers are necessary or looking at the underlying problem and fixing it in a technical correct way.
Thanks,
tglx
Quoted 5 lines · Thomas Gleixner
Quoted 4 lines · Matthew Garrett
No. Suspend blockers are designed to ensure that suspend isn't racy with respect to wakeup events. The bit that mitigates badly written applications is the bit where the scheduler doesn't run any more.
Quoted 8 lines
Quoted 4 lines
If you're happy with a single badly written application being able to cripple your power management story, you don't need opportunistic suspend. But you still have complications when it comes to deciding to enter suspend at the same time as you receive a wakeup event.
Wrong. Setting the QoS requirements of the badly written app to any latency will allow the kernel to suspend even if the crappy app is active.
That's not what I want if I'm using the app at the time...
Quoted 3 lines
And again. I'm opposing the general chant that fixing crappy applications in the kernel is a good thing. It's the worst decision we could make.
You still need the in-kernel suspend blockers if you want to guarantee that you can't lose wakeup events. But yes, if you're not concerned handling badly behaved applications then I believe that you can lose opportunistic suspend and just use the scheduler.
Quoted 4 lines
The whole notion of treating suspend to RAM any different than a plain idle C-State is wrong. It's not different at all. You just use a different mechanism which has longer takedown and wakeup latencies and requires to shut down stuff and setup extra wakeup sources.
My question was about explicit suspend states, not implicitly handling an identical state based on scheduler constraints. Suspend-as-a-C-state isn't usable on x86 - you have to explicitly trigger it based on some policy. And if you want to be able to do that without risking the loss of wakeup events then you need in-kernel suspend blockers.
Quoted 5 lines
I'm starting to get really grumpy about the chant that suspend blockers are the only way to fix missed wakeups. That might be the only way you can think of with your pink android glasses on, but again this is not rocket science even if it does not fit into the current way the kernel handles the whole suspend mechanism.
I don't work for Google. I'm not an Android developer.
Quoted 3 lines
So if we really sit back and look at suspend as another idle state, then we have first off the same requirements for entering it as we have for any other idle state:
There are various platforms where we cannot treat suspend as an idle state. Any solution that requires that doesn't actually solve the problem. Yes, this is *trivial* if you can depend on the scheduler. But we can't, and so it's difficult.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 11 lines · Matthew Garrett
Quoted 10 lines · Thomas Gleixner
Quoted 8 lines · Matthew Garrett
No. Suspend blockers are designed to ensure that suspend isn't racy with respect to wakeup events. The bit that mitigates badly written applications is the bit where the scheduler doesn't run any more.
If you're happy with a single badly written application being able to cripple your power management story, you don't need opportunistic suspend. But you still have complications when it comes to deciding to enter suspend at the same time as you receive a wakeup event.
Quoted 5 lines
Quoted 3 lines
Wrong. Setting the QoS requirements of the badly written app to any latency will allow the kernel to suspend even if the crappy app is active.
That's not what I want if I'm using the app at the time...
Your crappy app does not use suspend blockers either.
Quoted 8 lines
Quoted 3 lines
And again. I'm opposing the general chant that fixing crappy applications in the kernel is a good thing. It's the worst decision we could make.
You still need the in-kernel suspend blockers if you want to guarantee that you can't lose wakeup events. But yes, if you're not concerned handling badly behaved applications then I believe that you can lose opportunistic suspend and just use the scheduler.
No, we do not. We need correctly implemented drivers and a safe switchover from normal event delivery to wakeup based.
Quoted 8 lines
Quoted 4 lines
The whole notion of treating suspend to RAM any different than a plain idle C-State is wrong. It's not different at all. You just use a different mechanism which has longer takedown and wakeup latencies and requires to shut down stuff and setup extra wakeup sources.
My question was about explicit suspend states, not implicitly handling an identical state based on scheduler constraints. Suspend-as-a-C-state isn't usable on x86 - you have to explicitly trigger it based on some
And why not ? Just because suspend is not implemented as an ACPI C-state ?
Nonsense, if we want to push the system into suspend from the idle state we can do that. It's just not implemented and we've never tried to do it as it requires a non trivial amount of work, but I have done it on an ARM two years ago as a prove of concept and it works like a charm.
Quoted 2 lines
policy. And if you want to be able to do that without risking the loss of wakeup events then you need in-kernel suspend blockers.
Crap. Stop beating on those lost wakeup events. If we lose them then the drivers are broken and do not handle the switch over correctly. Or the suspend mechanism is broken as it does not evaluate the system state correctly. Blockers are just papering over that w/o tackling the real problem.
Quoted 8 lines
Quoted 3 lines
So if we really sit back and look at suspend as another idle state, then we have first off the same requirements for entering it as we have for any other idle state:
There are various platforms where we cannot treat suspend as an idle state. Any solution that requires that doesn't actually solve the problem. Yes, this is *trivial* if you can depend on the scheduler. But we can't, and so it's difficult.
Stop handwaving. Which platforms prevent us to go into suspend from idle ? Please point me to the relevant documentation which says so.
Just because we have not tried to implemented it does not mean that we cannot implement it.
Thanks,
tglx
Quoted 8 lines · Thomas Gleixner
Quoted 4 lines · Matthew Garrett
You still need the in-kernel suspend blockers if you want to guarantee that you can't lose wakeup events. But yes, if you're not concerned handling badly behaved applications then I believe that you can lose opportunistic suspend and just use the scheduler.
No, we do not. We need correctly implemented drivers and a safe switchover from normal event delivery to wakeup based.
What is a "Correctly implemented driver" in this case? One that receives a wakeup event and then prevents suspend being entered until userspace has acknowledged that event? Because that's what an in-kernel suspend blocker is.
Quoted 4 lines
Quoted 3 lines
My question was about explicit suspend states, not implicitly handling an identical state based on scheduler constraints. Suspend-as-a-C-state isn't usable on x86 - you have to explicitly trigger it based on some
Quoted 8 lines
And why not ? Just because suspend is not implemented as an ACPI C-state ?
Nonsense, if we want to push the system into suspend from the idle state we can do that. It's just not implemented and we've never tried to do it as it requires a non trivial amount of work, but I have done it on an ARM two years ago as a prove of concept and it works like a charm.
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Quoted 8 lines
Quoted 2 lines
policy. And if you want to be able to do that without risking the loss of wakeup events then you need in-kernel suspend blockers.
Crap. Stop beating on those lost wakeup events. If we lose them then the drivers are broken and do not handle the switch over correctly. Or the suspend mechanism is broken as it does not evaluate the system state correctly. Blockers are just papering over that w/o tackling the real problem.
Ger;kljaserf;kljf;kljer;klj. Suspend blockers are the mechanism for the driver to indicate whether the wakeup event has been handled. That's what they're there for. The in-kernel ones don't paper over anything.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 5 lines · Matthew Garrett
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
If all of userspace is blocked on devices, WTH is keeping us from hitting it?
Quoted 5 lines · Matthew Garrett
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
If all of userspace is blocked on devices, WTH is keeping us from hitting it?
Quoted 4 lines
What is a "Correctly implemented driver" in this case? One that receives a wakeup event and then prevents suspend being entered until userspace has acknowledged that event? Because that's what an in-kernel suspend blocker is.
Kernel side maybe - but even then its a subset of expressing latency/lowest level requirements. That bit isn't really too contentious. You need a kernel object to hang a constraint off.
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Quoted 3 lines
Suspend blockers are the mechanism for the
driver to indicate whether the wakeup event has been handled. That's what they're there for. The in-kernel ones don't paper over anything.
Semantically the in kernel blockers and the in kernel expression of device driven constraints are the same thing except that instead of yes/no you replace the boolean with information.
So we go from
block_suspend() / unblock_suspend()
to
add_pm_constraint(latency, level) remove_pm_constraint(latency, level);
And if Android choses to interpret that in its policy code as
if (latency > MAGIC) suspend_is_cool(); else suspend_isnt_cool();
that's now isolated in droidspace policy
Alan
Quoted 8 lines · Alan Cox
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
Quoted 7 lines
Quoted 3 lines
Suspend blockers are the mechanism for the
driver to indicate whether the wakeup event has been handled. That's what they're there for. The in-kernel ones don't paper over anything.Semantically the in kernel blockers and the in kernel expression of device driven constraints are the same thing except that instead of yes/no you replace the boolean with information.
In some cases, not all. It may be a latency constraint (in which case pm_qos is an appropriate mechanism), but instead it may be something like "A key was pressed but never read" or "A network packet was received but not delivered". These don't fit into the pm_qos model, but it's state that you have to track.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines
Quoted 2 lines
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
If one works so does the other.
Quoted 5 lines
In some cases, not all. It may be a latency constraint (in which case
pm_qosis an appropriate mechanism), but instead it may be something like "A key was pressed but never read" or "A network packet was received but not delivered". These don't fit into thepm_qosmodel, but it's state that you have to track.
I never mentioned pm_qos, just latency *and* knowing what suspend states are acceptable. You need both.
Alan
Quoted 5 lines · Alan Cox
Quoted 3 lines
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in TASK_RUNNABLE or has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.
Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
Quoted 9 lines · Alan Cox
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
I guess what Matthew wanted to say was that you couldn't use ACPI S3 as a very deep CPU idle state, because of the way wakeup sources are set up for it, while you could use it for aggressive power management with suspend blockers as proposed by Arve.
Rafael
Quoted 8 lines · On Thu, 27 May 2010 23:55:13 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines · Alan Cox
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.
Quoted 7 lines
Quoted 2 lines
Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
I guess what Matthew wanted to say was that you couldn't use ACPI S3 as a very deep CPU idle state, because of the way wakeup sources are set up for it, while you could use it for aggressive power management with suspend blockers as proposed by Arve.
Which is a nonsense. Because the entire Gnome desktop and KDE, and OpenOffice and Firefox and friends would need fitting out with suspend blockers.
x86 hardware is moving to fix these problems (at least on handheld devices initially). Look up the C6 power idle, and S0i1 and S0i3 standby states. I reckon the laptop folks can probably get the hardware fixed well before anyone can convert the entire PC desktop to include blockers.
Alan
Quoted 23 lines · Alan Cox
Quoted 8 lines · On Thu, 27 May 2010 23:55:13 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines · Alan Cox
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.Quoted 7 lines
Quoted 2 lines
Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
I guess what Matthew wanted to say was that you couldn't use ACPI S3 as a very deep CPU idle state, because of the way wakeup sources are set up for it, while you could use it for aggressive power management with suspend blockers as proposed by Arve.
Which is a nonsense. Because the entire Gnome desktop and KDE, and OpenOffice and Firefox and friends would need fitting out with suspend blockers.
Quoted 5 lines
x86 hardware is moving to fix these problems (at least on handheld devices initially). Look up the C6 power idle, and S0i1 and S0i3 standby states. I reckon the laptop folks can probably get the hardware fixed well before anyone can convert the entire PC desktop to include blockers.
To clarify, I'm not suggesting to spread suspend blockers all over the universe.
Rafael
Quoted 23 lines · Alan Cox
Quoted 8 lines · On Thu, 27 May 2010 23:55:13 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines · Alan Cox
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.Quoted 7 lines
Quoted 2 lines
Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
I guess what Matthew wanted to say was that you couldn't use ACPI S3 as a very deep CPU idle state, because of the way wakeup sources are set up for it, while you could use it for aggressive power management with suspend blockers as proposed by Arve.
Which is a nonsense. Because the entire Gnome desktop and KDE, and OpenOffice and Firefox and friends would need fitting out with suspend blockers.
Quoted 5 lines
x86 hardware is moving to fix these problems (at least on handheld devices initially). Look up the C6 power idle, and S0i1 and S0i3 standby states. I reckon the laptop folks can probably get the hardware fixed well before anyone can convert the entire PC desktop to include blockers.
To clarify, I'm not suggesting to spread suspend blockers all over the universe.
Rafael
Quoted 8 lines · On Thu, 27 May 2010 23:55:13 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 7 lines · Alan Cox
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.
Quoted 7 lines
Quoted 2 lines
Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
I guess what Matthew wanted to say was that you couldn't use ACPI S3 as a very deep CPU idle state, because of the way wakeup sources are set up for it, while you could use it for aggressive power management with suspend blockers as proposed by Arve.
Which is a nonsense. Because the entire Gnome desktop and KDE, and OpenOffice and Firefox and friends would need fitting out with suspend blockers.
x86 hardware is moving to fix these problems (at least on handheld devices initially). Look up the C6 power idle, and S0i1 and S0i3 standby states. I reckon the laptop folks can probably get the hardware fixed well before anyone can convert the entire PC desktop to include blockers.
Alan
Quoted 9 lines · Alan Cox
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
I guess what Matthew wanted to say was that you couldn't use ACPI S3 as a very deep CPU idle state, because of the way wakeup sources are set up for it, while you could use it for aggressive power management with suspend blockers as proposed by Arve.
Rafael
Quoted 6 lines
Quoted 1 line
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in
TASK_RUNNABLEor has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.
Yes I appreciate what suspend blockers are trying to do. Now how does that connect with my first sentence ?
Quoted 5 lines · Alan Cox
Quoted 3 lines
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
If one works so does the other.
Not at all. The entire point of opportunistic suspend is that I don't care is currently in TASK_RUNNABLE or has a timer that's due to expire in 100msec - based on policy (through not having any held suspend blockers), I'll go to sleep. That's easily possible on PCs.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 6 lines
Quoted 2 lines
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
If one works so does the other.
Quoted 5 lines
In some cases, not all. It may be a latency constraint (in which case
pm_qosis an appropriate mechanism), but instead it may be something like "A key was pressed but never read" or "A network packet was received but not delivered". These don't fit into thepm_qosmodel, but it's state that you have to track.
I never mentioned pm_qos, just latency *and* knowing what suspend states are acceptable. You need both.
Alan
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Alan Cox
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Quoted 6 lines
Quoted 2 lines
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
How does that solve the problems you mentioned above ? Wakeup guarantees, latencies ...
It's not a prove of the technical correctness of the approach if it can provide a useless functionality.
Thanks,
tglx
Quoted 7 lines · Thomas Gleixner
Quoted 3 lines · Matthew Garrett
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
How does that solve the problems you mentioned above ? Wakeup guarantees, latencies ...
Latency doesn't matter because we don't care when the next timer is due to expire. Wakeup guarantees can be provided via the suspend blocker implementation.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 11 lines · On Thu, 27 May 2010 19:23:03 +0100 Matthew Garrett <[email protected]> wrote:
Quoted 7 lines · Thomas Gleixner
Quoted 3 lines · Matthew Garrett
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
How does that solve the problems you mentioned above ? Wakeup guarantees, latencies ...
Latency doesn't matter because we don't care when the next timer is due to expire.
In your specific current implementation. It matters a hell of a lot in most cases.
Alan
Quoted 7 lines · Thomas Gleixner
Quoted 3 lines · Matthew Garrett
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
How does that solve the problems you mentioned above ? Wakeup guarantees, latencies ...
Latency doesn't matter because we don't care when the next timer is due to expire. Wakeup guarantees can be provided via the suspend blocker implementation.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Matthew Garrett
Quoted 6 lines · Alan Cox
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Quoted 6 lines
Quoted 2 lines
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
How does that solve the problems you mentioned above ? Wakeup guarantees, latencies ...
It's not a prove of the technical correctness of the approach if it can provide a useless functionality.
Thanks,
tglx
Quoted 8 lines · Alan Cox
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Actually, the reverse - there's no terribly good way to make PCs work with scheduler-based suspend, but there's no reason why they wouldn't work with the current opportunistic suspend implementation.
Quoted 7 lines
Quoted 3 lines
Suspend blockers are the mechanism for the
driver to indicate whether the wakeup event has been handled. That's what they're there for. The in-kernel ones don't paper over anything.Semantically the in kernel blockers and the in kernel expression of device driven constraints are the same thing except that instead of yes/no you replace the boolean with information.
In some cases, not all. It may be a latency constraint (in which case pm_qos is an appropriate mechanism), but instead it may be something like "A key was pressed but never read" or "A network packet was received but not delivered". These don't fit into the pm_qos model, but it's state that you have to track.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 4 lines
What is a "Correctly implemented driver" in this case? One that receives a wakeup event and then prevents suspend being entered until userspace has acknowledged that event? Because that's what an in-kernel suspend blocker is.
Kernel side maybe - but even then its a subset of expressing latency/lowest level requirements. That bit isn't really too contentious. You need a kernel object to hang a constraint off.
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
So PCs with current ACPI don't get opportunistic suspend capability. It probably won't be supported on the Commodore Amiga either - your point ?
Quoted 3 lines
Suspend blockers are the mechanism for the
driver to indicate whether the wakeup event has been handled. That's what they're there for. The in-kernel ones don't paper over anything.
Semantically the in kernel blockers and the in kernel expression of device driven constraints are the same thing except that instead of yes/no you replace the boolean with information.
So we go from
block_suspend() / unblock_suspend()
to
add_pm_constraint(latency, level) remove_pm_constraint(latency, level);
And if Android choses to interpret that in its policy code as
if (latency > MAGIC) suspend_is_cool(); else suspend_isnt_cool();
that's now isolated in droidspace policy
Alan
Quoted 15 lines · Matthew Garrett
Quoted 5 lines · Thomas Gleixner
Quoted 3 lines · Matthew Garrett
My question was about explicit suspend states, not implicitly handling an identical state based on scheduler constraints. Suspend-as-a-C-state isn't usable on x86 - you have to explicitly trigger it based on some
Quoted 8 lines
And why not ? Just because suspend is not implemented as an ACPI C-state ?
Nonsense, if we want to push the system into suspend from the idle state we can do that. It's just not implemented and we've never tried to do it as it requires a non trivial amount of work, but I have done it on an ARM two years ago as a prove of concept and it works like a charm.
Quoted 5 lines
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Right, it does not as of today. So we cannot use that on x86 hardware. Fine. That does not prevent us to implement it for architectures which can do it. And if x86 comes to the point where it can handle it as well we're going to use it. Where is the problem ? If x86 cannot guarantee the wakeup sources it's not going to be used for such devices. The kernel just does not provide the service for it, so what ?
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
policy. And if you want to be able to do that without risking the loss of wakeup events then you need in-kernel suspend blockers.
Crap. Stop beating on those lost wakeup events. If we lose them then the drivers are broken and do not handle the switch over correctly. Or the suspend mechanism is broken as it does not evaluate the system state correctly. Blockers are just papering over that w/o tackling the real problem.
Quoted 3 lines
Ger;kljaserf;kljf;kljer;klj. Suspend blockers are the mechanism for the driver to indicate whether the wakeup event has been handled. That's what they're there for. The in-kernel ones don't paper over anything.
So the driver says: events have been handled. Neat.
Now if that crappy app does not use the user space blockers or is not allowed to use them, then what are you guaranteeing ? All you guarantee is that the application has emptied the input queue. Nothing else. And that's the same as setting the QoS guarantee to NONE.
An application which uses the blocker is just holding off the system from going into deep idle. Nothing which cannot be done today.
So the only thing you are imposing to app writers is to use an interface which solves nothing and does not save you any power at all.
If the application drops the blocker after processing the event and before it goes back to the read event then you just postpone the CPU usage and therefor power consumption to a later point in time instead of going back to the blocking read right away.
Again what is it saving ? NOTHING! And for nothing you want to mess up the kernel big time ?
Runnable tasks and QoS guarantees are the indicators whether you can go to opportunistic suspend or not. Everything else is just window dressing.
Thanks,
tglx
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines · Matthew Garrett
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Quoted 7 lines
Right, it does not as of today. So we cannot use that on x86 hardware. Fine. That does not prevent us to implement it for architectures which can do it. And if x86 comes to the point where it can handle it as well we're going to use it. Where is the problem ? If x86 cannot guarantee the wakeup sources it's not going to be used for such devices. The kernel just does not provide the service for it, so what ?
We were talking about PCs. Suspend-as-c-state is already implemented for OMAP.
Quoted 3 lines
So the only thing you are imposing to app writers is to use an interface which solves nothing and does not save you any power at all.
It's already been demonstrated that the Android approach saves power.
Quoted 3 lines
Runnable tasks and QoS guarantees are the indicators whether you can go to opportunistic suspend or not. Everything else is just window dressing.
As I keep saying, this is all much less interesting if you don't care about handling suboptimal applications. If you do care about them then the Android approach works. Nobody has demonstrated a scheduler-based one that does.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines · Matthew Garrett
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Quoted 7 lines
Right, it does not as of today. So we cannot use that on x86 hardware. Fine. That does not prevent us to implement it for architectures which can do it. And if x86 comes to the point where it can handle it as well we're going to use it. Where is the problem ? If x86 cannot guarantee the wakeup sources it's not going to be used for such devices. The kernel just does not provide the service for it, so what ?
We were talking about PCs. Suspend-as-c-state is already implemented for OMAP.
Quoted 3 lines
So the only thing you are imposing to app writers is to use an interface which solves nothing and does not save you any power at all.
It's already been demonstrated that the Android approach saves power.
Quoted 3 lines
Runnable tasks and QoS guarantees are the indicators whether you can go to opportunistic suspend or not. Everything else is just window dressing.
As I keep saying, this is all much less interesting if you don't care about handling suboptimal applications. If you do care about them then the Android approach works. Nobody has demonstrated a scheduler-based one that does.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 16 lines · Matthew Garrett
Quoted 7 lines · Thomas Gleixner
Quoted 5 lines · Matthew Garrett
ACPI provides no guarantees about what level of hardware functionality remains during S3. You don't have any useful ability to determine which events will generate wakeups. And from a purely practical point of view, since the latency is in the range of seconds, you'll never have a low enough wakeup rate to hit it.
Quoted 7 lines
Right, it does not as of today. So we cannot use that on x86 hardware. Fine. That does not prevent us to implement it for architectures which can do it. And if x86 comes to the point where it can handle it as well we're going to use it. Where is the problem ? If x86 cannot guarantee the wakeup sources it's not going to be used for such devices. The kernel just does not provide the service for it, so what ?
Quoted 2 lines
We were talking about PCs. Suspend-as-c-state is already implemented for OMAP.
Ah, now we talk about PCs. And all of a sudden the problem of the unability of determining wakeup sources is not longer relevant ? So how do you guarantee that we don't miss one if we cant figure out which ones are kept alive in S3 ?
Quoted 5 lines
Quoted 3 lines
So the only thing you are imposing to app writers is to use an interface which solves nothing and does not save you any power at all.
It's already been demonstrated that the Android approach saves power.
Demonstrated ? Care to explain me how it makes a difference:
while (1) {
block();
read();
process_event();
unblock(); ---> suspend <--- resume
do_crap(); 1000000 cycles
}
vs.
while (1) {
read(); ---> suspend <--- resume
process_event();
do_crap(); 1000000 cycles
}
You spend the damned 10000000 cycles in any case just at a different point in time. So if you are so convinced and have fully understood all the implications, please enlighten me why do_crap() costs less power with the blockers approach.
An you are also stubbornly refusing to answer my analysis about the effect on apps which do not use the blocker or are not allowed to.
1) The kernel blocker does not guarantee that the lousy app has processed the event. It just guarantees that the lousy app has emptied the input queue. So what's the point of the kernel blocker in that case ?
2) What's the difference on setting that app to QoS(NONE) and let the kernel happily ignore it.
Come up with real explanations and numbers and not just the "it has been demonstrated" chant which is not holding water if you look at the above.
Quoted 8 lines
Quoted 3 lines
Runnable tasks and QoS guarantees are the indicators whether you can go to opportunistic suspend or not. Everything else is just window dressing.
As I keep saying, this is all much less interesting if you don't care about handling suboptimal applications. If you do care about them then the Android approach works. Nobody has demonstrated a scheduler-based one that does.
That does not make the android approach any better. They should have talked to us upfront and not after the fact. Just because they decided to do that in their google basement w/o talking to people who care is not proving that it's a good solution and even less a reason to merge it as is.
The kernel history is full of examples where crappy solutions got rejected and kept out of the kernel for a long time even if there was a need for them in the application field and they got shipped in quantities with out of tree patches (NOHZ, high resolution timers, ...). At some point people stopped arguing for crappy solutions and sat down and got it right. The problem of power management and opportunistic suspend is not different in any way.
Thanks,
tglx