Skip to content

Commit 2fff3f7

Browse files
committed
Documentation: PM: sleep: Update driver flags documentation
Update the documentation of the driver flags for system-wide power management to reflect the current code flows and be more consistent. Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2a3f347 commit 2fff3f7

File tree

3 files changed

+119
-87
lines changed

3 files changed

+119
-87
lines changed

Documentation/driver-api/pm/devices.rst

Lines changed: 92 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -772,62 +772,107 @@ the state of devices (possibly except for resuming them from runtime suspend)
772772
from their ``->prepare`` and ``->suspend`` callbacks (or equivalent) *before*
773773
invoking device drivers' ``->suspend`` callbacks (or equivalent).
774774

775+
.. _smart_suspend_flag:
776+
777+
The ``DPM_FLAG_SMART_SUSPEND`` Driver Flag
778+
------------------------------------------
779+
775780
Some bus types and PM domains have a policy to resume all devices from runtime
776781
suspend upfront in their ``->suspend`` callbacks, but that may not be really
777782
necessary if the driver of the device can cope with runtime-suspended devices.
778783
The driver can indicate that by setting ``DPM_FLAG_SMART_SUSPEND`` in
779-
:c:member:`power.driver_flags` at the probe time, by passing it to the
780-
:c:func:`dev_pm_set_driver_flags` helper. That also may cause middle-layer code
784+
:c:member:`power.driver_flags` at the probe time with the help of the
785+
:c:func:`dev_pm_set_driver_flags` helper routine.
786+
787+
However, setting that flag also causes the PM core and middle-layer code
781788
(bus types, PM domains etc.) to skip the ``->suspend_late`` and
782789
``->suspend_noirq`` callbacks provided by the driver if the device remains in
783-
runtime suspend at the beginning of the ``suspend_late`` phase of system-wide
784-
suspend (or in the ``poweroff_late`` phase of hibernation), when runtime PM
785-
has been disabled for it, under the assumption that its state should not change
786-
after that point until the system-wide transition is over (the PM core itself
787-
does that for devices whose "noirq", "late" and "early" system-wide PM callbacks
788-
are executed directly by it). If that happens, the driver's system-wide resume
789-
callbacks, if present, may still be invoked during the subsequent system-wide
790-
resume transition and the device's runtime power management status may be set
791-
to "active" before enabling runtime PM for it, so the driver must be prepared to
792-
cope with the invocation of its system-wide resume callbacks back-to-back with
793-
its ``->runtime_suspend`` one (without the intervening ``->runtime_resume`` and
794-
so on) and the final state of the device must reflect the "active" runtime PM
795-
status in that case.
790+
runtime suspend during the ``suspend_late`` phase of system-wide suspend (or
791+
during the ``poweroff_late`` or ``freeze_late`` phase of hibernation),
792+
after runtime PM was disabled for it. [Without doing that, the same driver
793+
callback might be executed twice in a row for the same device, which would not
794+
be valid in general.] If the middle-layer system-wide PM callbacks are present
795+
for the device, they are responsible for doing the above, and the PM core takes
796+
care of it otherwise.
797+
798+
In addition, with ``DPM_FLAG_SMART_SUSPEND`` set, the driver's ``->thaw_late``
799+
and ``->thaw_noirq`` callbacks are skipped if the device remained in runtime
800+
suspend during the preceding "freeze" transition related to hibernation.
801+
Again, if the middle-layer callbacks are present for the device, they are
802+
responsible for doing that, or the PM core takes care of it otherwise.
803+
804+
805+
The ``DPM_FLAG_MAY_SKIP_RESUME`` Driver Flag
806+
--------------------------------------------
796807

797808
During system-wide resume from a sleep state it's easiest to put devices into
798809
the full-power state, as explained in :file:`Documentation/power/runtime_pm.rst`.
799810
[Refer to that document for more information regarding this particular issue as
800811
well as for information on the device runtime power management framework in
801-
general.]
802-
803-
However, it often is desirable to leave devices in suspend after system
804-
transitions to the working state, especially if those devices had been in
812+
general.] However, it often is desirable to leave devices in suspend after
813+
system transitions to the working state, especially if those devices had been in
805814
runtime suspend before the preceding system-wide suspend (or analogous)
806-
transition. Device drivers can use the ``DPM_FLAG_MAY_SKIP_RESUME`` flag to
807-
indicate to the PM core (and middle-layer code) that they prefer the specific
808-
devices handled by them to be left suspended and they have no problems with
809-
skipping their system-wide resume callbacks for this reason. Whether or not the
810-
devices will actually be left in suspend may depend on their state before the
811-
given system suspend-resume cycle and on the type of the system transition under
812-
way. In particular, devices are not left suspended if that transition is a
813-
restore from hibernation, as device states are not guaranteed to be reflected
814-
by the information stored in the hibernation image in that case.
815-
816-
The middle-layer code involved in the handling of the device is expected to
817-
indicate to the PM core if the device may be left in suspend by setting its
818-
:c:member:`power.may_skip_resume` status bit which is checked by the PM core
819-
during the "noirq" phase of the preceding system-wide suspend (or analogous)
820-
transition. The middle layer is then responsible for handling the device as
821-
appropriate in its "noirq" resume callback, which is executed regardless of
822-
whether or not the device is left suspended, but the other resume callbacks
823-
(except for ``->complete``) will be skipped automatically by the PM core if the
824-
device really can be left in suspend.
825-
826-
For devices whose "noirq", "late" and "early" driver callbacks are invoked
827-
directly by the PM core, all of the system-wide resume callbacks are skipped if
828-
``DPM_FLAG_MAY_SKIP_RESUME`` is set and the device is in runtime suspend during
829-
the ``suspend_noirq`` (or analogous) phase or the transition under way is a
830-
proper system suspend (rather than anything related to hibernation) and the
831-
device's wakeup settings are suitable for runtime PM (that is, it cannot
832-
generate wakeup signals at all or it is allowed to wake up the system from
833-
sleep).
815+
transition.
816+
817+
To that end, device drivers can use the ``DPM_FLAG_MAY_SKIP_RESUME`` flag to
818+
indicate to the PM core and middle-layer code that they allow their "noirq" and
819+
"early" resume callbacks to be skipped if the device can be left in suspend
820+
after system-wide PM transitions to the working state. Whether or not that is
821+
the case generally depends on the state of the device before the given system
822+
suspend-resume cycle and on the type of the system transition under way.
823+
In particular, the "restore" and "thaw" transitions related to hibernation are
824+
not affected by ``DPM_FLAG_MAY_SKIP_RESUME`` at all. [All devices are always
825+
resumed during the "restore" transition and whether or not any driver callbacks
826+
are skipped during the "freeze" transition depends whether or not the
827+
``DPM_FLAG_SMART_SUSPEND`` flag is set (see `above <smart_suspend_flag_>`_).]
828+
829+
The ``DPM_FLAG_MAY_SKIP_RESUME`` flag is taken into account in combination with
830+
the :c:member:`power.may_skip_resume` status bit set by the PM core during the
831+
"suspend" phase of suspend-type transitions. If the driver or the middle layer
832+
has a reason to prevent the driver's "noirq" and "early" resume callbacks from
833+
being skipped during the subsequent resume transition of the system, it should
834+
clear :c:member:`power.may_skip_resume` in its ``->suspend``, ``->suspend_late``
835+
or ``->suspend_noirq`` callback. [Note that the drivers setting
836+
``DPM_FLAG_SMART_SUSPEND`` need to clear :c:member:`power.may_skip_resume` in
837+
their ``->suspend`` callback in case the other two are skipped.]
838+
839+
Setting the :c:member:`power.may_skip_resume` status bit along with the
840+
``DPM_FLAG_MAY_SKIP_RESUME`` flag is necessary, but generally not sufficient,
841+
for the driver's "noirq" and "early" resume callbacks to be skipped. Whether or
842+
not they should be skipped can be determined by evaluating the
843+
:c:func:`dev_pm_skip_resume` helper function.
844+
845+
If that function returns ``true``, the driver's "noirq" and "early" resume
846+
callbacks should be skipped and the device's runtime PM status will be set to
847+
"suspended" by the PM core. Otherwise, if the device was runtime-suspended
848+
during the preceding system-wide suspend transition and
849+
``DPM_FLAG_SMART_SUSPEND`` is set for it, its runtime PM status will be set to
850+
"active" by the PM core. [Hence, the drivers that do not set
851+
``DPM_FLAG_SMART_SUSPEND`` should not expect the runtime PM status of their
852+
devices to be changed from "suspended" to "active" by the PM core during
853+
system-wide resume-type transitions.]
854+
855+
If the ``DPM_FLAG_MAY_SKIP_RESUME`` flag is not set for a device, but
856+
``DPM_FLAG_SMART_SUSPEND`` is set and the driver's "late" and "noirq" suspend
857+
callbacks are skipped, its system-wide "noirq" and "early" resume callbacks, if
858+
present, are invoked as usual and the device's runtime PM status is set to
859+
"active" by the PM core before enabling runtime PM for it. In that case, the
860+
driver must be prepared to cope with the invocation of its system-wide resume
861+
callbacks back-to-back with its ``->runtime_suspend`` one (without the
862+
intervening ``->runtime_resume`` and system-wide suspend callbacks) and the
863+
final state of the device must reflect the "active" runtime PM status in that
864+
case. [Note that this is not a problem at all if the driver's
865+
``->suspend_late`` callback pointer points to the same function as its
866+
``->runtime_suspend`` one and its ``->resume_early`` callback pointer points to
867+
the same function as the ``->runtime_resume`` one, while none of the other
868+
system-wide suspend-resume callbacks of the driver are present, for example.]
869+
870+
Likewise, if ``DPM_FLAG_MAY_SKIP_RESUME`` is set for a device, its driver's
871+
system-wide "noirq" and "early" resume callbacks may be skipped while its "late"
872+
and "noirq" suspend callbacks may have been executed (in principle, regardless
873+
of whether or not ``DPM_FLAG_SMART_SUSPEND`` is set). In that case, the driver
874+
needs to be able to cope with the invocation of its ``->runtime_resume``
875+
callback back-to-back with its "late" and "noirq" suspend ones. [For instance,
876+
that is not a concern if the driver sets both ``DPM_FLAG_SMART_SUSPEND`` and
877+
``DPM_FLAG_MAY_SKIP_RESUME`` and uses the same pair of suspend/resume callback
878+
functions for runtime PM and system-wide suspend/resume.]

