Skip to content

Commit 2c2ca02

Browse files
committed
PM: sleep: Make async resume handle consumers like children
JIRA: https://issues.redhat.com/browse/RHEL-109251 commit ed18738 Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Date: Thu, 03 Jul 2025 16:53:33 +0000 Avoid starting "async" resume processing upfront for devices that have suppliers and start "async" resume processing for a device's consumers right after resuming the device itself. Suggested-by: Saravana Kannan <saravanak@google.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Link: https://patch.msgid.link/3378088.aeNJFYEL58@rjwysocki.net Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent e72ccd4 commit 2c2ca02

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

drivers/base/power/main.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,27 @@ static void dpm_async_resume_children(struct device *dev, async_func_t func)
661661
/*
662662
* Start processing "async" children of the device unless it's been
663663
* started already for them.
664-
*
665-
* This could have been done for the device's "async" consumers too, but
666-
* they either need to wait for their parents or the processing has
667-
* already started for them after their parents were processed.
668664
*/
669665
device_for_each_child(dev, func, dpm_async_with_cleanup);
670666
}
671667

668+
static void dpm_async_resume_subordinate(struct device *dev, async_func_t func)
669+
{
670+
struct device_link *link;
671+
int idx;
672+
673+
dpm_async_resume_children(dev, func);
674+
675+
idx = device_links_read_lock();
676+
677+
/* Start processing the device's "async" consumers. */
678+
list_for_each_entry_rcu(link, &dev->links.consumers, s_node)
679+
if (READ_ONCE(link->status) != DL_STATE_DORMANT)
680+
dpm_async_with_cleanup(link->consumer, func);
681+
682+
device_links_read_unlock(idx);
683+
}
684+
672685
static void dpm_clear_async_state(struct device *dev)
673686
{
674687
reinit_completion(&dev->power.completion);
@@ -677,7 +690,14 @@ static void dpm_clear_async_state(struct device *dev)
677690

678691
static bool dpm_root_device(struct device *dev)
679692
{
680-
return !dev->parent;
693+
lockdep_assert_held(&dpm_list_mtx);
694+
695+
/*
696+
* Since this function is required to run under dpm_list_mtx, the
697+
* list_empty() below will only return true if the device's list of
698+
* consumers is actually empty before calling it.
699+
*/
700+
return !dev->parent && list_empty(&dev->links.suppliers);
681701
}
682702

683703
static void async_resume_noirq(void *data, async_cookie_t cookie);
@@ -766,7 +786,7 @@ static void device_resume_noirq(struct device *dev, pm_message_t state, bool asy
766786
pm_dev_err(dev, state, async ? " async noirq" : " noirq", error);
767787
}
768788

769-
dpm_async_resume_children(dev, async_resume_noirq);
789+
dpm_async_resume_subordinate(dev, async_resume_noirq);
770790
}
771791

772792
static void async_resume_noirq(void *data, async_cookie_t cookie)
@@ -909,7 +929,7 @@ static void device_resume_early(struct device *dev, pm_message_t state, bool asy
909929
pm_dev_err(dev, state, async ? " async early" : " early", error);
910930
}
911931

912-
dpm_async_resume_children(dev, async_resume_early);
932+
dpm_async_resume_subordinate(dev, async_resume_early);
913933
}
914934

915935
static void async_resume_early(void *data, async_cookie_t cookie)
@@ -1085,7 +1105,7 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
10851105
pm_dev_err(dev, state, async ? " async" : "", error);
10861106
}
10871107

1088-
dpm_async_resume_children(dev, async_resume);
1108+
dpm_async_resume_subordinate(dev, async_resume);
10891109
}
10901110

10911111
static void async_resume(void *data, async_cookie_t cookie)

0 commit comments

Comments
 (0)