Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
2ee60e17 | 11 | #include <linux/module.h> |
1da177e4 LT |
12 | #include <linux/sched.h> |
13 | #include <linux/delay.h> | |
14 | #include <asm/delay.h> | |
8a9e1b0f | 15 | #include <asm/msr.h> |
1da177e4 LT |
16 | |
17 | #ifdef CONFIG_SMP | |
18 | #include <asm/smp.h> | |
19 | #endif | |
20 | ||
8a9e1b0f VP |
21 | int read_current_timer(unsigned long *timer_value) |
22 | { | |
23 | rdtscll(*timer_value); | |
24 | return 0; | |
25 | } | |
26 | ||
1da177e4 LT |
27 | void __delay(unsigned long loops) |
28 | { | |
29 | unsigned bclock, now; | |
30 | ||
31 | rdtscl(bclock); | |
32 | do | |
33 | { | |
34 | rep_nop(); | |
35 | rdtscl(now); | |
36 | } | |
37 | while((now-bclock) < loops); | |
38 | } | |
2ee60e17 | 39 | EXPORT_SYMBOL(__delay); |
1da177e4 LT |
40 | |
41 | inline void __const_udelay(unsigned long xloops) | |
42 | { | |
92cb7612 MT |
43 | __delay(((xloops * HZ * |
44 | cpu_data(raw_smp_processor_id()).loops_per_jiffy) >> 32) + 1); | |
1da177e4 | 45 | } |
2ee60e17 | 46 | EXPORT_SYMBOL(__const_udelay); |
1da177e4 LT |
47 | |
48 | void __udelay(unsigned long usecs) | |
49 | { | |
b9a8d94a | 50 | __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */ |
1da177e4 | 51 | } |
2ee60e17 | 52 | EXPORT_SYMBOL(__udelay); |
1da177e4 LT |
53 | |
54 | void __ndelay(unsigned long nsecs) | |
55 | { | |
56 | __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ | |
57 | } | |
2ee60e17 | 58 | EXPORT_SYMBOL(__ndelay); |