[RFC] div64_64 support

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Stephen Hemminger
Date: Friday, February 23, 2007 - 6:05 pm

Since there already two users of full 64 bit division in the kernel,
and other places maybe hiding out as well. Add a full 64/64 bit divide.

Yes this expensive, but there are places where it is necessary.
It is not clear if doing the scaling buys any advantage on 64 bit platforms,
so for them a full divide is done.

---
 include/asm-arm/div64.h      |    2 ++
 include/asm-generic/div64.h  |    8 ++++++++
 include/asm-m68k/div64.h     |    2 ++
 include/asm-mips/div64.h     |    8 ++++++++
 include/asm-um/div64.h       |    1 +
 include/asm-xtensa/div64.h   |    1 +
 lib/div64.c                  |   22 ++++++++++++++++++++++
 net/ipv4/tcp_cubic.c         |   22 ----------------------
 net/netfilter/xt_connbytes.c |   16 ----------------
 9 files changed, 44 insertions(+), 38 deletions(-)

--- linux-2.6.21-rc1.orig/include/asm-arm/div64.h	2007-02-23 16:44:41.000000000 -0800
+++ linux-2.6.21-rc1/include/asm-arm/div64.h	2007-02-23 16:57:36.000000000 -0800
@@ -221,6 +221,8 @@
 	__nr;								\
 })
 
+extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
+
 #endif
 
 #endif
--- linux-2.6.21-rc1.orig/include/asm-generic/div64.h	2007-02-23 16:35:27.000000000 -0800
+++ linux-2.6.21-rc1/include/asm-generic/div64.h	2007-02-23 16:56:40.000000000 -0800
@@ -30,9 +30,17 @@
 	__rem;							\
  })
 
+/*
+ * div64_64 - Divide two 64 bit numbers
+ */
+static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
+{
+	return dividend / divisor;
+}
 #elif BITS_PER_LONG == 32
 
 extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
+extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
 
 /* The unnecessary pointer compare is there
  * to check for type safety (n must be 64bit)
--- linux-2.6.21-rc1.orig/include/asm-m68k/div64.h	2007-02-23 16:45:20.000000000 -0800
+++ linux-2.6.21-rc1/include/asm-m68k/div64.h	2007-02-23 16:56:27.000000000 -0800
@@ -23,4 +23,6 @@
 	__rem;							\
 })
 
+extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
+
 #endif /* _M68K_DIV64_H */
--- linux-2.6.21-rc1.orig/include/asm-mips/div64.h	2007-02-23 16:45:25.000000000 -0800
+++ linux-2.6.21-rc1/include/asm-mips/div64.h	2007-02-23 16:59:52.000000000 -0800
@@ -78,6 +78,9 @@
 	__quot = __quot << 32 | __low; \
 	(n) = __quot; \
 	__mod; })
+
+extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
+
 #endif /* (_MIPS_SZLONG == 32) */
 
 #if (_MIPS_SZLONG == 64)
@@ -101,6 +104,11 @@
 	(n) = __quot; \
 	__mod; })
 
+static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
+{
+	return dividend / divisor;
+}
+
 #endif /* (_MIPS_SZLONG == 64) */
 
 #endif /* _ASM_DIV64_H */
--- linux-2.6.21-rc1.orig/include/asm-um/div64.h	2007-02-23 16:45:37.000000000 -0800
+++ linux-2.6.21-rc1/include/asm-um/div64.h	2007-02-23 16:58:29.000000000 -0800
@@ -3,4 +3,5 @@
 
 #include "asm/arch/div64.h"
 
+extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
 #endif
--- linux-2.6.21-rc1.orig/include/asm-xtensa/div64.h	2007-02-23 16:45:43.000000000 -0800
+++ linux-2.6.21-rc1/include/asm-xtensa/div64.h	2007-02-23 16:58:04.000000000 -0800
@@ -16,4 +16,5 @@
 	n /= (unsigned int) base; \
 	__res; })
 
+extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
 #endif
--- linux-2.6.21-rc1.orig/lib/div64.c	2007-02-23 16:50:40.000000000 -0800
+++ linux-2.6.21-rc1/lib/div64.c	2007-02-23 16:54:56.000000000 -0800
@@ -18,6 +18,7 @@
 
 #include <linux/types.h>
 #include <linux/module.h>
+#include <asm/bitops.h>
 #include <asm/div64.h>
 
 /* Not needed on 64bit architectures */
