Skip to content

Commit ed18738

Browse files
committed
PM: sleep: Make async resume handle consumers like children
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 <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Ulf Hansson <[email protected]> Reviewed-by: Sudeep Holla <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 5e8be76 commit ed18738

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
@@ -647,14 +647,27 @@ static void dpm_async_resume_children(struct device *dev, async_func_t func)
647647
/*
648648
* Start processing "async" children of the device unless it's been
649649
* started already for them.
650-
*
651-
* This could have been done for the device's "async" consumers too, but
652-
* they either need to wait for their parents or the processing has
653-
* already started for them after their parents were processed.
654650
*/
655651
device_for_each_child(dev, func, dpm_async_with_cleanup);
656652
}
657653

654+
static void dpm_async_resume_subordinate(struct device *dev, async_func_t func)
655+
{
656+
struct device_link *link;
657+
int idx;
658+
659+
dpm_async_resume_children(dev, func);
660+
661+
idx = device_links_read_lock();
662+
663+
/* Start processing the device's "async" consumers. */
664+
list_for_each_entry_rcu(link, &dev->links.consumers, s_node)
665+
if (READ_ONCE(link->status) != DL_STATE_DORMANT)
666+
dpm_async_with_cleanup(link->consumer, func);
667+
668+
device_links_read_unlock(idx);
669+
}
670+
658671
static void dpm_clear_async_state(struct device *dev)
659672
{
660673
reinit_completion(&dev->power.completion);
@@ -663,7 +676,14 @@ static void dpm_clear_async_state(struct device *dev)
663676

664677
static bool dpm_root_device(struct device *dev)
665678
{
666-
return !dev->parent;
679+
lockdep_assert_held(&dpm_list_mtx);
680+
681+
/*
682+
* Since this function is required to run under dpm_list_mtx, the
683+
* list_empty() below will only return true if the device's list of
684+
* consumers is actually empty before calling it.
685+
*/
686+
return !dev->parent && list_empty(&dev->links.suppliers);
667687
}
668688

669689
static void async_resume_noirq(void *data, async_cookie_t cookie);
@@ -752,7 +772,7 @@ static void device_resume_noirq(struct device *dev, pm_message_t state, bool asy
752772
pm_dev_err(dev, state, async ? " async noirq" : " noirq", error);
753773
}
754774

755-
dpm_async_resume_children(dev, async_resume_noirq);
775+
dpm_async_resume_subordinate(dev, async_resume_noirq);
756776
}
757777

758778
static void async_resume_noirq(void *data, async_cookie_t cookie)
@@ -895,7 +915,7 @@ static void device_resume_early(struct device *dev, pm_message_t state, bool asy
895915
pm_dev_err(dev, state, async ? " async early" : " early", error);
896916
}
897917

898-
dpm_async_resume_children(dev, async_resume_early);
918+
dpm_async_resume_subordinate(dev, async_resume_early);
899919
}
900920

901921
static void async_resume_early(void *data, async_cookie_t cookie)
@@ -1071,7 +1091,7 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
10711091
pm_dev_err(dev, state, async ? " async" : "", error);
10721092
}
10731093

1074-
dpm_async_resume_children(dev, async_resume);
1094+
dpm_async_resume_subordinate(dev, async_resume);
10751095
}
10761096

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

0 commit comments

Comments
 (0)