blob: 33a873a3c223f82416a9ed2ea239cc15c928a5bd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Precise Delay Loops for x86-64
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.
9 */
10
11#include <linux/config.h>
12#include <linux/sched.h>
13#include <linux/delay.h>
14#include <asm/delay.h>
Venkatesh Pallipadi8a9e1b02005-06-23 00:08:13 -070015#include <asm/msr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef CONFIG_SMP
18#include <asm/smp.h>
19#endif
20
21int x86_udelay_tsc = 0; /* Delay via TSC */
22
Venkatesh Pallipadi8a9e1b02005-06-23 00:08:13 -070023int read_current_timer(unsigned long *timer_value)
24{
25 rdtscll(*timer_value);
26 return 0;
27}
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029void __delay(unsigned long loops)
30{
31 unsigned bclock, now;
32
33 rdtscl(bclock);
34 do
35 {
36 rep_nop();
37 rdtscl(now);
38 }
39 while((now-bclock) < loops);
40}
41
42inline void __const_udelay(unsigned long xloops)
43{
Ingo Molnar39c715b2005-06-21 17:14:34 -070044 __delay(((xloops * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32) * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47void __udelay(unsigned long usecs)
48{
49 __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
50}
51
52void __ndelay(unsigned long nsecs)
53{
54 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
55}