1 /* 2 * Precise Delay Loops for i386 3 * 4 * Copyright (C) 1993 Linus Torvalds 5 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz> 6 * 7 * The __delay function must _NOT_ be inlined as its execution time 8 * depends wildly on alignment on many x86 processors. The additional 9 * jump magic is needed to get the timing stable on all the CPU's 10 * we have to worry about. 11 */ 12 13 #include <xen/delay.h> 14 #include <xen/time.h> 15 #include <asm/msr.h> 16 #include <asm/processor.h> 17 __udelay(unsigned long usecs)18void __udelay(unsigned long usecs) 19 { 20 unsigned long ticks = usecs * (cpu_khz / 1000); 21 unsigned long s, e; 22 23 s = rdtsc_ordered(); 24 do 25 { 26 rep_nop(); 27 e = rdtsc_ordered(); 28 } while ((e-s) < ticks); 29 } 30