ktime: Sanitize ktime_to_us/ms conversion
authorThomas Gleixner <tglx@linutronix.de>
Wed, 16 Jul 2014 21:03:55 +0000 (21:03 +0000)
committerDanny Wood <danwood76@gmail.com>
Tue, 28 Sep 2021 12:06:40 +0000 (13:06 +0100)
With the plain nanoseconds based ktime_t we can simply use
ktime_divns() instead of going through loops and hoops of
timespec/timeval conversion.

Change-Id: Ib33ea80bc3fdd26fcada1072b1f8ffc26081c0ba
Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>
include/linux/hrtimer.h
include/linux/ktime.h
kernel/hrtimer.c

index d19a5c2d2270ebb9bbe01a167a97875e255da357..a3919d428fd09cbbac0522dbcec5ce1828ac006a 100644 (file)
@@ -452,12 +452,6 @@ extern void hrtimer_run_pending(void);
 /* Bootup initialization: */
 extern void __init hrtimers_init(void);
 
-#if BITS_PER_LONG < 64
-extern u64 ktime_divns(const ktime_t kt, s64 div);
-#else /* BITS_PER_LONG < 64 */
-# define ktime_divns(kt, div)          (u64)((kt).tv64 / (div))
-#endif
-
 /* Show pending timers: */
 extern void sysrq_timer_list_show(void);
 
index bbca12804d12434ebfb100487c460c2ed21f99ed..e18ab688f9c10f2f8a5f7a723e46646d24c1845b 100644 (file)
@@ -301,16 +301,20 @@ static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2)
        return 0;
 }
 
+#if BITS_PER_LONG < 64
+extern u64 ktime_divns(const ktime_t kt, s64 div);
+#else /* BITS_PER_LONG < 64 */
+# define ktime_divns(kt, div)          (u64)((kt).tv64 / (div))
+#endif
+
 static inline s64 ktime_to_us(const ktime_t kt)
 {
-       struct timeval tv = ktime_to_timeval(kt);
-       return (s64) tv.tv_sec * USEC_PER_SEC + tv.tv_usec;
+       return ktime_divns(kt, NSEC_PER_USEC);
 }
 
 static inline s64 ktime_to_ms(const ktime_t kt)
 {
-       struct timeval tv = ktime_to_timeval(kt);
-       return (s64) tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC;
+       return ktime_divns(kt, NSEC_PER_MSEC);
 }
 
 static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
index 0b6513de91a2c964c5a8355a2ba743199c3d711e..e1ef3f3b18fc0cc51cf2e400e26440c5cc8720b1 100644 (file)
@@ -349,6 +349,7 @@ u64 ktime_divns(const ktime_t kt, s64 div)
 
        return dclc;
 }
+EXPORT_SYMBOL_GPL(ktime_divns);
 #endif /* BITS_PER_LONG >= 64 */
 
 /*