Documentation/power/pci.rst

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,32 +1010,33 @@ if the device is in runtime suspend when the system suspend starts. That also
10101010
affects all of the ancestors of the device, so this flag should only be used if
10111011
absolutely necessary.
10121012

1013-
The DPM_FLAG_SMART_PREPARE flag instructs the PCI bus type to only return a
1014-
positive value from pci_pm_prepare() if the ->prepare callback provided by the
1013+
The DPM_FLAG_SMART_PREPARE flag causes the PCI bus type to return a positive
1014+
value from pci_pm_prepare() only if the ->prepare callback provided by the
10151015
driver of the device returns a positive value. That allows the driver to opt
1016-
out from using the direct-complete mechanism dynamically.
1016+
out from using the direct-complete mechanism dynamically (whereas setting
1017+
DPM_FLAG_NO_DIRECT_COMPLETE means permanent opt-out).
10171018

10181019
The DPM_FLAG_SMART_SUSPEND flag tells the PCI bus type that from the driver's
10191020
perspective the device can be safely left in runtime suspend during system
10201021
suspend. That causes pci_pm_suspend(), pci_pm_freeze() and pci_pm_poweroff()
1021-
to skip resuming the device from runtime suspend unless there are PCI-specific
1022-
reasons for doing that. Also, it causes pci_pm_suspend_late/noirq(),
1023-
pci_pm_freeze_late/noirq() and pci_pm_poweroff_late/noirq() to return early
1024-
if the device remains in runtime suspend in the beginning of the "late" phase
1025-
of the system-wide transition under way. Moreover, if the device is in
1026-
runtime suspend in pci_pm_resume_noirq() or pci_pm_restore_noirq(), its runtime
1027-
power management status will be changed to "active" (as it is going to be put
1028-
into D0 going forward), but if it is in runtime suspend in pci_pm_thaw_noirq(),
1029-
the function will set the power.direct_complete flag for it (to make the PM core
1030-
skip the subsequent "thaw" callbacks for it) and return.
1031-
1032-
Setting the DPM_FLAG_MAY_SKIP_RESUME flag means that the driver prefers the
1033-
device to be left in suspend after system-wide transitions to the working state.
1034-
This flag is checked by the PM core, but the PCI bus type informs the PM core
1035-
which devices may be left in suspend from its perspective (that happens during
1036-
the "noirq" phase of system-wide suspend and analogous transitions) and next it
1037-
uses the dev_pm_skip_resume() helper to decide whether or not to return from
1038-
pci_pm_resume_noirq() and pci_pm_resume_early() upfront.
1022+
to avoid resuming the device from runtime suspend unless there are PCI-specific
1023+
reasons for doing that. Also, it causes pci_pm_suspend_late/noirq() and
1024+
pci_pm_poweroff_late/noirq() to return early if the device remains in runtime
1025+
suspend during the "late" phase of the system-wide transition under way.
1026+
Moreover, if the device is in runtime suspend in pci_pm_resume_noirq() or
1027+
pci_pm_restore_noirq(), its runtime PM status will be changed to "active" (as it
1028+
is going to be put into D0 going forward).
1029+
1030+
Setting the DPM_FLAG_MAY_SKIP_RESUME flag means that the driver allows its
1031+
"noirq" and "early" resume callbacks to be skipped if the device can be left
1032+
in suspend after a system-wide transition into the working state. This flag is
1033+
taken into consideration by the PM core along with the power.may_skip_resume
1034+
status bit of the device which is set by pci_pm_suspend_noirq() in certain
1035+
situations. If the PM core determines that the driver's "noirq" and "early"
1036+
resume callbacks should be skipped, the dev_pm_skip_resume() helper function
1037+
will return "true" and that will cause pci_pm_resume_noirq() and
1038+
pci_pm_resume_early() to return upfront without touching the device and
1039+
executing the driver callbacks.
10391040

