Skip to content

Commit

Permalink
pm: device_runtime: Avoid unnecessary work
Browse files Browse the repository at this point in the history
Similar to what is done in pm_device_runtime_get,
we don't need to wait the device be suspended if
the work is still in the work queue. In this case
we just cancel the work and update the device state
to active.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin authored and fabiobaltieri committed Dec 14, 2023
1 parent dca352b commit b161105
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion subsys/pm/device_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,14 @@ int pm_device_runtime_disable(const struct device *dev)
goto unlock;
}

/* wait until possible async suspend is completed */
if (!k_is_pre_kernel()) {
if ((pm->state == PM_DEVICE_STATE_SUSPENDING) &&
((k_work_cancel_delayable(&pm->work) & K_WORK_RUNNING) == 0)) {
pm->state = PM_DEVICE_STATE_ACTIVE;
goto clear_bit;
}

/* wait until possible async suspend is completed */
while (pm->state == PM_DEVICE_STATE_SUSPENDING) {
k_sem_give(&pm->lock);

Expand All @@ -368,6 +374,7 @@ int pm_device_runtime_disable(const struct device *dev)
pm->state = PM_DEVICE_STATE_ACTIVE;
}

clear_bit:
atomic_clear_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_ENABLED);

unlock:
Expand Down

0 comments on commit b161105

Please sign in to comment.