X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=kitten%2Farch%2Fx86_64%2Flib%2Fdelay.c;fp=kitten%2Farch%2Fx86_64%2Flib%2Fdelay.c;h=d74e060fb58f19f5f4afd180cfe937d550aadc08;hb=66a1a4c7a9edcd7d8bc207aca093d694a6e6b5b2;hp=0000000000000000000000000000000000000000;hpb=f7cf9c19ecb0a589dd45ae0d2c91814bd3c2acc2;p=palacios.git diff --git a/kitten/arch/x86_64/lib/delay.c b/kitten/arch/x86_64/lib/delay.c new file mode 100644 index 0000000..d74e060 --- /dev/null +++ b/kitten/arch/x86_64/lib/delay.c @@ -0,0 +1,48 @@ +/* + * Precise Delay Loops for x86-64 + * + * Copyright (C) 1993 Linus Torvalds + * Copyright (C) 1997 Martin Mares + * + * The __delay function must _NOT_ be inlined as its execution time + * depends wildly on alignment on many x86 processors. + */ + +#include +#include +#include +#include +#include +#include + +void __delay(unsigned long cycles) +{ + unsigned bclock, now; + + rdtscl(bclock); + do + { + rep_nop(); + rdtscl(now); + } + while((now-bclock) < cycles); +} + +inline void __const_udelay(unsigned long xsecs) +{ + __delay( + (xsecs * cpu_info[this_cpu].arch.tsc_khz * 1000) /* cycles * 2**32 */ + >> 32 /* div by 2**32 */ + ); +} + +void __udelay(unsigned long usecs) +{ + __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */ +} + +void __ndelay(unsigned long nsecs) +{ + __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */ +} +