Skip to content

Commit 12826a4

Browse files
committed
treewide: Remove redundant
Merge series from Sakari Ailus <[email protected]>: Late last year I posted a set to switch to __pm_runtime_mark_last_busy() and gradually get rid of explicit pm_runtime_mark_last_busy() calls in drivers, embedding them in the appropriate pm_runtime_*autosuspend*() calls. The overall feedback I got at the time was that this is an unnecessary intermediate step, and removing the pm_runtime_mark_last_busy() calls can be done after adding them to the relevant Runtime PM autosuspend related functions.
2 parents 571defe + 2bd9648 commit 12826a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+186
-133
lines changed

Documentation/power/runtime_pm.rst

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,9 @@ suspending the device are satisfied) and to queue up a suspend request for the
154154
device in that case. If there is no idle callback, or if the callback returns
155155
0, then the PM core will attempt to carry out a runtime suspend of the device,
156156
also respecting devices configured for autosuspend. In essence this means a
157-
call to pm_runtime_autosuspend() (do note that drivers needs to update the
158-
device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
159-
this circumstance). To prevent this (for example, if the callback routine has
160-
started a delayed suspend), the routine must return a non-zero value. Negative
161-
error return codes are ignored by the PM core.
157+
call to pm_runtime_autosuspend(). To prevent this (for example, if the callback
158+
routine has started a delayed suspend), the routine must return a non-zero
159+
value. Negative error return codes are ignored by the PM core.
162160

163161
The helper functions provided by the PM core, described in Section 4, guarantee
164162
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:
330328
'power.disable_depth' is different from 0
331329

332330
`int pm_runtime_autosuspend(struct device *dev);`
333-
- same as pm_runtime_suspend() except that the autosuspend delay is taken
334-
`into account;` if pm_runtime_autosuspend_expiration() says the delay has
335-
not yet expired then an autosuspend is scheduled for the appropriate time
336-
and 0 is returned
331+
- same as pm_runtime_suspend() except that a call to
332+
pm_runtime_mark_last_busy() is made and an autosuspend is scheduled for
333+
the appropriate time and 0 is returned
337334

338335
`int pm_runtime_resume(struct device *dev);`
339336
- execute the subsystem-level resume callback for the device; returns 0 on
@@ -357,9 +354,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
357354
success or error code if the request has not been queued up
358355

359356
`int pm_request_autosuspend(struct device *dev);`
360-
- schedule the execution of the subsystem-level suspend callback for the
361-
device when the autosuspend delay has expired; if the delay has already
362-
expired then the work item is queued up immediately
357+
- Call pm_runtime_mark_last_busy() and schedule the execution of the
358+
subsystem-level suspend callback for the device when the autosuspend delay
359+
expires
363360

364361
`int pm_schedule_suspend(struct device *dev, unsigned int delay);`
365362
- schedule the execution of the subsystem-level suspend callback for the
@@ -411,8 +408,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
411408
pm_request_idle(dev) and return its result
412409

