linux-mips
[Top] [All Lists]

[PATCH] Use do_div for a subtract loop

To: linux-mips@linux-mips.org
Subject: [PATCH] Use do_div for a subtract loop
From: Thiemo Seufer <ths@networkno.de>
Date: Tue, 1 May 2007 19:11:21 +0100
Cc: ralf@linux-mips.org
Original-recipient: rfc822;linux-mips@linux-mips.org
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.13 (2006-08-11)
Hello All,

this patch switches the subtract loop in timespec_add_ns to use
do_div. The latest GCC SVN version grew intelligent enough to
optimize the loop to a division which calls libgcc's __udivdi3,
which breaks kernel builds.

Tested by building and booting a little endian qemu MIPS kernel.


Thiemo


Signed-off-by: Thiemo Seufer <ths@networkno.de>

diff --git a/include/linux/time.h b/include/linux/time.h
index 8ea8dea..e1a11d7 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -5,6 +5,7 @@
 
 #ifdef __KERNEL__
 # include <linux/seqlock.h>
+# include <asm/div64.h>
 #endif
 
 #ifndef _STRUCT_TIMESPEC
@@ -169,9 +170,10 @@ extern struct timeval ns_to_timeval(const s64 nsec);
 static inline void timespec_add_ns(struct timespec *a, u64 ns)
 {
        ns += a->tv_nsec;
-       while(unlikely(ns >= NSEC_PER_SEC)) {
-               ns -= NSEC_PER_SEC;
-               a->tv_sec++;
+       if(unlikely(ns >= NSEC_PER_SEC)) {
+               u64 tmp = ns;
+               ns = do_div(tmp, NSEC_PER_SEC);
+               a->tv_sec += tmp;
        }
        a->tv_nsec = ns;
 }

<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH] Use do_div for a subtract loop, Thiemo Seufer <=