Skip to contentSkip to conversation

PM/runtime: Do not needlessly call ktime_get

PATCH In review Ladislav Michl 4 participants 4 messages Jan 10, 2019 – Jan 16, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM/runtime: Do not needlessly call ktime_get

pm_runtime_autosuspend_expiration calls ktime_get even when its returned value may be unused. Therefore get current time later and remove gotos while there.

---
NOTE: Depends on Vincent's "[PATCH v2] PM/runtime: Fix autosuspend_delay
on 32bits arch"!

 drivers/base/power/runtime.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/base/power/runtime.c +8 -11
index 457be03b744d..836b1b8784eb 100644
@@ -129,24 +129,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_to_ns(ktime_get());
+	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_to_ns(ktime_get()))
+		return expires;	/* Expires in the future */
 
- out:
-	return expires;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);
 
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Ladislav Michl

pm_runtime_autosuspend_expiration calls ktime_get even when its returned value may be unused. Therefore get current time later and remove gotos while there.

Acked-by on v1 1/1
#2 lore raw
In reply to Ladislav Michl
Quoted 6 lines · Ladislav Michl

pm_runtime_autosuspend_expiration calls ktime_get even when its returned value may be unused. Therefore get current time later and remove gotos while there.

Quoted 47 lines

---
NOTE: Depends on Vincent's "[PATCH v2] PM/runtime: Fix autosuspend_delay
on 32bits arch"!

 drivers/base/power/runtime.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/base/power/runtime.c +8 -12
index 457be03b744d..836b1b8784eb 100644
@@ -129,24 +129,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_to_ns(ktime_get());
+       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_to_ns(ktime_get()))
+               return expires; /* Expires in the future */
 
- out:
-       return expires;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);
 
--

2.20.1