aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2014-07-16 17:03:55 -0400
committerJohn Stultz <john.stultz@linaro.org>2014-07-23 13:16:50 -0400
commit166afb64511eef08e13331b970c44fe91cea45ef (patch)
tree0354ca4d028a51653d299709dd9a2c7d3d13289a
parent24e4a8c3e8868874835b0f1ad6dd417341e99822 (diff)
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>
-rw-r--r--include/linux/hrtimer.h6
-rw-r--r--include/linux/ktime.h12
-rw-r--r--kernel/time/hrtimer.c1
3 files changed, 9 insertions, 10 deletions
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index e84eb4f228cd..adf5056bd7b3 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -457,12 +457,6 @@ extern void hrtimer_run_pending(void);
457/* Bootup initialization: */ 457/* Bootup initialization: */
458extern void __init hrtimers_init(void); 458extern void __init hrtimers_init(void);
459 459
460#if BITS_PER_LONG < 64
461extern u64 ktime_divns(const ktime_t kt, s64 div);
462#else /* BITS_PER_LONG < 64 */
463# define ktime_divns(kt, div) (u64)((kt).tv64 / (div))
464#endif
465
466/* Show pending timers: */ 460/* Show pending timers: */
467extern void sysrq_timer_list_show(void); 461extern void sysrq_timer_list_show(void);
468 462
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)
157 return ktime_compare(cmp1, cmp2) < 0; 157 return ktime_compare(cmp1, cmp2) < 0;
158} 158}
159 159
160#if BITS_PER_LONG < 64
161extern u64 ktime_divns(const ktime_t kt, s64 div);
162#else /* BITS_PER_LONG < 64 */
163# define ktime_divns(kt, div) (u64)((kt).tv64 / (div))
164#endif
165
160static inline s64 ktime_to_us(const ktime_t kt) 166static inline s64 ktime_to_us(const ktime_t kt)
161{ 167{
162 struct timeval tv = ktime_to_timeval(kt); 168 return ktime_divns(kt, NSEC_PER_USEC);
163 return (s64) tv.tv_sec * USEC_PER_SEC + tv.tv_usec;
164} 169}
165 170
166static inline s64 ktime_to_ms(const ktime_t kt) 171static inline s64 ktime_to_ms(const ktime_t kt)
167{ 172{
168 struct timeval tv = ktime_to_timeval(kt); 173 return ktime_divns(kt, NSEC_PER_MSEC);
169 return (s64) tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC;
170} 174}
171 175
172static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier) 176static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 19f211051c35..64843a836637 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -280,6 +280,7 @@ u64 ktime_divns(const ktime_t kt, s64 div)
280 280
281 return dclc; 281 return dclc;
282} 282}
283EXPORT_SYMBOL_GPL(ktime_divns);
283#endif /* BITS_PER_LONG >= 64 */ 284#endif /* BITS_PER_LONG >= 64 */
284 285
285/* 286/*