PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 9 of file virttime.c.

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 
21  hw_info = PAPI_get_hardware_info( );
22  if ( hw_info == NULL )
23  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
24 
25  elapsed_us = PAPI_get_virt_usec( );
26  elapsed_cyc = PAPI_get_virt_cyc( );
27 
28  if (!TESTS_QUIET) {
29  printf( "Testing virt time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
30  hw_info->cpu_max_mhz, hw_info->cpu_min_mhz );
31  printf( "Sleeping for 10 seconds.\n" );
32  }
33 
34  sleep( 10 );
35 
36  elapsed_us = PAPI_get_virt_usec( ) - elapsed_us;
37  elapsed_cyc = PAPI_get_virt_cyc( ) - elapsed_cyc;
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
sleep(1)
Hardware info structure.
Definition: papi.h:780
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:797
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
#define PAPI_EMISC
Definition: papi.h:267
int PAPI_library_init(int version)
Definition: papi.c:500
long long elapsed_cyc
Definition: zero_fork.c:50
printf("\tTry: -i 0 -i 1 \n\n")
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:796
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: