aboriginal

view sources/patches/linux-noperl-timeconst.patch @ 1619:3413e8427702

The lfs m4 build wasn't including -lrt when probing for posix_spawn, thus trying to recreate what was already there and causing a conflicting definition. Change patch to insert it into libc proper.
author Rob Landley <rob@landley.net>
date Fri, 23 Aug 2013 06:02:55 -0500
parents bee6b26a006d
children 6ffd2181ac58
line source
1 Replace timeconst.bc with the c version I've been using for years (to replace
2 the perl version). Eventually I should add bc to toybox, but for now...
4 diff --git a/kernel/Makefile b/kernel/Makefile
5 index eceac38..f00be6d 100644
6 --- /dev/null
7 +++ linux/kernel/mktimeconst.c
8 @@ -0,0 +1,110 @@
9 +/* Copyright 2010 Parallels Inc, licensed under GPLv2 */
10 +/* Copyright 2010-2013 Rob Landley <rob@landley.net> */
11 +
12 +#include <inttypes.h>
13 +#include <stdio.h>
14 +#include <stdlib.h>
15 +
16 +int main(int argc, char *argv[])
17 +{
18 + uint64_t hz, periods[] = {1000, 1000000};
19 + char *names[] = {"MSEC", "USEC"};
20 + FILE *file;
21 + int i, j;
22 +
23 + if (argc != 3 || (hz = atol(argv[1])) < 1
24 + || !(file = fopen(argv[2], "w")))
25 + {
26 + fprintf(stderr, "Usage: mktimeconst HZ FILENAME\n\n");
27 + fprintf(stderr, "Generate a header file with constants to convert between\n");
28 + fprintf(stderr, "decimal HZ timer ticks and milisecond or microsecond delays,\n");
29 + fprintf(stderr, "using reciprocal multiplication to avoid 64 bit division.\n");
30 + exit(1);
31 + }
32 +
33 + fprintf(file,
34 + "/* Automatically generated by kernel/mktimeconst */\n"
35 + "/* Conversion constants for HZ == %"PRIu64" */\n\n"
36 + "#ifndef __KERNEL_TIMECONST_H\n"
37 + "#define __KERNEL_TIMECONST_H\n\n"
38 + "#include <linux/param.h>\n"
39 + "#include <linux/types.h>\n\n"
40 + "#if HZ != %"PRIu64"\n"
41 + "#error \"kernel/timeconst.h has the wrong HZ value!\"\n"
42 + "#endif\n\n", hz, hz);
43 +
44 + /* Repeat for MSEC and USEC */
45 +
46 + for (i = 0; i < 2; i++) {
47 + uint64_t gcd, period;
48 +
49 + /* Find greatest common denominator using Euclid's algorithm. */
50 +
51 + gcd = hz;
52 + period = periods[i];
53 + while (period) {
54 + uint64_t temp = gcd % period;
55 + gcd = period;
56 + period = temp;
57 + }
58 +
59 + /* Output both directions (HZ_TO_PERIOD and PERIOD_TO_HZ) */
60 +
61 + for (j = 0; j < 2; j++) {
62 + char name[16];
63 + uint64_t from = j ? periods[i] : hz;
64 + uint64_t to = j ? hz : periods[i];
65 + uint64_t mul32 = 0, adj32 = 0, shift = 0;
66 +
67 + sprintf(name, j ? "%s_TO_HZ" : "HZ_TO_%s", names[i]);
68 +
69 + /* Figure out what shift value gives 32 significant
70 + bits of MUL32 data. (Worst case to=1 from=1000000
71 + uses 52 bits, to<<shift won't overflow 64 bit math.)
72 + */
73 +
74 + for (;;) {
75 + mul32 = ((to << shift) + from - 1) / from;
76 + if (mul32 >= (1UL<<31))
77 + break;
78 + shift++;
79 + }
80 +
81 + /* ADJ32 is is just (((FROM/GCD)-1)<<SHIFT)/(FROM/GCD)
82 + but this can overflow 64 bit math (examples, HZ=24
83 + or HZ=122). Worst case scenario uses 32+20+20=72
84 + bits. Workaround: split off bottom 32 bits and
85 + reassemble after calculation (32+64=96 bits). */
86 +
87 + adj32 = from / gcd;
88 +
89 + if (shift > 32) {
90 + uint64_t upper, lower;
91 +
92 + upper = (adj32 - 1) << (shift - 32);
93 + lower = (upper % adj32) << 32;
94 + adj32 = ((upper/adj32) << 32) + (lower/adj32);
95 + } else
96 + adj32 = ((adj32 - 1) << shift) / adj32;
97 +
98 + /* Emit the constants into the header file. */
99 +
100 + fprintf(file, "#define %s_MUL32\tU64_C(0x%"PRIx64")\n",
101 + name, mul32);
102 + fprintf(file, "#define %s_ADJ32\tU64_C(0x%"PRIx64")\n",
103 + name, adj32);
104 + fprintf(file, "#define %s_SHR32\t%"PRIu64"\n",
105 + name, shift);
106 + fprintf(file, "#define %s_NUM\t\tU64_C(%"PRIu64")\n",
107 + name, to/gcd);
108 + fprintf(file, "#define %s_DEN\t\tU64_C(%"PRIu64")\n\n",
109 + name, from/gcd);
110 + }
111 + }
112 + fprintf(file, "#endif /* __KERNEL_TIMECONST_H */\n");
113 +
114 + /* Notice if the disk fills up. */
115 +
116 + fflush(stdout);
117 + return ferror(stdout);
118 +}
119 --- linux/kernel/timeconst.bc 2013-04-28 19:36:01.000000000 -0500
120 +++ /dev/null 2013-02-23 10:58:11.743993346 -0600
121 @@ -1,108 +0,0 @@
122 -scale=0
123 -
124 -define gcd(a,b) {
125 - auto t;
126 - while (b) {
127 - t = b;
128 - b = a % b;
129 - a = t;
130 - }
131 - return a;
132 -}
133 -
134 -/* Division by reciprocal multiplication. */
135 -define fmul(b,n,d) {
136 - return (2^b*n+d-1)/d;
137 -}
138 -
139 -/* Adjustment factor when a ceiling value is used. Use as:
140 - (imul * n) + (fmulxx * n + fadjxx) >> xx) */
141 -define fadj(b,n,d) {
142 - auto v;
143 - d = d/gcd(n,d);
144 - v = 2^b*(d-1)/d;
145 - return v;
146 -}
147 -
148 -/* Compute the appropriate mul/adj values as well as a shift count,
149 - which brings the mul value into the range 2^b-1 <= x < 2^b. Such
150 - a shift value will be correct in the signed integer range and off
151 - by at most one in the upper half of the unsigned range. */
152 -define fmuls(b,n,d) {
153 - auto s, m;
154 - for (s = 0; 1; s++) {
155 - m = fmul(s,n,d);
156 - if (m >= 2^(b-1))
157 - return s;
158 - }
159 - return 0;
160 -}
161 -
162 -define timeconst(hz) {
163 - print "/* Automatically generated by kernel/timeconst.bc */\n"
164 - print "/* Time conversion constants for HZ == ", hz, " */\n"
165 - print "\n"
166 -
167 - print "#ifndef KERNEL_TIMECONST_H\n"
168 - print "#define KERNEL_TIMECONST_H\n\n"
169 -
170 - print "#include <linux/param.h>\n"
171 - print "#include <linux/types.h>\n\n"
172 -
173 - print "#if HZ != ", hz, "\n"
174 - print "#error \qkernel/timeconst.h has the wrong HZ value!\q\n"
175 - print "#endif\n\n"
176 -
177 - if (hz < 2) {
178 - print "#error Totally bogus HZ value!\n"
179 - } else {
180 - s=fmuls(32,1000,hz)
181 - obase=16
182 - print "#define HZ_TO_MSEC_MUL32\tU64_C(0x", fmul(s,1000,hz), ")\n"
183 - print "#define HZ_TO_MSEC_ADJ32\tU64_C(0x", fadj(s,1000,hz), ")\n"
184 - obase=10
185 - print "#define HZ_TO_MSEC_SHR32\t", s, "\n"
186 -
187 - s=fmuls(32,hz,1000)
188 - obase=16
189 - print "#define MSEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000), ")\n"
190 - print "#define MSEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000), ")\n"
191 - obase=10
192 - print "#define MSEC_TO_HZ_SHR32\t", s, "\n"
193 -
194 - obase=10
195 - cd=gcd(hz,1000)
196 - print "#define HZ_TO_MSEC_NUM\t\t", 1000/cd, "\n"
197 - print "#define HZ_TO_MSEC_DEN\t\t", hz/cd, "\n"
198 - print "#define MSEC_TO_HZ_NUM\t\t", hz/cd, "\n"
199 - print "#define MSEC_TO_HZ_DEN\t\t", 1000/cd, "\n"
200 - print "\n"
201 -
202 - s=fmuls(32,1000000,hz)
203 - obase=16
204 - print "#define HZ_TO_USEC_MUL32\tU64_C(0x", fmul(s,1000000,hz), ")\n"
205 - print "#define HZ_TO_USEC_ADJ32\tU64_C(0x", fadj(s,1000000,hz), ")\n"
206 - obase=10
207 - print "#define HZ_TO_USEC_SHR32\t", s, "\n"
208 -
209 - s=fmuls(32,hz,1000000)
210 - obase=16
211 - print "#define USEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000000), ")\n"
212 - print "#define USEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000000), ")\n"
213 - obase=10
214 - print "#define USEC_TO_HZ_SHR32\t", s, "\n"
215 -
216 - obase=10
217 - cd=gcd(hz,1000000)
218 - print "#define HZ_TO_USEC_NUM\t\t", 1000000/cd, "\n"
219 - print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "\n"
220 - print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "\n"
221 - print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "\n"
222 - print "\n"
223 -
224 - print "#endif /* KERNEL_TIMECONST_H */\n"
225 - }
226 - halt
227 -}
228 -
229 -timeconst(hz)
230 --- linux/kernel/Makefile
231 +++ linux/kernel/Makefile
232 @@ -125,19 +125,13 @@
234 $(obj)/time.o: $(obj)/timeconst.h
236 -quiet_cmd_hzfile = HZFILE $@
237 - cmd_hzfile = echo "hz=$(CONFIG_HZ)" > $@
238 -
239 -targets += hz.bc
240 -$(obj)/hz.bc: $(objtree)/include/config/hz.h FORCE
241 - $(call if_changed,hzfile)
242 -
243 -quiet_cmd_bc = BC $@
244 - cmd_bc = bc -q $(filter-out FORCE,$^) > $@
245 +hostprogs-y += mktimeconst
246 +quiet_cmd_mktimeconst = TIMEC $@
247 + cmd_mktimeconst = $(obj)/mktimeconst $(CONFIG_HZ) $@ || ( rm -f $@ && exit 1 )
249 targets += timeconst.h
250 -$(obj)/timeconst.h: $(obj)/hz.bc $(src)/timeconst.bc FORCE
251 - $(call if_changed,bc)
252 +$(obj)/timeconst.h: $(obj)/mktimeconst FORCE
253 + $(call if_changed,mktimeconst)
255 ifeq ($(CONFIG_MODULE_SIG),y)
256 #