You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rdtsc_timer.h 763B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef _IPXE_RDTSC_TIMER_H
  2. #define _IPXE_RDTSC_TIMER_H
  3. /** @file
  4. *
  5. * RDTSC timer
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #ifdef TIMER_RDTSC
  10. #define TIMER_PREFIX_rdtsc
  11. #else
  12. #define TIMER_PREFIX_rdtsc __rdtsc_
  13. #endif
  14. /**
  15. * RDTSC values can easily overflow an unsigned long. We discard the
  16. * low-order bits in order to obtain sensibly-scaled values.
  17. */
  18. #define TSC_SHIFT 8
  19. /**
  20. * Get current system time in ticks
  21. *
  22. * @ret ticks Current time, in ticks
  23. */
  24. static inline __always_inline unsigned long
  25. TIMER_INLINE ( rdtsc, currticks ) ( void ) {
  26. unsigned long ticks;
  27. __asm__ __volatile__ ( "rdtsc\n\t"
  28. "shrdl %1, %%edx, %%eax\n\t"
  29. : "=a" ( ticks ) : "i" ( TSC_SHIFT ) : "edx" );
  30. return ticks;
  31. }
  32. #endif /* _IPXE_RDTSC_TIMER_H */