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