diff options
author | H. Peter Anvin <hpa@zytor.com> | 2013-02-14 18:13:55 -0500 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2013-02-16 17:17:25 -0500 |
commit | 70730bca1331fc50c3caacaea00439de1325bd6e (patch) | |
tree | 43c9db2193af32e5aec6794dd67e0ae331380c31 /kernel/timeconst.bc | |
parent | 6543becf26fff612cdadeed7250ccc8d49f67f27 (diff) |
kernel: Replace timeconst.pl with a bc script
bc is the standard tool for multi-precision arithmetic. We switched
to Perl because akpm reported a hard-to-reproduce build hang, which
was very odd because affected and unaffected machines were all running
the same version of GNU bc.
Unfortunately switching to Perl required a really ugly "canning"
mechanism to support Perl < 5.8 installations lacking the Math::BigInt
module.
It was recently pointed out to me that some very old versions of GNU
make had problems with pipes in subshells, which was indeed the
construct used in the Makefile rules in that version of the patch;
Perl didn't need it so switching to Perl fixed the problem for
unrelated reasons. With the problem (hopefully) root-caused, we can
switch back to bc and do the arbitrary-precision arithmetic naturally.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'kernel/timeconst.bc')
-rw-r--r-- | kernel/timeconst.bc | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/kernel/timeconst.bc b/kernel/timeconst.bc new file mode 100644 index 000000000000..511bdf2cafda --- /dev/null +++ b/kernel/timeconst.bc | |||
@@ -0,0 +1,108 @@ | |||
1 | scale=0 | ||
2 | |||
3 | define gcd(a,b) { | ||
4 | auto t; | ||
5 | while (b) { | ||
6 | t = b; | ||
7 | b = a % b; | ||
8 | a = t; | ||
9 | } | ||
10 | return a; | ||
11 | } | ||
12 | |||
13 | /* Division by reciprocal multiplication. */ | ||
14 | define fmul(b,n,d) { | ||
15 | return (2^b*n+d-1)/d; | ||
16 | } | ||
17 | |||
18 | /* Adjustment factor when a ceiling value is used. Use as: | ||
19 | (imul * n) + (fmulxx * n + fadjxx) >> xx) */ | ||
20 | define fadj(b,n,d) { | ||
21 | auto v; | ||
22 | d = d/gcd(n,d); | ||
23 | v = 2^b*(d-1)/d; | ||
24 | return v; | ||
25 | } | ||
26 | |||
27 | /* Compute the appropriate mul/adj values as well as a shift count, | ||
28 | which brings the mul value into the range 2^b-1 <= x < 2^b. Such | ||
29 | a shift value will be correct in the signed integer range and off | ||
30 | by at most one in the upper half of the unsigned range. */ | ||
31 | define fmuls(b,n,d) { | ||
32 | auto s, m; | ||
33 | for (s = 0; 1; s++) { | ||
34 | m = fmul(s,n,d); | ||
35 | if (m >= 2^(b-1)) | ||
36 | return s; | ||
37 | } | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | define timeconst(hz) { | ||
42 | print "/* Automatically generated by kernel/timeconst.bc */\n" | ||
43 | print "/* Time conversion constants for HZ == ", hz, " */\n" | ||
44 | print "\n" | ||
45 | |||
46 | print "#ifndef KERNEL_TIMECONST_H\n" | ||
47 | print "#define KERNEL_TIMECONST_H\n\n" | ||
48 | |||
49 | print "#include <linux/param.h>\n" | ||
50 | print "#include <linux/types.h>\n\n" | ||
51 | |||
52 | print "#if HZ != ", hz, "\n" | ||
53 | print "#error \qkernel/timeconst.h has the wrong HZ value!\q\n" | ||
54 | print "#endif\n\n" | ||
55 | |||
56 | if (hz < 2) { | ||
57 | print "#error Totally bogus HZ value!\n" | ||
58 | } else { | ||
59 | s=fmuls(32,1000,hz) | ||
60 | obase=16 | ||
61 | print "#define HZ_TO_MSEC_MUL32\tU64_C(0x", fmul(s,1000,hz), ")\n" | ||
62 | print "#define HZ_TO_MSEC_ADJ32\tU64_C(0x", fadj(s,1000,hz), ")\n" | ||
63 | obase=10 | ||
64 | print "#define HZ_TO_MSEC_SHR32\t", s, "\n" | ||
65 | |||
66 | s=fmuls(32,hz,1000) | ||
67 | obase=16 | ||
68 | print "#define MSEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000), ")\n" | ||
69 | print "#define MSEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000), ")\n" | ||
70 | obase=10 | ||
71 | print "#define MSEC_TO_HZ_SHR32\t", s, "\n" | ||
72 | |||
73 | obase=10 | ||
74 | cd=gcd(hz,1000) | ||
75 | print "#define HZ_TO_MSEC_NUM\t\t", 1000/cd, "\n" | ||
76 | print "#define HZ_TO_MSEC_DEN\t\t", hz/cd, "\n" | ||
77 | print "#define MSEC_TO_HZ_NUM\t\t", hz/cd, "\n" | ||
78 | print "#define MSEC_TO_HZ_DEN\t\t", 1000/cd, "\n" | ||
79 | print "\n" | ||
80 | |||
81 | s=fmuls(32,1000000,hz) | ||
82 | obase=16 | ||
83 | print "#define HZ_TO_USEC_MUL32\tU64_C(0x", fmul(s,1000000,hz), ")\n" | ||
84 | print "#define HZ_TO_USEC_ADJ32\tU64_C(0x", fadj(s,1000000,hz), ")\n" | ||
85 | obase=10 | ||
86 | print "#define HZ_TO_USEC_SHR32\t", s, "\n" | ||
87 | |||
88 | s=fmuls(32,hz,1000000) | ||
89 | obase=16 | ||
90 | print "#define USEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000000), ")\n" | ||
91 | print "#define USEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000000), ")\n" | ||
92 | obase=10 | ||
93 | print "#define USEC_TO_HZ_SHR32\t", s, "\n" | ||
94 | |||
95 | obase=10 | ||
96 | cd=gcd(hz,1000000) | ||
97 | print "#define HZ_TO_USEC_NUM\t\t", 1000000/cd, "\n" | ||
98 | print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "\n" | ||
99 | print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "\n" | ||
100 | print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "\n" | ||
101 | print "\n" | ||
102 | |||
103 | print "#endif /* KERNEL_TIMECONST_H */\n" | ||
104 | } | ||
105 | halt | ||
106 | } | ||
107 | |||
108 | timeconst(hz) | ||