annotate sources/patches/linux-noperl-timeconst.patch @ 1698:49abeb0ead62 draft

linux 3.17
author Rob Landley <rob@landley.net>
date Sun, 05 Oct 2014 23:23:42 -0500
parents cc716bec3527
children db11c049b66b
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
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
4 --- /dev/null
1698
49abeb0ead62 linux 3.17
Rob Landley <rob@landley.net>
parents: 1644
diff changeset
5 +++ linux/kernel/time/mktimeconst.c
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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 +}
1698
49abeb0ead62 linux 3.17
Rob Landley <rob@landley.net>
parents: 1644
diff changeset
117 --- linux/kernel/time/timeconst.bc 2013-04-28 19:36:01.000000000 -0500
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
118 +++ /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
119 @@ -1,108 +0,0 @@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
120 -scale=0
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
121 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
122 -define gcd(a,b) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
123 - auto t;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
124 - while (b) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
125 - t = b;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
126 - b = a % b;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
127 - a = t;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
128 - }
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
129 - return a;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
130 -}
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
131 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
132 -/* Division by reciprocal multiplication. */
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
133 -define fmul(b,n,d) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
137 -/* 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
138 - (imul * n) + (fmulxx * n + fadjxx) >> xx) */
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
139 -define fadj(b,n,d) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
140 - auto v;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
141 - d = d/gcd(n,d);
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
142 - v = 2^b*(d-1)/d;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
146 -/* 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
147 - 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
148 - 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
149 - 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
150 -define fmuls(b,n,d) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
151 - auto s, m;
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
152 - for (s = 0; 1; s++) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
153 - m = fmul(s,n,d);
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
154 - if (m >= 2^(b-1))
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
160 -define timeconst(hz) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
161 - print "/* Automatically generated by kernel/timeconst.bc */\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
162 - print "/* Time conversion constants for HZ == ", hz, " */\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
163 - print "\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
164 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
165 - print "#ifndef KERNEL_TIMECONST_H\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
166 - print "#define KERNEL_TIMECONST_H\n\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
167 -
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
168 - print "#include <linux/param.h>\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
169 - print "#include <linux/types.h>\n\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
170 -
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
171 - print "#if HZ != ", hz, "\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
172 - 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
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
175 - if (hz < 2) {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
176 - print "#error Totally bogus HZ value!\n"
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
177 - } else {
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
178 - s=fmuls(32,1000,hz)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
179 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
180 - 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
181 - 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
182 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
185 - s=fmuls(32,hz,1000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
186 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
187 - 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
188 - 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
189 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
192 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
193 - cd=gcd(hz,1000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
194 - 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
195 - 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
196 - 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
197 - 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
198 - print "\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
199 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
200 - s=fmuls(32,1000000,hz)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
201 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
202 - 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
203 - 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
204 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
207 - s=fmuls(32,hz,1000000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
208 - obase=16
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
209 - 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
210 - 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
211 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
214 - obase=10
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
215 - cd=gcd(hz,1000000)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
216 - 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
217 - 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
218 - 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
219 - 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
220 - print "\n"
1337
1bc0c01950ca Switch to the noperl patches for 2.6.38.
Rob Landley <rob@landley.net>
parents:
diff changeset
221 -
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
227 -timeconst(hz)
1698
49abeb0ead62 linux 3.17
Rob Landley <rob@landley.net>
parents: 1644
diff changeset
228 --- linux/kernel/time/Makefile
49abeb0ead62 linux 3.17
Rob Landley <rob@landley.net>
parents: 1644
diff changeset
229 +++ linux/kernel/time/Makefile
49abeb0ead62 linux 3.17
Rob Landley <rob@landley.net>
parents: 1644
diff changeset
230 @@ -125,17 +125,11 @@
1598
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
231
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
232 $(obj)/time.o: $(obj)/timeconst.h
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 -quiet_cmd_hzfile = HZFILE $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
237 -targets += hz.bc
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
238 -$(obj)/hz.bc: $(objtree)/include/config/hz.h FORCE
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
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
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
241 -quiet_cmd_bc = BC $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
242 - cmd_bc = bc -q $(filter-out FORCE,$^) > $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
243 +hostprogs-y += mktimeconst
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
244 +quiet_cmd_mktimeconst = TIMEC $@
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
245 + 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
246
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
247 targets += timeconst.h
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
248 -$(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
249 - $(call if_changed,bc)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
250 +$(obj)/timeconst.h: $(obj)/mktimeconst FORCE
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
251 + $(call if_changed,mktimeconst)
3cbf1abde44a Update to linux 3.9.
Rob Landley <rob@landley.net>
parents: 1570
diff changeset
252