pm: device_runtime: Avoid unnecessary resume/suspend
We don't need to wait an async put to happen in case it has not started yet. In this case we can simply cancelling the pending work and change the internal state because the device is still active. This way we avoid a suspend and resume cycle. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
2236eaf52c
commit
0ea173b774
@ -177,8 +177,22 @@ int pm_device_runtime_get(const struct device *dev)
|
||||
|
||||
pm->usage++;
|
||||
|
||||
/*
|
||||
* Check if the device has a pending suspend operation (not started
|
||||
* yet) and cancel it. This way we avoid unnecessary operations because
|
||||
* the device is actually active.
|
||||
*/
|
||||
if ((pm->state == PM_DEVICE_STATE_SUSPENDING) &&
|
||||
((k_work_cancel_delayable(&pm->work) & K_WORK_RUNNING) == 0)) {
|
||||
pm->state = PM_DEVICE_STATE_ACTIVE;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
if (!k_is_pre_kernel()) {
|
||||
/* wait until possible async suspend is completed */
|
||||
/*
|
||||
* If the device is already suspending there is
|
||||
* nothing else we can do but wait until it finishes.
|
||||
*/
|
||||
while (pm->state == PM_DEVICE_STATE_SUSPENDING) {
|
||||
k_sem_give(&pm->lock);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user