Skip to contentSkip to conversation

PM: runtime: Update last_busy in rpm_resume() for active devices

PATCH In review Rafael J. Wysocki 4 participants 4 messages Nov 6 – Nov 14

Subsystems (4)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 PM: runtime: Update last_busy in rpm_resume() for active devices

From: "Rafael J. Wysocki" <[email protected]>

Setting an autosuspend delay for a device can be expected to cause a runtime suspend of the device after calling, say, pm_runtime_put() to be deferred, so the time between the last successful attempt to resume the device and its subsequent suspend is at least equal to the autosuspend delay.

However, that expectation is only met after the device has been actually resumed in rpm_resume() by invoking its runtime resume callback. If the runtime PM status of the device is already "active" when rpm_resume() runs for it, the device's last_busy timestamp is not updated which may allow a subsequent pm_runtime_put() invocation (or similar) to suspend it right away.

This is arguably inconsistent and confusing, so make rpm_resume() also update the device's last_busy timestamp when it finds that the device is already "active" and it is about to return 1 early.

---
 drivers/base/power/runtime.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/runtime.c +6 -0
@@ -819,6 +819,12 @@ static int rpm_resume(struct device *dev
 		pm_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;
 	}
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Setting an autosuspend delay for a device can be expected to cause a runtime suspend of the device after calling, say, pm_runtime_put() to be deferred, so the time between the last successful attempt to resume the device and its subsequent suspend is at least equal to the autosuspend delay.

However, that expectation is only met after the device has been actually resumed in rpm_resume() by invoking its runtime resume callback. If the runtime PM status of the device is already "active" when rpm_resume() runs for it, the device's last_busy timestamp is not updated which may allow a subsequent pm_runtime_put() invocation (or similar) to suspend it right away.

This is arguably inconsistent and confusing, so make rpm_resume() also update the device's last_busy timestamp when it finds that the device is already "active" and it is about to return 1 early.

Quoted 5 lines
Quoted 19 lines
---
 drivers/base/power/runtime.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/runtime.c +6 -0
@@ -819,6 +819,12 @@ static int rpm_resume(struct device *dev
 		pm_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;
 	}
Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Rafael J. Wysocki
Quoted 15 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Setting an autosuspend delay for a device can be expected to cause a runtime suspend of the device after calling, say, pm_runtime_put() to be deferred, so the time between the last successful attempt to resume the device and its subsequent suspend is at least equal to the autosuspend delay.

However, that expectation is only met after the device has been actually resumed in rpm_resume() by invoking its runtime resume callback. If the runtime PM status of the device is already "active" when rpm_resume() runs for it, the device's last_busy timestamp is not updated which may allow a subsequent pm_runtime_put() invocation (or similar) to suspend it right away.

Quoted 7 lines

This is arguably inconsistent and confusing, so make rpm_resume() also update the device's last_busy timestamp when it finds that the device is already "active" and it is about to return 1 early.

Ha, I suppose you can call it Reported-by, even if it's somewhat of a tangent IMO :)

Quoted 2 lines
Reviewed-by on v1 1/1
#3 lore raw
In reply to Rafael J. Wysocki
Quoted 20 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Setting an autosuspend delay for a device can be expected to cause a runtime suspend of the device after calling, say, pm_runtime_put() to be deferred, so the time between the last successful attempt to resume the device and its subsequent suspend is at least equal to the autosuspend delay.

However, that expectation is only met after the device has been actually resumed in rpm_resume() by invoking its runtime resume callback. If the runtime PM status of the device is already "active" when rpm_resume() runs for it, the device's last_busy timestamp is not updated which may allow a subsequent pm_runtime_put() invocation (or similar) to suspend it right away.

This is arguably inconsistent and confusing, so make rpm_resume() also update the device's last_busy timestamp when it finds that the device is already "active" and it is about to return 1 early.

Quoted 5 lines

I guess I may be too late, but in any case, this makes perfect sense to me!

Quoted 22 lines
---
 drivers/base/power/runtime.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/base/power/runtime.c +6 -0
@@ -819,6 +819,12 @@ static int rpm_resume(struct device *dev
                pm_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;
        }