PAPI  5.7.0.0
virttime.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 
5 #include "papi.h"
6 #include "papi_test.h"
7 
8 int
9 main( int argc, char **argv )
10 {
11  int retval;
12  long long elapsed_us, elapsed_cyc;
13  const PAPI_hw_info_t *hw_info;
14 
15  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
16 
18  if ( retval != PAPI_VER_CURRENT )
19  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
20 
22  if ( hw_info == NULL )
23  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
24 
27 
28  if (!TESTS_QUIET) {
29  printf( "Testing virt time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
31  printf( "Sleeping for 10 seconds.\n" );
32  }
33 
34  sleep( 10 );
35 
38 
39  if (!TESTS_QUIET) {
40  printf( "%lld us. %lld cyc.\n", elapsed_us, elapsed_cyc );
41  }
42 
43 /* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
44  On Pentium III and 4, for example, cycles is a measured value, while useconds
45  is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
46  Thus, any error in MHz is propagated to useconds.
47  Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
48  and cycles are computed from useconds. Also, MHz comes from a scan of system info,
49  Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
50  can be further impacted by errors in reported MHz.
51  Without knowing the error bars on these system values, we can't really specify
52  error ranges for our reported values, but we *DO* know that errors for at least
53  one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
54 */
55 
56  /* We'll accept 1.5 part per thousand error here (to allow Pentium 4
57  and Alpha to pass) */
58  if ( elapsed_us > 100000 )
59  test_fail( __FILE__, __LINE__, "Virt time greater than .1 seconds!",
60  PAPI_EMISC );
61 
62  test_pass( __FILE__ );
63 
64  return 0;
65 
66 }
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:781
long long PAPI_get_virt_usec(void)
Definition: papi.c:6372
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6300
int cpu_min_mhz
Definition: papi.h:798
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_EMISC
Definition: fpapi.h:119
long long elapsed_cyc
Definition: zero_fork.c:50
int main(int argc, char **argv)
Definition: virttime.c:9
int TESTS_QUIET
Definition: test_utils.c:18
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:797
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
long long elapsed_us
Definition: zero_fork.c:50
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28