/arch/x86_64/lib/delay.c

https://bitbucket.org/evzijst/gittest · C · 48 lines · 31 code · 8 blank · 9 comment · 1 complexity · 39de9276b3adf0121e318e073102a719 MD5 · raw file

  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. #ifdef CONFIG_SMP
  15. #include <asm/smp.h>
  16. #endif
  17. int x86_udelay_tsc = 0; /* Delay via TSC */
  18. void __delay(unsigned long loops)
  19. {
  20. unsigned bclock, now;
  21. rdtscl(bclock);
  22. do
  23. {
  24. rep_nop();
  25. rdtscl(now);
  26. }
  27. while((now-bclock) < loops);
  28. }
  29. inline void __const_udelay(unsigned long xloops)
  30. {
  31. __delay(((xloops * cpu_data[_smp_processor_id()].loops_per_jiffy) >> 32) * HZ);
  32. }
  33. void __udelay(unsigned long usecs)
  34. {
  35. __const_udelay(usecs * 0x000010c6); /* 2**32 / 1000000 */
  36. }
  37. void __ndelay(unsigned long nsecs)
  38. {
  39. __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
  40. }