delay_64.c 1.2 KB

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