History

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.

Thomas Gleixner committed 12 years ago

Commit 166afb61 parent 24e4a8c3 files · +9 −10Browse files

Unified · Split

3 files
  1. include/linux/hrtimer.h +0 −6
  2. include/linux/ktime.h +8 −4
  3. kernel/time/hrtimer.c +1 −0
include/linux/hrtimer.h+0−6
@@ -457,12 +457,6 @@ extern void hrtimer_run_pending(void); · 456 unmodified lines
457457 /* Bootup initialization: */
458458 extern void __init hrtimers_init(void);
459459
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−
466460 /* Show pending timers: */
467461 extern void sysrq_timer_list_show(void);
468462
include/linux/ktime.h+8−4
@@ -157,16 +157,20 @@ static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) · 156 unmodified lines
157157 return ktime_compare(cmp1, cmp2) < 0;
158158 }
159159
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+
160166 static inline s64 ktime_to_us(const ktime_t kt)
161167 {
162− struct timeval tv = ktime_to_timeval(kt);
163− return (s64) tv.tv_sec * USEC_PER_SEC + tv.tv_usec;
168+ return ktime_divns(kt, NSEC_PER_USEC);
164169 }
165170
166171 static inline s64 ktime_to_ms(const ktime_t kt)
167172 {
168− struct timeval tv = ktime_to_timeval(kt);
169− return (s64) tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC;
173+ return ktime_divns(kt, NSEC_PER_MSEC);
170174 }
171175
172176 static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
kernel/time/hrtimer.c+1−0
@@ -280,6 +280,7 @@ u64 ktime_divns(const ktime_t kt, s64 div) · 279 unmodified lines
280280
281281 return dclc;
282282 }
283+EXPORT_SYMBOL_GPL(ktime_divns);
283284 #endif /* BITS_PER_LONG >= 64 */
284285
285286 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t