blob: 0ebbfb9e7c7f8d2b86abeb23f07b0cfbf0ebe56f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Andi Kleen2ee60e172006-06-26 13:59:44 +020011#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/sched.h>
13#include <linux/delay.h>
14#include <asm/delay.h>
Venkatesh Pallipadi8a9e1b02005-06-23 00:08:13 -070015#include <asm/msr.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#ifdef CONFIG_SMP
18#include <asm/smp.h>
19#endif
20
Venkatesh Pallipadi8a9e1b02005-06-23 00:08:13 -070021int read_current_timer(unsigned long *timer_value)
22{
23 rdtscll(*timer_value);
24 return 0;
25}
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027void __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}
Andi Kleen2ee60e172006-06-26 13:59:44 +020039EXPORT_SYMBOL(__delay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41inline void __const_udelay(unsigned long xloops)
42{
Mike Travis92cb7612007-10-19 20:35:04 +020043 __delay(((xloops * HZ *
44 cpu_data(raw_smp_processor_id()).loops_per_jiffy) >> 32) + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
Andi Kleen2ee60e172006-06-26 13:59:44 +020046EXPORT_SYMBOL(__const_udelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48void __udelay(unsigned long usecs)
49{
Paolo 'Blaisorblade' Giarrussob9a8d942006-12-07 02:14:07 +010050 __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
Andi Kleen2ee60e172006-06-26 13:59:44 +020052EXPORT_SYMBOL(__udelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54void __ndelay(unsigned long nsecs)
55{
56 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
57}
Andi Kleen2ee60e172006-06-26 13:59:44 +020058EXPORT_SYMBOL(__ndelay);