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> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <asm/delay.h> |
Venkatesh Pallipadi | 8a9e1b0 | 2005-06-23 00:08:13 -0700 | [diff] [blame] | 15 | #include <asm/msr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #ifdef CONFIG_SMP |
| 18 | #include <asm/smp.h> |
| 19 | #endif |
| 20 | |
Venkatesh Pallipadi | 8a9e1b0 | 2005-06-23 00:08:13 -0700 | [diff] [blame] | 21 | int read_current_timer(unsigned long *timer_value) |
| 22 | { |
| 23 | rdtscll(*timer_value); |
| 24 | return 0; |
| 25 | } |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
| 39 | |
| 40 | inline void __const_udelay(unsigned long xloops) |
| 41 | { |
Ingo Molnar | 39c715b | 2005-06-21 17:14:34 -0700 | [diff] [blame] | 42 | __delay(((xloops * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32) * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void __udelay(unsigned long usecs) |
| 46 | { |
| 47 | __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */ |
| 48 | } |
| 49 | |
| 50 | void __ndelay(unsigned long nsecs) |
| 51 | { |
| 52 | __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ |
| 53 | } |