PM/runtime: Optimize pm_runtime_autosuspend_expiration()
Subsystems (4)
PATCH 1/1 PM/runtime: Optimize pm_runtime_autosuspend_expiration()
pm_runtime_autosuspend_expiration calls ktime_get_mono_fast_ns even when its returned value may be unused. Therefore get current time later and remove gotos while there.
---
This patch is based on top of bleeding-edge branch, where "[PATCH v2 ] PM-runtime: fix deadlock with ktime" is sitting. I expect v3 of that patch, which should not harm this one. It is meant to replace "PM/runtime: Do not needlessly call ktime_get" sent earlier.
drivers/base/power/runtime.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/base/power/runtime.c +8 -11
@@ -145,24 +145,21 @@ static void pm_runtime_cancel_pending(struct device *dev)u64 pm_runtime_autosuspend_expiration (struct device *dev) {int autosuspend_delay; -u64 last_busy, expires =0 ; -u64 now =ktime_get_mono_fast_ns (); +u64 expires;if (!dev->power.use_autosuspend) - goto out; +return 0 ; autosuspend_delay =READ_ONCE (dev->power.autosuspend_delay);if (autosuspend_delay <0 ) - goto out; - - last_busy =READ_ONCE (dev->power.last_busy); +return 0 ; - expires = last_busy + (u64 )autosuspend_delay *NSEC_PER_MSEC ; -if (expires <= now) - expires =0 ;/* Already expired. */ + expires =READ_ONCE (dev->power.last_busy); + expires += (u64 )autosuspend_delay *NSEC_PER_MSEC ; +if (expires >ktime_get_mono_fast_ns ()) +return expires;/* Expires in the future */ - out: -return expires; +return 0 ; }EXPORT_SYMBOL_GPL (pm_runtime_autosuspend_expiration);
Signature · 1 line
2.20.1
Rafael J. Wysocki
AppliedQuoted 45 lines · CET Ladislav Michl
pm_runtime_autosuspend_expirationcallsktime_get_mono_fast_nseven when its returned value may be unused. Therefore get current time later and remove gotos while there.Signed-off-by Ladislav Michl <[email protected]>Acked-by Tony Lindgren <[email protected]>Acked-by Vincent Guittot <[email protected]>---
This patch is based on top of bleeding-edge branch, where "[PATCH v2 ] PM-runtime: fix deadlock with ktime" is sitting. I expect v3 of that patch, which should not harm this one. It is meant to replace "PM/runtime: Do not needlessly callktime_get" sent earlier.drivers/base/power/runtime.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/base/power/runtime.c +4
-9@@ -145,24 +145,21 @@ static void pm_runtime_cancel_pending(struct device *dev)u64 pm_runtime_autosuspend_expiration (struct device *dev) {int autosuspend_delay; -u64 last_busy, expires =0 ; -u64 now =ktime_get_mono_fast_ns (); +u64 expires;if (!dev->power.use_autosuspend) - goto out; +return 0 ; autosuspend_delay =READ_ONCE (dev->power.autosuspend_delay);if (autosuspend_delay <0 ) - goto out; - - last_busy =READ_ONCE (dev->power.last_busy); +return 0 ; - expires = last_busy + (u64 )autosuspend_delay *NSEC_PER_MSEC ; -if (expires <= now) - expires =0 ;/* Already expired. */ + expires =READ_ONCE (dev->power.last_busy);
drivers/base/power/runtime.c static void pm_runtime_cancel_pending(struct device *dev) · line 165
Quoted 10 lines
drivers/base/power/runtime.c +4
-2+ expires += (u64 )autosuspend_delay *NSEC_PER_MSEC ; +if (expires >ktime_get_mono_fast_ns ()) +return expires;/* Expires in the future */ - out: -return expires; +return 0 ; }EXPORT_SYMBOL_GPL (pm_runtime_autosuspend_expiration);
Applied, thanks!