Commit 3927f2e8f9afa3424bb51ca81f7abac01ffd0005
Committed by
David S. Miller
1 parent
9d729f72dc
Exists in
master
and in
7 other branches
[NET]: div64_64 consolidate (rev3)
Here is the current version of the 64 bit divide common code. Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 13 changed files with 60 additions and 63 deletions Side-by-side Diff
include/asm-arm/div64.h
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | #define __ASM_ARM_DIV64 |
3 | 3 | |
4 | 4 | #include <asm/system.h> |
5 | +#include <linux/types.h> | |
5 | 6 | |
6 | 7 | /* |
7 | 8 | * The semantics of do_div() are: |
... | ... | @@ -222,6 +223,8 @@ |
222 | 223 | }) |
223 | 224 | |
224 | 225 | #endif |
226 | + | |
227 | +extern uint64_t div64_64(uint64_t dividend, uint64_t divisor); | |
225 | 228 | |
226 | 229 | #endif |
include/asm-generic/div64.h
... | ... | @@ -30,6 +30,11 @@ |
30 | 30 | __rem; \ |
31 | 31 | }) |
32 | 32 | |
33 | +static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor) | |
34 | +{ | |
35 | + return dividend / divisor; | |
36 | +} | |
37 | + | |
33 | 38 | #elif BITS_PER_LONG == 32 |
34 | 39 | |
35 | 40 | extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); |
... | ... | @@ -48,6 +53,8 @@ |
48 | 53 | __rem = __div64_32(&(n), __base); \ |
49 | 54 | __rem; \ |
50 | 55 | }) |
56 | + | |
57 | +extern uint64_t div64_64(uint64_t dividend, uint64_t divisor); | |
51 | 58 | |
52 | 59 | #else /* BITS_PER_LONG == ?? */ |
53 | 60 |
include/asm-i386/div64.h
1 | 1 | #ifndef __I386_DIV64 |
2 | 2 | #define __I386_DIV64 |
3 | 3 | |
4 | +#include <linux/types.h> | |
5 | + | |
4 | 6 | /* |
5 | 7 | * do_div() is NOT a C function. It wants to return |
6 | 8 | * two values (the quotient and the remainder), but |
... | ... | @@ -45,5 +47,7 @@ |
45 | 47 | return dum2; |
46 | 48 | |
47 | 49 | } |
50 | + | |
51 | +extern uint64_t div64_64(uint64_t dividend, uint64_t divisor); | |
48 | 52 | #endif |
include/asm-m68k/div64.h
1 | 1 | #ifndef _M68K_DIV64_H |
2 | 2 | #define _M68K_DIV64_H |
3 | 3 | |
4 | +#include <linux/types.h> | |
5 | + | |
4 | 6 | /* n = n / base; return rem; */ |
5 | 7 | |
6 | 8 | #define do_div(n, base) ({ \ |
... | ... | @@ -23,5 +25,6 @@ |
23 | 25 | __rem; \ |
24 | 26 | }) |
25 | 27 | |
28 | +extern uint64_t div64_64(uint64_t dividend, uint64_t divisor); | |
26 | 29 | #endif /* _M68K_DIV64_H */ |
include/asm-mips/div64.h
1 | 1 | /* |
2 | 2 | * Copyright (C) 2000, 2004 Maciej W. Rozycki |
3 | - * Copyright (C) 2003 Ralf Baechle | |
3 | + * Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org) | |
4 | 4 | * |
5 | 5 | * This file is subject to the terms and conditions of the GNU General Public |
6 | 6 | * License. See the file "COPYING" in the main directory of this archive |
... | ... | @@ -9,6 +9,8 @@ |
9 | 9 | #ifndef _ASM_DIV64_H |
10 | 10 | #define _ASM_DIV64_H |
11 | 11 | |
12 | +#include <linux/types.h> | |
13 | + | |
12 | 14 | #if (_MIPS_SZLONG == 32) |
13 | 15 | |
14 | 16 | #include <asm/compiler.h> |
... | ... | @@ -78,6 +80,8 @@ |
78 | 80 | __quot = __quot << 32 | __low; \ |
79 | 81 | (n) = __quot; \ |
80 | 82 | __mod; }) |
83 | + | |
84 | +extern uint64_t div64_64(uint64_t dividend, uint64_t divisor); | |
81 | 85 | #endif /* (_MIPS_SZLONG == 32) */ |
82 | 86 | |
83 | 87 | #if (_MIPS_SZLONG == 64) |
... | ... | @@ -100,6 +104,11 @@ |
100 | 104 | \ |
101 | 105 | (n) = __quot; \ |
102 | 106 | __mod; }) |
107 | + | |
108 | +static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor) | |
109 | +{ | |
110 | + return dividend / divisor; | |
111 | +} | |
103 | 112 | |
104 | 113 | #endif /* (_MIPS_SZLONG == 64) */ |
105 | 114 |
include/asm-um/div64.h
include/asm-xtensa/div64.h
... | ... | @@ -11,10 +11,16 @@ |
11 | 11 | #ifndef _XTENSA_DIV64_H |
12 | 12 | #define _XTENSA_DIV64_H |
13 | 13 | |
14 | +#include <linux/types.h> | |
15 | + | |
14 | 16 | #define do_div(n,base) ({ \ |
15 | 17 | int __res = n % ((unsigned int) base); \ |
16 | 18 | n /= (unsigned int) base; \ |
17 | 19 | __res; }) |
18 | 20 | |
21 | +static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor) | |
22 | +{ | |
23 | + return dividend / divisor; | |
24 | +} | |
19 | 25 | #endif |
lib/Makefile
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | |
5 | 5 | lib-y := ctype.o string.o vsprintf.o cmdline.o \ |
6 | 6 | rbtree.o radix-tree.o dump_stack.o \ |
7 | - idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \ | |
7 | + idr.o int_sqrt.o bitmap.o extable.o prio_tree.o \ | |
8 | 8 | sha1.o irq_regs.o reciprocal_div.o |
9 | 9 | |
10 | 10 | lib-$(CONFIG_MMU) += ioremap.o |
... | ... | @@ -12,7 +12,8 @@ |
12 | 12 | |
13 | 13 | lib-y += kobject.o kref.o kobject_uevent.o klist.o |
14 | 14 | |
15 | -obj-y += sort.o parser.o halfmd4.o debug_locks.o random32.o bust_spinlocks.o | |
15 | +obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ | |
16 | + bust_spinlocks.o | |
16 | 17 | |
17 | 18 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
18 | 19 | CFLAGS_kobject.o += -DDEBUG |
lib/div64.c
... | ... | @@ -58,5 +58,27 @@ |
58 | 58 | |
59 | 59 | EXPORT_SYMBOL(__div64_32); |
60 | 60 | |
61 | +/* 64bit divisor, dividend and result. dynamic precision */ | |
62 | +uint64_t div64_64(uint64_t dividend, uint64_t divisor) | |
63 | +{ | |
64 | + uint32_t d = divisor; | |
65 | + | |
66 | + if (divisor > 0xffffffffULL) { | |
67 | + unsigned int shift = fls(divisor >> 32); | |
68 | + | |
69 | + d = divisor >> shift; | |
70 | + dividend >>= shift; | |
71 | + } | |
72 | + | |
73 | + /* avoid 64 bit division if possible */ | |
74 | + if (dividend >> 32) | |
75 | + do_div(dividend, d); | |
76 | + else | |
77 | + dividend = (uint32_t) dividend / d; | |
78 | + | |
79 | + return dividend; | |
80 | +} | |
81 | +EXPORT_SYMBOL(div64_64); | |
82 | + | |
61 | 83 | #endif /* BITS_PER_LONG == 32 */ |
net/ipv4/tcp_cubic.c
... | ... | @@ -51,8 +51,6 @@ |
51 | 51 | module_param(tcp_friendliness, int, 0644); |
52 | 52 | MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness"); |
53 | 53 | |
54 | -#include <asm/div64.h> | |
55 | - | |
56 | 54 | /* BIC TCP Parameters */ |
57 | 55 | struct bictcp { |
58 | 56 | u32 cnt; /* increase cwnd by 1 after ACKs */ |
... | ... | @@ -91,27 +89,6 @@ |
91 | 89 | bictcp_reset(inet_csk_ca(sk)); |
92 | 90 | if (initial_ssthresh) |
93 | 91 | tcp_sk(sk)->snd_ssthresh = initial_ssthresh; |
94 | -} | |
95 | - | |
96 | -/* 64bit divisor, dividend and result. dynamic precision */ | |
97 | -static inline u_int64_t div64_64(u_int64_t dividend, u_int64_t divisor) | |
98 | -{ | |
99 | - u_int32_t d = divisor; | |
100 | - | |
101 | - if (divisor > 0xffffffffULL) { | |
102 | - unsigned int shift = fls(divisor >> 32); | |
103 | - | |
104 | - d = divisor >> shift; | |
105 | - dividend >>= shift; | |
106 | - } | |
107 | - | |
108 | - /* avoid 64 bit division if possible */ | |
109 | - if (dividend >> 32) | |
110 | - do_div(dividend, d); | |
111 | - else | |
112 | - dividend = (uint32_t) dividend / d; | |
113 | - | |
114 | - return dividend; | |
115 | 92 | } |
116 | 93 | |
117 | 94 | /* |
net/ipv4/tcp_yeah.c
... | ... | @@ -73,27 +73,6 @@ |
73 | 73 | yeah->pkts_acked = pkts_acked; |
74 | 74 | } |
75 | 75 | |
76 | -/* 64bit divisor, dividend and result. dynamic precision */ | |
77 | -static inline u64 div64_64(u64 dividend, u64 divisor) | |
78 | -{ | |
79 | - u32 d = divisor; | |
80 | - | |
81 | - if (divisor > 0xffffffffULL) { | |
82 | - unsigned int shift = fls(divisor >> 32); | |
83 | - | |
84 | - d = divisor >> shift; | |
85 | - dividend >>= shift; | |
86 | - } | |
87 | - | |
88 | - /* avoid 64 bit division if possible */ | |
89 | - if (dividend >> 32) | |
90 | - do_div(dividend, d); | |
91 | - else | |
92 | - dividend = (u32) dividend / d; | |
93 | - | |
94 | - return dividend; | |
95 | -} | |
96 | - | |
97 | 76 | static void tcp_yeah_cong_avoid(struct sock *sk, u32 ack, |
98 | 77 | u32 seq_rtt, u32 in_flight, int flag) |
99 | 78 | { |
net/ipv4/tcp_yeah.h
net/netfilter/xt_connbytes.c
... | ... | @@ -24,22 +24,6 @@ |
24 | 24 | MODULE_DESCRIPTION("iptables match for matching number of pkts/bytes per connection"); |
25 | 25 | MODULE_ALIAS("ipt_connbytes"); |
26 | 26 | |
27 | -/* 64bit divisor, dividend and result. dynamic precision */ | |
28 | -static u_int64_t div64_64(u_int64_t dividend, u_int64_t divisor) | |
29 | -{ | |
30 | - u_int32_t d = divisor; | |
31 | - | |
32 | - if (divisor > 0xffffffffULL) { | |
33 | - unsigned int shift = fls(divisor >> 32); | |
34 | - | |
35 | - d = divisor >> shift; | |
36 | - dividend >>= shift; | |
37 | - } | |
38 | - | |
39 | - do_div(dividend, d); | |
40 | - return dividend; | |
41 | -} | |
42 | - | |
43 | 27 | static int |
44 | 28 | match(const struct sk_buff *skb, |
45 | 29 | const struct net_device *in, |