Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / arch / x86_64 / lib / delay.c
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 <lwk/smp.h>
12 #include <lwk/cpuinfo.h>
13 #include <lwk/delay.h>
14 #include <arch/msr.h>
15 #include <arch/processor.h>
16 #include <arch/smp.h>
17
18 void __delay(unsigned long cycles)
19 {
20         unsigned bclock, now;
21         
22         rdtscl(bclock);
23         do
24         {
25                 rep_nop(); 
26                 rdtscl(now);
27         }
28         while((now-bclock) < cycles);
29 }
30
31 inline void __const_udelay(unsigned long xsecs)
32 {
33         __delay(
34           (xsecs * cpu_info[this_cpu].arch.tsc_khz * 1000)  /* cycles * 2**32 */
35           >> 32                                             /* div by 2**32 */
36         );
37 }
38
39 void __udelay(unsigned long usecs)
40 {
41         __const_udelay(usecs * 0x000010c6);  /* 2**32 / 1000000 */
42 }
43
44 void __ndelay(unsigned long nsecs)
45 {
46         __const_udelay(nsecs * 0x00005);  /* 2**32 / 1000000000 (rounded up) */
47 }
48