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