PM: runtime: Consolidation of last_busy updates and calling rpm_idle() in rpm_resume()
Subsystems (4)
Rafael J. Wysocki
maintainerv2 cover PM: runtime: Consolidation of last_busy updates and calling rpm_idle() in rpm_resume()
Hi All,
This is a follow-up series for
which is in linux-next and it replaces
https://lore.kernel.org/linux-pm/[email protected]/
and
https://lore.kernel.org/linux-pm/[email protected]/
(hence v2).
It makes essentially the same changes as the two patches above, but in a different order and with somewhat (hopefully) more convincing explanation. It requires this series to be applied:
https://lore.kernel.org/linux-pm/[email protected]/
The first patch simply drops a direct pm_runtime_mark_last_busy() call from rpm_resume() that becomes redundant after apply the above series.
The second patch causes rpm_resume() to call rpm_idle() in the case when the given device is active to start with which is already done in the case when the device needs to be resumed. The goal is to make the behavior of rpm_resume() more consistent and more predictable.
Thanks!
Rafael J. Wysocki
maintainerPATCH v2 1/2 PM: runtime: Drop redundant last_busy update from rpm_resume()
From: "Rafael J. Wysocki" <[email protected]>
Since rpm_idle() updates the last_busy timestamp of the device unconditionally and rpm_resume() calls it after resuming the device successfully, the direct last_busy update after changing the runtime PM status of the device to RPM_ACTIVE is redundant.
Drop it.
No intentional functional impact.
---
Applies on top of
https://lore.kernel.org/linux-pm/[email protected]/
--- drivers/base/power/runtime.c | 1 - 1 file changed, 1 deletion(-)
drivers/base/power/runtime.c +0 -1
@@ -1004,7 +1004,6 @@ static int rpm_resume(struct device *dev }else { no_callback:__update_runtime_status (dev,RPM_ACTIVE ); -pm_runtime_mark_last_busy (dev);if (parent)atomic_inc (&parent->power.child_count); }
Re: [PATCH v2 1/2] PM: runtime: Drop redundant last_busy update from rpm_resume()
Quoted 8 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Since
rpm_idle()updates thelast_busytimestamp of the device unconditionally andrpm_resume()calls it after resuming the device successfully, the directlast_busyupdate after changing the runtime PM status of the device toRPM_ACTIVEis redundant.
Quoted 5 lines
Drop it.
No intentional functional impact.
Signed-off-by Rafael J. Wysocki <[email protected]>
Kind regards
Uffe
Quoted 23 lines
---
Applies on top of
https://lore.kernel.org/linux-pm/[email protected]/
--- drivers/base/power/runtime.c | 1 - 1 file changed, 1 deletion(-)drivers/base/power/runtime.c +0
-1@@ -1004,7 +1004,6 @@ static int rpm_resume(struct device *dev }else { no_callback:__update_runtime_status (dev,RPM_ACTIVE ); -pm_runtime_mark_last_busy (dev);if (parent)atomic_inc (&parent->power.child_count); }
Rafael J. Wysocki
maintainerPATCH v2 2/2 PM: runtime: Call rpm_idle() in rpm_resume() for active devices
In reply to Rafael J. WysockiFrom: "Rafael J. Wysocki" <[email protected]>
If rpm_resume() actually resumes the device successfully (that is, the device's runtime resume callback is invoked and does not fail), it calls rpm_idle() to check whether or not the device really is in use and possibly start an autosuspend timer for it or advance its last_busy timestamp. However, rpm_idle() is not called by rpm_resume() if the runtime PM status of the device is RPM_ACTIVE to start with, which is inconsistent and may be confusing.
Most importantly, if no runtime PM references to the given device are held when rpm_resume() is about to return, skipping the rpm_idle() invocation means missing an opportunity to suspend the device that is not otherwise prevented from suspending. If autosuspend is used by the device, an autosuspend timer can be expected to be started for it when rpm_resume() is about to return, but that will not happen if the device's runtime PM status is RPM_ACTIVE to start with. The next opportunity to start an autosuspend timer for the device may not appear at any time soon.
Address this by rearranging rpm_resume() to call rpm_idle() also if the device was already active and drop the direct last_busy update carried out in that case as it is not necessary any more because rpm_idle() updates last_busy. Also make the rpm_resume() kerneldoc comment match the new code flow.
Note that if the device is prevented from suspending when rpm_idle() is called, the overhead of calling rpm_idle() boils down to checking that the device in fact cannot be suspended, so it should not be significant.
--- drivers/base/power/runtime.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/base/power/runtime.c +8 -10
@@ -833,7 +833,8 @@ static int rpm_suspend(struct device *de* suspending (deferred_resume) or wait for it to finish. If the RPM_ASYNC * flag is set then queue a resume request; otherwise run the * ->runtime_resume() callback directly. Queue an idle notification for the -* device if the resume succeeded. +* device if the resume succeeded or the device's runtime PM status was +* RPM_ACTIVE to start with. * * This function must be called under dev->power.lock with interrupts disabled. */
@@ -872,14 +873,8 @@ static int rpm_resume(struct device *devpm_runtime_deactivate_timer (dev);if (dev->power.runtime_status ==RPM_ACTIVE ) { -/* -* The attempt to resume the device means that it is needed for -* something, so update its last_busy timestamp as in the case -* in which it actually resumes below. -*/ -pm_runtime_mark_last_busy (dev); retval =1 ; - goto out; + goto success; } if (dev->power.runtime_status == RPM_RESUMING ||
@@ -1009,8 +1004,11 @@ static int rpm_resume(struct device *dev }wake_up_all (&dev->power.wait_queue); -if (retval >=0 ) -rpm_idle (dev,RPM_ASYNC ); +if (retval <0 ) + goto out; + + success: +rpm_idle (dev,RPM_ASYNC ); out:if (parent && !dev->power.irq_safe) {
Re: [PATCH v2 2/2] PM: runtime: Call rpm_idle() in rpm_resume() for active devices
Quoted 21 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
If
rpm_resume()actually resumes the device successfully (that is, the device's runtime resume callback is invoked and does not fail), it callsrpm_idle()to check whether or not the device really is in use and possibly start an autosuspend timer for it or advance itslast_busytimestamp. However,rpm_idle()is not called byrpm_resume()if the runtime PM status of the device isRPM_ACTIVEto start with, which is inconsistent and may be confusing.Most importantly, if no runtime PM references to the given device are held when
rpm_resume()is about to return, skipping therpm_idle()invocation means missing an opportunity to suspend the device that is not otherwise prevented from suspending. If autosuspend is used by the device, an autosuspend timer can be expected to be started for it whenrpm_resume()is about to return, but that will not happen if the device's runtime PM status isRPM_ACTIVEto start with. The next opportunity to start an autosuspend timer for the device may not appear at any time soon.
Quoted 5 lines
Address this by rearranging
rpm_resume()to callrpm_idle()also if the device was already active and drop the directlast_busyupdate carried out in that case as it is not necessary any more becauserpm_idle()updateslast_busy. Also make therpm_resume()kerneldoc comment match the new code flow.
While I in principle agree with the change, I am slightly worried about users that call pm_runtime_resume() and who call pm_runtime_get* quite soon after. I can tell if this is a common behaviour, but I am sure I have seen something like that. Did you check?
Anyway, for these cases we may end up doing an unnecessary round of suspend/resume of the device. Maybe not a big deal, but something that could have a negative impact on probing/boot.
Quoted 6 lines
Note that if the device is prevented from suspending when
rpm_idle()is called, the overhead of callingrpm_idle()boils down to checking that the device in fact cannot be suspended, so it should not be significant.Signed-off-by Rafael J. Wysocki <[email protected]>
Kind regards
Uffe
Quoted 49 lines
--- drivers/base/power/runtime.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/base/power/runtime.c +8
-10@@ -833,7 +833,8 @@ static int rpm_suspend(struct device *de* suspending (deferred_resume) or wait for it to finish. If the RPM_ASYNC * flag is set then queue a resume request; otherwise run the * ->runtime_resume() callback directly. Queue an idle notification for the -* device if the resume succeeded. +* device if the resume succeeded or the device's runtime PM status was +* RPM_ACTIVE to start with. * * This function must be called under dev->power.lock with interrupts disabled. */ @@ -872,14 +873,8 @@ static int rpm_resume(struct device *devpm_runtime_deactivate_timer (dev);if (dev->power.runtime_status ==RPM_ACTIVE ) { -/* -* The attempt to resume the device means that it is needed for -* something, so update its last_busy timestamp as in the case -* in which it actually resumes below. -*/ -pm_runtime_mark_last_busy (dev); retval =1 ; - goto out; + goto success; } if (dev->power.runtime_status == RPM_RESUMING ||@@ -1009,8 +1004,11 @@ static int rpm_resume(struct device *dev }wake_up_all (&dev->power.wait_queue); -if (retval >=0 ) -rpm_idle (dev,RPM_ASYNC ); +if (retval <0 ) + goto out; + + success: +rpm_idle (dev,RPM_ASYNC ); out:if (parent && !dev->power.irq_safe) {
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH v2 2/2] PM: runtime: Call rpm_idle() in rpm_resume() for active devices
Quoted 29 lines · Ulf Hansson
Quoted 21 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
If
rpm_resume()actually resumes the device successfully (that is, the device's runtime resume callback is invoked and does not fail), it callsrpm_idle()to check whether or not the device really is in use and possibly start an autosuspend timer for it or advance itslast_busytimestamp. However,rpm_idle()is not called byrpm_resume()if the runtime PM status of the device isRPM_ACTIVEto start with, which is inconsistent and may be confusing.Most importantly, if no runtime PM references to the given device are held when
rpm_resume()is about to return, skipping therpm_idle()invocation means missing an opportunity to suspend the device that is not otherwise prevented from suspending. If autosuspend is used by the device, an autosuspend timer can be expected to be started for it whenrpm_resume()is about to return, but that will not happen if the device's runtime PM status isRPM_ACTIVEto start with. The next opportunity to start an autosuspend timer for the device may not appear at any time soon.Quoted 5 lines
Address this by rearranging
rpm_resume()to callrpm_idle()also if the device was already active and drop the directlast_busyupdate carried out in that case as it is not necessary any more becauserpm_idle()updateslast_busy. Also make therpm_resume()kerneldoc comment match the new code flow.
Quoted 4 lines
While I in principle agree with the change, I am slightly worried about users that call
pm_runtime_resume()and who call pm_runtime_get* quite soon after. I can tell if this is a common behaviour, but I am sure I have seen something like that. Did you check?
I don't know how many of them there are, if that's what you're asking, but they should at least use an autosuspend delay.
Also note that if the initial pm_runtime_resume() resumes the device and there is no autosuspend delay, it will suspend immediately even without this change.
Quoted 3 lines
Anyway, for these cases we may end up doing an unnecessary round of suspend/resume of the device. Maybe not a big deal, but something that could have a negative impact on probing/boot.
If this adversely affects anyone, I'd like to understand why and help them to do the right thing because they are probably doing something super-fragile that works incidentally.
To me, consistency in the core is more important than preserving the existing behavior to support such fragile cases.
Quoted 56 lines
Quoted 55 lines
Note that if the device is prevented from suspending when
rpm_idle()is called, the overhead of callingrpm_idle()boils down to checking that the device in fact cannot be suspended, so it should not be significant.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/base/power/runtime.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)drivers/base/power/runtime.c +8
-10@@ -833,7 +833,8 @@ static int rpm_suspend(struct device *de* suspending (deferred_resume) or wait for it to finish. If the RPM_ASYNC * flag is set then queue a resume request; otherwise run the * ->runtime_resume() callback directly. Queue an idle notification for the -* device if the resume succeeded. +* device if the resume succeeded or the device's runtime PM status was +* RPM_ACTIVE to start with. * * This function must be called under dev->power.lock with interrupts disabled. */ @@ -872,14 +873,8 @@ static int rpm_resume(struct device *devpm_runtime_deactivate_timer (dev);if (dev->power.runtime_status ==RPM_ACTIVE ) { -/* -* The attempt to resume the device means that it is needed for -* something, so update its last_busy timestamp as in the case -* in which it actually resumes below. -*/ -pm_runtime_mark_last_busy (dev); retval =1 ; - goto out; + goto success; } if (dev->power.runtime_status == RPM_RESUMING ||@@ -1009,8 +1004,11 @@ static int rpm_resume(struct device *dev }wake_up_all (&dev->power.wait_queue); -if (retval >=0 ) -rpm_idle (dev,RPM_ASYNC ); +if (retval <0 ) + goto out; + + success: +rpm_idle (dev,RPM_ASYNC ); out:if (parent && !dev->power.irq_safe) {