Re: [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()

From: Rafael J. Wysocki (Intel)

Date: Sun Nov 15 2026 - 12:35:23 EST


On Sat, Nov 14, 2026 at 1:59 AM Brian Norris <briannorris@xxxxxxxxxxxx> wrote:
>
> On Fri, Nov 13, 2026 at 02:27:23PM +0100, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>
> >
> > When rpm_idle() is about to call rpm_suspend(), there are no reasons
> > preventing the device from being suspended, but if the device uses an
> > autosuspend delay, it needs to be taken into account.
> >
> > For this purpose, rpm_idle() adds RPM_AUTO to the flags passed to
> > rpm_suspend(), but doing that alone is insufficient because the point
> > in time from which the autosuspend delay is counted may be too early.
> >
> > For example, if the device has children (or consumers) and the last
> > of them goes into runtime suspend, the parent may now become eligible
> > for suspending, but it may not be worthwhile for it to suspend until
> > a certain time later.
> >
> > Quoting Alan Stern [1]:
> >
> > Let's say the last remaining active child goes into runtime suspend at
> > time T. Let's also say that the parent expects none of the children
> > will need to resume until time T + D. Is D sufficiently large to make
> > it worthwhile for the parent to suspend and then resume? If not, the
> > parent should remain active. If yes, the parent should autosuspend --
> > and the length of time the parent should wait before autosuspending is
> > on the order of the value of D (let's call it D*) that corresponds to
> > this crossover point. Thus the parent's autosuspend delay should be
> > set to D*, or something close to it, in order to achieve both
> > objectives.
> >
> > Moreover, if the parent's autosuspend delay is set to D*, it should be
> > counted from time T at which the last child has suspended, but that does
> > not happen because the parent's last_busy timestamp is not updated at
> > time T. That leads to undesirable parent suspends occurring between
> > child suspend and resume [2].
> >
> > To address this issue, make rpm_idle() update the last_busy timestamp
> > of the device when it is about to call rpm_suspend() which most often
> > is right after the device's last child (or consumer) has gone into
> > runtime suspend.
>
> Is it worthwhile to note (or at least hint at) how many other things
> change along with this? e.g., how pm_runtime_allow() (and therefore
> auto > control/power), all non-autosuspend pm_runtime_put() variants,
> etc, also extend the autosuspend timer? I think we agreed these are
> acceptable effects, and likely even desireable, but I'd say these are
> fairly major changes.

Fair enough, I'll add the following to the changelog when applying the patch:

"This potentially changes observable behavior in all situations in
which pm_runtime_put(), pm_runtime_put_sync(), pm_runtime_idle(), or
pm_request() idle is used on a device with an autosuspend delay. That
includes changing a device's "power/control" sysfs attribute value
from "on" to "auto" (if there are no other active runtime PM
references to the given device), accessing PCI configuration space
from user space etc. Namely, in all of those cases, the runtime
suspend of the device following the runtime PM helper call (if it
causes a runtime suspend to occur) will be deferred by the full
autosuspend delay, which arguably is more consistent and predictable
than deferring the runtime suspend in question by a more-or-less
unknown (and basically random) time depending on when the most recent
update of the device's last_busy timestamp has occurred.

It will also cause the majority of the direct
pm_runtime_mark_last_busy() calls to become redundant, and they will
be taken care of later."

> In any case, the change looks good to me:
>
> Reviewed-by: Brian Norris <briannorris@xxxxxxxxxxxx>

Thank you!

> I meant to make time to test this out a bit more, but ran out; maybe
> next week.

That will be much appreciated.