FLA_Clock.c File Reference

(r)


Functions

double FLA_Clock_helper (void)
double FLA_Clock ()
double FLA_F2C() fla_clock_f (void)
void detect_clocks (void)
void rdtsc (unsigned int *high, unsigned int *low)

Variables

double gtod_ref_time_sec = 0.0

Function Documentation

void detect_clocks ( void   ) 

References rdtsc().

00202 {
00203   FILE *infile;
00204   char buffer[256], *p;
00205 #ifdef __i386__
00206   unsigned int high, low;
00207 #endif
00208 
00209   if ( clocks == 0.0 )
00210   {
00211     p = (char *)NULL;
00212     infile = fopen("/proc/cpuinfo", "r");
00213     while (fgets(buffer, sizeof(buffer), infile))
00214     {
00215       if (!strncmp("cpu MHz", buffer, 6))
00216       {
00217         p = strchr(buffer, ':') + 1;
00218         break;
00219       }
00220     }
00221     clocks = 1.e6 * atof(p);
00222 #ifdef __i386__
00223     rdtsc(&high, &low);
00224     initialclockoffset = high;
00225 #endif
00226   }
00227 }

double FLA_Clock ( void   ) 

double FLA_F2C() fla_clock_f ( void   ) 

References FLA_Clock().

00048 {
00049   return FLA_Clock();
00050 }

double FLA_Clock_helper ( void   ) 

References gtod_ref_time_sec.

Referenced by FLA_Clock().

00068 {
00069   double the_time, norm_sec;
00070   struct timeval tv;
00071 
00072   gettimeofday( &tv, NULL );
00073 
00074   // If this is the first invocation of through FLA_Clock(), then initialize
00075   // the "reference time" global variable to the seconds field of the tv
00076   // struct.
00077   if( gtod_ref_time_sec == 0.0 )
00078     gtod_ref_time_sec = ( double ) tv.tv_sec;
00079 
00080   // Normalize the seconds field of the tv struct so that it is relative to the
00081   // "reference time" that was recorded during the first invocation of
00082   // FLA_Clock().
00083   norm_sec = ( double ) tv.tv_sec - gtod_ref_time_sec;
00084 
00085   // Compute the number of seconds since the reference time.
00086   the_time = norm_sec + tv.tv_usec * 1.0e-6;
00087 
00088   return the_time;
00089 }

void rdtsc ( unsigned int *  high,
unsigned int *  low 
) [inline]

Referenced by detect_clocks().

00141 {
00142   asm("rdtsc" : "=a" (*low), "=d"(*high): : "cc");
00143 }


Variable Documentation

double gtod_ref_time_sec = 0.0

Referenced by FLA_Clock_helper().


Generated on Mon Jul 6 05:45:53 2009 for libflame by  doxygen 1.5.9