Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86_64 / lib / delay.c
blob6e2d66472eb1938f50aa45c2e0306b124f7885b1
1 /*
2 * Precise Delay Loops for x86-64
4 * Copyright (C) 1993 Linus Torvalds
5 * Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
7 * The __delay function must _NOT_ be inlined as its execution time
8 * depends wildly on alignment on many x86 processors.
9 */
11 #include <linux/config.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
14 #include <asm/delay.h>
16 #ifdef CONFIG_SMP
17 #include <asm/smp.h>
18 #endif
20 int x86_udelay_tsc = 0; /* Delay via TSC */
22 void __delay(unsigned long loops)
24 unsigned bclock, now;
26 rdtscl(bclock);
29 rep_nop();
30 rdtscl(now);
32 while((now-bclock) < loops);
35 inline void __const_udelay(unsigned long xloops)
37 __delay(((xloops * cpu_data[_smp_processor_id()].loops_per_jiffy) >> 32) * HZ);
40 void __udelay(unsigned long usecs)
42 __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
45 void __ndelay(unsigned long nsecs)
47 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */