PAPI  5.6.0.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 9 of file realtime.c.

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

Here is the call graph for this function: