rdtsc_timer.c File Reference

RDTSC timer. More...

#include <assert.h>
#include <gpxe/timer.h>
#include <gpxe/timer2.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static void rdtsc_udelay (unsigned long usecs)
 Delay for a fixed number of microseconds.
static unsigned long rdtsc_ticks_per_sec (void)
 Get number of ticks per second.
 PROVIDE_TIMER (rdtsc, udelay, rdtsc_udelay)
 PROVIDE_TIMER_INLINE (rdtsc, currticks)
 PROVIDE_TIMER (rdtsc, ticks_per_sec, rdtsc_ticks_per_sec)

Variables

static unsigned long rdtsc_ticks_per_usec
 Number of TSC ticks per microsecond.


Detailed Description

RDTSC timer.

Definition in file rdtsc_timer.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

static void rdtsc_udelay ( unsigned long  usecs  )  [static]

Delay for a fixed number of microseconds.

Parameters:
usecs Number of microseconds for which to delay

Definition at line 43 of file rdtsc_timer.c.

References currticks(), DBG, rdtsc_ticks_per_usec, timer2_udelay(), and TSC_SHIFT.

00043                                                  {
00044         unsigned long start;
00045         unsigned long elapsed;
00046 
00047         /* Sanity guard, since we may divide by this */
00048         if ( ! usecs )
00049                 usecs = 1;
00050 
00051         start = currticks();
00052         if ( rdtsc_ticks_per_usec ) {
00053                 /* Already calibrated; busy-wait until done */
00054                 do {
00055                         elapsed = ( currticks() - start );
00056                 } while ( elapsed < ( usecs * rdtsc_ticks_per_usec ) );
00057         } else {
00058                 /* Not yet calibrated; use timer2 and calibrate
00059                  * based on result.
00060                  */
00061                 timer2_udelay ( usecs );
00062                 elapsed = ( currticks() - start );
00063                 rdtsc_ticks_per_usec = ( elapsed / usecs );
00064                 DBG ( "RDTSC timer calibrated: %ld ticks in %ld usecs "
00065                       "(%ld MHz)\n", elapsed, usecs,
00066                       ( rdtsc_ticks_per_usec << TSC_SHIFT ) );
00067         }
00068 }

static unsigned long rdtsc_ticks_per_sec ( void   )  [static]

Get number of ticks per second.

Return values:
ticks_per_sec Number of ticks per second

Definition at line 75 of file rdtsc_timer.c.

References assert, rdtsc_ticks_per_usec, and udelay().

00075                                                   {
00076 
00077         /* Calibrate timer, if not already done */
00078         if ( ! rdtsc_ticks_per_usec )
00079                 udelay ( 1 );
00080 
00081         /* Sanity check */
00082         assert ( rdtsc_ticks_per_usec != 0 );
00083 
00084         return ( rdtsc_ticks_per_usec * 1000 * 1000 );
00085 }

PROVIDE_TIMER ( rdtsc  ,
udelay  ,
rdtsc_udelay   
)

PROVIDE_TIMER_INLINE ( rdtsc  ,
currticks   
)

PROVIDE_TIMER ( rdtsc  ,
ticks_per_sec  ,
rdtsc_ticks_per_sec   
)


Variable Documentation

unsigned long rdtsc_ticks_per_usec [static]

Number of TSC ticks per microsecond.

This is calibrated on the first use of the timer.

Definition at line 36 of file rdtsc_timer.c.

Referenced by rdtsc_ticks_per_sec(), and rdtsc_udelay().


Generated on Tue Apr 6 20:01:11 2010 for gPXE by  doxygen 1.5.7.1