Commit 3e999770 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM: sleep: Restore asynchronous device resume optimization

Before commit 7839d007 ("PM: sleep: Fix possible deadlocks in core
system-wide PM code"), the resume of devices that were allowed to resume
asynchronously was scheduled before starting the resume of the other
devices, so the former did not have to wait for the latter unless
functional dependencies were present.

Commit 7839d007 removed that optimization in order to address a
correctness issue, but it can be restored with the help of a new device
power management flag, so do that now.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: default avatarStanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
parent 7839d007
...@@ -579,7 +579,7 @@ bool dev_pm_skip_resume(struct device *dev) ...@@ -579,7 +579,7 @@ bool dev_pm_skip_resume(struct device *dev)
} }
/** /**
* __device_resume_noirq - Execute a "noirq resume" callback for given device. * device_resume_noirq - Execute a "noirq resume" callback for given device.
* @dev: Device to handle. * @dev: Device to handle.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
* @async: If true, the device is being resumed asynchronously. * @async: If true, the device is being resumed asynchronously.
...@@ -587,7 +587,7 @@ bool dev_pm_skip_resume(struct device *dev) ...@@ -587,7 +587,7 @@ bool dev_pm_skip_resume(struct device *dev)
* The driver of @dev will not receive interrupts while this function is being * The driver of @dev will not receive interrupts while this function is being
* executed. * executed.
*/ */
static void __device_resume_noirq(struct device *dev, pm_message_t state, bool async) static void device_resume_noirq(struct device *dev, pm_message_t state, bool async)
{ {
pm_callback_t callback = NULL; pm_callback_t callback = NULL;
const char *info = NULL; const char *info = NULL;
...@@ -674,8 +674,8 @@ static bool dpm_async_fn(struct device *dev, async_func_t func) ...@@ -674,8 +674,8 @@ static bool dpm_async_fn(struct device *dev, async_func_t func)
{ {
reinit_completion(&dev->power.completion); reinit_completion(&dev->power.completion);
if (!is_async(dev)) if (is_async(dev)) {
return false; dev->power.async_in_progress = true;
get_device(dev); get_device(dev);
...@@ -683,7 +683,13 @@ static bool dpm_async_fn(struct device *dev, async_func_t func) ...@@ -683,7 +683,13 @@ static bool dpm_async_fn(struct device *dev, async_func_t func)
return true; return true;
put_device(dev); put_device(dev);
}
/*
* Because async_schedule_dev_nocall() above has returned false or it
* has not been called at all, func() is not running and it is safe to
* update the async_in_progress flag without extra synchronization.
*/
dev->power.async_in_progress = false;
return false; return false;
} }
...@@ -691,18 +697,10 @@ static void async_resume_noirq(void *data, async_cookie_t cookie) ...@@ -691,18 +697,10 @@ static void async_resume_noirq(void *data, async_cookie_t cookie)
{ {
struct device *dev = data; struct device *dev = data;
__device_resume_noirq(dev, pm_transition, true); device_resume_noirq(dev, pm_transition, true);
put_device(dev); put_device(dev);
} }
static void device_resume_noirq(struct device *dev)
{
if (dpm_async_fn(dev, async_resume_noirq))
return;
__device_resume_noirq(dev, pm_transition, false);
}
static void dpm_noirq_resume_devices(pm_message_t state) static void dpm_noirq_resume_devices(pm_message_t state)
{ {
struct device *dev; struct device *dev;
...@@ -712,19 +710,29 @@ static void dpm_noirq_resume_devices(pm_message_t state) ...@@ -712,19 +710,29 @@ static void dpm_noirq_resume_devices(pm_message_t state)
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
pm_transition = state; pm_transition = state;
/*
* Trigger the resume of "async" devices upfront so they don't have to
* wait for the "non-async" ones they don't depend on.
*/
list_for_each_entry(dev, &dpm_noirq_list, power.entry)
dpm_async_fn(dev, async_resume_noirq);
while (!list_empty(&dpm_noirq_list)) { while (!list_empty(&dpm_noirq_list)) {
dev = to_device(dpm_noirq_list.next); dev = to_device(dpm_noirq_list.next);
get_device(dev);
list_move_tail(&dev->power.entry, &dpm_late_early_list); list_move_tail(&dev->power.entry, &dpm_late_early_list);
if (!dev->power.async_in_progress) {
get_device(dev);
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
device_resume_noirq(dev); device_resume_noirq(dev, state, false);
put_device(dev); put_device(dev);
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
} }
}
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
async_synchronize_full(); async_synchronize_full();
dpm_show_time(starttime, state, 0, "noirq"); dpm_show_time(starttime, state, 0, "noirq");
...@@ -747,14 +755,14 @@ void dpm_resume_noirq(pm_message_t state) ...@@ -747,14 +755,14 @@ void dpm_resume_noirq(pm_message_t state)
} }
/** /**
* __device_resume_early - Execute an "early resume" callback for given device. * device_resume_early - Execute an "early resume" callback for given device.
* @dev: Device to handle. * @dev: Device to handle.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
* @async: If true, the device is being resumed asynchronously. * @async: If true, the device is being resumed asynchronously.
* *
* Runtime PM is disabled for @dev while this function is being executed. * Runtime PM is disabled for @dev while this function is being executed.
*/ */
static void __device_resume_early(struct device *dev, pm_message_t state, bool async) static void device_resume_early(struct device *dev, pm_message_t state, bool async)
{ {
pm_callback_t callback = NULL; pm_callback_t callback = NULL;
const char *info = NULL; const char *info = NULL;
...@@ -820,18 +828,10 @@ static void async_resume_early(void *data, async_cookie_t cookie) ...@@ -820,18 +828,10 @@ static void async_resume_early(void *data, async_cookie_t cookie)
{ {
struct device *dev = data; struct device *dev = data;
__device_resume_early(dev, pm_transition, true); device_resume_early(dev, pm_transition, true);
put_device(dev); put_device(dev);
} }
static void device_resume_early(struct device *dev)
{
if (dpm_async_fn(dev, async_resume_early))
return;
__device_resume_early(dev, pm_transition, false);
}
/** /**
* dpm_resume_early - Execute "early resume" callbacks for all devices. * dpm_resume_early - Execute "early resume" callbacks for all devices.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
...@@ -845,19 +845,29 @@ void dpm_resume_early(pm_message_t state) ...@@ -845,19 +845,29 @@ void dpm_resume_early(pm_message_t state)
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
pm_transition = state; pm_transition = state;
/*
* Trigger the resume of "async" devices upfront so they don't have to
* wait for the "non-async" ones they don't depend on.
*/
list_for_each_entry(dev, &dpm_late_early_list, power.entry)
dpm_async_fn(dev, async_resume_early);
while (!list_empty(&dpm_late_early_list)) { while (!list_empty(&dpm_late_early_list)) {
dev = to_device(dpm_late_early_list.next); dev = to_device(dpm_late_early_list.next);
get_device(dev);
list_move_tail(&dev->power.entry, &dpm_suspended_list); list_move_tail(&dev->power.entry, &dpm_suspended_list);
if (!dev->power.async_in_progress) {
get_device(dev);
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
device_resume_early(dev); device_resume_early(dev, state, false);
put_device(dev); put_device(dev);
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
} }
}
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
async_synchronize_full(); async_synchronize_full();
dpm_show_time(starttime, state, 0, "early"); dpm_show_time(starttime, state, 0, "early");
...@@ -876,12 +886,12 @@ void dpm_resume_start(pm_message_t state) ...@@ -876,12 +886,12 @@ void dpm_resume_start(pm_message_t state)
EXPORT_SYMBOL_GPL(dpm_resume_start); EXPORT_SYMBOL_GPL(dpm_resume_start);
/** /**
* __device_resume - Execute "resume" callbacks for given device. * device_resume - Execute "resume" callbacks for given device.
* @dev: Device to handle. * @dev: Device to handle.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
* @async: If true, the device is being resumed asynchronously. * @async: If true, the device is being resumed asynchronously.
*/ */
static void __device_resume(struct device *dev, pm_message_t state, bool async) static void device_resume(struct device *dev, pm_message_t state, bool async)
{ {
pm_callback_t callback = NULL; pm_callback_t callback = NULL;
const char *info = NULL; const char *info = NULL;
...@@ -975,18 +985,10 @@ static void async_resume(void *data, async_cookie_t cookie) ...@@ -975,18 +985,10 @@ static void async_resume(void *data, async_cookie_t cookie)
{ {
struct device *dev = data; struct device *dev = data;
__device_resume(dev, pm_transition, true); device_resume(dev, pm_transition, true);
put_device(dev); put_device(dev);
} }
static void device_resume(struct device *dev)
{
if (dpm_async_fn(dev, async_resume))
return;
__device_resume(dev, pm_transition, false);
}
/** /**
* dpm_resume - Execute "resume" callbacks for non-sysdev devices. * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
* @state: PM transition of the system being carried out. * @state: PM transition of the system being carried out.
...@@ -1006,16 +1008,25 @@ void dpm_resume(pm_message_t state) ...@@ -1006,16 +1008,25 @@ void dpm_resume(pm_message_t state)
pm_transition = state; pm_transition = state;
async_error = 0; async_error = 0;
/*
* Trigger the resume of "async" devices upfront so they don't have to
* wait for the "non-async" ones they don't depend on.
*/
list_for_each_entry(dev, &dpm_suspended_list, power.entry)
dpm_async_fn(dev, async_resume);
while (!list_empty(&dpm_suspended_list)) { while (!list_empty(&dpm_suspended_list)) {
dev = to_device(dpm_suspended_list.next); dev = to_device(dpm_suspended_list.next);
get_device(dev); get_device(dev);
if (!dev->power.async_in_progress) {
mutex_unlock(&dpm_list_mtx); mutex_unlock(&dpm_list_mtx);
device_resume(dev); device_resume(dev, state, false);
mutex_lock(&dpm_list_mtx); mutex_lock(&dpm_list_mtx);
}
if (!list_empty(&dev->power.entry)) if (!list_empty(&dev->power.entry))
list_move_tail(&dev->power.entry, &dpm_prepared_list); list_move_tail(&dev->power.entry, &dpm_prepared_list);
......
...@@ -681,6 +681,7 @@ struct dev_pm_info { ...@@ -681,6 +681,7 @@ struct dev_pm_info {
bool wakeup_path:1; bool wakeup_path:1;
bool syscore:1; bool syscore:1;
bool no_pm_callbacks:1; /* Owned by the PM core */ bool no_pm_callbacks:1; /* Owned by the PM core */
bool async_in_progress:1; /* Owned by the PM core */
unsigned int must_resume:1; /* Owned by the PM core */ unsigned int must_resume:1; /* Owned by the PM core */
unsigned int may_skip_resume:1; /* Set by subsystems */ unsigned int may_skip_resume:1; /* Set by subsystems */
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment