summaryrefslogtreecommitdiff
path: root/include/linux/ktime.h
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2014-07-17 01:03:55 +0400
committerJohn Stultz <john.stultz@linaro.org>2014-07-23 21:16:50 +0400
commit166afb64511eef08e13331b970c44fe91cea45ef (patch)
tree0354ca4d028a51653d299709dd9a2c7d3d13289a /include/linux/ktime.h
parent24e4a8c3e8868874835b0f1ad6dd417341e99822 (diff)
downloadlinux-166afb64511eef08e13331b970c44fe91cea45ef.tar.xz
ktime: Sanitize ktime_to_us/ms conversion
With the plain nanoseconds based ktime_t we can simply use ktime_divns() instead of going through loops and hoops of timespec/timeval conversion. 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>
Diffstat (limited to 'include/linux/ktime.h')
-rw-r--r--include/linux/ktime.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/linux/ktime.h b/include/linux/ktime.h
index fbc64f8481b7..74eaba9b3569 100644
--- a/include/linux/ktime.h
+++ b/include/linux/ktime.h
@@ -157,16 +157,20 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2)
return ktime_compare(cmp1, cmp2) < 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)