Commit b9095fd8a7f41dc7ac0b0b7864f74766a3056f96

Authored by H. Peter Anvin
1 parent c25bd29805

Make constants in kernel/timeconst.h fixed 64 bits

Force constants in kernel/timeconst.h (except shift counts) to be 64 bits,
using U64_C() constructor macros, and eliminate constants that cannot
be represented at all in 64 bits.  This avoids warnings with some gcc
versions.

Drop generating 64-bit constants, since we have no real hope of
getting a full set (operation on 64-bit values requires a 128-bit
intermediate result, which gcc only supports on 64-bit platforms, and
only with libgcc support on some.)  Note that the use of these
constants does not depend on if we are on a 32- or 64-bit architecture.

This resolves Bugzilla 10153.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>

Showing 2 changed files with 52 additions and 76 deletions Side-by-side Diff

... ... @@ -246,7 +246,7 @@
246 246 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
247 247 #else
248 248 # if BITS_PER_LONG == 32
249   - return ((u64)HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
  249 + return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
250 250 # else
251 251 return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN;
252 252 # endif
... ... @@ -262,7 +262,7 @@
262 262 return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
263 263 #else
264 264 # if BITS_PER_LONG == 32
265   - return ((u64)HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
  265 + return (HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
266 266 # else
267 267 return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN;
268 268 # endif
... ... @@ -476,7 +476,7 @@
476 476 if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
477 477 return MAX_JIFFY_OFFSET;
478 478  
479   - return ((u64)MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
  479 + return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
480 480 >> MSEC_TO_HZ_SHR32;
481 481 #endif
482 482 }
... ... @@ -491,7 +491,7 @@
491 491 #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
492 492 return u * (HZ / USEC_PER_SEC);
493 493 #else
494   - return ((u64)USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
  494 + return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
495 495 >> USEC_TO_HZ_SHR32;
496 496 #endif
497 497 }
1 1 #!/usr/bin/perl
2 2 # -----------------------------------------------------------------------
3 3 #
4   -# Copyright 2007 rPath, Inc. - All Rights Reserved
  4 +# Copyright 2007-2008 rPath, Inc. - All Rights Reserved
5 5 #
6 6 # This file is part of the Linux kernel, and is made available under
7 7 # the terms of the GNU General Public License version 2 or (at your
8 8  
9 9  
10 10  
11 11  
12 12  
13 13  
14 14  
15 15  
16 16  
17 17  
18 18  
19 19  
20 20  
21 21  
22 22  
23 23  
24 24  
25 25  
26 26  
27 27  
28 28  
29 29  
30 30  
31 31  
32 32  
33 33  
34 34  
35 35  
36 36  
37 37  
38 38  
39 39  
40 40  
41 41  
42 42  
43 43  
44 44  
45 45  
46 46  
47 47  
48 48  
49 49  
50 50  
51 51  
52 52  
53 53  
54 54  
55 55  
56 56  
57 57  
58 58  
59 59  
60 60  
61 61  
62 62  
63 63  
64 64  
65 65  
66 66  
... ... @@ -20,198 +20,138 @@
20 20 %canned_values = (
21 21 24 => [
22 22 '0xa6aaaaab','0x2aaaaaa',26,
23   - '0xa6aaaaaaaaaaaaab','0x2aaaaaaaaaaaaaa',58,
24 23 125,3,
25 24 '0xc49ba5e4','0x1fbe76c8b4',37,
26   - '0xc49ba5e353f7ceda','0x1fbe76c8b439581062',69,
27 25 3,125,
28 26 '0xa2c2aaab','0xaaaa',16,
29   - '0xa2c2aaaaaaaaaaab','0xaaaaaaaaaaaa',48,
30 27 125000,3,
31 28 '0xc9539b89','0x7fffbce4217d',47,
32   - '0xc9539b8887229e91','0x7fffbce4217d2849cb25',79,
33 29 3,125000,
34 30 ], 32 => [
35 31 '0xfa000000','0x6000000',27,
36   - '0xfa00000000000000','0x600000000000000',59,
37 32 125,4,
38 33 '0x83126e98','0xfdf3b645a',36,
39   - '0x83126e978d4fdf3c','0xfdf3b645a1cac0831',68,
40 34 4,125,
41 35 '0xf4240000','0x0',17,
42   - '0xf424000000000000','0x0',49,
43 36 31250,1,
44 37 '0x8637bd06','0x3fff79c842fa',46,
45   - '0x8637bd05af6c69b6','0x3fff79c842fa5093964a',78,
46 38 1,31250,
47 39 ], 48 => [
48 40 '0xa6aaaaab','0x6aaaaaa',27,
49   - '0xa6aaaaaaaaaaaaab','0x6aaaaaaaaaaaaaa',59,
50 41 125,6,
51 42 '0xc49ba5e4','0xfdf3b645a',36,
52   - '0xc49ba5e353f7ceda','0xfdf3b645a1cac0831',68,
53 43 6,125,
54 44 '0xa2c2aaab','0x15555',17,
55   - '0xa2c2aaaaaaaaaaab','0x1555555555555',49,
56 45 62500,3,
57 46 '0xc9539b89','0x3fffbce4217d',46,
58   - '0xc9539b8887229e91','0x3fffbce4217d2849cb25',78,
59 47 3,62500,
60 48 ], 64 => [
61 49 '0xfa000000','0xe000000',28,
62   - '0xfa00000000000000','0xe00000000000000',60,
63 50 125,8,
64 51 '0x83126e98','0x7ef9db22d',35,
65   - '0x83126e978d4fdf3c','0x7ef9db22d0e560418',67,
66 52 8,125,
67 53 '0xf4240000','0x0',18,
68   - '0xf424000000000000','0x0',50,
69 54 15625,1,
70 55 '0x8637bd06','0x1fff79c842fa',45,
71   - '0x8637bd05af6c69b6','0x1fff79c842fa5093964a',77,
72 56 1,15625,
73 57 ], 100 => [
74 58 '0xa0000000','0x0',28,
75   - '0xa000000000000000','0x0',60,
76 59 10,1,
77 60 '0xcccccccd','0x733333333',35,
78   - '0xcccccccccccccccd','0x73333333333333333',67,
79 61 1,10,
80 62 '0x9c400000','0x0',18,
81   - '0x9c40000000000000','0x0',50,
82 63 10000,1,
83 64 '0xd1b71759','0x1fff2e48e8a7',45,
84   - '0xd1b71758e219652c','0x1fff2e48e8a71de69ad4',77,
85 65 1,10000,
86 66 ], 122 => [
87 67 '0x8325c53f','0xfbcda3a',28,
88   - '0x8325c53ef368eb05','0xfbcda3ac10c9714',60,
89 68 500,61,
90 69 '0xf9db22d1','0x7fbe76c8b',35,
91   - '0xf9db22d0e560418a','0x7fbe76c8b43958106',67,
92 70 61,500,
93 71 '0x8012e2a0','0x3ef36',18,
94   - '0x8012e29f79b47583','0x3ef368eb04325',50,
95 72 500000,61,
96 73 '0xffda4053','0x1ffffbce4217',45,
97   - '0xffda4052d666a983','0x1ffffbce4217d2849cb2',77,
98 74 61,500000,
99 75 ], 128 => [
100 76 '0xfa000000','0x1e000000',29,
101   - '0xfa00000000000000','0x1e00000000000000',61,
102 77 125,16,
103 78 '0x83126e98','0x3f7ced916',34,
104   - '0x83126e978d4fdf3c','0x3f7ced916872b020c',66,
105 79 16,125,
106 80 '0xf4240000','0x40000',19,
107   - '0xf424000000000000','0x4000000000000',51,
108 81 15625,2,
109 82 '0x8637bd06','0xfffbce4217d',44,
110   - '0x8637bd05af6c69b6','0xfffbce4217d2849cb25',76,
111 83 2,15625,
112 84 ], 200 => [
113 85 '0xa0000000','0x0',29,
114   - '0xa000000000000000','0x0',61,
115 86 5,1,
116 87 '0xcccccccd','0x333333333',34,
117   - '0xcccccccccccccccd','0x33333333333333333',66,
118 88 1,5,
119 89 '0x9c400000','0x0',19,
120   - '0x9c40000000000000','0x0',51,
121 90 5000,1,
122 91 '0xd1b71759','0xfff2e48e8a7',44,
123   - '0xd1b71758e219652c','0xfff2e48e8a71de69ad4',76,
124 92 1,5000,
125 93 ], 250 => [
126 94 '0x80000000','0x0',29,
127   - '0x8000000000000000','0x0',61,
128 95 4,1,
129 96 '0x80000000','0x180000000',33,
130   - '0x8000000000000000','0x18000000000000000',65,
131 97 1,4,
132 98 '0xfa000000','0x0',20,
133   - '0xfa00000000000000','0x0',52,
134 99 4000,1,
135 100 '0x83126e98','0x7ff7ced9168',43,
136   - '0x83126e978d4fdf3c','0x7ff7ced916872b020c4',75,
137 101 1,4000,
138 102 ], 256 => [
139 103 '0xfa000000','0x3e000000',30,
140   - '0xfa00000000000000','0x3e00000000000000',62,
141 104 125,32,
142 105 '0x83126e98','0x1fbe76c8b',33,
143   - '0x83126e978d4fdf3c','0x1fbe76c8b43958106',65,
144 106 32,125,
145 107 '0xf4240000','0xc0000',20,
146   - '0xf424000000000000','0xc000000000000',52,
147 108 15625,4,
148 109 '0x8637bd06','0x7ffde7210be',43,
149   - '0x8637bd05af6c69b6','0x7ffde7210be9424e592',75,
150 110 4,15625,
151 111 ], 300 => [
152 112 '0xd5555556','0x2aaaaaaa',30,
153   - '0xd555555555555556','0x2aaaaaaaaaaaaaaa',62,
154 113 10,3,
155 114 '0x9999999a','0x1cccccccc',33,
156   - '0x999999999999999a','0x1cccccccccccccccc',65,
157 115 3,10,
158 116 '0xd0555556','0xaaaaa',20,
159   - '0xd055555555555556','0xaaaaaaaaaaaaa',52,
160 117 10000,3,
161 118 '0x9d495183','0x7ffcb923a29',43,
162   - '0x9d495182a9930be1','0x7ffcb923a29c779a6b5',75,
163 119 3,10000,
164 120 ], 512 => [
165 121 '0xfa000000','0x7e000000',31,
166   - '0xfa00000000000000','0x7e00000000000000',63,
167 122 125,64,
168 123 '0x83126e98','0xfdf3b645',32,
169   - '0x83126e978d4fdf3c','0xfdf3b645a1cac083',64,
170 124 64,125,
171 125 '0xf4240000','0x1c0000',21,
172   - '0xf424000000000000','0x1c000000000000',53,
173 126 15625,8,
174 127 '0x8637bd06','0x3ffef39085f',42,
175   - '0x8637bd05af6c69b6','0x3ffef39085f4a1272c9',74,
176 128 8,15625,
177 129 ], 1000 => [
178 130 '0x80000000','0x0',31,
179   - '0x8000000000000000','0x0',63,
180 131 1,1,
181 132 '0x80000000','0x0',31,
182   - '0x8000000000000000','0x0',63,
183 133 1,1,
184 134 '0xfa000000','0x0',22,
185   - '0xfa00000000000000','0x0',54,
186 135 1000,1,
187 136 '0x83126e98','0x1ff7ced9168',41,
188   - '0x83126e978d4fdf3c','0x1ff7ced916872b020c4',73,
189 137 1,1000,
190 138 ], 1024 => [
191 139 '0xfa000000','0xfe000000',32,
192   - '0xfa00000000000000','0xfe00000000000000',64,
193 140 125,128,
194 141 '0x83126e98','0x7ef9db22',31,
195   - '0x83126e978d4fdf3c','0x7ef9db22d0e56041',63,
196 142 128,125,
197 143 '0xf4240000','0x3c0000',22,
198   - '0xf424000000000000','0x3c000000000000',54,
199 144 15625,16,
200 145 '0x8637bd06','0x1fff79c842f',41,
201   - '0x8637bd05af6c69b6','0x1fff79c842fa5093964',73,
202 146 16,15625,
203 147 ], 1200 => [
204 148 '0xd5555556','0xd5555555',32,
205   - '0xd555555555555556','0xd555555555555555',64,
206 149 5,6,
207 150 '0x9999999a','0x66666666',31,
208   - '0x999999999999999a','0x6666666666666666',63,
209 151 6,5,
210 152 '0xd0555556','0x2aaaaa',22,
211   - '0xd055555555555556','0x2aaaaaaaaaaaaa',54,
212 153 2500,3,
213 154 '0x9d495183','0x1ffcb923a29',41,
214   - '0x9d495182a9930be1','0x1ffcb923a29c779a6b5',73,
215 155 3,2500,
216 156 ]
217 157 );
... ... @@ -264,6 +204,15 @@
264 204 return 0;
265 205 }
266 206  
  207 +# Generate a hex value if the result fits in 64 bits;
  208 +# otherwise skip.
  209 +sub bignum_hex($) {
  210 + my($x) = @_;
  211 + my $s = $x->as_hex();
  212 +
  213 + return (length($s) > 18) ? undef : $s;
  214 +}
  215 +
267 216 # Provides mul, adj, and shr factors for a specific
268 217 # (bit, time, hz) combination
269 218 sub muladj($$$) {
... ... @@ -271,7 +220,7 @@
271 220 my $s = fmuls($b, $t, $hz);
272 221 my $m = fmul($s, $t, $hz);
273 222 my $a = fadj($s, $t, $hz);
274   - return ($m->as_hex(), $a->as_hex(), $s);
  223 + return (bignum_hex($m), bignum_hex($a), $s);
275 224 }
276 225  
277 226 # Provides numerator, denominator values
278 227  
... ... @@ -288,12 +237,10 @@
288 237  
289 238 # HZ_TO_xx
290 239 push(@val, muladj(32, $t, $hz));
291   - push(@val, muladj(64, $t, $hz));
292 240 push(@val, numden($t, $hz));
293 241  
294 242 # xx_TO_HZ
295 243 push(@val, muladj(32, $hz, $t));
296   - push(@val, muladj(64, $hz, $t));
297 244 push(@val, numden($hz, $t));
298 245  
299 246 return @val;
... ... @@ -318,6 +265,19 @@
318 265 return @val;
319 266 }
320 267  
  268 +sub outputval($$)
  269 +{
  270 + my($name, $val) = @_;
  271 + my $csuf;
  272 +
  273 + if (defined($val)) {
  274 + if ($name !~ /SHR/) {
  275 + $val = "U64_C($val)";
  276 + }
  277 + printf "#define %-23s %s\n", $name.$csuf, $val.$csuf;
  278 + }
  279 +}
  280 +
321 281 sub output($@)
322 282 {
323 283 my($hz, @val) = @_;
... ... @@ -331,6 +291,7 @@
331 291 print "\n";
332 292  
333 293 print "#include <linux/param.h>\n";
  294 + print "#include <linux/types.h>\n";
334 295  
335 296 print "\n";
336 297 print "#if HZ != $hz\n";
337 298  
338 299  
... ... @@ -340,15 +301,13 @@
340 301  
341 302 foreach $pfx ('HZ_TO_MSEC','MSEC_TO_HZ',
342 303 'HZ_TO_USEC','USEC_TO_HZ') {
343   - foreach $bit (32, 64) {
  304 + foreach $bit (32) {
344 305 foreach $suf ('MUL', 'ADJ', 'SHR') {
345   - printf "#define %-23s %s\n",
346   - "${pfx}_$suf$bit", shift(@val);
  306 + outputval("${pfx}_$suf$bit", shift(@val));
347 307 }
348 308 }
349 309 foreach $suf ('NUM', 'DEN') {
350   - printf "#define %-23s %s\n",
351   - "${pfx}_$suf", shift(@val);
  310 + outputval("${pfx}_$suf", shift(@val));
352 311 }
353 312 }
354 313  
... ... @@ -356,6 +315,23 @@
356 315 print "#endif /* KERNEL_TIMECONST_H */\n";
357 316 }
358 317  
  318 +# Pretty-print Perl values
  319 +sub perlvals(@) {
  320 + my $v;
  321 + my @l = ();
  322 +
  323 + foreach $v (@_) {
  324 + if (!defined($v)) {
  325 + push(@l, 'undef');
  326 + } elsif ($v =~ /^0x/) {
  327 + push(@l, "\'".$v."\'");
  328 + } else {
  329 + push(@l, $v.'');
  330 + }
  331 + }
  332 + return join(',', @l);
  333 +}
  334 +
359 335 ($hz) = @ARGV;
360 336  
361 337 # Use this to generate the %canned_values structure
362 338  
363 339  
... ... @@ -373,15 +349,15 @@
373 349 print "$pf$hz => [\n";
374 350 while (scalar(@values)) {
375 351 my $bit;
376   - foreach $bit (32, 64) {
  352 + foreach $bit (32) {
377 353 my $m = shift(@values);
378 354 my $a = shift(@values);
379 355 my $s = shift(@values);
380   - print "\t\t\'",$m,"\',\'",$a,"\',",$s,",\n";
  356 + print "\t\t", perlvals($m,$a,$s), ",\n";
381 357 }
382 358 my $n = shift(@values);
383 359 my $d = shift(@values);
384   - print "\t\t",$n,',',$d,",\n";
  360 + print "\t\t", perlvals($n,$d), ",\n";
385 361 }
386 362 print "\t]";
387 363 $pf = ', ';