Skip to content

Commit

Permalink
[PATCH] x86_64: Make udelay more accurate
Browse files Browse the repository at this point in the history
The attempt to avoid overflow in __delay caused varying precision
on different CPUs depending on differences in the CPU speed.

We should be able to do this multiplication with out overflowing
provided the
cpu is running at less than about 128 GHz.  xloops < 20000 * 0x10c6.
loops_per_jiffy * HZ <= cpu_clock_speed.  So if the cpu clock speed
< 2^64/(20000 * 0x10c6) = 2^64/ 51E6CC0 < 2^64/2^27 = 2^37 = 128G we
will not overflow the calculation.

Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Ross Biro authored and Linus Torvalds committed Jan 12, 2006
1 parent e4e9407 commit 79c62cf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/x86_64/lib/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void __delay(unsigned long loops)

inline void __const_udelay(unsigned long xloops)
{
__delay(((xloops * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32) * HZ);
__delay((xloops * HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32);
}

void __udelay(unsigned long usecs)
Expand Down

0 comments on commit 79c62cf

Please sign in to comment.