pm, restore async device resume optimization
Subsystems (2)
cover pm, restore async device resume optimization
From: "yenchia.chen" <[email protected]>
We have met a deadlock issue on our device when resuming. After applying this patch which is picked from mainline, issue solved. We'd like to backport to 5.15.y and could you help to review? thanks.
[ Upstream commit 3e999770ac1c7c31a70685dd5b88e89473509e9c ]
Rafael J. Wysocki (1):
PM: sleep: Restore asynchronous device resume optimization
drivers/base/power/main.c | 117 +++++++++++++++++++++----------------- include/linux/pm.h | 1 + 2 files changed, 65 insertions(+), 53 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/1 PM: sleep: Restore asynchronous device resume optimization
From: "Rafael J. Wysocki" <[email protected]>
Before commit 7839d0078e0d ("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 7839d0078e0d 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.
--- drivers/base/power/main.c | 117 +++++++++++++++++++++----------------- include/linux/pm.h | 1 + 2 files changed, 65 insertions(+), 53 deletions(-)
drivers/base/power/main.c +64 -53
@@ -580,7 +580,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. * @state: PM transition of the system being carried out. * @async: If true, the device is being resumed asynchronously.
@@ -588,7 +588,7 @@ bool dev_pm_skip_resume(struct device *dev)* The driver of @dev will not receive interrupts while this function is being * 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 ;const char *info =NULL ;
@@ -675,16 +675,22 @@ static bool dpm_async_fn(struct device *dev, async_func_t func) {reinit_completion (&dev->power.completion); -if (!is_async (dev)) -return false; - -get_device (dev); +if (is_async (dev)) { + dev->power.async_in_progress = true; -if (async_schedule_dev_nocall (func, dev)) -return true; +get_device (dev); -put_device (dev); +if (async_schedule_dev_nocall (func, dev)) +return true; +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; }
@@ -692,18 +698,10 @@ static void async_resume_noirq(void *data, async_cookie_t cookie) {struct device *dev = data; -__device_resume_noirq (dev, pm_transition, true); +device_resume_noirq (dev, pm_transition, true);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) {struct device *dev;
@@ -713,18 +711,28 @@ static void dpm_noirq_resume_devices(pm_message_t state)mutex_lock (&dpm_list_mtx); 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)) { dev =to_device (dpm_noirq_list.next); -get_device (dev);list_move_tail (&dev->power.entry, &dpm_late_early_list); -mutex_unlock (&dpm_list_mtx); +if (!dev->power.async_in_progress) { +get_device (dev); -device_resume_noirq (dev); +mutex_unlock (&dpm_list_mtx); -put_device (dev); +device_resume_noirq (dev, state, false); -mutex_lock (&dpm_list_mtx); +put_device (dev); + +mutex_lock (&dpm_list_mtx); + } }mutex_unlock (&dpm_list_mtx);async_synchronize_full ();
@@ -750,14 +758,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. * @state: PM transition of the system being carried out. * @async: If true, the device is being resumed asynchronously. * * 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 ;const char *info =NULL ;
@@ -823,18 +831,10 @@ static void async_resume_early(void *data, async_cookie_t cookie) {struct device *dev = data; -__device_resume_early (dev, pm_transition, true); +device_resume_early (dev, pm_transition, true);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. * @state: PM transition of the system being carried out.
@@ -848,18 +848,28 @@ void dpm_resume_early(pm_message_t state)mutex_lock (&dpm_list_mtx); 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)) { dev =to_device (dpm_late_early_list.next); -get_device (dev);list_move_tail (&dev->power.entry, &dpm_suspended_list); -mutex_unlock (&dpm_list_mtx); +if (!dev->power.async_in_progress) { +get_device (dev); -device_resume_early (dev); +mutex_unlock (&dpm_list_mtx); -put_device (dev); +device_resume_early (dev, state, false); -mutex_lock (&dpm_list_mtx); +put_device (dev); + +mutex_lock (&dpm_list_mtx); + } }mutex_unlock (&dpm_list_mtx);async_synchronize_full ();
@@ -879,12 +889,12 @@ void dpm_resume_start(pm_message_t state)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. * @state: PM transition of the system being carried out. * @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 ;const char *info =NULL ;
@@ -978,18 +988,10 @@ static void async_resume(void *data, async_cookie_t cookie) {struct device *dev = data; -__device_resume (dev, pm_transition, true); +device_resume (dev, pm_transition, true);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. * @state: PM transition of the system being carried out.
@@ -1009,16 +1011,25 @@ void dpm_resume(pm_message_t state) pm_transition = state; 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)) { dev =to_device (dpm_suspended_list.next);get_device (dev); -mutex_unlock (&dpm_list_mtx); +if (!dev->power.async_in_progress) { +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))list_move_tail (&dev->power.entry, &dpm_prepared_list);
include/linux/pm.h +1 -0
@@ -606,6 +606,7 @@ struct dev_pm_info { bool wakeup_path:1; bool syscore:1; 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 may_skip_resume:1; /* Set by subsystems */#else
Signature · 1 line
2.18.0
kernel test robot
build botRe: [PATCH 5.15 1/1] PM: sleep: Restore asynchronous device resume optimization
FYI: kernel test robot notices the stable kernel rule is not satisfied.
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-3
Rule: The upstream commit ID must be specified with a separate line above the commit text.
Subject: [PATCH 5.15 1/1] PM: sleep: Restore asynchronous device resume optimization
Please ignore this mail if the patch is not relevant for upstream.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Greg Kroah-Hartman
maintainerRe: [PATCH 5.15 1/1] PM: sleep: Restore asynchronous device resume optimization
In reply to Yenchia ChenQuoted 8 lines · Yenchia Chen
From: "Rafael J. Wysocki" <[email protected]>
Before commit
7839d0078e0d("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.
Quoted 7 lines
Commit
7839d0078e0dremoved 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 Rafael J. Wysocki <[email protected]>Reviewed-by Stanislaw Gruszka <[email protected]>Signed-off-by yenchia.chen <[email protected]>
Please sign off using your name, not your email alias.
Also, what git id is this?
thanks,
greg k-h
PATCH v2 1/1 PM: sleep: Restore asynchronous device resume optimization
From: "Rafael J. Wysocki" <[email protected]>
commit 3e999770ac1c7c31a70685dd5b88e89473509e9c upstream.
Before commit 7839d0078e0d ("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 7839d0078e0d 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.
--- drivers/base/power/main.c | 117 +++++++++++++++++++++----------------- include/linux/pm.h | 1 + 2 files changed, 65 insertions(+), 53 deletions(-)
drivers/base/power/main.c +64 -53
@@ -580,7 +580,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. * @state: PM transition of the system being carried out. * @async: If true, the device is being resumed asynchronously.
@@ -588,7 +588,7 @@ bool dev_pm_skip_resume(struct device *dev)* The driver of @dev will not receive interrupts while this function is being * 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 ;const char *info =NULL ;
@@ -675,16 +675,22 @@ static bool dpm_async_fn(struct device *dev, async_func_t func) {reinit_completion (&dev->power.completion); -if (!is_async (dev)) -return false; - -get_device (dev); +if (is_async (dev)) { + dev->power.async_in_progress = true; -if (async_schedule_dev_nocall (func, dev)) -return true; +get_device (dev); -put_device (dev); +if (async_schedule_dev_nocall (func, dev)) +return true; +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; }
@@ -692,18 +698,10 @@ static void async_resume_noirq(void *data, async_cookie_t cookie) {struct device *dev = data; -__device_resume_noirq (dev, pm_transition, true); +device_resume_noirq (dev, pm_transition, true);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) {struct device *dev;
@@ -713,18 +711,28 @@ static void dpm_noirq_resume_devices(pm_message_t state)mutex_lock (&dpm_list_mtx); 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)) { dev =to_device (dpm_noirq_list.next); -get_device (dev);list_move_tail (&dev->power.entry, &dpm_late_early_list); -mutex_unlock (&dpm_list_mtx); +if (!dev->power.async_in_progress) { +get_device (dev); -device_resume_noirq (dev); +mutex_unlock (&dpm_list_mtx); -put_device (dev); +device_resume_noirq (dev, state, false); -mutex_lock (&dpm_list_mtx); +put_device (dev); + +mutex_lock (&dpm_list_mtx); + } }mutex_unlock (&dpm_list_mtx);async_synchronize_full ();
@@ -750,14 +758,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. * @state: PM transition of the system being carried out. * @async: If true, the device is being resumed asynchronously. * * 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 ;const char *info =NULL ;
@@ -823,18 +831,10 @@ static void async_resume_early(void *data, async_cookie_t cookie) {struct device *dev = data; -__device_resume_early (dev, pm_transition, true); +device_resume_early (dev, pm_transition, true);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. * @state: PM transition of the system being carried out.
@@ -848,18 +848,28 @@ void dpm_resume_early(pm_message_t state)mutex_lock (&dpm_list_mtx); 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)) { dev =to_device (dpm_late_early_list.next); -get_device (dev);list_move_tail (&dev->power.entry, &dpm_suspended_list); -mutex_unlock (&dpm_list_mtx); +if (!dev->power.async_in_progress) { +get_device (dev); -device_resume_early (dev); +mutex_unlock (&dpm_list_mtx); -put_device (dev); +device_resume_early (dev, state, false); -mutex_lock (&dpm_list_mtx); +put_device (dev); + +mutex_lock (&dpm_list_mtx); + } }mutex_unlock (&dpm_list_mtx);async_synchronize_full ();
@@ -879,12 +889,12 @@ void dpm_resume_start(pm_message_t state)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. * @state: PM transition of the system being carried out. * @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 ;const char *info =NULL ;
@@ -978,18 +988,10 @@ static void async_resume(void *data, async_cookie_t cookie) {struct device *dev = data; -__device_resume (dev, pm_transition, true); +device_resume (dev, pm_transition, true);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. * @state: PM transition of the system being carried out.
@@ -1009,16 +1011,25 @@ void dpm_resume(pm_message_t state) pm_transition = state; 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)) { dev =to_device (dpm_suspended_list.next);get_device (dev); -mutex_unlock (&dpm_list_mtx); +if (!dev->power.async_in_progress) { +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))list_move_tail (&dev->power.entry, &dpm_prepared_list);
include/linux/pm.h +1 -0
@@ -606,6 +606,7 @@ struct dev_pm_info { bool wakeup_path:1; bool syscore:1; 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 may_skip_resume:1; /* Set by subsystems */#else
Signature · 1 line
2.18.0
Greg Kroah-Hartman
maintainerQuoted 7 lines · Yenchia Chen
From: "yenchia.chen" <[email protected]>
We have met a deadlock issue on our device when resuming. After applying this patch which is picked from mainline, issue solved. We'd like to backport to 5.15.y and could you help to review? thanks.
[ Upstream commit
3e999770ac1c7c31a70685dd5b88e89473509e9c]
For obvious reasons (and as per the documentation), we can't take commits that are not also in all newer kernel releases, otherwise you would have a regression if you moved to a newer kernel, right?
Please submit a series for all affected releases if you wish for a patch to be applied to the trees.
thanks,
greg k-h
Quoted 12 lines
Quoted 7 lines
From: "yenchia.chen" <[email protected]>
We have met a deadlock issue on our device when resuming. After applying this patch which is picked from mainline, issue solved. We'd like to backport to 5.15.y and could you help to review? thanks.
[ Upstream commit
3e999770ac1c7c31a70685dd5b88e89473509e9c]For obvious reasons (and as per the documentation), we can't take commits that are not also in all newer kernel releases, otherwise you would have a regression if you moved to a newer kernel, right?
Quoted 6 lines
Please submit a series for all affected releases if you wish for a patch to be applied to the trees.
thanks,
greg k-h
Another mail thread for 6.1.y and 6.6.y are created.