PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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.

5 {
6  int retval;
7  long long elapsed_us, elapsed_cyc;
8  const PAPI_hw_info_t *hw_info;
9 
10  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
11 
13  if ( retval != PAPI_VER_CURRENT )
14  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
15 
16  hw_info = PAPI_get_hardware_info( );
17  if ( hw_info == NULL )
18  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
19 
20  elapsed_us = PAPI_get_real_usec( );
21 
22  elapsed_cyc = PAPI_get_real_cyc( );
23 
24  printf( "Testing real time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
25  hw_info->cpu_max_mhz, hw_info->cpu_min_mhz );
26  printf( "Sleeping for 10 seconds.\n" );
27 
28  sleep( 10 );
29 
30  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
31 
32  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
33 
34  printf( "%lld us. %lld cyc.\n", elapsed_us, elapsed_cyc );
35  printf( "%f Computed MHz.\n",
36  ( float ) elapsed_cyc / ( float ) elapsed_us );
37 
38 /* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
39  On Pentium III and 4, for example, cycles is a measured value, while useconds
40  is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
41  Thus, any error in MHz is propagated to useconds.
42  Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
43  and cycles are computed from useconds. Also, MHz comes from a scan of system info,
44  Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
45  can be further impacted by errors in reported MHz.
46  Without knowing the error bars on these system values, we can't really specify
47  error ranges for our reported values, but we *DO* know that errors for at least
48  one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
49  Newer multicore Intel processors seem to have broken the relationship between the
50  clock rate reported in /proc/cpuinfo and the actual computed clock. To accomodate
51  this artifact, the test no longer fails, but merely reports results out of range.
52 */
53 
54  if ( elapsed_us < 9000000 )
55  printf( "NOTE: Elapsed real time less than 9 seconds!\n" );
56  if ( elapsed_us > 11000000 )
57  printf( "NOTE: Elapsed real time greater than 11 seconds!\n" );
58  if ( ( float ) elapsed_cyc < 9.0 * hw_info->cpu_max_mhz * 1000000.0 )
59  printf( "NOTE: Elapsed real cycles less than 9*MHz*1000000.0!\n" );
60  if ( ( float ) elapsed_cyc > 11.0 * hw_info->cpu_max_mhz * 1000000.0 )
61  printf( "NOTE: Elapsed real cycles greater than 11*MHz*1000000.0!\n" );
62 
63  test_pass( __FILE__, NULL, 0 );
64  exit( 1 );
65 }
sleep(1)
Hardware info structure.
Definition: papi.h:775
int cpu_min_mhz
Definition: papi.h:792
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
long long elapsed_cyc
Definition: zero_fork.c:43
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
int cpu_max_mhz
Definition: papi.h:791
long long PAPI_get_real_cyc(void)
Definition: papi.c:6091
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
void exit()

Here is the call graph for this function: