Changes to Runtime PM
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Alan Stern
Rafael:
Hi Alan,
First, I think we should CC linux-pm at least with this.
Quite right. I have also removed linux-usb and Oliver since they aren't directly involved, and updated the Subject: line.
Quoted 10 lines
Quoted 10 lines
It turns out that the existing "
from_wq" arguments can be subsumed into an "rpmflags" variable, along with the other things we've been talking about. Even better, one of the flag bits can be used to indicate whether a call should be synchronous.Which leads to the possibility of merging the
__pm_runtime_Xand__pm_request_Xpairs of routines. They all make similar checks when they start; this is needlessly duplicated code. Unfortunately, they are slightly inconsistent in a few obscure respects:
Quoted 8 lines
Quoted 2 lines
If the current status is
RPM_RESUMINGthen__rpm_request_suspendsucceeds but__rpm_runtime_suspendfails. Similarly for idle.That was intentional.
__rpm_runtime_suspendhas to fail in that case, but__rpm_request_suspendneed not, because__rpm_runtime_suspendis going to be called after it anyway. So, the decision whether or not to suspend the device is always made by__rpm_runtime_suspendand I'd like that to stay this way.
Okay, so you would like __rpm_runtime_suspend to fail while the device is resuming but __rpm_request_suspend to succeed.
Quoted 26 lines
Quoted 3 lines
The routines in each pair sometimes differ in whether they cancel other pending requests first vs. check for invalid conditions (such as wrong
usage_count) first.That might be intentional as well, at least in some cases.
Quoted 10 lines
It seems to me that the
__pm_runtime_Xand__pm_request_Xfunctions should behave the same, as nearly as possible.To make everything more uniform, we should agree on some fixed scheme like this:
First check for things that make the function impossible:
power.runtime_error set,usage_countorchild_countset wrong, ordisable_depth> 0. If these checks fail, return immediately.OK
Quoted 7 lines
Then check the current status and the pending requests to see if they rule out the current function:
idle is allowed only in
RPM_ACTIVEand when there are no pending requests (but the suspend timer can be running);
Quoted 7 lines
Quoted 5 lines
suspend is not allowed if the status is
RPM_SUSPENDEDorRPM_RESUMING, or if there is a pending resume (either a request or a deferred resume);resume is not allowed if the status is
RPM_ACTIVE.OK, but that need not apply to the
_ldle()variants.
I don't understand. Are you referring to the "idle is allowed only..." paragraph above? What's the connection with resume?
Quoted 12 lines
Quoted 11 lines
If this check succeeds, then cancel any pending requests (exception: doing an idle should not cause the suspend timer to be cancelled) and either carry out the action, put it on the workqueue, defer it, or start the timer.
This almost agrees with the rules laid out in
Documentation/power/runtime.txt. The only difference I can see is what should happen if __pm_{runtime|request}_resume is called while the status isRPM_ACTIVEand there is a pending idle or suspend request or a scheduled suspend. Under these conditions I think we probably shouldn't cancel a pending idle request.
Quoted 7 lines
That would be fine.
Quoted 1 line
I'm not sure about pending or scheduled suspends.
I actually think we may try not to cancel any pending/scheduled operations at all and let things work out. If the caller is not careful enough to use the reference counting, so be it.
Well, pending or scheduled operations can certainly be cancelled safely when one of the synchronous operations starts. For example, when a runtime resume is starting we can cancel a pending resume request. (It should not be possible for there to be any pending idle or suspend requests at this time, because the status is RPM_SUSPENDED.)
However, if you want to avoid cancelling pending or scheduled operations when one of the routines fails because it was called at the wrong time, I'm okay with that. In fact, it's what I suggested above.
As for the asynchronous routines... If a request is successfully queued then it _has_ to cancel pending requests, since only one request can be pending at a time. But we can theoretically have both a pending request and a scheduled suspend. I don't see any point in allowing it, though. In general we should let the most recent successful function call win.
Quoted 12 lines
Quoted 3 lines
(This scheme is a little peculiar because it means that scheduling a suspend will cancel a pending idle, but idle requests are then allowed after the suspend has been scheduled. I guess we can live with this.)
Well, see above. :-)
Quoted 5 lines
This differs a little from what we do now, in that it doesn't allow a suspend to be requested while the device is resuming. I think this makes sense for two reasons: When the resume finishes there will be an idle notification anyway, and if the workqueue tries to carry out the suspend too soon (before the resume has finished) then it will fail.
Quoted 7 lines
Idle notification need not imply suspend and the resume winning the race with a pending suspend is totally fine by me.
Quoted 1 line
Does this all seem reasonable?
Generally, it does, but I'm not sure about the "request suspend" case. In fact I think it's better to let the resulting
__rpm_runtime_suspend()run.
Fair enough.
Alan Stern
Quoted 25 lines · Alan Stern
Quoted 6 lines · Rafael J. Wysocki
Quoted 1 line · Alan Stern
Rafael:
Hi Alan,
First, I think we should CC linux-pm at least with this.
Quite right. I have also removed linux-usb and Oliver since they aren't directly involved, and updated the Subject: line.
Quoted 13 lines
Quoted 12 lines
It turns out that the existing "
from_wq" arguments can be subsumed into an "rpmflags" variable, along with the other things we've been talking about. Even better, one of the flag bits can be used to indicate whether a call should be synchronous.Which leads to the possibility of merging the
__pm_runtime_Xand__pm_request_Xpairs of routines. They all make similar checks when they start; this is needlessly duplicated code. Unfortunately, they are slightly inconsistent in a few obscure respects:If the current status is
RPM_RESUMINGthen__rpm_request_suspendsucceeds but__rpm_runtime_suspendfails. Similarly for idle.
Quoted 8 lines
Quoted 5 lines
That was intentional.
__rpm_runtime_suspendhas to fail in that case, but__rpm_request_suspendneed not, because__rpm_runtime_suspendis going to be called after it anyway. So, the decision whether or not to suspend the device is always made by__rpm_runtime_suspendand I'd like that to stay this way.Okay, so you would like
__rpm_runtime_suspendto fail while the device is resuming but__rpm_request_suspendto succeed.
Yes.
Quoted 30 lines
Quoted 30 lines
Quoted 3 lines
The routines in each pair sometimes differ in whether they cancel other pending requests first vs. check for invalid conditions (such as wrong
usage_count) first.That might be intentional as well, at least in some cases.
Quoted 10 lines
It seems to me that the
__pm_runtime_Xand__pm_request_Xfunctions should behave the same, as nearly as possible.To make everything more uniform, we should agree on some fixed scheme like this:
First check for things that make the function impossible:
power.runtime_error set,usage_countorchild_countset wrong, ordisable_depth> 0. If these checks fail, return immediately.OK
Quoted 11 lines
Then check the current status and the pending requests to see if they rule out the current function:
idle is allowed only in
RPM_ACTIVEand when there are no pending requests (but the suspend timer can be running);suspend is not allowed if the status is
RPM_SUSPENDEDorRPM_RESUMING, or if there is a pending resume (either a request or a deferred resume);
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
resume is not allowed if the status is
RPM_ACTIVE.OK, but that need not apply to the
_ldle()variants.I don't understand. Are you referring to the "idle is allowed only..." paragraph above? What's the connection with resume?
Sorry, I thought *_request_*() and wrote _idle(). Must be too tired. :-)
Quoted 20 lines
Quoted 12 lines
Quoted 11 lines
If this check succeeds, then cancel any pending requests (exception: doing an idle should not cause the suspend timer to be cancelled) and either carry out the action, put it on the workqueue, defer it, or start the timer.
This almost agrees with the rules laid out in
Documentation/power/runtime.txt. The only difference I can see is what should happen if __pm_{runtime|request}_resume is called while the status isRPM_ACTIVEand there is a pending idle or suspend request or a scheduled suspend. Under these conditions I think we probably shouldn't cancel a pending idle request.Quoted 7 lines
That would be fine.
Quoted 1 line
I'm not sure about pending or scheduled suspends.
I actually think we may try not to cancel any pending/scheduled operations at all and let things work out. If the caller is not careful enough to use the reference counting, so be it.
Quoted 5 lines
Well, pending or scheduled operations can certainly be cancelled safely when one of the synchronous operations starts. For example, when a runtime resume is starting we can cancel a pending resume request. (It should not be possible for there to be any pending idle or suspend requests at this time, because the status is
RPM_SUSPENDED.)
Cancelling a pending operation of the same kind is reasonable.
Quoted 3 lines
However, if you want to avoid cancelling pending or scheduled operations when one of the routines fails because it was called at the wrong time, I'm okay with that. In fact, it's what I suggested above.
OK, then.
Quoted 6 lines
As for the asynchronous routines... If a request is successfully queued then it _has_ to cancel pending requests, since only one request can be pending at a time. But we can theoretically have both a pending request and a scheduled suspend. I don't see any point in allowing it, though. In general we should let the most recent successful function call win.
OK
Thanks,
Rafael
Quoted 18 lines · Rafael J. Wysocki
Quoted 18 lines
Quoted 18 lines
Quoted 4 lines
First check for things that make the function impossible:
power.runtime_error set,usage_countorchild_countset wrong, ordisable_depth> 0. If these checks fail, return immediately.OK
Quoted 11 lines
Then check the current status and the pending requests to see if they rule out the current function:
idle is allowed only in
RPM_ACTIVEand when there are no pending requests (but the suspend timer can be running);suspend is not allowed if the status is
RPM_SUSPENDEDorRPM_RESUMING, or if there is a pending resume (either a request or a deferred resume);
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
resume is not allowed if the status is
RPM_ACTIVE.OK, but that need not apply to the
_ldle()variants.I don't understand. Are you referring to the "idle is allowed only..." paragraph above? What's the connection with resume?
Sorry, I thought *_request_*() and wrote
_idle(). Must be too tired. :-)
I'm still not sure what you mean. I meant those conditions to apply to both the synchronous and asynchronous calls (except of course that we will allow async suspend if the status is RPM_RESUMING). Did you have something else is mind?
Alan Stern
Quoted 27 lines · Alan Stern
Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines
Quoted 14 lines
Quoted 4 lines
First check for things that make the function impossible:
power.runtime_error set,usage_countorchild_countset wrong, ordisable_depth> 0. If these checks fail, return immediately.OK
Quoted 7 lines
Then check the current status and the pending requests to see if they rule out the current function:
idle is allowed only in
RPM_ACTIVEand when there are no pending requests (but the suspend timer can be running);Quoted 7 lines
Quoted 5 lines
suspend is not allowed if the status is
RPM_SUSPENDEDorRPM_RESUMING, or if there is a pending resume (either a request or a deferred resume);resume is not allowed if the status is
RPM_ACTIVE.OK, but that need not apply to the
_ldle()variants.I don't understand. Are you referring to the "idle is allowed only..." paragraph above? What's the connection with resume?
Quoted 6 lines
Quoted 1 line
Sorry, I thought *_request_*() and wrote
_idle(). Must be too tired. :-)I'm still not sure what you mean. I meant those conditions to apply to both the synchronous and asynchronous calls (except of course that we will allow async suspend if the status is
RPM_RESUMING). Did you have something else is mind?
No, I didn't.
Thanks,
Rafael