aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/lib
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
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')
-rw-r--r--arch/x86/lib/Makefile2
-rw-r--r--arch/x86/lib/delay.c (renamed from arch/x86/lib/delay_32.c)11
-rw-r--r--arch/x86/lib/delay_64.c128
3 files changed, 6 insertions, 135 deletions
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 76f60f52a885..86960a6c41c0 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -4,7 +4,7 @@
4 4
5obj-$(CONFIG_SMP) := msr-on-cpu.o 5obj-$(CONFIG_SMP) := msr-on-cpu.o
6 6
7lib-y := delay_$(BITS).o 7lib-y := delay.o
8lib-y += usercopy_$(BITS).o getuser_$(BITS).o putuser_$(BITS).o 8lib-y += usercopy_$(BITS).o getuser_$(BITS).o putuser_$(BITS).o
9lib-y += memcpy_$(BITS).o 9lib-y += memcpy_$(BITS).o
10 10
diff --git a/arch/x86/lib/delay_32.c b/arch/x86/lib/delay.c
index 0b659a320b1e..f4568605d7d5 100644
--- a/arch/x86/lib/delay_32.c
+++ b/arch/x86/lib/delay.c
@@ -29,7 +29,7 @@
29/* simple loop based delay: */ 29/* simple loop based delay: */
30static void delay_loop(unsigned long loops) 30static void delay_loop(unsigned long loops)
31{ 31{
32 __asm__ __volatile__( 32 asm volatile(
33 " test %0,%0 \n" 33 " test %0,%0 \n"
34 " jz 3f \n" 34 " jz 3f \n"
35 " jmp 1f \n" 35 " jmp 1f \n"
@@ -108,31 +108,30 @@ void __delay(unsigned long loops)
108{ 108{
109 delay_fn(loops); 109 delay_fn(loops);
110} 110}
111EXPORT_SYMBOL(__delay);
111 112
112inline void __const_udelay(unsigned long xloops) 113inline void __const_udelay(unsigned long xloops)
113{ 114{
114 int d0; 115 int d0;
115 116
116 xloops *= 4; 117 xloops *= 4;
117 __asm__("mull %%edx" 118 asm("mull %%edx"
118 :"=d" (xloops), "=&a" (d0) 119 :"=d" (xloops), "=&a" (d0)
119 :"1" (xloops), "0" 120 :"1" (xloops), "0"
120 (cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4))); 121 (cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
121 122
122 __delay(++xloops); 123 __delay(++xloops);
123} 124}
125EXPORT_SYMBOL(__const_udelay);
124 126
125void __udelay(unsigned long usecs) 127void __udelay(unsigned long usecs)
126{ 128{
127 __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */ 129 __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
128} 130}
131EXPORT_SYMBOL(__udelay);
129 132
130void __ndelay(unsigned long nsecs) 133void __ndelay(unsigned long nsecs)
131{ 134{
132 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ 135 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
133} 136}
134
135EXPORT_SYMBOL(__delay);
136EXPORT_SYMBOL(__const_udelay);
137EXPORT_SYMBOL(__udelay);
138EXPORT_SYMBOL(__ndelay); 137EXPORT_SYMBOL(__ndelay);
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);