delay.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/config.h>
  11. #include <linux/sched.h>
  12. #include <linux/delay.h>
  13. #include <asm/delay.h>
  14. #include <asm/msr.h>
  15. #ifdef CONFIG_SMP
  16. #include <asm/smp.h>
  17. #endif
  18. int read_current_timer(unsigned long *timer_value)
  19. {
  20. rdtscll(*timer_value);
  21. return 0;
  22. }
  23. void __delay(unsigned long loops)
  24. {
  25. unsigned bclock, now;
  26. rdtscl(bclock);
  27. do
  28. {
  29. rep_nop();
  30. rdtscl(now);
  31. }
  32. while((now-bclock) < loops);
  33. }
  34. inline void __const_udelay(unsigned long xloops)
  35. {
  36. __delay(((xloops * cpu_data[raw_smp_processor_id()].loops_per_jiffy) >> 32) * HZ);
  37. }
  38. void __udelay(unsigned long usecs)
  39. {
  40. __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
  41. }
  42. void __ndelay(unsigned long nsecs)
  43. {
  44. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  45. }