With the plain nanoseconds based ktime_t we can simply use ktime_divns() instead of going through loops and hoops of timespec/timeval conversion.
Unified · Split
| @@ -457,12 +457,6 @@ extern void hrtimer_run_pending(void); · 456 unmodified lines | |||
| 457 | /* Bootup initialization: */ | 457 | /* Bootup initialization: */ |
| 458 | extern void __init hrtimers_init(void); | 458 | extern void __init hrtimers_init(void); |
| 459 | 459 | ||
| 460 | #if BITS_PER_LONG < 64 | ||
| 461 | extern 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: */ |
| 467 | extern void sysrq_timer_list_show(void); | 461 | extern void sysrq_timer_list_show(void); |
| 468 | 462 | ||
| @@ -157,16 +157,20 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) · 156 unmodified lines | |||
| 157 | return ktime_compare(cmp1, cmp2) < 0; | 157 | return ktime_compare(cmp1, cmp2) < 0; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | #if BITS_PER_LONG < 64 | ||
| 161 | extern 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 | |||
| 160 | static inline s64 ktime_to_us(const ktime_t kt) | 166 | static 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 | ||
| 166 | static inline s64 ktime_to_ms(const ktime_t kt) | 171 | static 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 | ||
| 172 | static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier) | 176 | static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier) |
| @@ -280,6 +280,7 @@ u64 ktime_divns(const ktime_t kt, s64 div) · 279 unmodified lines | |||
| 280 | 280 | ||
| 281 | return dclc; | 281 | return dclc; |
| 282 | } | 282 | } |
| 283 | EXPORT_SYMBOL_GPL(ktime_divns); | ||
| 283 | #endif /* BITS_PER_LONG >= 64 */ | 284 | #endif /* BITS_PER_LONG >= 64 */ |
| 284 | 285 | ||
| 285 | /* | 286 | /* |