PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow_allcounters.c
Go to the documentation of this file.
1 /*
2 * File: overflow_allcounters.c
3 * Author: Haihang You
4 * you@cs.utk.edu
5 * Mods: Vince Weaver
6 * vweaver1@eecs.utk.edu
7 * Mods: <your name here>
8 * <your email address>
9 */
10 
11 /* This file performs the following test: overflow all counters
12  to test availability of overflow of all counters
13 
14  - Start eventset 1
15  - Do flops
16  - Stop and measure eventset 1
17  - Set up overflow on eventset 1
18  - Start eventset 1
19  - Do flops
20  - Stop eventset 1
21 */
22 
23 #include "papi_test.h"
24 
25 #define OVER_FMT "handler(%d ) Overflow at %p! bit=0x%llx \n"
26 #define OUT_FMT "%-12s : %16lld%16lld\n"
27 
28 static int total = 0; /* total overflows */
29 
30 
31 void
32 handler( int EventSet, void *address, long long overflow_vector, void *context )
33 {
34 
35  ( void ) context;
36 
37  if ( !TESTS_QUIET ) {
38  printf( OVER_FMT, EventSet, address, overflow_vector );
39  }
40  total++;
41 }
42 
43 int
44 main( int argc, char **argv )
45 {
46  int EventSet = PAPI_NULL;
47  long long *values;
48  int num_flops, retval, i, j;
49  int *events, mythreshold;
50  char **names;
51  const PAPI_hw_info_t *hw_info = NULL;
52  int num_events, *ovt;
53  char name[PAPI_MAX_STR_LEN];
54  int using_perfmon = 0;
55  int using_aix = 0;
56  int cid;
57 
58  /* Set TESTS_QUIET variable */
59  tests_quiet( argc, argv );
60 
62  if ( retval != PAPI_VER_CURRENT ) {
63  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
64  }
65 
66  hw_info = PAPI_get_hardware_info( );
67  if ( hw_info == NULL ) {
68  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval );
69  }
70 
71  cid = PAPI_get_component_index("perfmon");
72  if (cid>=0) using_perfmon = 1;
73 
74  cid = PAPI_get_component_index("aix");
75  if (cid>=0) using_aix = 1;
76 
77  /* add PAPI_TOT_CYC and one of the events in */
78  /* PAPI_FP_INS, PAPI_FP_OPS PAPI_TOT_INS, */
79  /* depending on the availability of the event*/
80  /* on the platform */
81  EventSet = enum_add_native_events( &num_events, &events, 1 , 1, 0);
82 
83  if (!TESTS_QUIET) printf("Trying %d events\n",num_events);
84 
85  names = ( char ** ) calloc( ( unsigned int ) num_events,
86  sizeof ( char * ) );
87 
88  for ( i = 0; i < num_events; i++ ) {
89  if ( PAPI_event_code_to_name( events[i], name ) != PAPI_OK ) {
90  test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name", retval);
91  }
92  else {
93  names[i] = strdup( name );
94  if (!TESTS_QUIET) printf("%i: %s\n",i,names[i]);
95  }
96  }
97 
98  values = ( long long * )
99  calloc( ( unsigned int ) ( num_events * ( num_events + 1 ) ),
100  sizeof ( long long ) );
101  ovt = ( int * ) calloc( ( unsigned int ) num_events, sizeof ( int ) );
102 
103 #if defined(linux)
104  {
105  char *tmp = getenv( "THRESHOLD" );
106  if ( tmp ) {
107  mythreshold = atoi( tmp );
108  }
109  else if (hw_info->cpu_max_mhz!=0) {
110  mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
111  if (!TESTS_QUIET) printf("Using a threshold of %d (20,000 * MHz)\n",mythreshold);
112 
113  }
114  else {
115  if (!TESTS_QUIET) printf("Using default threshold of %d\n",THRESHOLD);
116  mythreshold = THRESHOLD;
117  }
118  }
119 #else
120  mythreshold = THRESHOLD;
121 #endif
122 
123  num_flops = NUM_FLOPS * 2;
124 
125  /* initial test to make sure they all work */
126  if (!TESTS_QUIET) printf("Testing that the events all work with no overflow\n");
127 
128  retval = PAPI_start( EventSet );
129  if ( retval != PAPI_OK ) {
130  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
131  }
132 
133  do_flops( num_flops );
134 
135  retval = PAPI_stop( EventSet, values );
136  if ( retval != PAPI_OK ) {
137  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
138  }
139 
140  /* done with initial test */
141 
142  /* keep adding events? */
143  for ( i = 0; i < num_events; i++ ) {
144 
145  /* Enable overflow */
146  if (!TESTS_QUIET) printf("Testing with overflow set on %s\n",
147  names[i]);
148 
149  retval = PAPI_overflow( EventSet, events[i],
150  mythreshold, 0, handler );
151  if ( retval != PAPI_OK ) {
152  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
153  }
154 
155  retval = PAPI_start( EventSet );
156  if ( retval != PAPI_OK ) {
157  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
158  }
159 
160  do_flops( num_flops );
161 
162  retval = PAPI_stop( EventSet, values + ( i + 1 ) * num_events );
163  if ( retval != PAPI_OK ) {
164  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
165  }
166 
167  /* Disable overflow */
168  retval = PAPI_overflow( EventSet, events[i], 0, 0, handler );
169  if ( retval != PAPI_OK ) {
170  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
171  }
172  ovt[i] = total;
173  total = 0;
174  }
175 
176  if ( !TESTS_QUIET ) {
177 
178  printf("\nResults in Matrix-view:\n");
179  printf( "Test Overflow on %d counters with %d events.\n",
180  num_events,num_events );
181  printf( "-----------------------------------------------\n" );
182  printf( "Threshold for overflow is: %d\n", mythreshold );
183  printf( "Using %d iterations of c += a*b\n", num_flops );
184  printf( "-----------------------------------------------\n" );
185 
186  printf( "Test type : " );
187  for ( i = 0; i < num_events + 1; i++ ) {
188  printf( "%16d", i );
189  }
190  printf( "\n" );
191  for ( j = 0; j < num_events; j++ ) {
192  printf( "%-27s : ", names[j] );
193  for ( i = 0; i < num_events + 1; i++ ) {
194  printf( "%16lld", *( values + j + num_events * i ) );
195  }
196  printf( "\n" );
197  }
198  printf( "Overflows : %16s", "" );
199  for ( i = 0; i < num_events; i++ ) {
200  printf( "%16d", ovt[i] );
201  }
202  printf( "\n" );
203  printf( "-----------------------------------------------\n" );
204  }
205 
206  /* validation */
207 
208  if ( !TESTS_QUIET ) {
209  printf("\nResults broken out for validation\n");
210  }
211 
212  if (!TESTS_QUIET) {
213 
214  for ( j = 0; j < num_events+1; j++ ) {
215  if (j==0) {
216  printf("Test results, no overflow:\n\t");
217  }
218  else {
219  printf("Overflow of event %d, %s\n\t",j-1,names[j-1]);
220  }
221  for(i=0; i < num_events; i++) {
222  if (i==j-1) {
223  printf("*%lld* ",values[(num_events*j)+i]);
224  }
225  else {
226  printf("%lld ",values[(num_events*j)+i]);
227  }
228  }
229  printf("\n");
230  if (j!=0) {
231  printf("\tOverflow should be %lld / %d = %lld\n",
232  values[(num_events*j)+(j-1)],
233  mythreshold,
234  values[(num_events*j)+(j-1)]/mythreshold);
235  printf("\tOverflow was %d\n",ovt[j-1]);
236  }
237  }
238  }
239 
240  for ( j = 0; j < num_events; j++ ) {
241  //printf("Validation: %lld / %d != %d (%lld)\n",
242  // *( values + j + num_events * (j+1) ) ,
243  // mythreshold,
244  // ovt[j],
245  // *(values+j+num_events*(j+1))/mythreshold);
246  if ( *( values + j + num_events * ( j + 1 ) ) / mythreshold != ovt[j] ) {
247  char error_string[BUFSIZ];
248 
249  if ( using_perfmon )
250  test_warn( __FILE__, __LINE__,
251  "perfmon component handles overflow differently than perf_events",
252  1 );
253  else if ( using_aix )
254  test_warn( __FILE__, __LINE__,
255  "AIX (pmapi) component handles overflow differently than various other components",
256  1 );
257  else {
258  sprintf( error_string,
259  "Overflow value differs from expected %lld / %d != %d (%lld)",
260  *( values + j + num_events * ( j + 1 ) ), mythreshold,
261  ovt[j],
262  *( values + j +
263  num_events * ( j + 1 ) ) / mythreshold );
264  test_fail( __FILE__, __LINE__, error_string, 1 );
265  }
266  }
267  }
268 
269  retval = PAPI_cleanup_eventset( EventSet );
270  if ( retval != PAPI_OK )
271  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
272 
273  retval = PAPI_destroy_eventset( &EventSet );
274  if ( retval != PAPI_OK )
275  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
276 
277  free( ovt );
278  for ( i = 0; i < num_events; i++ )
279  free( names[i] );
280  free( names );
281  free( events );
282  free( values );
283  test_pass( __FILE__, NULL, 0 );
284  exit( 1 );
285 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define NUM_FLOPS
char * getenv()
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define OVER_FMT
int num_events
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4655
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
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:495
int i
Definition: fileop.c:140
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
free(dummyfile[xx])
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long
Definition: iozone.c:19827
int PAPI_get_component_index(char *name)
Definition: papi.c:6469
char events[MAX_EVENTS][BUFSIZ]
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
int enum_add_native_events(int *num_events, int **evtcodes, int need_interrupts, int no_software_events, int cidx)
Definition: test_utils.c:761
void do_flops(int n)
Definition: multiplex.c:23
int EventSet
char * name
Definition: iozone.c:23648
static int total
Definition: rapl_overflow.c:5
int cpu_max_mhz
Definition: papi.h:791
int
Definition: iozone.c:18528
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
long long mythreshold
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define THRESHOLD
Definition: earprofile.c:31
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
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
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.
const char * names[NUM_EVENTS]
void exit()
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")