delay_64.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include <linux/module.h>
  11. #include <linux/sched.h>
  12. #include <linux/timex.h>
  13. #include <linux/preempt.h>
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <asm/delay.h>
  17. #include <asm/msr.h>
  18. #ifdef CONFIG_SMP
  19. #include <asm/smp.h>
  20. #endif
  21. int __devinit read_current_timer(unsigned long *timer_value)
  22. {
  23. rdtscll(*timer_value);
  24. return 0;
  25. }
  26. void __delay(unsigned long loops)
  27. {
  28. unsigned bclock, now;
  29. preempt_disable(); /* TSC's are pre-cpu */
  30. rdtscl(bclock);
  31. do {
  32. rep_nop();
  33. rdtscl(now);
  34. }
  35. while ((now-bclock) < loops);
  36. preempt_enable();
  37. }
  38. EXPORT_SYMBOL(__delay);
  39. inline void __const_udelay(unsigned long xloops)
  40. {
  41. __delay(((xloops * HZ *
  42. cpu_data(raw_smp_processor_id()).loops_per_jiffy) >> 32) + 1);
  43. }
  44. EXPORT_SYMBOL(__const_udelay);
  45. void __udelay(unsigned long usecs)
  46. {
  47. __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
  48. }
  49. EXPORT_SYMBOL(__udelay);
  50. void __ndelay(unsigned long nsecs)
  51. {
  52. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  53. }
  54. EXPORT_SYMBOL(__ndelay);