@@ -58,4 +59,25 @@
 
 EXPORT_SYMBOL(__div64_32);
 
+/* Use scaling to do a full 64 bit division  */
+uint64_t div64_64(uint64_t dividend, uint64_t divisor)
+{
+	uint32_t d = divisor;
+
+	if (divisor > 0xffffffffULL) {
+		unsigned int shift = fls(divisor >> 32);
+
+		d = divisor >> shift;
+		dividend >>= shift;
+	}
+
+	/* avoid 64 bit division if possible */
+	if (dividend >> 32)
+		do_div(dividend, d);
+	else
+		dividend = (uint32_t) dividend / d;
+
+	return dividend;
+}
+
 #endif /* BITS_PER_LONG == 32 */
--- linux-2.6.21-rc1.orig/net/ipv4/tcp_cubic.c	2007-02-23 16:33:52.000000000 -0800
+++ linux-2.6.21-rc1/net/ipv4/tcp_cubic.c	2007-02-23 16:45:50.000000000 -0800
@@ -51,7 +51,6 @@
 module_param(tcp_friendliness, int, 0644);
 MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness");
 
-#include <asm/div64.h>
 
 /* BIC TCP Parameters */
 struct bictcp {
@@ -93,27 +92,6 @@
 		tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
 }
 
-/* 64bit divisor, dividend and result. dynamic precision */
-static inline u_int64_t div64_64(u_int64_t dividend, u_int64_t divisor)
-{
-	u_int32_t d = divisor;
-
-	if (divisor > 0xffffffffULL) {
-		unsigned int shift = fls(divisor >> 32);
-
-		d = divisor >> shift;
-		dividend >>= shift;
-	}
-
-	/* avoid 64 bit division if possible */
-	if (dividend >> 32)
-		do_div(dividend, d);
-	else
-		dividend = (uint32_t) dividend / d;
-
-	return dividend;
-}
-
 /*
  * calculate the cubic root of x using Newton-Raphson
  */
--- linux-2.6.21-rc1.orig/net/netfilter/xt_connbytes.c	2007-02-23 16:40:57.000000000 -0800
+++ linux-2.6.21-rc1/net/netfilter/xt_connbytes.c	2007-02-23 16:41:09.000000000 -0800
@@ -24,22 +24,6 @@
 MODULE_DESCRIPTION("iptables match for matching number of pkts/bytes per connection");
 MODULE_ALIAS("ipt_connbytes");
 
