Re: [PATCH v2 3/5] PM: runtime: Propagate last_busy from dependent to dependency
From: Rafael J. Wysocki (Intel)
Date: Thu Nov 05 2026 - 07:10:03 EST
On Wed, Nov 4, 2026 at 8:31 PM Brian Norris <briannorris@xxxxxxxxxxxx> wrote:
>
> On Wed, Nov 04, 2026 at 02:34:22PM +0100, Rafael J. Wysocki (Intel) wrote:
> > I should have responded to the v1 of this, but didn't manage to get to
> > it. Sorry about that.
>
> Hehe, well that's what v2 is for :)
>
> Thanks for looking.
>
> > On Tue, Nov 3, 2026 at 11:23 PM Brian Norris <briannorris@xxxxxxxxxxxx> wrote:
> > >
> > > When a child device suspends, it does not update the last_busy timestamp
> > > for its parent. If that parent configured autosuspend and didn't
> > > otherwise maintain its last_busy timestamp, it may now be immediately
> > > eligible to suspend. This is probably not expected -- the parent should
> > > wait for its autosuspend delay before suspending.
> >
> > Let's first talk about what autosuspend is for: My understanding is
> > that it is there to avoid incurring the runtime PM suspend and resume
> > latency (and cost in terms of energy) in the cases when the device is
> > known or at least is expected to be needed in the near future. IOW,
> > we want to defer the runtime suspend of the device because if it
> > suspended, it would be resumed shortly thereafter.
> >
> > I'm not sure if that is always the case when a dependent device
> > suspends and its reference to the parent/supplier is dropped.
>
> To be clear: dropping a reference is not the point at which we extend
> the timer -- it's simply the point at which we propagate the last_busy
> timestamp.
>
> The naive algorithm is:
> Every time a device updates its last_busy, sync that timestamp to all
> its dependencies.
>
> My proposal modifies that naive algorithm so that it avoids additional
> graph walks -- it defers that "sync" step until later. (Now that I'm
> spelling this out, I feel like I should have included this in the commit
> message...)
OK, thanks for explaining!
You seem to be arguing that the current behavior is counter-intuitive
because people would generally expect the parent's (or supplier's)
last_busy to be automatically advanced to the last "busy" time of its
last active child (or consumer).
That is a bit far-fetched IMV because the child's last "busy" time
need not be the same as the parent's last "busy" time, at least in
principle (of course, that is debatable, but that debate can be had
later).
Still, the underlying observation seems to be that if the child
suspends and then resumes relatively shortly, it may not make sense to
suspend and resume the parent in the meantime, which is fair enough.
Of course, advancing the parent's last_busy will only help here if its
autosuspend delay is long enough though.
So you can argue that if the parent's autosuspend delay is long
enough, then it should prevent the parent from suspending across
relatively short periods of child suspension. Again, this is fair
enough, so why does it not happen at times?
It certainly does happen when the parent actually has to resume
because rpm_resume() calls pm_runtime_mark_last_busy() for it then and
(given a sufficiently long autosuspend delay) it will stay active if
the child resumes a short enough time after suspending. However, when
the child resumes, the parent is still active, so rpm_resume()
triggered by the child does not advance its last_busy timestamp, so at
one point in the future it will suspend when the child suspends.
This arguably is inconsistent, so my approach to addressing the
problem at hand would be the attached patch (sorry for the attachment,
but GMail is generally not good at handling appended patches). If I'm
not mistaken, it should be sufficient to address the particular issue
that triggered commit c537d3457542.
Note that I'm not worried about the potential raciness of this new
last_busy update with other possible concurrent updates of last_busy
because they all use approximations of the current time and if they
are close enough to each other, it should not matter who wins the
race.
> With that said:
>
> > The core calls pm_runtime_mark_last_busy() for resuming devices under
> > the assumption that they are resumed for a reason and so it is likely
> > that they will be needed in near future, but I'm not sure if that
> > assumption can be extended to a child suspend case.
>
> But that's not what I'm doing: I'm not calling mark_last_busy() -- I'm
> just making mark_last_busy() transitive to all dependencies. So any time
> we *already* say the child is busy, I also extend that to the parent --
> I'm not generating any new timestamps; I only reuse the timestamps we
> already selected.
>
> My view on the logic (using your terms above): when a child calls
> mark_last_busy(), it suggests that child might be needed in the near
> future. Whenever a child device is needed, so is its parent (barring
> ignore_children). Thus, mark_last_busy() should also refresh the
> parent's busy timestamp.
Of course, it can be argued this way though there are
counter-arguments (probably not worth discussing in detail at this
point) and there is the question how much of a difference this would
make after addressing the rpm_resume() inconsistency mentioned above
(which IMV needs to be address regardless because it is not limited to
the parent-child or supplier-consumer situations).
> Importantly (in the same topic Jonathan was already asking about): this
> does *not* mean the parent gets a whole new autosuspend delay period --
> but it *does* mean that if the parent has a longer delay period
> (presumably because it has a more expensive/slow suspend/resume latency)
> it waits a bit longer (in case the child wakes back up, for one) to
> autosuspend.
>
> In concrete terms of commit c537d3457542 ("iio: adc: stm32-adc: fix
> runtime autosuspend delay when slow polling"):
>
> * child device has 100ms delay
> * parent devices has 2s delay
>
> SEQUENCE:
> 1) child is active for longer than 2 seconds
> 2) [timestamp N] child finishes I/O, drops reference with put_autosuspend()
> 3) [N + 100ms] child suspends
>
> CURRENT BEHVIOR:
> 4) [N + 100ms] parent suspends immediately after #3
>
> PROPOSAL:
> 4) [N + 2s] parent suspends (if there was no other last_busy update)
>
> The only last_busy timestamp is N; we just use it in more places,
> because the parent was, in fact, busy at timestamp N.
>
> > One might argue
> > though that extending it to the child/consumer resume case would make
> > sense.
> >
> > > The effect of this behavior is that a parent device may suspend sooner
> > > than its autosuspend delay, simply because its usage was accounted by
> > > its children, and not by direct references to the parent device.
> >
> > The distinction between "direct references to the parent device" and
> > "usage accounted for by its children" is not clear to me TBH.
>
> "Direct reference" is to mean "pm_runtime_put_autosuspend()" or anything
> similar that updates last_busy. We expect that when the device in
> question is the target object for I/O or whatever is keeping the device
> busy.
>
> But if the I/O is performed by a child, then it's no longer "direct
> reference" -- it's "usage accounted by its children".
>
> > There are references to the parent device in both cases and it is not
> > like drivers can always expect all runtime PM references to come from
> > specific code paths updating last_busy. There is at least one
> > reference controlled by user space (the "control" attribute in sysfs)
> > and dropping it may also cause the device to suspend immediately if
> > last_busy has not been updated recently. How is this situation
> > different from the one related to child/consumer suspend?
>
> I think I've improperly directed you to focus on the "reference" part,
> which IMO is a bit of a distraction. The point is: when was the device
> "busy" (or "last used")? The 'control' attribute does not represent
> "last used"; it just represents some unrelated policy to prevent
> suspension.
Or not, depending on why user space flips the "control" attribute
which is not known to the kernel.
> > > This was noticed in several cases, and some have implemented
> > > workarounds, such as in commit c537d3457542 ("iio: adc: stm32-adc: fix
> > > runtime autosuspend delay when slow polling"). At the same time, Ulf
> > > suggested these problems "should be solved in the runtime PM core" [1].
> >
> > So I need to be explained how commit 9bdbb1139ca1 ("iio: adc:
> > stm32-adc: add power management support") works because ATM I don't
> > seem to understand it. It looks to me like the .runtime_idle()
> > callback updates last_busy for the device for which it is called, not
> > for its parent.
>
> Note: stm32-adc-core (drivers/iio/adc/stm32-adc-core.c) is the parent.
> stm32-adc (drivers/iio/adc/stm32-adc.c) is the child.
It would really have helped if that had been described properly in the
changelog of commit c537d3457542. Oh well.
> When the child suspends, the parent checks .runtime_idle(). This updates
> last_busy but still falls through to autosuspend -- that means we get a
> slightly suboptimal sequence like the following:
>
> 1) child is active for longer than 2 seconds
> 2) [timestamp N] child finishes I/O, drops reference with put_autosuspend()
> 3) [N + 100ms] child suspends
> 4) parent runtime_idle() updates last_busy to [P = approx N + 100ms]
> 5) [P + 2s] parent suspends
>
> Step 5 happens approximately 100ms later than it really should, but it's
> good enough.
>
> NB: I think this is also why greybus (gb_bundle_idle(),
> gb_interface_runtime_idle(), etc.) and USB (usb_runtime_idle(),
> dwc3_runtime_idle()) look the way they do, with a built-in
> mark_last_busy() in runtime_idle().
So I'm wondering how much of this will still be needed with the
attached patch applied.
> I also think that some other areas could use some logic like this. For
> example, drivers/pci/pcie/portdrv.c has a 100ms autosuspend delay so
> that lspci doesn't cause repeated suspend/resume. But suppose config
> access for a child of a port are slow ... then the port still might
> suspend immediately, between config accesses. (Never mind that
> pci_config_pm_runtime_put() doesn't update last_busy...)
But at the point when the first config space access takes place, it is
unclear that the next one will happen, which is part of the problem
here: The child resume needs to be expected to happen shortly for all
of this to make sense.
---
drivers/base/power/runtime.c | 6 ++++++
1 file changed, 6 insertions(+)
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -819,6 +819,12 @@ static int rpm_resume(struct device *dev
pm_runtime_deactivate_timer(dev);
if (dev->power.runtime_status == RPM_ACTIVE) {
+ /*
+ * An attempt to resume the device means that it is needed for
+ * something, so update its last_busy timestamp in analogy with
+ * the case in which it actually resumes below.
+ */
+ pm_runtime_mark_last_busy(dev);
retval = 1;
goto out;
}