annotate 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 3cbf1abde44a
children 6ffd2181ac58
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
1 Replace timeconst.bc with the c version I've been using for years (to replace
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 diff --git a/kernel/Makefile b/kernel/Makefile
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
5 index eceac38..f00be6d 100644
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
6 --- /dev/null
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
7 +++ linux/kernel/mktimeconst.c
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
8 @@ -0,0 +1,110 @@
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 +/* Copyright 2010 Parallels Inc, licensed under GPLv2 */
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
10 +/* 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
11 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 +#include <inttypes.h>
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 +#include <stdio.h>
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 +#include <stdlib.h>
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 +int main(int argc, char *argv[])
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 +{
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 + uint64_t hz, periods[] = {1000, 1000000};
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 + char *names[] = {"MSEC", "USEC"};
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 + FILE *file;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 + int i, j;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 + 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
24 + || !(file = fopen(argv[2], "w")))
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 + {
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 + 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
27 + 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
28 + 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
29 + 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
30 + exit(1);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 + }
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 + fprintf(file,
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 + "/* Automatically generated by kernel/mktimeconst */\n"
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 + "/* 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
36 + "#ifndef __KERNEL_TIMECONST_H\n"
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 + "#define __KERNEL_TIMECONST_H\n\n"
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 + "#include <linux/param.h>\n"
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 + "#include <linux/types.h>\n\n"
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 + "#if HZ != %"PRIu64"\n"
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 + "#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
42 + "#endif\n\n", hz, hz);
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 + /* Repeat for MSEC and USEC */
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 + for (i = 0; i < 2; i++) {
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 + uint64_t gcd, period;
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 + /* 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
50 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 + gcd = hz;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 + period = periods[i];
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 + while (period) {
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 + uint64_t temp = gcd % period;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
55 + gcd = period;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 + period = temp;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 + }
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 + /* 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
60 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 + for (j = 0; j < 2; j++) {
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 + char name[16];
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 + 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
64 + 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
65 + 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
66 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 + 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
68 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 + /* 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
70 + 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
71 + 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
72 + */
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
74 + for (;;) {
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 + 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
76 + if (mul32 >= (1UL<<31))
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
77 + break;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
78 + shift++;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
79 + }
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
80 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
81 + /* 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
82 + 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
83 + 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
84 + 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
85 + 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
86 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
87 + adj32 = from / gcd;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
88 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
89 + if (shift > 32) {
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 + uint64_t upper, lower;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
91 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
92 + upper = (adj32 - 1) << (shift - 32);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
93 + lower = (upper % adj32) << 32;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
94 + adj32 = ((upper/adj32) << 32) + (lower/adj32);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
95 + } else
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
96 + adj32 = ((adj32 - 1) << shift) / adj32;
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 + /* 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
99 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
100 + 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
101 + name, mul32);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
102 + 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
103 + name, adj32);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
104 + 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
105 + name, shift);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
106 + 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
107 + name, to/gcd);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
108 + 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
109 + name, from/gcd);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 + }
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 + 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
113 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
114 + /* Notice if the disk fills up. */
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
115 +
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
116 + fflush(stdout);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
117 + return ferror(stdout);
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
118 +}
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
119 --- linux/kernel/timeconst.bc 2013-04-28 19:36:01.000000000 -0500
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
120 +++ /dev/null 2013-02-23 10:58:11.743993346 -0600
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
121 @@ -1,108 +0,0 @@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
122 -scale=0
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
123 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
124 -define gcd(a,b) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
125 - auto t;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
126 - while (b) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
127 - t = b;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
128 - b = a % b;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
129 - a = t;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
130 - }
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
131 - return a;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
132 -}
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
133 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
134 -/* Division by reciprocal multiplication. */
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
135 -define fmul(b,n,d) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
136 - 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
137 -}
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
138 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
139 -/* Adjustment factor when a ceiling value is used. Use as:
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
140 - (imul * n) + (fmulxx * n + fadjxx) >> xx) */
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
141 -define fadj(b,n,d) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
142 - auto v;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
143 - d = d/gcd(n,d);
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
144 - v = 2^b*(d-1)/d;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
145 - return v;
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
146 -}
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
147 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
148 -/* Compute the appropriate mul/adj values as well as a shift count,
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
149 - which brings the mul value into the range 2^b-1 <= x < 2^b. Such
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
150 - a shift value will be correct in the signed integer range and off
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
151 - by at most one in the upper half of the unsigned range. */
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
152 -define fmuls(b,n,d) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
153 - auto s, m;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
154 - for (s = 0; 1; s++) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
155 - m = fmul(s,n,d);
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
156 - if (m >= 2^(b-1))
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
157 - return s;
1337
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 - return 0;
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
160 -}
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
162 -define timeconst(hz) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
163 - print "/* Automatically generated by kernel/timeconst.bc */\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
164 - print "/* Time conversion constants for HZ == ", hz, " */\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
165 - print "\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
166 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
167 - print "#ifndef KERNEL_TIMECONST_H\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
168 - print "#define KERNEL_TIMECONST_H\n\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
169 -
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
170 - print "#include <linux/param.h>\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
171 - print "#include <linux/types.h>\n\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
172 -
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
173 - print "#if HZ != ", hz, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
174 - print "#error \qkernel/timeconst.h has the wrong HZ value!\q\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
175 - print "#endif\n\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
176 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
177 - if (hz < 2) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
178 - print "#error Totally bogus HZ value!\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
179 - } else {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
180 - s=fmuls(32,1000,hz)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
181 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
182 - print "#define HZ_TO_MSEC_MUL32\tU64_C(0x", fmul(s,1000,hz), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
183 - print "#define HZ_TO_MSEC_ADJ32\tU64_C(0x", fadj(s,1000,hz), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
184 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
185 - 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
186 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
187 - s=fmuls(32,hz,1000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
188 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
189 - print "#define MSEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
190 - print "#define MSEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
191 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
192 - 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
193 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
194 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
195 - cd=gcd(hz,1000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
196 - print "#define HZ_TO_MSEC_NUM\t\t", 1000/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
197 - print "#define HZ_TO_MSEC_DEN\t\t", hz/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
198 - print "#define MSEC_TO_HZ_NUM\t\t", hz/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
199 - print "#define MSEC_TO_HZ_DEN\t\t", 1000/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
200 - print "\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
201 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
202 - s=fmuls(32,1000000,hz)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
203 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
204 - print "#define HZ_TO_USEC_MUL32\tU64_C(0x", fmul(s,1000000,hz), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
205 - print "#define HZ_TO_USEC_ADJ32\tU64_C(0x", fadj(s,1000000,hz), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
206 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
207 - 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
208 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
209 - s=fmuls(32,hz,1000000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
210 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
211 - print "#define USEC_TO_HZ_MUL32\tU64_C(0x", fmul(s,hz,1000000), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
212 - print "#define USEC_TO_HZ_ADJ32\tU64_C(0x", fadj(s,hz,1000000), ")\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
213 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
214 - 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
215 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
216 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
217 - cd=gcd(hz,1000000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
218 - print "#define HZ_TO_USEC_NUM\t\t", 1000000/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
219 - print "#define HZ_TO_USEC_DEN\t\t", hz/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
220 - print "#define USEC_TO_HZ_NUM\t\t", hz/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
221 - print "#define USEC_TO_HZ_DEN\t\t", 1000000/cd, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
222 - print "\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
223 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
224 - 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
225 - }
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
226 - halt
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
227 -}
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
228 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
229 -timeconst(hz)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
230 --- linux/kernel/Makefile
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
231 +++ linux/kernel/Makefile
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
232 @@ -125,19 +125,13 @@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
233
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
234 $(obj)/time.o: $(obj)/timeconst.h
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
235
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
236 -quiet_cmd_hzfile = HZFILE $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
237 - 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
238 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
239 -targets += hz.bc
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
240 -$(obj)/hz.bc: $(objtree)/include/config/hz.h FORCE
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
241 - $(call if_changed,hzfile)
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
242 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
243 -quiet_cmd_bc = BC $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
244 - cmd_bc = bc -q $(filter-out FORCE,$^) > $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
245 +hostprogs-y += mktimeconst
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
246 +quiet_cmd_mktimeconst = TIMEC $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
247 + cmd_mktimeconst = $(obj)/mktimeconst $(CONFIG_HZ) $@ || ( rm -f $@ && exit 1 )
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
248
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
249 targets += timeconst.h
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
250 -$(obj)/timeconst.h: $(obj)/hz.bc $(src)/timeconst.bc FORCE
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
251 - $(call if_changed,bc)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
252 +$(obj)/timeconst.h: $(obj)/mktimeconst FORCE
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
253 + $(call if_changed,mktimeconst)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
254
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
255 ifeq ($(CONFIG_MODULE_SIG),y)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
256 #