PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
virttime.c
Go to the documentation of this file.
1 #include "papi_test.h"
2 
3 int
4 main( int argc, char **argv )
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_virt_usec( );
21  elapsed_cyc = PAPI_get_virt_cyc( );
22 
23  printf( "Testing virt time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
24  hw_info->cpu_max_mhz, hw_info->cpu_min_mhz );
25  printf( "Sleeping for 10 seconds.\n" );
26 
27  sleep( 10 );
28 
29  elapsed_us = PAPI_get_virt_usec( ) - elapsed_us;
30  elapsed_cyc = PAPI_get_virt_cyc( ) - elapsed_cyc;
31 
32  printf( "%lld us. %lld cyc.\n", elapsed_us, elapsed_cyc );
33 
34 /* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
35  On Pentium III and 4, for example, cycles is a measured value, while useconds
36  is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
37  Thus, any error in MHz is propagated to useconds.
38  Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
39  and cycles are computed from useconds. Also, MHz comes from a scan of system info,
40  Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
41  can be further impacted by errors in reported MHz.
42  Without knowing the error bars on these system values, we can't really specify
43  error ranges for our reported values, but we *DO* know that errors for at least
44  one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
45 */
46 
47  /* We'll accept 1.5 part per thousand error here (to allow Pentium 4
48  and Alpha to pass) */
49  if ( elapsed_us > 100000 )
50  test_fail( __FILE__, __LINE__, "Virt time greater than .1 seconds!",
51  PAPI_EMISC );
52 
53  test_pass( __FILE__, NULL, 0 );
54  exit( 1 );
55 }
#define PAPI_EMISC
Definition: fpapi.h:119
sleep(1)
Hardware info structure.
Definition: papi.h:775
long long PAPI_get_virt_usec(void)
Definition: papi.c:6233
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6161
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
int cpu_max_mhz
Definition: papi.h:791
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
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
int main(int argc, char **argv)
List all appio events codes and names.
void exit()