Skip to content

Commit

Permalink
pm: device_runtime: Simplify runtime_enable
Browse files Browse the repository at this point in the history
Move the check of PM_DEVICE_FLAG_RUNTIME_ENABLED to the beginning of
the function. With this we avoid taking/release the semaphore and also
we no longer need check it in runtime_enable_sync(), because it was
already checked in pm_device_runtime_enable().

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
  • Loading branch information
Flavio Ceolin authored and henrikbrixandersen committed Feb 6, 2024
1 parent 75fd75c commit 7812e54
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions subsys/pm/device_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,6 @@ static int runtime_enable_sync(const struct device *dev)
struct pm_device_isr *pm = dev->pm_isr;
k_spinlock_key_t k = k_spin_lock(&pm->lock);

/* Because context is locked we can access flags directly. */
if (pm->base.flags & BIT(PM_DEVICE_FLAG_RUNTIME_ENABLED)) {
ret = 0;
goto unlock;
}

if (pm->base.state == PM_DEVICE_STATE_ACTIVE) {
ret = pm->base.action_cb(dev, PM_DEVICE_ACTION_SUSPEND);
if (ret < 0) {
Expand Down Expand Up @@ -423,6 +417,10 @@ int pm_device_runtime_enable(const struct device *dev)
goto end;
}

if (atomic_test_bit(&pm->base.flags, PM_DEVICE_FLAG_RUNTIME_ENABLED)) {
goto end;
}

if (pm_device_state_is_locked(dev)) {
ret = -EPERM;
goto end;
Expand All @@ -437,10 +435,6 @@ int pm_device_runtime_enable(const struct device *dev)
(void)k_sem_take(&pm->lock, K_FOREVER);
}

if (atomic_test_bit(&pm->base.flags, PM_DEVICE_FLAG_RUNTIME_ENABLED)) {
goto unlock;
}

/* lazy init of PM fields */
if (pm->dev == NULL) {
pm->dev = dev;
Expand Down

0 comments on commit 7812e54

Please sign in to comment.