PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow_index.c
Go to the documentation of this file.
1 /*
2 * File: overflow_index.c
3 * Author: min@cs.utk.edu
4 * Min Zhou
5 */
6 
7 /* This file performs the following test: overflow dispatch on 2 counters. */
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 
12 #include "papi.h"
13 #include "papi_test.h"
14 
15 #include "do_loops.h"
16 
17 #define OVER_FMT "handler(%d) Overflow at %p! vector=%#llx\n"
18 #define OUT_FMT "%-12s : %16lld%16lld\n"
19 #define INDEX_FMT "Overflows vector %#llx: \n"
20 
21 typedef struct
22 {
23  long long mask;
24  int count;
25 } ocount_t;
26 
27 /* there are three possible vectors, one counter overflows, the other
28  counter overflows, both overflow */
29 static ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} };
30 static int total_unknown = 0;
31 
32 static void
33 handler( int EventSet, void *address, long long overflow_vector, void *context )
34 {
35  int i;
36 
37  ( void ) context;
38 
39  if ( !TESTS_QUIET ) {
40  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
41  }
42 
43  /* Look for the overflow_vector entry */
44 
45  for ( i = 0; i < 3; i++ ) {
46  if ( overflow_counts[i].mask == overflow_vector ) {
47  overflow_counts[i].count++;
48  return;
49  }
50  }
51 
52  /* Didn't find it so add it. */
53 
54  for ( i = 0; i < 3; i++ ) {
55  if ( overflow_counts[i].mask == ( long long ) 0 ) {
56  overflow_counts[i].mask = overflow_vector;
57  overflow_counts[i].count = 1;
58  return;
59  }
60  }
61 
62  /* Unknown entry!?! */
63 
64  total_unknown++;
65 }
66 
67 int
68 main( int argc, char **argv )
69 {
70  int EventSet = PAPI_NULL;
71  long long ( values[3] )[2];
72  int retval;
73  int PAPI_event, k, i;
75  int index_array[2], number;
76  int num_events1, mask1;
77  int quiet;
78 
79  /* Set TESTS_QUIET variable */
80  quiet = tests_quiet( argc, argv );
81 
83  if ( retval != PAPI_VER_CURRENT ) {
84  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
85  }
86 
87  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
88  PAPI_TOT_INS, depends on the availability of the event on the
89  platform */
90  EventSet = add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );
91 
92  if (num_events1==0) {
93  if (!quiet) printf("Trouble adding events\n");
94  test_skip(__FILE__,__LINE__,"Adding events",0);
95  }
96 
97  retval = PAPI_start( EventSet );
98  if ( retval != PAPI_OK )
99  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
100 
101  do_flops( NUM_FLOPS );
102 
103  retval = PAPI_stop( EventSet, values[0] );
104  if ( retval != PAPI_OK )
105  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
106 
107  retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler );
108  if ( retval != PAPI_OK )
109  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
110  retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, THRESHOLD, 0, handler );
111  if ( retval != PAPI_OK )
112  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
113 
114  retval = PAPI_start( EventSet );
115  if ( retval != PAPI_OK )
116  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
117 
118  do_flops( NUM_FLOPS );
119 
120  retval = PAPI_stop( EventSet, values[1] );
121  if ( retval != PAPI_OK )
122  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
123 
124  retval = PAPI_event_code_to_name( PAPI_event, event_name );
125  if (retval != PAPI_OK ) {
126  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
127  }
128 
129  if (!quiet) {
130  printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
131  printf( "---------------------------------------------------------------\n" );
132  printf( "Threshold for overflow is: %d\n", THRESHOLD );
133  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
134  printf( "-----------------------------------------------\n" );
135 
136  printf( "Test type : %16d%16d\n", 1, 2 );
137  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
138  printf( OUT_FMT, event_name, ( values[0] )[1], ( values[1] )[1] );
139  }
140 
141  if ( overflow_counts[0].count == 0 && overflow_counts[1].count == 0 ) {
142  test_fail( __FILE__, __LINE__,
143  "one counter had no overflows", 1 );
144  }
145 
146  for ( k = 0; k < 3; k++ ) {
147  if ( overflow_counts[k].mask ) {
148  number = 2;
149  retval = PAPI_get_overflow_event_index( EventSet,
150  overflow_counts[k].mask,
151  index_array, &number );
152  if ( retval != PAPI_OK ) {
153  test_fail( __FILE__, __LINE__,
154  "PAPI_get_overflow_event_index", retval );
155  }
156  if (!quiet) {
157  printf( INDEX_FMT, ( long long ) overflow_counts[k].mask );
158  printf( " counts: %d ", overflow_counts[k].count );
159  for ( i = 0; i < number; i++ )
160  printf( " Event Index %d ", index_array[i] );
161  printf( "\n" );
162  }
163  }
164  }
165 
166  if (!quiet) {
167  printf( "Case 2 %s Overflows: %d\n", "Unknown", total_unknown );
168  printf( "-----------------------------------------------\n" );
169  }
170 
171  if ( total_unknown > 0 ) {
172  test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );
173  }
174 
175  retval = PAPI_cleanup_eventset( EventSet );
176  if ( retval != PAPI_OK ) {
177  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
178  }
179 
180  test_pass( __FILE__ );
181 
182  return 0;
183 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
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 INDEX_FMT
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
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 ** argv
Definition: iozone.c:1610
#define OUT_FMT
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
long long mask
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
int k
Definition: iozone.c:19136
long long
Definition: iozone.c:19827
#define OVER_FMT
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
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_get_overflow_event_index(int EventSet, long long overflow_vector, int *array, int *number)
Definition: papi.c:6517
static int total_unknown
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
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:646
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define THRESHOLD
Definition: earprofile.c:37
static ocount_t overflow_counts[3]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.