All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks
@ 2025-04-10 15:30 Sakari Ailus
  2025-04-10 15:31 ` [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend() Sakari Ailus
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:30 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Folks,

The original plan for adding pm_runtime_mark_last_busy() calls to
functions dealing with Runtime PM autosuspend originally included a few
intermediate steps of driver conversion, including the use of recently
added __pm_runtime_put_autosuspend(). The review of the set converting the
users first to __pm_runtime_put_autosuspend() concluded this wasn't
necessary. See
<URL:https://lore.kernel.org/all/20241004094101.113349-1-sakari.ailus@linux.intel.com/>.

This set extends the inclusion of the pm_runtime_mark_last_busy() call to
the _autosuspend() variants of the Runtime PM functions dealing with
suspending devices, i.e. pm_runtime_put_autosuspend(),
pm_runtime_put_sync_autosuspend(), pm_runtime_autosuspend() and
pm_request_autosuspend(). This will introduce, for a brief amount of time,
unnecessary calls to pm_runtime_mark_last_busy() but this wasn't seen as
an issue. Also, all users of these functions, including those that did not
call pm_runtime_mark_last_busy(), will now include that call. Presumably
in the vast majority of the cases a missing call would have been a bug.

Once this set is merged, I'll post further patches to remove the extra
pm_runtime_mark_last_busy() calls. The current set of these patches is
here
<URL:https://git.kernel.org/pub/scm/linux/kernel/git/sailus/linux-next.git/log/?h=pm-direct-on-next>.

It'd be best to have all merged within the same cycle.

The changes in the patches to remove the pm_runtime_mark_last_busy() calls
have been generated using the following Coccinelle spatch:

@@
expression E;
identifier label, rval;
@@
- pm_runtime_mark_last_busy(E);
...
(
  label:
|
)
...
(
  pm_runtime_put_autosuspend(E);
|
  pm_runtime_put_sync_autosuspend(E);
|
  pm_runtime_autosuspend(E);
|
  pm_request_autosuspend(E);
|
  (void)pm_runtime_put_autosuspend(E);
|
  (void)pm_runtime_put_sync_autosuspend(E);
|
  (void)pm_runtime_autosuspend(E);
|
  (void)pm_request_autosuspend(E);
|
  return pm_runtime_put_autosuspend(E);
|
  return pm_runtime_put_sync_autosuspend(E);
|
  return pm_runtime_autosuspend(E);
|
  return pm_request_autosuspend(E);
|
  rval = pm_runtime_put_autosuspend(E);
|
  rval = pm_runtime_put_sync_autosuspend(E);
|
  rval = pm_runtime_autosuspend(E);
|
  rval = pm_request_autosuspend(E);
)

Sakari Ailus (7):
  Documentation: pm: runtime: Fix a reference to
    pm_runtime_autosuspend()
  pm: runtime: Document return values of suspend related API functions
  pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
  pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()
  pm: runtime: Mark last busy stamp in pm_runtime_autosuspend()
  pm: runtime: Mark last busy stamp in pm_request_autosuspend()
  Documentation: PM: *_autosuspend() functions update last busy time

 Documentation/power/runtime_pm.rst |  50 ++++----
 include/linux/pm_runtime.h         | 187 +++++++++++++++++++++++++----
 2 files changed, 186 insertions(+), 51 deletions(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend()
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 20:13   ` Laurent Pinchart
  2025-04-10 15:31 ` [PATCH 2/7] pm: runtime: Document return values of suspend related API functions Sakari Ailus
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

pm_runtime_autosuspend() got accidentally renamed as
__pm_runtime_autosuspend() whereas the intention in the patch was to
rename pm_runtime_put_autosuspend() only. Fix it.

Fixes: b7d46644e554 ("PM: runtime: Add pm_runtime_put_autosuspend() replacement")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/power/runtime_pm.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index 12f429359a82..63344bea8393 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -154,7 +154,7 @@ suspending the device are satisfied) and to queue up a suspend request for the
 device in that case.  If there is no idle callback, or if the callback returns
 0, then the PM core will attempt to carry out a runtime suspend of the device,
 also respecting devices configured for autosuspend.  In essence this means a
-call to __pm_runtime_autosuspend() (do note that drivers needs to update the
+call to pm_runtime_autosuspend() (do note that drivers needs to update the
 device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
 this circumstance).  To prevent this (for example, if the callback routine has
 started a delayed suspend), the routine must return a non-zero value.  Negative
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/7] pm: runtime: Document return values of suspend related API functions
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
  2025-04-10 15:31 ` [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend() Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 15:31 ` [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend() Sakari Ailus
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Document return values for device suspend and idle related API functions.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/linux/pm_runtime.h | 147 ++++++++++++++++++++++++++++++++++---
 1 file changed, 138 insertions(+), 9 deletions(-)

diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 7fb5a459847e..3e31cbebc527 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -333,6 +333,20 @@ static inline void pm_runtime_release_supplier(struct device_link *link) {}
  * Invoke the "idle check" callback of @dev and, depending on its return value,
  * set up autosuspend of @dev or suspend it (depending on whether or not
  * autosuspend has been enabled for it).
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing
+ *            or device not in %RPM_ACTIVE state.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
+ * Other values and conditions for the above values are possible as returned by
+ * Runtime PM idle and suspend callbacks.
  */
 static inline int pm_runtime_idle(struct device *dev)
 {
@@ -342,6 +356,18 @@ static inline int pm_runtime_idle(struct device *dev)
 /**
  * pm_runtime_suspend - Suspend a device synchronously.
  * @dev: Target device.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
+ * Other values and conditions for the above values are possible as returned by
+ * Runtime PM suspend callbacks.
  */
 static inline int pm_runtime_suspend(struct device *dev)
 {
@@ -354,6 +380,18 @@ static inline int pm_runtime_suspend(struct device *dev)
  *
  * Set up autosuspend of @dev or suspend it (depending on whether or not
  * autosuspend is enabled for it) without engaging its "idle check" callback.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
+ * Other values and conditions for the above values are possible as returned by
+ * Runtime PM suspend callbacks.
  */
 static inline int pm_runtime_autosuspend(struct device *dev)
 {
@@ -375,6 +413,18 @@ static inline int pm_runtime_resume(struct device *dev)
  *
  * Queue up a work item to run an equivalent of pm_runtime_idle() for @dev
  * asynchronously.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing
+ *            or device not in %RPM_ACTIVE state.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
  */
 static inline int pm_request_idle(struct device *dev)
 {
@@ -396,6 +446,17 @@ static inline int pm_request_resume(struct device *dev)
  *
  * Queue up a work item to run an equivalent pm_runtime_autosuspend() for @dev
  * asynchronously.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
  */
 static inline int pm_request_autosuspend(struct device *dev)
 {
@@ -460,6 +521,17 @@ static inline int pm_runtime_resume_and_get(struct device *dev)
  *
  * Decrement the runtime PM usage counter of @dev and if it turns out to be
  * equal to 0, queue up a work item for @dev like in pm_request_idle().
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
  */
 static inline int pm_runtime_put(struct device *dev)
 {
@@ -472,6 +544,17 @@ static inline int pm_runtime_put(struct device *dev)
  *
  * Decrement the runtime PM usage counter of @dev and if it turns out to be
  * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
  */
 static inline int __pm_runtime_put_autosuspend(struct device *dev)
 {
@@ -484,6 +567,17 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
  *
  * Decrement the runtime PM usage counter of @dev and if it turns out to be
  * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
  */
 static inline int pm_runtime_put_autosuspend(struct device *dev)
 {
@@ -500,9 +594,20 @@ static inline int pm_runtime_put_autosuspend(struct device *dev)
  * return value, set up autosuspend of @dev or suspend it (depending on whether
  * or not autosuspend has been enabled for it).
  *
- * The possible return values of this function are the same as for
- * pm_runtime_idle() and the runtime PM usage counter of @dev remains
- * decremented in all cases, even if it returns an error code.
+ * The runtime PM usage counter of @dev remains decremented in all cases, even
+ * if it returns an error code.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
+ * Other values and conditions for the above values are possible as returned by
+ * Runtime PM suspend callbacks.
  */
 static inline int pm_runtime_put_sync(struct device *dev)
 {
@@ -516,9 +621,21 @@ static inline int pm_runtime_put_sync(struct device *dev)
  * Decrement the runtime PM usage counter of @dev and if it turns out to be
  * equal to 0, carry out runtime-suspend of @dev synchronously.
  *
- * The possible return values of this function are the same as for
- * pm_runtime_suspend() and the runtime PM usage counter of @dev remains
- * decremented in all cases, even if it returns an error code.
+ * The runtime PM usage counter of @dev remains decremented in all cases, even
+ * if it returns an error code.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EAGAIN: usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
+ * Other values and conditions for the above values are possible as returned by
+ * Runtime PM suspend callbacks.
  */
 static inline int pm_runtime_put_sync_suspend(struct device *dev)
 {
@@ -533,9 +650,21 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev)
  * equal to 0, set up autosuspend of @dev or suspend it synchronously (depending
  * on whether or not autosuspend has been enabled for it).
  *
- * The possible return values of this function are the same as for
- * pm_runtime_autosuspend() and the runtime PM usage counter of @dev remains
- * decremented in all cases, even if it returns an error code.
+ * The runtime PM usage counter of @dev remains decremented in all cases, even
+ * if it returns an error code.
+ *
+ * Return:
+ * * 0: Success.
+ * * -EINVAL: Runtime PM error.
+ * * -EACCES: Runtime PM disabled.
+ * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
+ * * -EBUSY: Runtime PM child_count non-zero.
+ * * -EPERM: Device PM QoS resume latency 0.
+ * * -EINPROGRESS: Suspend already in progress.
+ * * -ENOSYS: CONFIG_PM not enabled.
+ * * 1: Device already suspended.
+ * Other values and conditions for the above values are possible as returned by
+ * Runtime PM suspend callbacks.
  */
 static inline int pm_runtime_put_sync_autosuspend(struct device *dev)
 {
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
  2025-04-10 15:31 ` [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend() Sakari Ailus
  2025-04-10 15:31 ` [PATCH 2/7] pm: runtime: Document return values of suspend related API functions Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 20:17   ` Laurent Pinchart
  2025-04-10 15:31 ` [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend() Sakari Ailus
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Set device's last busy timestamp to current time in
pm_runtime_put_autosuspend(). Callers wishing not to do that will need to
use __pm_runtime_put_autosuspend().

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/power/runtime_pm.rst | 23 ++++++++++-------------
 include/linux/pm_runtime.h         | 12 +++++++-----
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index 63344bea8393..e7bbdc66d64c 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -411,8 +411,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
       pm_request_idle(dev) and return its result
 
   `int pm_runtime_put_autosuspend(struct device *dev);`
-    - does the same as __pm_runtime_put_autosuspend() for now, but in the
-      future, will also call pm_runtime_mark_last_busy() as well, DO NOT USE!
+    - set the power.last_busy field to the current time and decrement the
+      device's usage counter; if the result is 0 then run
+      pm_request_autosuspend(dev) and return its result
 
   `int __pm_runtime_put_autosuspend(struct device *dev);`
     - decrement the device's usage counter; if the result is 0 then run
@@ -870,11 +871,9 @@ device is automatically suspended (the subsystem or driver still has to call
 the appropriate PM routines); rather it means that runtime suspends will
 automatically be delayed until the desired period of inactivity has elapsed.
 
-Inactivity is determined based on the power.last_busy field.  Drivers should
-call pm_runtime_mark_last_busy() to update this field after carrying out I/O,
-typically just before calling __pm_runtime_put_autosuspend().  The desired
-length of the inactivity period is a matter of policy.  Subsystems can set this
-length initially by calling pm_runtime_set_autosuspend_delay(), but after device
+Inactivity is determined based on the power.last_busy field. The desired length
+of the inactivity period is a matter of policy.  Subsystems can set this length
+initially by calling pm_runtime_set_autosuspend_delay(), but after device
 registration the length should be controlled by user space, using the
 /sys/devices/.../power/autosuspend_delay_ms attribute.
 
@@ -885,7 +884,7 @@ instead of the non-autosuspend counterparts::
 
 	Instead of: pm_runtime_suspend    use: pm_runtime_autosuspend;
 	Instead of: pm_schedule_suspend   use: pm_request_autosuspend;
-	Instead of: pm_runtime_put        use: __pm_runtime_put_autosuspend;
+	Instead of: pm_runtime_put        use: pm_runtime_put_autosuspend;
 	Instead of: pm_runtime_put_sync   use: pm_runtime_put_sync_autosuspend.
 
 Drivers may also continue to use the non-autosuspend helper functions; they
@@ -922,12 +921,10 @@ Here is a schematic pseudo-code example::
 	foo_io_completion(struct foo_priv *foo, void *req)
 	{
 		lock(&foo->private_lock);
-		if (--foo->num_pending_requests == 0) {
-			pm_runtime_mark_last_busy(&foo->dev);
-			__pm_runtime_put_autosuspend(&foo->dev);
-		} else {
+		if (--foo->num_pending_requests == 0)
+			pm_runtime_put_autosuspend(&foo->dev);
+		else
 			foo_process_next_request(foo);
-		}
 		unlock(&foo->private_lock);
 		/* Send req result back to the user ... */
 	}
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 3e31cbebc527..0ade3f75d903 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -562,11 +562,13 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
 }
 
 /**
- * pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
+ * pm_runtime_put_autosuspend - Update the last access time of a device, drop
+ * its usage counter and queue autosuspend if the usage counter becomes 0.
  * @dev: Target device.
  *
- * Decrement the runtime PM usage counter of @dev and if it turns out to be
- * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
+ * Update the last access time of @dev and decrement its runtime PM usage
+ * counter and if it turns out to be equal to 0, queue up a work item for @dev
+ * like in pm_request_autosuspend().
  *
  * Return:
  * * 0: Success.
@@ -581,8 +583,8 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
  */
 static inline int pm_runtime_put_autosuspend(struct device *dev)
 {
-	return __pm_runtime_suspend(dev,
-	    RPM_GET_PUT | RPM_ASYNC | RPM_AUTO);
+	pm_runtime_mark_last_busy(dev);
+	return __pm_runtime_put_autosuspend(dev);
 }
 
 /**
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
                   ` (2 preceding siblings ...)
  2025-04-10 15:31 ` [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend() Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 20:23   ` Laurent Pinchart
  2025-04-10 15:31 ` [PATCH 5/7] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend() Sakari Ailus
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Set device's last busy timestamp to current time in
pm_runtime_put_sync_autosuspend().

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/power/runtime_pm.rst |  3 ++-
 include/linux/pm_runtime.h         | 11 +++++++----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index e7bbdc66d64c..9c21c913f9cf 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -428,7 +428,8 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
       pm_runtime_suspend(dev) and return its result
 
   `int pm_runtime_put_sync_autosuspend(struct device *dev);`
-    - decrement the device's usage counter; if the result is 0 then run
+    - set the power.last_busy field to the current time and decrement the
+      device's usage counter; if the result is 0 then run
       pm_runtime_autosuspend(dev) and return its result
 
   `void pm_runtime_enable(struct device *dev);`
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 0ade3f75d903..e26caf2c0552 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -645,12 +645,14 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev)
 }
 
 /**
- * pm_runtime_put_sync_autosuspend - Drop device usage counter and autosuspend if 0.
+ * pm_runtime_put_sync_autosuspend - Update the last access time of a device,
+ * drop device usage counter and autosuspend if 0.
  * @dev: Target device.
  *
- * Decrement the runtime PM usage counter of @dev and if it turns out to be
- * equal to 0, set up autosuspend of @dev or suspend it synchronously (depending
- * on whether or not autosuspend has been enabled for it).
+ * Update the last access time of @dev, decrement the runtime PM usage counter
+ * of @dev and if it turns out to be equal to 0, set up autosuspend of @dev or
+ * suspend it synchronously (depending on whether or not autosuspend has been
+ * enabled for it).
  *
  * The runtime PM usage counter of @dev remains decremented in all cases, even
  * if it returns an error code.
@@ -670,6 +672,7 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev)
  */
 static inline int pm_runtime_put_sync_autosuspend(struct device *dev)
 {
+	pm_runtime_mark_last_busy(dev);
 	return __pm_runtime_suspend(dev, RPM_GET_PUT | RPM_AUTO);
 }
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 5/7] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend()
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
                   ` (3 preceding siblings ...)
  2025-04-10 15:31 ` [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend() Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 20:27   ` Laurent Pinchart
  2025-04-10 15:31 ` [PATCH 6/7] pm: runtime: Mark last busy stamp in pm_request_autosuspend() Sakari Ailus
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Set device's last busy timestamp to current time in
pm_runtime_autosuspend().

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/power/runtime_pm.rst | 15 ++++++---------
 include/linux/pm_runtime.h         |  9 ++++++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index 9c21c913f9cf..39a0b62f6648 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -154,11 +154,9 @@ suspending the device are satisfied) and to queue up a suspend request for the
 device in that case.  If there is no idle callback, or if the callback returns
 0, then the PM core will attempt to carry out a runtime suspend of the device,
 also respecting devices configured for autosuspend.  In essence this means a
-call to pm_runtime_autosuspend() (do note that drivers needs to update the
-device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
-this circumstance).  To prevent this (for example, if the callback routine has
-started a delayed suspend), the routine must return a non-zero value.  Negative
-error return codes are ignored by the PM core.
+call to pm_runtime_autosuspend(). To prevent this (for example, if the callback
+routine has started a delayed suspend), the routine must return a non-zero
+value.  Negative error return codes are ignored by the PM core.
 
 The helper functions provided by the PM core, described in Section 4, guarantee
 that the following constraints are met with respect to runtime PM callbacks for
@@ -330,10 +328,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
       'power.disable_depth' is different from 0
 
   `int pm_runtime_autosuspend(struct device *dev);`
-    - same as pm_runtime_suspend() except that the autosuspend delay is taken
-      `into account;` if pm_runtime_autosuspend_expiration() says the delay has
-      not yet expired then an autosuspend is scheduled for the appropriate time
-      and 0 is returned
+    - same as pm_runtime_suspend() except that a call to
+      pm_runtime_mark_last_busy() is made and an autosuspend is scheduled for
+      the appropriate time and 0 is returned
 
   `int pm_runtime_resume(struct device *dev);`
     - execute the subsystem-level resume callback for the device; returns 0 on
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index e26caf2c0552..3d12cfb0bf00 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -375,11 +375,13 @@ static inline int pm_runtime_suspend(struct device *dev)
 }
 
 /**
- * pm_runtime_autosuspend - Set up autosuspend of a device or suspend it.
+ * pm_runtime_autosuspend - Update the last access time and set up autosuspend
+ * of a device.
  * @dev: Target device.
  *
- * Set up autosuspend of @dev or suspend it (depending on whether or not
- * autosuspend is enabled for it) without engaging its "idle check" callback.
+ * First update the last access time, then set up autosuspend of @dev or suspend
+ * it (depending on whether or not autosuspend is enabled for it) without
+ * engaging its "idle check" callback.
  *
  * Return:
  * * 0: Success.
@@ -395,6 +397,7 @@ static inline int pm_runtime_suspend(struct device *dev)
  */
 static inline int pm_runtime_autosuspend(struct device *dev)
 {
+	pm_runtime_mark_last_busy(dev);
 	return __pm_runtime_suspend(dev, RPM_AUTO);
 }
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 6/7] pm: runtime: Mark last busy stamp in pm_request_autosuspend()
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
                   ` (4 preceding siblings ...)
  2025-04-10 15:31 ` [PATCH 5/7] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend() Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 20:28   ` Laurent Pinchart
  2025-04-10 15:31 ` [PATCH 7/7] Documentation: PM: *_autosuspend() functions update last busy time Sakari Ailus
  2025-04-29 11:10 ` [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Rafael J. Wysocki
  7 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Set device's last busy timestamp to current time in
pm_request_autosuspend().

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/power/runtime_pm.rst | 6 +++---
 include/linux/pm_runtime.h         | 8 +++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index 39a0b62f6648..91bc93422262 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -354,9 +354,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
       success or error code if the request has not been queued up
 
   `int pm_request_autosuspend(struct device *dev);`
-    - schedule the execution of the subsystem-level suspend callback for the
-      device when the autosuspend delay has expired; if the delay has already
-      expired then the work item is queued up immediately
+    - Call pm_runtime_mark_last_busy() and schedule the execution of the
+      subsystem-level suspend callback for the device when the autosuspend delay
+      expires
 
   `int pm_schedule_suspend(struct device *dev, unsigned int delay);`
     - schedule the execution of the subsystem-level suspend callback for the
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 3d12cfb0bf00..61ca98cd0aa2 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -444,11 +444,12 @@ static inline int pm_request_resume(struct device *dev)
 }
 
 /**
- * pm_request_autosuspend - Queue up autosuspend of a device.
+ * pm_request_autosuspend - Update the last access time and queue up autosuspend
+ * of a device.
  * @dev: Target device.
  *
- * Queue up a work item to run an equivalent pm_runtime_autosuspend() for @dev
- * asynchronously.
+ * Update the last access time of a device and queue up a work item to run an
+ * equivalent pm_runtime_autosuspend() for @dev asynchronously.
  *
  * Return:
  * * 0: Success.
@@ -463,6 +464,7 @@ static inline int pm_request_resume(struct device *dev)
  */
 static inline int pm_request_autosuspend(struct device *dev)
 {
+	pm_runtime_mark_last_busy(dev);
 	return __pm_runtime_suspend(dev, RPM_ASYNC | RPM_AUTO);
 }
 
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 7/7] Documentation: PM: *_autosuspend() functions update last busy time
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
                   ` (5 preceding siblings ...)
  2025-04-10 15:31 ` [PATCH 6/7] pm: runtime: Mark last busy stamp in pm_request_autosuspend() Sakari Ailus
@ 2025-04-10 15:31 ` Sakari Ailus
  2025-04-10 20:29   ` Laurent Pinchart
  2025-04-29 11:10 ` [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Rafael J. Wysocki
  7 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-10 15:31 UTC (permalink / raw)
  To: linux-pm; +Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Laurent Pinchart

Document that the *_autosuspend() variants of the Runtime PM functions
update the last busy timestamp.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 Documentation/power/runtime_pm.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
index 91bc93422262..c8dbdb8595e5 100644
--- a/Documentation/power/runtime_pm.rst
+++ b/Documentation/power/runtime_pm.rst
@@ -887,7 +887,8 @@ instead of the non-autosuspend counterparts::
 
 Drivers may also continue to use the non-autosuspend helper functions; they
 will behave normally, which means sometimes taking the autosuspend delay into
-account (see pm_runtime_idle).
+account (see pm_runtime_idle). The autosuspend variants of the functions also
+call pm_runtime_mark_last_busy().
 
 Under some circumstances a driver or subsystem may want to prevent a device
 from autosuspending immediately, even though the usage counter is zero and the
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend()
  2025-04-10 15:31 ` [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend() Sakari Ailus
@ 2025-04-10 20:13   ` Laurent Pinchart
  2025-04-15 17:27     ` Rafael J. Wysocki
  0 siblings, 1 reply; 20+ messages in thread
From: Laurent Pinchart @ 2025-04-10 20:13 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Sakari,

Thank you for the patch.

On Thu, Apr 10, 2025 at 06:31:00PM +0300, Sakari Ailus wrote:
> pm_runtime_autosuspend() got accidentally renamed as
> __pm_runtime_autosuspend() whereas the intention in the patch was to
> rename pm_runtime_put_autosuspend() only. Fix it.
> 
> Fixes: b7d46644e554 ("PM: runtime: Add pm_runtime_put_autosuspend() replacement")
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  Documentation/power/runtime_pm.rst | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> index 12f429359a82..63344bea8393 100644
> --- a/Documentation/power/runtime_pm.rst
> +++ b/Documentation/power/runtime_pm.rst
> @@ -154,7 +154,7 @@ suspending the device are satisfied) and to queue up a suspend request for the
>  device in that case.  If there is no idle callback, or if the callback returns
>  0, then the PM core will attempt to carry out a runtime suspend of the device,
>  also respecting devices configured for autosuspend.  In essence this means a
> -call to __pm_runtime_autosuspend() (do note that drivers needs to update the
> +call to pm_runtime_autosuspend() (do note that drivers needs to update the
>  device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
>  this circumstance).  To prevent this (for example, if the callback routine has
>  started a delayed suspend), the routine must return a non-zero value.  Negative

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
  2025-04-10 15:31 ` [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend() Sakari Ailus
@ 2025-04-10 20:17   ` Laurent Pinchart
  2025-04-11  6:27     ` Sakari Ailus
  0 siblings, 1 reply; 20+ messages in thread
From: Laurent Pinchart @ 2025-04-10 20:17 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Sakari,

Thank you for the patch.

On Thu, Apr 10, 2025 at 06:31:02PM +0300, Sakari Ailus wrote:
> Set device's last busy timestamp to current time in
> pm_runtime_put_autosuspend(). Callers wishing not to do that will need to
> use __pm_runtime_put_autosuspend().
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  Documentation/power/runtime_pm.rst | 23 ++++++++++-------------
>  include/linux/pm_runtime.h         | 12 +++++++-----
>  2 files changed, 17 insertions(+), 18 deletions(-)
> 
> diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> index 63344bea8393..e7bbdc66d64c 100644
> --- a/Documentation/power/runtime_pm.rst
> +++ b/Documentation/power/runtime_pm.rst
> @@ -411,8 +411,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
>        pm_request_idle(dev) and return its result
>  
>    `int pm_runtime_put_autosuspend(struct device *dev);`
> -    - does the same as __pm_runtime_put_autosuspend() for now, but in the
> -      future, will also call pm_runtime_mark_last_busy() as well, DO NOT USE!
> +    - set the power.last_busy field to the current time and decrement the
> +      device's usage counter; if the result is 0 then run
> +      pm_request_autosuspend(dev) and return its result
>  
>    `int __pm_runtime_put_autosuspend(struct device *dev);`
>      - decrement the device's usage counter; if the result is 0 then run
> @@ -870,11 +871,9 @@ device is automatically suspended (the subsystem or driver still has to call
>  the appropriate PM routines); rather it means that runtime suspends will
>  automatically be delayed until the desired period of inactivity has elapsed.
>  
> -Inactivity is determined based on the power.last_busy field.  Drivers should
> -call pm_runtime_mark_last_busy() to update this field after carrying out I/O,
> -typically just before calling __pm_runtime_put_autosuspend().  The desired
> -length of the inactivity period is a matter of policy.  Subsystems can set this
> -length initially by calling pm_runtime_set_autosuspend_delay(), but after device
> +Inactivity is determined based on the power.last_busy field. The desired length
> +of the inactivity period is a matter of policy.  Subsystems can set this length
> +initially by calling pm_runtime_set_autosuspend_delay(), but after device
>  registration the length should be controlled by user space, using the
>  /sys/devices/.../power/autosuspend_delay_ms attribute.
>  
> @@ -885,7 +884,7 @@ instead of the non-autosuspend counterparts::
>  
>  	Instead of: pm_runtime_suspend    use: pm_runtime_autosuspend;
>  	Instead of: pm_schedule_suspend   use: pm_request_autosuspend;
> -	Instead of: pm_runtime_put        use: __pm_runtime_put_autosuspend;
> +	Instead of: pm_runtime_put        use: pm_runtime_put_autosuspend;
>  	Instead of: pm_runtime_put_sync   use: pm_runtime_put_sync_autosuspend.
>  
>  Drivers may also continue to use the non-autosuspend helper functions; they
> @@ -922,12 +921,10 @@ Here is a schematic pseudo-code example::
>  	foo_io_completion(struct foo_priv *foo, void *req)
>  	{
>  		lock(&foo->private_lock);
> -		if (--foo->num_pending_requests == 0) {
> -			pm_runtime_mark_last_busy(&foo->dev);
> -			__pm_runtime_put_autosuspend(&foo->dev);
> -		} else {
> +		if (--foo->num_pending_requests == 0)
> +			pm_runtime_put_autosuspend(&foo->dev);
> +		else
>  			foo_process_next_request(foo);
> -		}
>  		unlock(&foo->private_lock);
>  		/* Send req result back to the user ... */
>  	}
> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> index 3e31cbebc527..0ade3f75d903 100644
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -562,11 +562,13 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
>  }
>  
>  /**
> - * pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
> + * pm_runtime_put_autosuspend - Update the last access time of a device, drop
> + * its usage counter and queue autosuspend if the usage counter becomes 0.
>   * @dev: Target device.
>   *
> - * Decrement the runtime PM usage counter of @dev and if it turns out to be
> - * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
> + * Update the last access time of @dev and decrement its runtime PM usage

s/ and decrement/, decrement/

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> + * counter and if it turns out to be equal to 0, queue up a work item for @dev
> + * like in pm_request_autosuspend().
>   *
>   * Return:
>   * * 0: Success.
> @@ -581,8 +583,8 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
>   */
>  static inline int pm_runtime_put_autosuspend(struct device *dev)
>  {
> -	return __pm_runtime_suspend(dev,
> -	    RPM_GET_PUT | RPM_ASYNC | RPM_AUTO);
> +	pm_runtime_mark_last_busy(dev);
> +	return __pm_runtime_put_autosuspend(dev);
>  }
>  
>  /**

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()
  2025-04-10 15:31 ` [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend() Sakari Ailus
@ 2025-04-10 20:23   ` Laurent Pinchart
  2025-06-16  5:51     ` Sakari Ailus
  0 siblings, 1 reply; 20+ messages in thread
From: Laurent Pinchart @ 2025-04-10 20:23 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Sakari,

Thank you for the patch.

On Thu, Apr 10, 2025 at 06:31:03PM +0300, Sakari Ailus wrote:
> Set device's last busy timestamp to current time in
> pm_runtime_put_sync_autosuspend().
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I was a bit puzzled by why this function exists. Reading
Documentation/power/runtime_pm.rst answered that question: if I
understand it correctly, the function is meant to be used by code that
doesn't know whether or not autosuspend has been enabled for a device,
such as core code in subsystems.

I looked at usage patterns, and found the function being used in drivers
as well, for instance in drivers/media/i2c/tc358746.c. Given that the
driver unconditionally enabled autosuspend, is this incorrect usage of
the API ?

> ---
>  Documentation/power/runtime_pm.rst |  3 ++-
>  include/linux/pm_runtime.h         | 11 +++++++----
>  2 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> index e7bbdc66d64c..9c21c913f9cf 100644
> --- a/Documentation/power/runtime_pm.rst
> +++ b/Documentation/power/runtime_pm.rst
> @@ -428,7 +428,8 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
>        pm_runtime_suspend(dev) and return its result
>  
>    `int pm_runtime_put_sync_autosuspend(struct device *dev);`
> -    - decrement the device's usage counter; if the result is 0 then run
> +    - set the power.last_busy field to the current time and decrement the
> +      device's usage counter; if the result is 0 then run
>        pm_runtime_autosuspend(dev) and return its result
>  
>    `void pm_runtime_enable(struct device *dev);`
> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> index 0ade3f75d903..e26caf2c0552 100644
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -645,12 +645,14 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev)
>  }
>  
>  /**
> - * pm_runtime_put_sync_autosuspend - Drop device usage counter and autosuspend if 0.
> + * pm_runtime_put_sync_autosuspend - Update the last access time of a device,
> + * drop device usage counter and autosuspend if 0.
>   * @dev: Target device.
>   *
> - * Decrement the runtime PM usage counter of @dev and if it turns out to be
> - * equal to 0, set up autosuspend of @dev or suspend it synchronously (depending
> - * on whether or not autosuspend has been enabled for it).
> + * Update the last access time of @dev, decrement the runtime PM usage counter
> + * of @dev and if it turns out to be equal to 0, set up autosuspend of @dev or
> + * suspend it synchronously (depending on whether or not autosuspend has been
> + * enabled for it).
>   *
>   * The runtime PM usage counter of @dev remains decremented in all cases, even
>   * if it returns an error code.
> @@ -670,6 +672,7 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev)
>   */
>  static inline int pm_runtime_put_sync_autosuspend(struct device *dev)
>  {
> +	pm_runtime_mark_last_busy(dev);
>  	return __pm_runtime_suspend(dev, RPM_GET_PUT | RPM_AUTO);
>  }
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 5/7] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend()
  2025-04-10 15:31 ` [PATCH 5/7] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend() Sakari Ailus
@ 2025-04-10 20:27   ` Laurent Pinchart
  0 siblings, 0 replies; 20+ messages in thread
From: Laurent Pinchart @ 2025-04-10 20:27 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Sakari,

Thank you for the patch.

On Thu, Apr 10, 2025 at 06:31:04PM +0300, Sakari Ailus wrote:
> Set device's last busy timestamp to current time in
> pm_runtime_autosuspend().
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  Documentation/power/runtime_pm.rst | 15 ++++++---------
>  include/linux/pm_runtime.h         |  9 ++++++---
>  2 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> index 9c21c913f9cf..39a0b62f6648 100644
> --- a/Documentation/power/runtime_pm.rst
> +++ b/Documentation/power/runtime_pm.rst
> @@ -154,11 +154,9 @@ suspending the device are satisfied) and to queue up a suspend request for the
>  device in that case.  If there is no idle callback, or if the callback returns
>  0, then the PM core will attempt to carry out a runtime suspend of the device,
>  also respecting devices configured for autosuspend.  In essence this means a
> -call to pm_runtime_autosuspend() (do note that drivers needs to update the
> -device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
> -this circumstance).  To prevent this (for example, if the callback routine has
> -started a delayed suspend), the routine must return a non-zero value.  Negative
> -error return codes are ignored by the PM core.
> +call to pm_runtime_autosuspend(). To prevent this (for example, if the callback
> +routine has started a delayed suspend), the routine must return a non-zero
> +value.  Negative error return codes are ignored by the PM core.
>  
>  The helper functions provided by the PM core, described in Section 4, guarantee
>  that the following constraints are met with respect to runtime PM callbacks for
> @@ -330,10 +328,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
>        'power.disable_depth' is different from 0
>  
>    `int pm_runtime_autosuspend(struct device *dev);`
> -    - same as pm_runtime_suspend() except that the autosuspend delay is taken
> -      `into account;` if pm_runtime_autosuspend_expiration() says the delay has
> -      not yet expired then an autosuspend is scheduled for the appropriate time
> -      and 0 is returned
> +    - same as pm_runtime_suspend() except that a call to
> +      pm_runtime_mark_last_busy() is made and an autosuspend is scheduled for
> +      the appropriate time and 0 is returned
>  
>    `int pm_runtime_resume(struct device *dev);`
>      - execute the subsystem-level resume callback for the device; returns 0 on
> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> index e26caf2c0552..3d12cfb0bf00 100644
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -375,11 +375,13 @@ static inline int pm_runtime_suspend(struct device *dev)
>  }
>  
>  /**
> - * pm_runtime_autosuspend - Set up autosuspend of a device or suspend it.
> + * pm_runtime_autosuspend - Update the last access time and set up autosuspend
> + * of a device.
>   * @dev: Target device.
>   *
> - * Set up autosuspend of @dev or suspend it (depending on whether or not
> - * autosuspend is enabled for it) without engaging its "idle check" callback.
> + * First update the last access time, then set up autosuspend of @dev or suspend
> + * it (depending on whether or not autosuspend is enabled for it) without
> + * engaging its "idle check" callback.
>   *
>   * Return:
>   * * 0: Success.
> @@ -395,6 +397,7 @@ static inline int pm_runtime_suspend(struct device *dev)
>   */
>  static inline int pm_runtime_autosuspend(struct device *dev)
>  {
> +	pm_runtime_mark_last_busy(dev);
>  	return __pm_runtime_suspend(dev, RPM_AUTO);
>  }
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 6/7] pm: runtime: Mark last busy stamp in pm_request_autosuspend()
  2025-04-10 15:31 ` [PATCH 6/7] pm: runtime: Mark last busy stamp in pm_request_autosuspend() Sakari Ailus
@ 2025-04-10 20:28   ` Laurent Pinchart
  0 siblings, 0 replies; 20+ messages in thread
From: Laurent Pinchart @ 2025-04-10 20:28 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Sakari,

Thank you for the patch.

On Thu, Apr 10, 2025 at 06:31:05PM +0300, Sakari Ailus wrote:
> Set device's last busy timestamp to current time in
> pm_request_autosuspend().
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  Documentation/power/runtime_pm.rst | 6 +++---
>  include/linux/pm_runtime.h         | 8 +++++---
>  2 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> index 39a0b62f6648..91bc93422262 100644
> --- a/Documentation/power/runtime_pm.rst
> +++ b/Documentation/power/runtime_pm.rst
> @@ -354,9 +354,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
>        success or error code if the request has not been queued up
>  
>    `int pm_request_autosuspend(struct device *dev);`
> -    - schedule the execution of the subsystem-level suspend callback for the
> -      device when the autosuspend delay has expired; if the delay has already
> -      expired then the work item is queued up immediately
> +    - Call pm_runtime_mark_last_busy() and schedule the execution of the
> +      subsystem-level suspend callback for the device when the autosuspend delay
> +      expires
>  
>    `int pm_schedule_suspend(struct device *dev, unsigned int delay);`
>      - schedule the execution of the subsystem-level suspend callback for the
> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> index 3d12cfb0bf00..61ca98cd0aa2 100644
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -444,11 +444,12 @@ static inline int pm_request_resume(struct device *dev)
>  }
>  
>  /**
> - * pm_request_autosuspend - Queue up autosuspend of a device.
> + * pm_request_autosuspend - Update the last access time and queue up autosuspend
> + * of a device.
>   * @dev: Target device.
>   *
> - * Queue up a work item to run an equivalent pm_runtime_autosuspend() for @dev
> - * asynchronously.
> + * Update the last access time of a device and queue up a work item to run an
> + * equivalent pm_runtime_autosuspend() for @dev asynchronously.
>   *
>   * Return:
>   * * 0: Success.
> @@ -463,6 +464,7 @@ static inline int pm_request_resume(struct device *dev)
>   */
>  static inline int pm_request_autosuspend(struct device *dev)
>  {
> +	pm_runtime_mark_last_busy(dev);
>  	return __pm_runtime_suspend(dev, RPM_ASYNC | RPM_AUTO);
>  }
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 7/7] Documentation: PM: *_autosuspend() functions update last busy time
  2025-04-10 15:31 ` [PATCH 7/7] Documentation: PM: *_autosuspend() functions update last busy time Sakari Ailus
@ 2025-04-10 20:29   ` Laurent Pinchart
  0 siblings, 0 replies; 20+ messages in thread
From: Laurent Pinchart @ 2025-04-10 20:29 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Sakari,

Thank you for the patch.

On Thu, Apr 10, 2025 at 06:31:06PM +0300, Sakari Ailus wrote:
> Document that the *_autosuspend() variants of the Runtime PM functions
> update the last busy timestamp.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  Documentation/power/runtime_pm.rst | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> index 91bc93422262..c8dbdb8595e5 100644
> --- a/Documentation/power/runtime_pm.rst
> +++ b/Documentation/power/runtime_pm.rst
> @@ -887,7 +887,8 @@ instead of the non-autosuspend counterparts::
>  
>  Drivers may also continue to use the non-autosuspend helper functions; they
>  will behave normally, which means sometimes taking the autosuspend delay into
> -account (see pm_runtime_idle).
> +account (see pm_runtime_idle). The autosuspend variants of the functions also
> +call pm_runtime_mark_last_busy().
>  
>  Under some circumstances a driver or subsystem may want to prevent a device
>  from autosuspending immediately, even though the usage counter is zero and the

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
  2025-04-10 20:17   ` Laurent Pinchart
@ 2025-04-11  6:27     ` Sakari Ailus
  2025-04-11  6:33       ` Sakari Ailus
  0 siblings, 1 reply; 20+ messages in thread
From: Sakari Ailus @ 2025-04-11  6:27 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Laurent,

Thanks for the review.

On Thu, Apr 10, 2025 at 11:17:11PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thank you for the patch.
> 
> On Thu, Apr 10, 2025 at 06:31:02PM +0300, Sakari Ailus wrote:
> > Set device's last busy timestamp to current time in
> > pm_runtime_put_autosuspend(). Callers wishing not to do that will need to
> > use __pm_runtime_put_autosuspend().
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> >  Documentation/power/runtime_pm.rst | 23 ++++++++++-------------
> >  include/linux/pm_runtime.h         | 12 +++++++-----
> >  2 files changed, 17 insertions(+), 18 deletions(-)
> > 
> > diff --git a/Documentation/power/runtime_pm.rst b/Documentation/power/runtime_pm.rst
> > index 63344bea8393..e7bbdc66d64c 100644
> > --- a/Documentation/power/runtime_pm.rst
> > +++ b/Documentation/power/runtime_pm.rst
> > @@ -411,8 +411,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
> >        pm_request_idle(dev) and return its result
> >  
> >    `int pm_runtime_put_autosuspend(struct device *dev);`
> > -    - does the same as __pm_runtime_put_autosuspend() for now, but in the
> > -      future, will also call pm_runtime_mark_last_busy() as well, DO NOT USE!
> > +    - set the power.last_busy field to the current time and decrement the
> > +      device's usage counter; if the result is 0 then run
> > +      pm_request_autosuspend(dev) and return its result
> >  
> >    `int __pm_runtime_put_autosuspend(struct device *dev);`
> >      - decrement the device's usage counter; if the result is 0 then run
> > @@ -870,11 +871,9 @@ device is automatically suspended (the subsystem or driver still has to call
> >  the appropriate PM routines); rather it means that runtime suspends will
> >  automatically be delayed until the desired period of inactivity has elapsed.
> >  
> > -Inactivity is determined based on the power.last_busy field.  Drivers should
> > -call pm_runtime_mark_last_busy() to update this field after carrying out I/O,
> > -typically just before calling __pm_runtime_put_autosuspend().  The desired
> > -length of the inactivity period is a matter of policy.  Subsystems can set this
> > -length initially by calling pm_runtime_set_autosuspend_delay(), but after device
> > +Inactivity is determined based on the power.last_busy field. The desired length
> > +of the inactivity period is a matter of policy.  Subsystems can set this length
> > +initially by calling pm_runtime_set_autosuspend_delay(), but after device
> >  registration the length should be controlled by user space, using the
> >  /sys/devices/.../power/autosuspend_delay_ms attribute.
> >  
> > @@ -885,7 +884,7 @@ instead of the non-autosuspend counterparts::
> >  
> >  	Instead of: pm_runtime_suspend    use: pm_runtime_autosuspend;
> >  	Instead of: pm_schedule_suspend   use: pm_request_autosuspend;
> > -	Instead of: pm_runtime_put        use: __pm_runtime_put_autosuspend;
> > +	Instead of: pm_runtime_put        use: pm_runtime_put_autosuspend;
> >  	Instead of: pm_runtime_put_sync   use: pm_runtime_put_sync_autosuspend.
> >  
> >  Drivers may also continue to use the non-autosuspend helper functions; they
> > @@ -922,12 +921,10 @@ Here is a schematic pseudo-code example::
> >  	foo_io_completion(struct foo_priv *foo, void *req)
> >  	{
> >  		lock(&foo->private_lock);
> > -		if (--foo->num_pending_requests == 0) {
> > -			pm_runtime_mark_last_busy(&foo->dev);
> > -			__pm_runtime_put_autosuspend(&foo->dev);
> > -		} else {
> > +		if (--foo->num_pending_requests == 0)
> > +			pm_runtime_put_autosuspend(&foo->dev);
> > +		else
> >  			foo_process_next_request(foo);
> > -		}
> >  		unlock(&foo->private_lock);
> >  		/* Send req result back to the user ... */
> >  	}
> > diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> > index 3e31cbebc527..0ade3f75d903 100644
> > --- a/include/linux/pm_runtime.h
> > +++ b/include/linux/pm_runtime.h
> > @@ -562,11 +562,13 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
> >  }
> >  
> >  /**
> > - * pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
> > + * pm_runtime_put_autosuspend - Update the last access time of a device, drop
> > + * its usage counter and queue autosuspend if the usage counter becomes 0.
> >   * @dev: Target device.
> >   *
> > - * Decrement the runtime PM usage counter of @dev and if it turns out to be
> > - * equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
> > + * Update the last access time of @dev and decrement its runtime PM usage
> 
> s/ and decrement/, decrement/

Ack. I'll address this in v2, but wait for other comments still awhile.

> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> > + * counter and if it turns out to be equal to 0, queue up a work item for @dev
> > + * like in pm_request_autosuspend().
> >   *
> >   * Return:
> >   * * 0: Success.
> > @@ -581,8 +583,8 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
> >   */
> >  static inline int pm_runtime_put_autosuspend(struct device *dev)
> >  {
> > -	return __pm_runtime_suspend(dev,
> > -	    RPM_GET_PUT | RPM_ASYNC | RPM_AUTO);
> > +	pm_runtime_mark_last_busy(dev);
> > +	return __pm_runtime_put_autosuspend(dev);
> >  }
> >  
> >  /**

-- 
Kind regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
  2025-04-11  6:27     ` Sakari Ailus
@ 2025-04-11  6:33       ` Sakari Ailus
  0 siblings, 0 replies; 20+ messages in thread
From: Sakari Ailus @ 2025-04-11  6:33 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

On Fri, Apr 11, 2025 at 06:27:06AM +0000, Sakari Ailus wrote:
> > s/ and decrement/, decrement/
> 
> Ack. I'll address this in v2, but wait for other comments still awhile.

The paragraph now looks like:

 * Update the last access time of @dev, decrement runtime PM usage counter of
 * @dev and if it turns out to be equal to 0, queue up a work item for @dev like
 * in pm_request_autosuspend().

I.e. runtime PM usage counter of @dev is decremented, not the usage counter
of the last access time.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend()
  2025-04-10 20:13   ` Laurent Pinchart
@ 2025-04-15 17:27     ` Rafael J. Wysocki
  0 siblings, 0 replies; 20+ messages in thread
From: Rafael J. Wysocki @ 2025-04-15 17:27 UTC (permalink / raw)
  To: Laurent Pinchart, Sakari Ailus
  Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

On Thu, Apr 10, 2025 at 10:14 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Sakari,
>
> Thank you for the patch.
>
> On Thu, Apr 10, 2025 at 06:31:00PM +0300, Sakari Ailus wrote:
> > pm_runtime_autosuspend() got accidentally renamed as
> > __pm_runtime_autosuspend() whereas the intention in the patch was to
> > rename pm_runtime_put_autosuspend() only. Fix it.
> >
> > Fixes: b7d46644e554 ("PM: runtime: Add pm_runtime_put_autosuspend() replacement")
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Applied as 6.15-rc material, thanks!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks
  2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
                   ` (6 preceding siblings ...)
  2025-04-10 15:31 ` [PATCH 7/7] Documentation: PM: *_autosuspend() functions update last busy time Sakari Ailus
@ 2025-04-29 11:10 ` Rafael J. Wysocki
  2025-06-16  5:42   ` Sakari Ailus
  7 siblings, 1 reply; 20+ messages in thread
From: Rafael J. Wysocki @ 2025-04-29 11:10 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek,
	Laurent Pinchart

Hi,

On Thu, Apr 10, 2025 at 5:31 PM Sakari Ailus
<sakari.ailus@linux.intel.com> wrote:
>
> Folks,
>
> The original plan for adding pm_runtime_mark_last_busy() calls to
> functions dealing with Runtime PM autosuspend originally included a few
> intermediate steps of driver conversion, including the use of recently
> added __pm_runtime_put_autosuspend(). The review of the set converting the
> users first to __pm_runtime_put_autosuspend() concluded this wasn't
> necessary. See
> <URL:https://lore.kernel.org/all/20241004094101.113349-1-sakari.ailus@linux.intel.com/>.
>
> This set extends the inclusion of the pm_runtime_mark_last_busy() call to
> the _autosuspend() variants of the Runtime PM functions dealing with
> suspending devices, i.e. pm_runtime_put_autosuspend(),
> pm_runtime_put_sync_autosuspend(), pm_runtime_autosuspend() and
> pm_request_autosuspend(). This will introduce, for a brief amount of time,
> unnecessary calls to pm_runtime_mark_last_busy() but this wasn't seen as
> an issue. Also, all users of these functions, including those that did not
> call pm_runtime_mark_last_busy(), will now include that call. Presumably
> in the vast majority of the cases a missing call would have been a bug.
>
> Once this set is merged, I'll post further patches to remove the extra
> pm_runtime_mark_last_busy() calls. The current set of these patches is
> here
> <URL:https://git.kernel.org/pub/scm/linux/kernel/git/sailus/linux-next.git/log/?h=pm-direct-on-next>.
>
> It'd be best to have all merged within the same cycle.
>
> The changes in the patches to remove the pm_runtime_mark_last_busy() calls
> have been generated using the following Coccinelle spatch:
>
> @@
> expression E;
> identifier label, rval;
> @@
> - pm_runtime_mark_last_busy(E);
> ...
> (
>   label:
> |
> )
> ...
> (
>   pm_runtime_put_autosuspend(E);
> |
>   pm_runtime_put_sync_autosuspend(E);
> |
>   pm_runtime_autosuspend(E);
> |
>   pm_request_autosuspend(E);
> |
>   (void)pm_runtime_put_autosuspend(E);
> |
>   (void)pm_runtime_put_sync_autosuspend(E);
> |
>   (void)pm_runtime_autosuspend(E);
> |
>   (void)pm_request_autosuspend(E);
> |
>   return pm_runtime_put_autosuspend(E);
> |
>   return pm_runtime_put_sync_autosuspend(E);
> |
>   return pm_runtime_autosuspend(E);
> |
>   return pm_request_autosuspend(E);
> |
>   rval = pm_runtime_put_autosuspend(E);
> |
>   rval = pm_runtime_put_sync_autosuspend(E);
> |
>   rval = pm_runtime_autosuspend(E);
> |
>   rval = pm_request_autosuspend(E);
> )
>
> Sakari Ailus (7):
>   Documentation: pm: runtime: Fix a reference to
>     pm_runtime_autosuspend()
>   pm: runtime: Document return values of suspend related API functions
>   pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
>   pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()
>   pm: runtime: Mark last busy stamp in pm_runtime_autosuspend()
>   pm: runtime: Mark last busy stamp in pm_request_autosuspend()
>   Documentation: PM: *_autosuspend() functions update last busy time
>
>  Documentation/power/runtime_pm.rst |  50 ++++----
>  include/linux/pm_runtime.h         | 187 +++++++++++++++++++++++++----
>  2 files changed, 186 insertions(+), 51 deletions(-)
>
> --

Am I correctly expecting a v2 of this series to be posted?

Thanks!

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks
  2025-04-29 11:10 ` [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Rafael J. Wysocki
@ 2025-06-16  5:42   ` Sakari Ailus
  0 siblings, 0 replies; 20+ messages in thread
From: Sakari Ailus @ 2025-06-16  5:42 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, Len Brown, Pavel Machek, Laurent Pinchart

On Tue, Apr 29, 2025 at 01:10:59PM +0200, Rafael J. Wysocki wrote:
> > Sakari Ailus (7):
> >   Documentation: pm: runtime: Fix a reference to
> >     pm_runtime_autosuspend()
> >   pm: runtime: Document return values of suspend related API functions
> >   pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
> >   pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()
> >   pm: runtime: Mark last busy stamp in pm_runtime_autosuspend()
> >   pm: runtime: Mark last busy stamp in pm_request_autosuspend()
> >   Documentation: PM: *_autosuspend() functions update last busy time
> >
> >  Documentation/power/runtime_pm.rst |  50 ++++----
> >  include/linux/pm_runtime.h         | 187 +++++++++++++++++++++++++----
> >  2 files changed, 186 insertions(+), 51 deletions(-)
> >
> > --
> 
> Am I correctly expecting a v2 of this series to be posted?

And replying to the correct thread this time. I'll send v2 soon.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend()
  2025-04-10 20:23   ` Laurent Pinchart
@ 2025-06-16  5:51     ` Sakari Ailus
  0 siblings, 0 replies; 20+ messages in thread
From: Sakari Ailus @ 2025-06-16  5:51 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-pm, Rafael J. Wysocki, Len Brown, Pavel Machek

Hi Laurent,

On Thu, Apr 10, 2025 at 11:23:18PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
> 
> Thank you for the patch.
> 
> On Thu, Apr 10, 2025 at 06:31:03PM +0300, Sakari Ailus wrote:
> > Set device's last busy timestamp to current time in
> > pm_runtime_put_sync_autosuspend().
> > 
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> I was a bit puzzled by why this function exists. Reading
> Documentation/power/runtime_pm.rst answered that question: if I
> understand it correctly, the function is meant to be used by code that
> doesn't know whether or not autosuspend has been enabled for a device,
> such as core code in subsystems.
> 
> I looked at usage patterns, and found the function being used in drivers
> as well, for instance in drivers/media/i2c/tc358746.c. Given that the
> driver unconditionally enabled autosuspend, is this incorrect usage of
> the API ?

The documentation (Documentation/power/runtime_pm.rst, section 9) appears
to say that functions should be used instead of pm_runtime_put_sync() if
the driver has enabled autosuspend. I wonder if the documentation should be
changed, to tell to use pm_runtime_put_sync() instead, for
pm_runtime_put_sync_autosuspend() indeed is effectively
pm_runtime_put_autosuspend() if autosuspend has been enabled.

I wonder what Rafael thinks.

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2025-06-16  5:51 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 15:30 [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Sakari Ailus
2025-04-10 15:31 ` [PATCH 1/7] Documentation: pm: runtime: Fix a reference to pm_runtime_autosuspend() Sakari Ailus
2025-04-10 20:13   ` Laurent Pinchart
2025-04-15 17:27     ` Rafael J. Wysocki
2025-04-10 15:31 ` [PATCH 2/7] pm: runtime: Document return values of suspend related API functions Sakari Ailus
2025-04-10 15:31 ` [PATCH 3/7] pm: runtime: Mark last busy stamp in pm_runtime_put_autosuspend() Sakari Ailus
2025-04-10 20:17   ` Laurent Pinchart
2025-04-11  6:27     ` Sakari Ailus
2025-04-11  6:33       ` Sakari Ailus
2025-04-10 15:31 ` [PATCH 4/7] pm: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend() Sakari Ailus
2025-04-10 20:23   ` Laurent Pinchart
2025-06-16  5:51     ` Sakari Ailus
2025-04-10 15:31 ` [PATCH 5/7] pm: runtime: Mark last busy stamp in pm_runtime_autosuspend() Sakari Ailus
2025-04-10 20:27   ` Laurent Pinchart
2025-04-10 15:31 ` [PATCH 6/7] pm: runtime: Mark last busy stamp in pm_request_autosuspend() Sakari Ailus
2025-04-10 20:28   ` Laurent Pinchart
2025-04-10 15:31 ` [PATCH 7/7] Documentation: PM: *_autosuspend() functions update last busy time Sakari Ailus
2025-04-10 20:29   ` Laurent Pinchart
2025-04-29 11:10 ` [PATCH 0/7] Update last busy timestamp in Runtime PM autosuspend callbacks Rafael J. Wysocki
2025-06-16  5:42   ` Sakari Ailus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.