aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/lib/delay_64.c
diff options
context:
space:
mode:
authorGlauber Costa <gcosta@redhat.com>2008-07-03 11:35:41 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-09 02:52:05 -0400
commitf0fbf0abc093ec8bf64506eee4ede9e5daf40ffd (patch)
treeca56be34bf193e386591fe5c4bdb3032a28dcad1 /arch/x86/lib/delay_64.c
parent7e58818d32c18197602d1869b22cfda99efd05fe (diff)
x86: integrate delay functions.
delay_32.c, delay_64.c are now equal, and are integrated into delay.c. Signed-off-by: Glauber Costa <gcosta@redhat.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/lib/delay_64.c')
-rw-r--r--arch/x86/lib/delay_64.c128
1 files changed, 0 insertions, 128 deletions
diff --git a/arch/x86/lib/delay_64.c b/arch/x86/lib/delay_64.c
deleted file mode 100644
index ff3dfecdb6f9..000000000000
--- a/arch/x86/lib/delay_64.c
+++ /dev/null
@@ -1,128 +0,0 @@
1/*
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/module.h>
12#include <linux/sched.h>
13#include <linux/timex.h>
14#include <linux/preempt.h>
15#include <linux/delay.h>
16#include <linux/init.h>
17
18#include <asm/delay.h>
19#include <asm/msr.h>
20
21#ifdef CONFIG_SMP
22#include <asm/smp.h>
23#endif
24
25/* simple loop based delay: */
26static void delay_loop(unsigned long loops)
27{
28 asm volatile(
29 " test %0,%0 \n"
30 " jz 3f \n"
31 " jmp 1f \n"
32
33 ".align 16 \n"
34 "1: jmp 2f \n"
35
36 ".align 16 \n"
37 "2: dec %0 \n"
38 " jnz 2b \n"
39 "3: dec %0 \n"
40
41 : /* we don't need output */
42 :"a" (loops)
43 );
44}
45
46static void delay_tsc(unsigned long loops)
47{
48 unsigned bclock, now;
49 int cpu;
50
51 preempt_disable();
52 cpu = smp_processor_id();
53 rdtscl(bclock);
54 for (;;) {
55 rdtscl(now);
56 if ((now - bclock) >= loops)
57 break;
58
59 /* Allow RT tasks to run */
60 preempt_enable();
61 rep_nop();
62 preempt_disable();
63
64 /*
65 * It is possible that we moved to another CPU, and
66 * since TSC's are per-cpu we need to calculate
67 * that. The delay must guarantee that we wait "at
68 * least" the amount of time. Being moved to another
69 * CPU could make the wait longer but we just need to
70 * make sure we waited long enough. Rebalance the
71 * counter for this CPU.
72 */
73 if (unlikely(cpu != smp_processor_id())) {
74 loops -= (now - bclock);
75 cpu = smp_processor_id();
76 rdtscl(bclock);
77 }
78 }
79 preempt_enable();
80}
81
82static void (*delay_fn)(unsigned long) = delay_loop;
83
84void use_tsc_delay(void)
85{
86 delay_fn = delay_tsc;
87}
88
89int __devinit read_current_timer(unsigned long *timer_value)
90{
91 if (delay_fn == delay_tsc) {
92 rdtscll(*timer_value);
93 return 0;
94 }
95 return -1;
96}
97
98void __delay(unsigned long loops)
99{
100 delay_fn(loops);
101}
102EXPORT_SYMBOL(__delay);
103
104inline void __const_udelay(unsigned long xloops)
105{
106 int d0;
107 xloops *= 4;
108 __asm__("mull %%edx"
109 :"=d" (xloops), "=&a" (d0)
110 :"1" (xloops), "0"
111 (cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
112
113 __delay(++xloops);
114}
115
116EXPORT_SYMBOL(__const_udelay);
117
118void __udelay(unsigned long usecs)
119{
120 __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
121}
122EXPORT_SYMBOL(__udelay);
123
124void __ndelay(unsigned long nsecs)
125{
126 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
127}
128EXPORT_SYMBOL(__ndelay);