* [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()
@ 2026-11-13 13:27 Rafael J. Wysocki
2026-11-14 0:59 ` Brian Norris
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2026-11-13 13:27 UTC (permalink / raw)
To: Linux PM; +Cc: LKML, Brian Norris, Alan Stern, Sakari Ailus, Ulf Hansson
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
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.
Updating the last_busy timestamp when rpm_idle() returns an error
without calling rpm_suspend() is not useful because the device is then
going to remain active for an unknown amount of time and its autosuspend
delay needs to take effect later.
Link: https://lore.kernel.org/linux-pm/fc43eb13-816b-4cd0-9711-848fdab605ef@rowland.harvard.edu/ [1]
Link: https://lore.kernel.org/linux-pm/CAJZ5v0hKpjMsGQm8Cpa89x5wkNxqkggDNbp+eQ0S-E52DETWjQ@mail.gmail.com/ [2]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/base/power/runtime.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -560,7 +560,11 @@ static int rpm_idle(struct device *dev,
out:
trace_rpm_return_int(dev, _THIS_IP_, retval);
- return retval ? retval : rpm_suspend(dev, rpmflags | RPM_AUTO);
+ if (retval)
+ return retval;
+
+ pm_runtime_mark_last_busy(dev);
+ return rpm_suspend(dev, rpmflags | RPM_AUTO);
}
/**
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()
2026-11-13 13:27 [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle() Rafael J. Wysocki
@ 2026-11-14 0:59 ` Brian Norris
2026-11-15 17:35 ` Rafael J. Wysocki (Intel)
2026-11-14 3:40 ` Alan Stern
2026-11-14 8:01 ` Ulf Hansson
2 siblings, 1 reply; 6+ messages in thread
From: Brian Norris @ 2026-11-14 0:59 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux PM, LKML, Alan Stern, Sakari Ailus, Ulf Hansson
On Fri, Nov 13, 2026 at 02:27:23PM +0100, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> 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.
In any case, the change looks good to me:
Reviewed-by: Brian Norris <briannorris@chromium.org>
I meant to make time to test this out a bit more, but ran out; maybe
next week.
Thanks,
Brian
> Updating the last_busy timestamp when rpm_idle() returns an error
> without calling rpm_suspend() is not useful because the device is then
> going to remain active for an unknown amount of time and its autosuspend
> delay needs to take effect later.
>
> Link: https://lore.kernel.org/linux-pm/fc43eb13-816b-4cd0-9711-848fdab605ef@rowland.harvard.edu/ [1]
> Link: https://lore.kernel.org/linux-pm/CAJZ5v0hKpjMsGQm8Cpa89x5wkNxqkggDNbp+eQ0S-E52DETWjQ@mail.gmail.com/ [2]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/base/power/runtime.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -560,7 +560,11 @@ static int rpm_idle(struct device *dev,
>
> out:
> trace_rpm_return_int(dev, _THIS_IP_, retval);
> - return retval ? retval : rpm_suspend(dev, rpmflags | RPM_AUTO);
> + if (retval)
> + return retval;
> +
> + pm_runtime_mark_last_busy(dev);
> + return rpm_suspend(dev, rpmflags | RPM_AUTO);
> }
>
> /**
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()
2026-11-13 13:27 [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle() Rafael J. Wysocki
2026-11-14 0:59 ` Brian Norris
@ 2026-11-14 3:40 ` Alan Stern
2026-11-14 8:01 ` Ulf Hansson
2 siblings, 0 replies; 6+ messages in thread
From: Alan Stern @ 2026-11-14 3:40 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux PM, LKML, Brian Norris, Sakari Ailus, Ulf Hansson
On Fri, Nov 13, 2026 at 02:27:23PM +0100, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> 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.
>
> Updating the last_busy timestamp when rpm_idle() returns an error
> without calling rpm_suspend() is not useful because the device is then
> going to remain active for an unknown amount of time and its autosuspend
> delay needs to take effect later.
>
> Link: https://lore.kernel.org/linux-pm/fc43eb13-816b-4cd0-9711-848fdab605ef@rowland.harvard.edu/ [1]
> Link: https://lore.kernel.org/linux-pm/CAJZ5v0hKpjMsGQm8Cpa89x5wkNxqkggDNbp+eQ0S-E52DETWjQ@mail.gmail.com/ [2]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
Acked-by: Alan Stern <stern@rowland.harvard.edu>
> drivers/base/power/runtime.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -560,7 +560,11 @@ static int rpm_idle(struct device *dev,
>
> out:
> trace_rpm_return_int(dev, _THIS_IP_, retval);
> - return retval ? retval : rpm_suspend(dev, rpmflags | RPM_AUTO);
> + if (retval)
> + return retval;
> +
> + pm_runtime_mark_last_busy(dev);
> + return rpm_suspend(dev, rpmflags | RPM_AUTO);
> }
>
> /**
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()
2026-11-13 13:27 [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle() Rafael J. Wysocki
2026-11-14 0:59 ` Brian Norris
2026-11-14 3:40 ` Alan Stern
@ 2026-11-14 8:01 ` Ulf Hansson
2 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2026-11-14 8:01 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux PM, LKML, Brian Norris, Alan Stern, Sakari Ailus
On Fri, Nov 13, 2026 at 2:27 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> 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.
>
> Updating the last_busy timestamp when rpm_idle() returns an error
> without calling rpm_suspend() is not useful because the device is then
> going to remain active for an unknown amount of time and its autosuspend
> delay needs to take effect later.
>
> Link: https://lore.kernel.org/linux-pm/fc43eb13-816b-4cd0-9711-848fdab605ef@rowland.harvard.edu/ [1]
> Link: https://lore.kernel.org/linux-pm/CAJZ5v0hKpjMsGQm8Cpa89x5wkNxqkggDNbp+eQ0S-E52DETWjQ@mail.gmail.com/ [2]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
I realized that I have joined these discussions a bit late. Thanks to
all of you for working on this, it's been on my todo list for a long
time! :-)
That said, please add:
Reviewed-by: Ulf Hansson <ulfh@kernel.org>
Kind regards
Uffe
> ---
> drivers/base/power/runtime.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -560,7 +560,11 @@ static int rpm_idle(struct device *dev,
>
> out:
> trace_rpm_return_int(dev, _THIS_IP_, retval);
> - return retval ? retval : rpm_suspend(dev, rpmflags | RPM_AUTO);
> + if (retval)
> + return retval;
> +
> + pm_runtime_mark_last_busy(dev);
> + return rpm_suspend(dev, rpmflags | RPM_AUTO);
> }
>
> /**
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()
2026-11-14 0:59 ` Brian Norris
@ 2026-11-15 17:35 ` Rafael J. Wysocki (Intel)
2026-11-16 23:12 ` Brian Norris
0 siblings, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-15 17:35 UTC (permalink / raw)
To: Brian Norris
Cc: Rafael J. Wysocki, Linux PM, LKML, Alan Stern, Sakari Ailus, Ulf Hansson
On Sat, Nov 14, 2026 at 1:59 AM Brian Norris <briannorris@chromium.org> wrote:
>
> On Fri, Nov 13, 2026 at 02:27:23PM +0100, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > 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@chromium.org>
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle()
2026-11-15 17:35 ` Rafael J. Wysocki (Intel)
@ 2026-11-16 23:12 ` Brian Norris
0 siblings, 0 replies; 6+ messages in thread
From: Brian Norris @ 2026-11-16 23:12 UTC (permalink / raw)
To: Rafael J. Wysocki (Intel)
Cc: Linux PM, LKML, Alan Stern, Sakari Ailus, Ulf Hansson
On Sun, Nov 15, 2026 at 06:35:04PM +0100, Rafael J. Wysocki (Intel) wrote:
> On Sat, Nov 14, 2026 at 1:59 AM Brian Norris <briannorris@chromium.org> wrote:
> > 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
nit: you split "pm_request_idle()" oddly
> 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."
Seems good, thanks! Who knows if anybody will actually read the
changelogs, but at least it leaves a paper trail for future cleanups
that will likely reference this change.
> > In any case, the change looks good to me:
> >
> > Reviewed-by: Brian Norris <briannorris@chromium.org>
>
> 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.
OK, I made some time:
Tested-by: Brian Norris <briannorris@chromium.org>
It tests out well (passing) with:
(a) the KUnit tests that try to imitate the stm32-adc parent/child
structure from commit c537d3457542 [1]
(b) my original KUnit test [2]. I've appended a slightly-updated v3, in
case you want to merge it
(c) some targeted PCIe tests on Pixel phones. Specifically, I see that
the portdrv.c 100ms autosuspend delay is now consistently applied
after both lspci (this used to work OK, simply because rpm_resume()
would also update last_busy) and after endpoint suspend (this
previously did not apply the autosuspend delay, as the endpoint
tended to stay active for a long time)
Thanks,
Brian
[1] https://lore.kernel.org/all/auzlLwlleGLPsLcw@google.com/
This test is inherently timing sensitive and therefore flaky. It
just serves as an example, not something to commit.
[2] [PATCH v2 4/5] PM: runtime: Add tests for last_busy propagation
https://lore.kernel.org/all/20261103141442.v2.4.I8ab8b7f662fe1921c7084a47d554535597cc2702@changeid/
From: Brian Norris <briannorris@chromium.org>
Date: Thu, 1 Oct 2026 11:53:49 -0700
Subject: [PATCH v3] PM: runtime: Add tests for dependency last_busy update
This is a regression test for the problem fixed in "PM: runtime: Update
last_busy before calling rpm_suspend() in rpm_idle()", ensuring that
when a child or consumer suspends, the corresponding parent or supplier
autosuspend timer expiration increases.
Signed-off-by: Brian Norris <briannorris@chromium.org>
---
Changes in v3:
* Minor style changes
* Target
"PM: runtime: Update last_busy before calling rpm_suspend() in
rpm_idle()"
instead of prior patch
"PM: runtime: Propagate last_busy from dependent to dependency"
(both solve the same problem)
Changes in v2:
* Use device_move() instead of manual re-parenting
* fsleep() instead of msleep()
drivers/base/power/runtime-test.c | 103 ++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/drivers/base/power/runtime-test.c b/drivers/base/power/runtime-test.c
index 24865ce844fc..685a3504cd7b 100644
--- a/drivers/base/power/runtime-test.c
+++ b/drivers/base/power/runtime-test.c
@@ -4,6 +4,7 @@
*/
#include <linux/cleanup.h>
+#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <linux/workqueue.h>
#include <kunit/device.h>
@@ -285,6 +286,106 @@ static void pm_runtime_supplier_suspend_test(struct kunit *test)
KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(norpm_supplier));
}
+static void pm_runtime_parent_last_used_test(struct kunit *test)
+{
+ struct device *parent, *dev;
+ u64 expiry1, expiry2;
+
+ parent = kunit_device_register(test, DEVICE_NAME "_parent");
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent);
+
+ dev = kunit_device_register(test, DEVICE_NAME);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+
+ KUNIT_ASSERT_EQ(test, 0, device_move(dev, parent, DPM_ORDER_NONE));
+
+ pm_runtime_set_active(parent);
+ pm_runtime_set_active(dev);
+ pm_runtime_use_autosuspend(parent);
+ pm_runtime_use_autosuspend(dev);
+
+ pm_runtime_set_autosuspend_delay(dev, 0);
+ /* Effectively infinite delay (prevent finishing autosuspend during this test). */
+ pm_runtime_set_autosuspend_delay(parent, 200000);
+
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_mark_last_busy(parent);
+
+ pm_runtime_get_noresume(dev);
+
+ pm_runtime_enable(parent);
+ pm_runtime_enable(dev);
+
+ expiry1 = pm_runtime_autosuspend_expiration(parent);
+ KUNIT_EXPECT_NE(test, 0, expiry1);
+
+ /* Make absolutely sure the clock advances. */
+ fsleep(1000);
+
+ KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync_autosuspend(dev));
+
+ KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
+
+ /* Flush, in case any request was pending. */
+ flush_workqueue(pm_wq);
+ KUNIT_EXPECT_FALSE(test, pm_runtime_suspended(parent));
+
+ expiry2 = pm_runtime_autosuspend_expiration(parent);
+ KUNIT_EXPECT_NE(test, 0, expiry2);
+ /* The child's last_busy time should have bumped up the parent's expiration. */
+ KUNIT_EXPECT_GT(test, expiry2, expiry1);
+}
+
+static void pm_runtime_supplier_last_used_test(struct kunit *test)
+{
+ struct device *supplier, *dev;
+ u64 expiry1, expiry2;
+
+ supplier = kunit_device_register(test, DEVICE_NAME "_supplier");
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, supplier);
+
+ dev = kunit_device_register(test, DEVICE_NAME);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+
+ KUNIT_ASSERT_NOT_NULL(test, device_link_add(dev, supplier, DL_FLAG_PM_RUNTIME));
+
+ pm_runtime_set_active(supplier);
+ pm_runtime_set_active(dev);
+ pm_runtime_use_autosuspend(supplier);
+ pm_runtime_use_autosuspend(dev);
+
+ pm_runtime_set_autosuspend_delay(dev, 0);
+ /* Effectively infinite delay (prevent finishing autosuspend during this test). */
+ pm_runtime_set_autosuspend_delay(supplier, 200000);
+
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_mark_last_busy(supplier);
+
+ pm_runtime_get_noresume(dev);
+
+ pm_runtime_enable(supplier);
+ pm_runtime_enable(dev);
+
+ expiry1 = pm_runtime_autosuspend_expiration(supplier);
+ KUNIT_EXPECT_NE(test, 0, expiry1);
+
+ /* Make absolutely sure the clock advances. */
+ fsleep(1000);
+
+ KUNIT_EXPECT_EQ(test, 0, pm_runtime_put_sync_autosuspend(dev));
+
+ KUNIT_EXPECT_TRUE(test, pm_runtime_suspended(dev));
+
+ /* Flush, in case any request was pending. */
+ flush_workqueue(pm_wq);
+ KUNIT_EXPECT_FALSE(test, pm_runtime_suspended(supplier));
+
+ expiry2 = pm_runtime_autosuspend_expiration(supplier);
+ KUNIT_EXPECT_NE(test, 0, expiry2);
+ /* The consumer's last_busy time should have bumped up the supplier's expiration. */
+ KUNIT_EXPECT_GT(test, expiry2, expiry1);
+}
+
static struct kunit_case pm_runtime_test_cases[] = {
KUNIT_CASE(pm_runtime_depth_test),
KUNIT_CASE(pm_runtime_already_suspended_test),
@@ -293,6 +394,8 @@ static struct kunit_case pm_runtime_test_cases[] = {
KUNIT_CASE(pm_runtime_error_test),
KUNIT_CASE(pm_runtime_probe_active_test),
KUNIT_CASE(pm_runtime_supplier_suspend_test),
+ KUNIT_CASE(pm_runtime_parent_last_used_test),
+ KUNIT_CASE(pm_runtime_supplier_last_used_test),
{}
};
--
2.56.1.703.gf848ed807c-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-16 23:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 13:27 [PATCH v1] PM: runtime: Update last_busy before calling rpm_suspend() in rpm_idle() Rafael J. Wysocki
2026-11-14 0:59 ` Brian Norris
2026-11-15 17:35 ` Rafael J. Wysocki (Intel)
2026-11-16 23:12 ` Brian Norris
2026-11-14 3:40 ` Alan Stern
2026-11-14 8:01 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®