Skip to content

Commit

Permalink
ktime: Sanitize ktime_to_us/ms conversion
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Signed-off-by: John Stultz <[email protected]>
  • Loading branch information
KAGA-KOKO authored and johnstultz-work committed Jul 23, 2014
1 parent 24e4a8c commit 166afb6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 0 additions & 6 deletions include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,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);

Expand Down
12 changes: 8 additions & 4 deletions include/linux/ktime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions kernel/time/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ u64 ktime_divns(const ktime_t kt, s64 div)

return dclc;
}
EXPORT_SYMBOL_GPL(ktime_divns);
#endif /* BITS_PER_LONG >= 64 */

/*
Expand Down

0 comments on commit 166afb6

Please sign in to comment.