hrtimer: use div64_64() in ktime_divns()
PATCH 1/1 hrtimer: use div64_64() in ktime_divns()
[ I apologize, the previous message was sent with a wrong subject. Fixed here ]
Unless I'm overlooking some subtle difference this change may simplify code a bit.
---
From: Dmitry Adamushko <[email protected]>
Subject: hrtimer: use div64_64() in ktime_divns()
ktime_divns() (as is now) re-implements the logic behind div64_64() so let's just make use of div64_64().
Also add a few explicit type conversions for ktime_divns() callers.
Signed-off-by Dmitry Adamushko <[email protected]>
---
include/linux/hrtimer.h +5 -5
@@ -20,6 +20,7 @@#include <linux/init.h> #include <linux/list.h> #include <linux/wait.h> +#include <asm/div64.h> struct hrtimer_clock_base ;struct hrtimer_cpu_base ;
@@ -331,11 +332,10 @@ 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 +static inline u64 ktime_divns (const ktime_t kt,u64 div) +{ +return div64_64 ((u64 )ktime_to_ns (kt), div); +}/* Show pending timers: */ extern void sysrq_timer_list_show (void );
kernel/hrtimer.c +3 -26
@@ -252,8 +252,7 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)* Functions for the union type storage format of ktime_t which are * too large for inlining: */ -#if BITS_PER_LONG <64 -# ifndef CONFIG_KTIME_SCALAR +#if BITS_PER_LONG <64 && !defined(CONFIG_KTIME_SCALAR )/** * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable * @kt: addend
@@ -301,29 +300,7 @@ ktime_t ktime_sub_ns(const ktime_t kt, u64 nsec) }EXPORT_SYMBOL_GPL (ktime_sub_ns); -# endif /* !CONFIG_KTIME_SCALAR */ - -/* -* Divide a ktime value by a nanosecond value -*/ -u64 ktime_divns (const ktime_t kt,s64 div) -{ -u64 dclc, inc, dns; -int sft =0 ; - - dclc = dns =ktime_to_ns (kt); - inc = div; -/* Make sure the divisor is less than 2^32: */ -while (div >>32 ) { - sft++; - div >>=1 ; - } - dclc >>= sft; -do_div (dclc, (unsigned long ) div); - -return dclc; -} -#endif /* BITS_PER_LONG >= 64 */ +#endif /* BITS_PER_LONG >= 64 && !CONFIG_KTIME_SCALAR */ /* * Add two ktime values and do a safety check for overflow:
@@ -698,7 +675,7 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval) interval.tv64 = timer->base->resolution.tv64;if (unlikely (delta.tv64 >= interval.tv64)) { -s64 incr =ktime_to_ns (interval); +u64 incr = (u64 )ktime_to_ns (interval); orun =ktime_divns (delta, incr); timer->expires =ktime_add_ns (timer->expires, incr * orun);
kernel/time/tick-sched.c +2 -2
@@ -60,9 +60,9 @@ static void tick_do_update_jiffies64(ktime_t now)/* Slow path for long timeouts */ if (unlikely (delta.tv64 >= tick_period.tv64)) { -s64 incr =ktime_to_ns (tick_period); +u64 incr = (u64 )ktime_to_ns (tick_period); - ticks =ktime_divns (delta, incr); + ticks = (unsigned long )ktime_divns (delta, incr); last_jiffies_update =ktime_add_ns (last_jiffies_update, incr * ticks);