PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero.c
Go to the documentation of this file.
1 /* This file performs the following test: start, stop and timer functionality
2 
3  - It attempts to use the following two counters. It may use less depending on
4  hardware counter resource limitations. These are counted in the default counting
5  domain and default granularity, depending on the platform. Usually this is
6  the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
7  + PAPI_FP_INS
8  + PAPI_TOT_CYC
9  - Get us.
10  - Start counters
11  - Do flops
12  - Stop and read counters
13  - Get us.
14 */
15 
16 #include "papi_test.h"
17 
18 #define MAX_CYCLE_ERROR 30
19 
20 int
21 main( int argc, char **argv )
22 {
23  int retval, num_tests = 1, tmp;
24  int EventSet1 = PAPI_NULL;
25  int PAPI_event, mask1;
26  int num_events;
27  long long **values;
28  long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
29  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
30  double cycles_error;
31 
32  /* Set TESTS_QUIET variable */
33  tests_quiet( argc, argv );
34 
35  /* Init the PAPI library */
37  if ( retval != PAPI_VER_CURRENT ) {
38  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
39  }
40 
41  /* add PAPI_TOT_CYC and one of the events in
42  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
43  depending on the availability of the event
44  on the platform */
45  EventSet1 = add_two_events( &num_events, &PAPI_event, &mask1 );
46 
47  retval = PAPI_event_code_to_name( PAPI_event, event_name );
48  if ( retval != PAPI_OK ) {
49  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
50  }
51  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
52 
53  values = allocate_test_space( num_tests, num_events );
54 
55  /* warm up the processor to pull it out of idle state */
56  do_flops( NUM_FLOPS*10 );
57 
58  /* Gather before stats */
59  elapsed_us = PAPI_get_real_usec( );
60  elapsed_cyc = PAPI_get_real_cyc( );
61  elapsed_virt_us = PAPI_get_virt_usec( );
62  elapsed_virt_cyc = PAPI_get_virt_cyc( );
63 
64  /* Start PAPI */
65  retval = PAPI_start( EventSet1 );
66  if ( retval != PAPI_OK ) {
67  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
68  }
69 
70  /* our work code */
72 
73  /* Stop PAPI */
74  retval = PAPI_stop( EventSet1, values[0] );
75  if ( retval != PAPI_OK ) {
76  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
77  }
78 
79  /* Calculate total values */
80  elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
81  elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
82  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
83  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
84 
85  remove_test_events( &EventSet1, mask1 );
86 
87  if ( !TESTS_QUIET ) {
88  printf( "Test case 0: start, stop.\n" );
89  printf( "-----------------------------------------------\n" );
90  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
91  printf( "Default domain is: %d (%s)\n", tmp,
93  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
94  printf( "Default granularity is: %d (%s)\n", tmp,
96  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
97  printf( "-------------------------------------------------------------------------\n" );
98 
99  printf( "Test type : \t 1\n" );
100 
101  sprintf( add_event_str, "%-12s : \t", event_name );
102 
103  /* cycles is first, other event second */
104  printf( TAB1, add_event_str, values[0][1] );
105 
106  /* If cycles is there, it's always the first event */
107  if ( mask1 & MASK_TOT_CYC ) {
108  printf( TAB1, "PAPI_TOT_CYC : \t", values[0][0] );
109  }
110  printf( TAB1, "Real usec : \t", elapsed_us );
111  printf( TAB1, "Real cycles : \t", elapsed_cyc );
112  printf( TAB1, "Virt usec : \t", elapsed_virt_us );
113  printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
114 
115  printf( "-------------------------------------------------------------------------\n" );
116 
117  printf( "Verification: PAPI_TOT_CYC should be roughly real_cycles\n" );
118  printf( "NOTE: Not true if dynamic frequency scaling is enabled.\n" );
119  printf( "Verification: PAPI_FP_INS should be roughly %d\n", 2*NUM_FLOPS );
120  }
121  /* Check that TOT_CYC and real_cycles roughly match */
122  cycles_error=100.0*((double)values[0][0] - (double)elapsed_cyc)/((double)elapsed_cyc);
123  if ((cycles_error > MAX_CYCLE_ERROR) || (cycles_error < -MAX_CYCLE_ERROR)) {
124  printf("PAPI_TOT_CYC Error of %.2f%%\n",cycles_error);
125  test_fail( __FILE__, __LINE__, "Cycles validation", 0 );
126  }
127  /* Check that FP_INS is reasonable */
128  if (abs(values[0][1] - (2*NUM_FLOPS)) > (2*NUM_FLOPS)) {
129  printf("%s Error of %.2f%%\n", event_name, (100.0 * (double)(values[0][1] - (2*NUM_FLOPS)))/(2*NUM_FLOPS));
130  test_fail( __FILE__, __LINE__, "FLOPS validation", 0 );
131  }
132  if (abs(values[0][1] - (2*NUM_FLOPS)) > (NUM_FLOPS/2)) {
133  printf("%s Error of %.2f%%\n", event_name, (100.0 * (double)(values[0][1] - (2*NUM_FLOPS)))/(2*NUM_FLOPS));
134  test_warn( __FILE__, __LINE__, "FLOPS validation", 0 );
135  }
136 
137  test_pass( __FILE__, values, num_tests );
138 
139  return 0;
140 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int mask1
Definition: zero_fork.c:41
int PAPI_event[2]
Definition: data_range.c:24
long long PAPI_get_virt_usec(void)
Definition: papi.c:6298
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6226
#define PAPI_NULL
Definition: papi.h:290
#define TAB1
Definition: papi_test.h:112
int num_events
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
long long elapsed_cyc
Definition: zero_fork.c:43
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
#define PAPI_DEFGRN
Definition: papi.h:432
#define MASK_TOT_CYC
Definition: papi_test.h:49
#define MAX_CYCLE_ERROR
Definition: zero.c:18
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
#define PAPI_DEFDOM
Definition: papi.h:430
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
long long PAPI_get_real_cyc(void)
Definition: papi.c:6143
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long elapsed_us
Definition: zero_fork.c:43
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
int EventSet1
Definition: zero_fork.c:40