Skip to content

Commit b3db492

Browse files
Sakari Ailusrafaeljw
authored andcommitted
PM: runtime: Mark last busy stamp in pm_runtime_put_autosuspend()
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 <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 271ff96 commit b3db492

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

Documentation/power/runtime_pm.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
411411
pm_request_idle(dev) and return its result
412412

413413
`int pm_runtime_put_autosuspend(struct device *dev);`
414-
- does the same as __pm_runtime_put_autosuspend() for now, but in the
415-
future, will also call pm_runtime_mark_last_busy() as well, DO NOT USE!
414+
- set the power.last_busy field to the current time and decrement the
415+
device's usage counter; if the result is 0 then run
416+
pm_request_autosuspend(dev) and return its result
416417

417418
`int __pm_runtime_put_autosuspend(struct device *dev);`
418419
- 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
870871
the appropriate PM routines); rather it means that runtime suspends will
871872
automatically be delayed until the desired period of inactivity has elapsed.
872873

873-
Inactivity is determined based on the power.last_busy field. Drivers should
874-
call pm_runtime_mark_last_busy() to update this field after carrying out I/O,
875-
typically just before calling __pm_runtime_put_autosuspend(). The desired
876-
length of the inactivity period is a matter of policy. Subsystems can set this
877-
length initially by calling pm_runtime_set_autosuspend_delay(), but after device
874+
Inactivity is determined based on the power.last_busy field. The desired length
875+
of the inactivity period is a matter of policy. Subsystems can set this length
876+
initially by calling pm_runtime_set_autosuspend_delay(), but after device
878877
registration the length should be controlled by user space, using the
879878
/sys/devices/.../power/autosuspend_delay_ms attribute.
880879

@@ -885,7 +884,7 @@ instead of the non-autosuspend counterparts::
885884

886885
Instead of: pm_runtime_suspend use: pm_runtime_autosuspend;
887886
Instead of: pm_schedule_suspend use: pm_request_autosuspend;
888-
Instead of: pm_runtime_put use: __pm_runtime_put_autosuspend;
887+
Instead of: pm_runtime_put use: pm_runtime_put_autosuspend;
889888
Instead of: pm_runtime_put_sync use: pm_runtime_put_sync_autosuspend.
890889

891890
Drivers may also continue to use the non-autosuspend helper functions; they
@@ -922,12 +921,10 @@ Here is a schematic pseudo-code example::
922921
foo_io_completion(struct foo_priv *foo, void *req)
923922
{
924923
lock(&foo->private_lock);
925-
if (--foo->num_pending_requests == 0) {
926-
pm_runtime_mark_last_busy(&foo->dev);
927-
__pm_runtime_put_autosuspend(&foo->dev);
928-
} else {
924+
if (--foo->num_pending_requests == 0)
925+
pm_runtime_put_autosuspend(&foo->dev);
926+
else
929927
foo_process_next_request(foo);
930-
}
931928
unlock(&foo->private_lock);
932929
/* Send req result back to the user ... */
933930
}

include/linux/pm_runtime.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,13 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
568568
}
569569

570570
/**
571-
* pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
571+
* pm_runtime_put_autosuspend - Update the last access time of a device, drop
572+
* its usage counter and queue autosuspend if the usage counter becomes 0.
572573
* @dev: Target device.
573574
*
574-
* Decrement the runtime PM usage counter of @dev and if it turns out to be
575-
* equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
575+
* Update the last access time of @dev, decrement runtime PM usage counter of
576+
* @dev and if it turns out to be equal to 0, queue up a work item for @dev like
577+
* in pm_request_autosuspend().
576578
*
577579
* Return:
578580
* * 0: Success.
@@ -587,8 +589,8 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev)
587589
*/
588590
static inline int pm_runtime_put_autosuspend(struct device *dev)
589591
{
590-
return __pm_runtime_suspend(dev,
591-
RPM_GET_PUT | RPM_ASYNC | RPM_AUTO);
592+
pm_runtime_mark_last_busy(dev);
593+
return __pm_runtime_put_autosuspend(dev);
592594
}
593595

594596
/**

0 commit comments

Comments
 (0)