From 3b47ec6410f29eafa80adae1005709a23d573ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 15 Nov 2024 15:35:56 +0100 Subject: [PATCH] pm: device_runtime: Optimize pm_device_runtime_usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no point in using lock or semaphore to read current usage counter as it may change after unlocking or giving back the semaphore. Value can only be trusted in the controlled environment (e.g. test). Signed-off-by: Krzysztof Chruściński --- subsys/pm/device_runtime.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/subsys/pm/device_runtime.c b/subsys/pm/device_runtime.c index f719b4772eb..4533886dd2a 100644 --- a/subsys/pm/device_runtime.c +++ b/subsys/pm/device_runtime.c @@ -563,25 +563,9 @@ bool pm_device_runtime_is_enabled(const struct device *dev) int pm_device_runtime_usage(const struct device *dev) { - struct pm_device *pm = dev->pm; - uint32_t usage; - if (!pm_device_runtime_is_enabled(dev)) { return -ENOTSUP; } - if (atomic_test_bit(&dev->pm_base->flags, PM_DEVICE_FLAG_ISR_SAFE)) { - struct pm_device_isr *pm_sync = dev->pm_isr; - k_spinlock_key_t k = k_spin_lock(&pm_sync->lock); - - usage = pm_sync->base.usage; - - k_spin_unlock(&pm_sync->lock, k); - } else { - (void)k_sem_take(&pm->lock, K_FOREVER); - usage = pm->base.usage; - k_sem_give(&pm->lock); - } - - return usage; + return dev->pm_base->usage; }