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