lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1208293220.5372.11.camel@earth>
Date:	Tue, 15 Apr 2008 23:00:20 +0200
From:	Dmitry Adamushko <dmitry.adamushko@...il.com>
To:	Thomas Gleixner <tglx@...utronix.de>
Cc:	Ingo Molnar <mingo@...e.hu>, linux-kernel@...r.kernel.org,
	dmitry.adamushko@...il.com
Subject: [PATCH, cleanup] 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 <dmitry.adamushko@...il.com>    
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 <dmitry.adamushko@...il.com>

---

diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 1ad56a7..49888a9 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -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);
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 98bee01..bfb0f94 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -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);
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 686da82..d3098d3 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -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);


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