-/* 64bit divisor, dividend and result. dynamic precision */
-static u_int64_t div64_64(u_int64_t dividend, u_int64_t divisor)
-{
-	u_int32_t d = divisor;
-
-	if (divisor > 0xffffffffULL) {
-		unsigned int shift = fls(divisor >> 32);
-
-		d = divisor >> shift;
-		dividend >>= shift;
-	}
-
-	do_div(dividend, d);
-	return dividend;
-}
-
 static int
 match(const struct sk_buff *skb,
       const struct net_device *in,
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] div64_64 support, Stephen Hemminger, (Fri Feb 23, 6:05 pm)
Re: [RFC] div64_64 support, Sami Farin, (Sat Feb 24, 9:19 am)
Re: [RFC] div64_64 support, Jan Engelhardt, (Mon Feb 26, 1:09 pm)
Re: [RFC] div64_64 support, Stephen Hemminger, (Mon Feb 26, 2:28 pm)
Re: [RFC] div64_64 support, Stephen Hemminger, (Mon Feb 26, 3:31 pm)
Re: [RFC] div64_64 support, Jan Engelhardt, (Mon Feb 26, 4:02 pm)
Re: [RFC] div64_64 support, Stephen Hemminger, (Mon Feb 26, 4:44 pm)
Re: [RFC] div64_64 support, Jan Engelhardt, (Mon Feb 26, 5:05 pm)
Re: [RFC] div64_64 support, Stephen Hemminger, (Mon Feb 26, 5:07 pm)
Re: [RFC] div64_64 support, Jan Engelhardt, (Mon Feb 26, 5:14 pm)
Re: [RFC] div64_64 support, H. Peter Anvin, (Mon Feb 26, 6:20 pm)
Re: [RFC] div64_64 support, Segher Boessenkool, (Mon Feb 26, 8:45 pm)
Re: [RFC] div64_64 support, Dan Williams, (Mon Feb 26, 11:21 pm)
Re: [RFC] div64_64 support, Andi Kleen, (Fri Mar 2, 7:31 pm)
Re: [RFC] div64_64 support, Stephen Hemminger, (Mon Mar 5, 4:57 pm)
Re: [RFC] div64_64 support, David Miller, (Mon Mar 5, 5:25 pm)
Re: [RFC] div64_64 support, Andi Kleen, (Tue Mar 6, 6:34 am)
Re: [RFC] div64_64 support, Andi Kleen, (Tue Mar 6, 6:36 am)
Re: [RFC] div64_64 support II, Andi Kleen, (Tue Mar 6, 7:04 am)
Re: [RFC] div64_64 support, Eric Dumazet, (Tue Mar 6, 7:19 am)
Re: [RFC] div64_64 support, Andi Kleen, (Tue Mar 6, 7:45 am)
Re: [RFC] div64_64 support, Roland Kuhn, (Tue Mar 6, 8:10 am)
Re: [RFC] div64_64 support II, Dagfinn Ilmari , (Tue Mar 6, 10:43 am)
Re: [RFC] div64_64 support II, David Miller, (Tue Mar 6, 11:25 am)
Re: [RFC] div64_64 support, Stephen Hemminger, (Tue Mar 6, 11:29 am)
Re: [RFC] div64_64 support II, H. Peter Anvin, (Tue Mar 6, 11:48 am)
Re: [RFC] div64_64 support, H. Peter Anvin, (Tue Mar 6, 11:50 am)
Re: [RFC] div64_64 support, Andi Kleen, (Tue Mar 6, 12:48 pm)
Re: [RFC] div64_64 support, Stephen Hemminger, (Tue Mar 6, 1:04 pm)
Re: [RFC] div64_64 support, Sami Farin, (Tue Mar 6, 2:53 pm)
Re: [RFC] div64_64 support, David Miller, (Tue Mar 6, 2:58 pm)
Re: [RFC] div64_64 support, Sami Farin, (Tue Mar 6, 3:24 pm)
[PATCH] tcp_cubic: faster cube root, Stephen Hemminger, (Tue Mar 6, 3:47 pm)
cube root benchmark code, Stephen Hemminger, (Tue Mar 6, 3:58 pm)
Re: [PATCH] tcp_cubic: faster cube root, David Miller, (Tue Mar 6, 9:20 pm)
Update to cube root benchmark code, Willy Tarreau, (Tue Mar 6, 11:08 pm)
Re: [PATCH] tcp_cubic: faster cube root, Andi Kleen, (Wed Mar 7, 5:12 am)
Re: [RFC] div64_64 support, Chuck Ebbert, (Wed Mar 7, 9:11 am)
Re: [RFC] div64_64 support, Sami Farin, (Wed Mar 7, 11:32 am)
Re: [PATCH] tcp_cubic: faster cube root, David Miller, (Wed Mar 7, 12:33 pm)
[PATCH] tcp_cubic: use 32 bit math, Stephen Hemminger, (Wed Mar 7, 6:07 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, David Miller, (Wed Mar 7, 7:55 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, Stephen Hemminger, (Wed Mar 7, 8:10 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, David Miller, (Wed Mar 7, 8:51 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, Willy Tarreau, (Wed Mar 7, 9:16 pm)
Re: asm volatile [Was: [RFC] div64_64 support], Sami Farin, (Thu Mar 8, 11:23 am)
Re: asm volatile, David Miller, (Thu Mar 8, 3:01 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, Willy Tarreau, (Sat Mar 10, 4:48 am)
Re: [PATCH] tcp_cubic: use 32 bit math, Stephen Hemminger, (Mon Mar 12, 2:11 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, Willy Tarreau, (Tue Mar 13, 1:50 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, Stephen Hemminger, (Wed Mar 21, 11:54 am)
Re: [PATCH] tcp_cubic: use 32 bit math, Willy Tarreau, (Wed Mar 21, 12:15 pm)
Re: [PATCH] tcp_cubic: use 32 bit math, Stephen Hemminger, (Wed Mar 21, 12:58 pm)
[PATCH 1/2] div64_64 optimization, Stephen Hemminger, (Wed Mar 21, 1:15 pm)
[PATCH 2/2] tcp: cubic optimization, Stephen Hemminger, (Wed Mar 21, 1:17 pm)
Re: [PATCH 1/2] div64_64 optimization, David Miller, (Thu Mar 22, 12:11 pm)
Re: [PATCH 2/2] tcp: cubic optimization, David Miller, (Thu Mar 22, 12:11 pm)