Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/config.h> |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/sched.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <asm/delay.h> |
Venkatesh Pallipadi | 8a9e1b0 | 2005-06-23 00:08:13 -0700 | [diff] [blame] | 16 | #include <asm/msr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef CONFIG_SMP |
| 19 | #include <asm/smp.h> |
| 20 | #endif |
| 21 | |
Venkatesh Pallipadi | 8a9e1b0 | 2005-06-23 00:08:13 -0700 | [diff] [blame] | 22 | int read_current_timer(unsigned long *timer_value) |
| 23 | { |
| 24 | rdtscll(*timer_value); |
| 25 | return 0; |
| 26 | } |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | void __delay(unsigned long loops) |
| 29 | { |
| 30 | unsigned bclock, now; |
| 31 | |
| 32 | rdtscl(bclock); |
| 33 | do |
| 34 | { |
| 35 | rep_nop(); |
| 36 | rdtscl(now); |
| 37 | } |
| 38 | while((now-bclock) < loops); |
| 39 | } |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 40 | EXPORT_SYMBOL(__delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | inline void __const_udelay(unsigned long xloops) |
| 43 | { |
Ross Biro | 79c62cf | 2006-01-11 22:43:51 +0100 | [diff] [blame] | 44 | __delay((xloops * HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 46 | EXPORT_SYMBOL(__const_udelay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | void __udelay(unsigned long usecs) |
| 49 | { |
| 50 | __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */ |
| 51 | } |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 52 | EXPORT_SYMBOL(__udelay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | void __ndelay(unsigned long nsecs) |
| 55 | { |
| 56 | __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ |
| 57 | } |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 58 | EXPORT_SYMBOL(__ndelay); |