realtime.c File Reference

Include dependency graph for realtime.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 4 of file realtime.c.

00005 {
00006     int retval;
00007     long long elapsed_us, elapsed_cyc;
00008     const PAPI_hw_info_t *hw_info;
00009 
00010     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00011 
00012     retval = PAPI_library_init( PAPI_VER_CURRENT );
00013     if ( retval != PAPI_VER_CURRENT )
00014         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00015 
00016     hw_info = PAPI_get_hardware_info(  );
00017     if ( hw_info == NULL )
00018         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00019 
00020     elapsed_us = PAPI_get_real_usec(  );
00021 
00022     elapsed_cyc = PAPI_get_real_cyc(  );
00023 
00024     printf( "Testing real time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
00025             hw_info->cpu_max_mhz, hw_info->cpu_min_mhz );
00026     printf( "Sleeping for 10 seconds.\n" );
00027 
00028     sleep( 10 );
00029 
00030     elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;
00031 
00032     elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;
00033 
00034     printf( "%lld us. %lld cyc.\n", elapsed_us, elapsed_cyc );
00035     printf( "%f Computed MHz.\n",
00036             ( float ) elapsed_cyc / ( float ) elapsed_us );
00037 
00038 /* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
00039    On Pentium III and 4, for example, cycles is a measured value, while useconds 
00040    is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
00041    Thus, any error in MHz is propagated to useconds.
00042    Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
00043    and cycles are computed from useconds. Also, MHz comes from a scan of system info,
00044    Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
00045    can be further impacted by errors in reported MHz.
00046    Without knowing the error bars on these system values, we can't really specify
00047    error ranges for our reported values, but we *DO* know that errors for at least
00048    one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
00049    Newer multicore Intel processors seem to have broken the relationship between the
00050    clock rate reported in /proc/cpuinfo and the actual computed clock. To accomodate
00051    this artifact, the test no longer fails, but merely reports results out of range.
00052 */
00053 
00054     if ( elapsed_us < 9000000 )
00055         printf( "NOTE: Elapsed real time less than 9 seconds!\n" );
00056     if ( elapsed_us > 11000000 )
00057         printf( "NOTE: Elapsed real time greater than 11 seconds!\n" );
00058     if ( ( float ) elapsed_cyc < 9.0 * hw_info->cpu_max_mhz * 1000000.0 )
00059         printf( "NOTE: Elapsed real cycles less than 9*MHz*1000000.0!\n" );
00060     if ( ( float ) elapsed_cyc > 11.0 * hw_info->cpu_max_mhz * 1000000.0 )
00061         printf( "NOTE: Elapsed real cycles greater than 11*MHz*1000000.0!\n" );
00062 
00063     test_pass( __FILE__, NULL, 0 );
00064     exit( 1 );
00065 }

Here is the call graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1