virttime.c File Reference

Include dependency graph for virttime.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 virttime.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_virt_usec(  );
00021     elapsed_cyc = PAPI_get_virt_cyc(  );
00022 
00023     printf( "Testing virt time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
00024             hw_info->cpu_max_mhz, hw_info->cpu_min_mhz );
00025     printf( "Sleeping for 10 seconds.\n" );
00026 
00027     sleep( 10 );
00028 
00029     elapsed_us = PAPI_get_virt_usec(  ) - elapsed_us;
00030     elapsed_cyc = PAPI_get_virt_cyc(  ) - elapsed_cyc;
00031 
00032     printf( "%lld us. %lld cyc.\n", elapsed_us, elapsed_cyc );
00033 
00034 /* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
00035    On Pentium III and 4, for example, cycles is a measured value, while useconds 
00036    is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
00037    Thus, any error in MHz is propagated to useconds.
00038    Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
00039    and cycles are computed from useconds. Also, MHz comes from a scan of system info,
00040    Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
00041    can be further impacted by errors in reported MHz.
00042    Without knowing the error bars on these system values, we can't really specify
00043    error ranges for our reported values, but we *DO* know that errors for at least
00044    one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
00045 */
00046 
00047     /* We'll accept 1.5 part per thousand error here (to allow Pentium 4 
00048        and Alpha to pass) */
00049     if ( elapsed_us > 100000 )
00050         test_fail( __FILE__, __LINE__, "Virt time greater than .1 seconds!",
00051                    PAPI_EMISC );
00052 
00053     test_pass( __FILE__, NULL, 0 );
00054     exit( 1 );
00055 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1