10401041
3.2. Device Runtime Power Management
10411042
------------------------------------

include/linux/pm.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -545,25 +545,11 @@ struct pm_subsys_data {
545545
* cleared by the drivers as the driver core will take care of that.
546546
*
547547
* NO_DIRECT_COMPLETE: Do not apply direct-complete optimization to the device.
548-
* SMART_PREPARE: Check the return value of the driver's ->prepare callback.
549-
* SMART_SUSPEND: No need to resume the device from runtime suspend.
550-
* MAY_SKIP_RESUME: Avoid resuming the device during system resume if possible.
551-
*
552-
* Setting SMART_PREPARE instructs bus types and PM domains which may want
553-
* system suspend/resume callbacks to be skipped for the device to return 0 from
554-
* their ->prepare callbacks if the driver's ->prepare callback returns 0 (in
555-
* other words, the system suspend/resume callbacks can only be skipped for the
556-
* device if its driver doesn't object against that). This flag has no effect
557-
* if NO_DIRECT_COMPLETE is set.
558-
*
559-
* Setting SMART_SUSPEND instructs bus types and PM domains which may want to
560-
* runtime resume the device upfront during system suspend that doing so is not
561-
* necessary from the driver's perspective. It also may cause them to skip
562-
* invocations of the ->suspend_late and ->suspend_noirq callbacks provided by
563-
* the driver if they decide to leave the device in runtime suspend.
564-
*
565-
* Setting MAY_SKIP_RESUME informs the PM core and middle-layer code that the
566-
* driver prefers the device to be left in suspend after system resume.
548+
* SMART_PREPARE: Take the driver ->prepare callback return value into account.
549+
* SMART_SUSPEND: Avoid resuming the device from runtime suspend.
550+
* MAY_SKIP_RESUME: Allow driver "noirq" and "early" callbacks to be skipped.
551+
*
552+
* See Documentation/driver-api/pm/devices.rst for details.
567553
*/
568554
#define DPM_FLAG_NO_DIRECT_COMPLETE BIT(0)
569555
#define DPM_FLAG_SMART_PREPARE BIT(1)

0 commit comments

Comments
 (0)