413410
`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!
411+
- set the power.last_busy field to the current time and decrement the
412+
device's usage counter; if the result is 0 then run
413+
pm_request_autosuspend(dev) and return its result
416414

417415
`int __pm_runtime_put_autosuspend(struct device *dev);`
418416
- decrement the device's usage counter; if the result is 0 then run
@@ -427,7 +425,8 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
427425
pm_runtime_suspend(dev) and return its result
428426

429427
`int pm_runtime_put_sync_autosuspend(struct device *dev);`
430-
- decrement the device's usage counter; if the result is 0 then run
428+
- set the power.last_busy field to the current time and decrement the
429+
device's usage counter; if the result is 0 then run
431430
pm_runtime_autosuspend(dev) and return its result
432431

433432
`void pm_runtime_enable(struct device *dev);`
@@ -870,11 +869,9 @@ device is automatically suspended (the subsystem or driver still has to call
870869
the appropriate PM routines); rather it means that runtime suspends will
871870
automatically be delayed until the desired period of inactivity has elapsed.
872871

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
872+
Inactivity is determined based on the power.last_busy field. The desired length
873+
of the inactivity period is a matter of policy. Subsystems can set this length
874+
initially by calling pm_runtime_set_autosuspend_delay(), but after device
878875
registration the length should be controlled by user space, using the
879876
/sys/devices/.../power/autosuspend_delay_ms attribute.
880877

@@ -885,12 +882,13 @@ instead of the non-autosuspend counterparts::
885882

886883
Instead of: pm_runtime_suspend use: pm_runtime_autosuspend;
887884
Instead of: pm_schedule_suspend use: pm_request_autosuspend;
888-
Instead of: pm_runtime_put use: __pm_runtime_put_autosuspend;
885+
Instead of: pm_runtime_put use: pm_runtime_put_autosuspend;
889886
Instead of: pm_runtime_put_sync use: pm_runtime_put_sync_autosuspend.
890887

891888
Drivers may also continue to use the non-autosuspend helper functions; they
892889
will behave normally, which means sometimes taking the autosuspend delay into
893-
account (see pm_runtime_idle).
890+
account (see pm_runtime_idle). The autosuspend variants of the functions also
891+
call pm_runtime_mark_last_busy().
894892

895893
Under some circumstances a driver or subsystem may want to prevent a device
896894
from autosuspending immediately, even though the usage counter is zero and the
@@ -922,12 +920,10 @@ Here is a schematic pseudo-code example::
922920
foo_io_completion(struct foo_priv *foo, void *req)
923921
{
924922
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 {
923+
if (--foo->num_pending_requests == 0)
924+
pm_runtime_put_autosuspend(&foo->dev);
925+
else
929926
foo_process_next_request(foo);
930-
}
931927
unlock(&foo->private_lock);
932928
/* Send req result back to the user ... */
933929
}

include/linux/pm_runtime.h

Lines changed: 163 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ static inline void pm_runtime_release_supplier(struct device_link *link) {}
337337
* Invoke the "idle check" callback of @dev and, depending on its return value,
338338
* set up autosuspend of @dev or suspend it (depending on whether or not
339339
* autosuspend has been enabled for it).
340+
*
341+
* Return:
342+
* * 0: Success.
343+
* * -EINVAL: Runtime PM error.
344+
* * -EACCES: Runtime PM disabled.
345+
* * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing
346+
* or device not in %RPM_ACTIVE state.
347+
* * -EBUSY: Runtime PM child_count non-zero.
348+
* * -EPERM: Device PM QoS resume latency 0.
349+
* * -EINPROGRESS: Suspend already in progress.
350+
* * -ENOSYS: CONFIG_PM not enabled.
351+
* * 1: Device already suspended.
352+
* Other values and conditions for the above values are possible as returned by
353+
* Runtime PM idle and suspend callbacks.
340354
*/
341355
static inline int pm_runtime_idle(struct device *dev)
342356
{
@@ -346,21 +360,48 @@ static inline int pm_runtime_idle(struct device *dev)
346360
/**
347361
* pm_runtime_suspend - Suspend a device synchronously.
348362
* @dev: Target device.
363+
*
364+
* Return:
365+
* * 0: Success.
366+
* * -EINVAL: Runtime PM error.
367+
* * -EACCES: Runtime PM disabled.
368+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
369+
* * -EBUSY: Runtime PM child_count non-zero.
370+
* * -EPERM: Device PM QoS resume latency 0.
371+
* * -ENOSYS: CONFIG_PM not enabled.
372+
* * 1: Device already suspended.
373+
* Other values and conditions for the above values are possible as returned by
374+
* Runtime PM suspend callbacks.
349375
*/
350376
static inline int pm_runtime_suspend(struct device *dev)
351377
{
352378
return __pm_runtime_suspend(dev, 0);
353379
}
354380

355381
/**
356-
* pm_runtime_autosuspend - Set up autosuspend of a device or suspend it.
382+
* pm_runtime_autosuspend - Update the last access time and set up autosuspend
383+
* of a device.
357384
* @dev: Target device.
358385
*
359-
* Set up autosuspend of @dev or suspend it (depending on whether or not
360-
* autosuspend is enabled for it) without engaging its "idle check" callback.
386+
* First update the last access time, then set up autosuspend of @dev or suspend
387+
* it (depending on whether or not autosuspend is enabled for it) without
388+
* engaging its "idle check" callback.
389+
*
390+
* Return:
391+
* * 0: Success.
392+
* * -EINVAL: Runtime PM error.
393+
* * -EACCES: Runtime PM disabled.
394+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
395+
* * -EBUSY: Runtime PM child_count non-zero.
396+
* * -EPERM: Device PM QoS resume latency 0.
397+
* * -ENOSYS: CONFIG_PM not enabled.
398+
* * 1: Device already suspended.
399+
* Other values and conditions for the above values are possible as returned by
400+
* Runtime PM suspend callbacks.
361401
*/
362402
static inline int pm_runtime_autosuspend(struct device *dev)
363403
{
404+
pm_runtime_mark_last_busy(dev);
364405
return __pm_runtime_suspend(dev, RPM_AUTO);
365406
}
366407

@@ -379,6 +420,18 @@ static inline int pm_runtime_resume(struct device *dev)
379420
*
380421
* Queue up a work item to run an equivalent of pm_runtime_idle() for @dev
381422
* asynchronously.
423+
*
424+
* Return:
425+
* * 0: Success.
426+
* * -EINVAL: Runtime PM error.
427+
* * -EACCES: Runtime PM disabled.
428+
* * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing
429+
* or device not in %RPM_ACTIVE state.
430+
* * -EBUSY: Runtime PM child_count non-zero.
431+
* * -EPERM: Device PM QoS resume latency 0.
432+
* * -EINPROGRESS: Suspend already in progress.
433+
* * -ENOSYS: CONFIG_PM not enabled.
434+
* * 1: Device already suspended.
382435
*/
383436
static inline int pm_request_idle(struct device *dev)
384437
{
@@ -395,14 +448,27 @@ static inline int pm_request_resume(struct device *dev)
395448
}
396449

397450
/**
398-
* pm_request_autosuspend - Queue up autosuspend of a device.
451+
* pm_request_autosuspend - Update the last access time and queue up autosuspend
452+
* of a device.
399453
* @dev: Target device.
400454
*
401-
* Queue up a work item to run an equivalent pm_runtime_autosuspend() for @dev
402-
* asynchronously.
455+
* Update the last access time of a device and queue up a work item to run an
456+
* equivalent pm_runtime_autosuspend() for @dev asynchronously.
457+
*
458+
* Return:
459+
* * 0: Success.
460+
* * -EINVAL: Runtime PM error.
461+
* * -EACCES: Runtime PM disabled.
462+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
463+
* * -EBUSY: Runtime PM child_count non-zero.
464+
* * -EPERM: Device PM QoS resume latency 0.
465+
* * -EINPROGRESS: Suspend already in progress.
466+
* * -ENOSYS: CONFIG_PM not enabled.
467+
* * 1: Device already suspended.
403468
*/
404469
static inline int pm_request_autosuspend(struct device *dev)
405470
{
471+
pm_runtime_mark_last_busy(dev);
406472
return __pm_runtime_suspend(dev, RPM_ASYNC | RPM_AUTO);
407473
}
408474

@@ -464,6 +530,17 @@ static inline int pm_runtime_resume_and_get(struct device *dev)
464530
*
465531
* Decrement the runtime PM usage counter of @dev and if it turns out to be
466532
* equal to 0, queue up a work item for @dev like in pm_request_idle().
533+
*
534+
* Return:
535+
* * 0: Success.
536+
* * -EINVAL: Runtime PM error.
537+
* * -EACCES: Runtime PM disabled.
538+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
539+
* * -EBUSY: Runtime PM child_count non-zero.
540+
* * -EPERM: Device PM QoS resume latency 0.
541+
* * -EINPROGRESS: Suspend already in progress.
542+
* * -ENOSYS: CONFIG_PM not enabled.
543+
* * 1: Device already suspended.
467544
*/
468545
static inline int pm_runtime_put(struct device *dev)
469546
{
@@ -478,23 +555,47 @@ DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
478555
*
479556
* Decrement the runtime PM usage counter of @dev and if it turns out to be
480557
* equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
558+
*
559+
* Return:
560+
* * 0: Success.
561+
* * -EINVAL: Runtime PM error.
562+
* * -EACCES: Runtime PM disabled.
563+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
564+
* * -EBUSY: Runtime PM child_count non-zero.
565+
* * -EPERM: Device PM QoS resume latency 0.
566+
* * -EINPROGRESS: Suspend already in progress.
567+
* * -ENOSYS: CONFIG_PM not enabled.
568+
* * 1: Device already suspended.
481569
*/
482570
static inline int __pm_runtime_put_autosuspend(struct device *dev)
483571
{
484572
return __pm_runtime_suspend(dev, RPM_GET_PUT | RPM_ASYNC | RPM_AUTO);
485573
}
486574

487575
/**
488-
* pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
576+
* pm_runtime_put_autosuspend - Update the last access time of a device, drop
577+
* its usage counter and queue autosuspend if the usage counter becomes 0.
489578
* @dev: Target device.
490579
*
491-
* Decrement the runtime PM usage counter of @dev and if it turns out to be
492-
* equal to 0, queue up a work item for @dev like in pm_request_autosuspend().
580+
* Update the last access time of @dev, decrement runtime PM usage counter of
581+
* @dev and if it turns out to be equal to 0, queue up a work item for @dev like
582+
* in pm_request_autosuspend().
583+
*
584+
* Return:
585+
* * 0: Success.
586+
* * -EINVAL: Runtime PM error.
587+
* * -EACCES: Runtime PM disabled.
588+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
589+
* * -EBUSY: Runtime PM child_count non-zero.
590+
* * -EPERM: Device PM QoS resume latency 0.
591+
* * -EINPROGRESS: Suspend already in progress.
592+
* * -ENOSYS: CONFIG_PM not enabled.
593+
* * 1: Device already suspended.
493594
*/
494595
static inline int pm_runtime_put_autosuspend(struct device *dev)
495596
{
496-
return __pm_runtime_suspend(dev,
497-
RPM_GET_PUT | RPM_ASYNC | RPM_AUTO);
597+
pm_runtime_mark_last_busy(dev);
598+
return __pm_runtime_put_autosuspend(dev);
498599
}
499600

500601
/**
@@ -506,9 +607,20 @@ static inline int pm_runtime_put_autosuspend(struct device *dev)
506607
* return value, set up autosuspend of @dev or suspend it (depending on whether
507608
* or not autosuspend has been enabled for it).
508609
*
509-
* The possible return values of this function are the same as for
510-
* pm_runtime_idle() and the runtime PM usage counter of @dev remains
511-
* decremented in all cases, even if it returns an error code.
610+
* The runtime PM usage counter of @dev remains decremented in all cases, even
611+
* if it returns an error code.
612+
*
613+
* Return:
614+
* * 0: Success.
615+
* * -EINVAL: Runtime PM error.
616+
* * -EACCES: Runtime PM disabled.
617+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
618+
* * -EBUSY: Runtime PM child_count non-zero.
619+
* * -EPERM: Device PM QoS resume latency 0.
620+
* * -ENOSYS: CONFIG_PM not enabled.
621+
* * 1: Device already suspended.
622+
* Other values and conditions for the above values are possible as returned by
623+
* Runtime PM suspend callbacks.
512624
*/
513625
static inline int pm_runtime_put_sync(struct device *dev)
514626
{
@@ -522,29 +634,56 @@ static inline int pm_runtime_put_sync(struct device *dev)
522634
* Decrement the runtime PM usage counter of @dev and if it turns out to be
523635
* equal to 0, carry out runtime-suspend of @dev synchronously.
524636
*
525-
* The possible return values of this function are the same as for
526-
* pm_runtime_suspend() and the runtime PM usage counter of @dev remains
527-
* decremented in all cases, even if it returns an error code.
637+
* The runtime PM usage counter of @dev remains decremented in all cases, even
638+
* if it returns an error code.
639+
*
640+
* Return:
641+
* * 0: Success.
642+
* * -EINVAL: Runtime PM error.
643+
* * -EACCES: Runtime PM disabled.
644+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
645+
* * -EAGAIN: usage_count non-zero or Runtime PM status change ongoing.
646+
* * -EBUSY: Runtime PM child_count non-zero.
647+
* * -EPERM: Device PM QoS resume latency 0.
648+
* * -ENOSYS: CONFIG_PM not enabled.
649+
* * 1: Device already suspended.
650+
* Other values and conditions for the above values are possible as returned by
651+
* Runtime PM suspend callbacks.
528652
*/
529653
static inline int pm_runtime_put_sync_suspend(struct device *dev)
530654
{
531655
return __pm_runtime_suspend(dev, RPM_GET_PUT);
532656
}
533657

534658
/**
535-
* pm_runtime_put_sync_autosuspend - Drop device usage counter and autosuspend if 0.
659+
* pm_runtime_put_sync_autosuspend - Update the last access time of a device,
660+
* drop device usage counter and autosuspend if 0.
536661
* @dev: Target device.
537662
*
538-
* Decrement the runtime PM usage counter of @dev and if it turns out to be
539-
* equal to 0, set up autosuspend of @dev or suspend it synchronously (depending
540-
* on whether or not autosuspend has been enabled for it).
663+
* Update the last access time of @dev, decrement the runtime PM usage counter
664+
* of @dev and if it turns out to be equal to 0, set up autosuspend of @dev or
665+
* suspend it synchronously (depending on whether or not autosuspend has been
666+
* enabled for it).
541667
*
542-
* The possible return values of this function are the same as for
543-
* pm_runtime_autosuspend() and the runtime PM usage counter of @dev remains
544-
* decremented in all cases, even if it returns an error code.
668+
* The runtime PM usage counter of @dev remains decremented in all cases, even
669+
* if it returns an error code.
670+
*
671+
* Return:
672+
* * 0: Success.
673+
* * -EINVAL: Runtime PM error.
674+
* * -EACCES: Runtime PM disabled.
675+
* * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing.
676+
* * -EBUSY: Runtime PM child_count non-zero.
677+
* * -EPERM: Device PM QoS resume latency 0.
678+
* * -EINPROGRESS: Suspend already in progress.
679+
* * -ENOSYS: CONFIG_PM not enabled.
680+
* * 1: Device already suspended.
681+
* Other values and conditions for the above values are possible as returned by
682+
* Runtime PM suspend callbacks.
545683
*/
546684
static inline int pm_runtime_put_sync_autosuspend(struct device *dev)
547685
{
686+
pm_runtime_mark_last_busy(dev);
548687
return __pm_runtime_suspend(dev, RPM_GET_PUT | RPM_AUTO);
549688
}
550689

0 commit comments

Comments
 (0)