PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow_twoevents.c File Reference
Include dependency graph for overflow_twoevents.c:

Go to the source code of this file.

Data Structures

struct  ocount_t
 

Macros

#define OVER_FMT   "handler(%d) Overflow at %p! vector=%#llx\n"
 
#define OUT_FMT   "%-12s : %18lld%18lld%18lld\n"
 
#define VEC_FMT   " at vector %#llx, event %-12s : %6d\n"
 

Functions

static void handler (int mode, void *address, long long overflow_vector, void *context)
 
static void handler_batch (int EventSet, void *address, long long overflow_vector, void *context)
 
static void handler_interleaf (int EventSet, void *address, long long overflow_vector, void *context)
 
int main (int argc, char **argv)
 

Variables

static ocount_t overflow_counts [2][3]
 
static int total_unknown = 0
 

Macro Definition Documentation

#define OUT_FMT   "%-12s : %18lld%18lld%18lld\n"

Definition at line 21 of file overflow_twoevents.c.

#define OVER_FMT   "handler(%d) Overflow at %p! vector=%#llx\n"

Definition at line 20 of file overflow_twoevents.c.

#define VEC_FMT   " at vector %#llx, event %-12s : %6d\n"

Definition at line 22 of file overflow_twoevents.c.

Function Documentation

static void handler ( int  mode,
void address,
long long  overflow_vector,
void context 
)
static

Definition at line 38 of file overflow_twoevents.c.

39 {
40  ( void ) context; /*unused */
41  int i;
42 
43  if ( !TESTS_QUIET ) {
44  fprintf( stderr, OVER_FMT, mode, address, overflow_vector );
45  }
46 
47  /* Look for the overflow_vector entry */
48 
49  for ( i = 0; i < 3; i++ ) {
50  if ( overflow_counts[mode][i].mask == overflow_vector ) {
51  overflow_counts[mode][i].count++;
52  return;
53  }
54  }
55 
56  /* Didn't find it so add it. */
57 
58  for ( i = 0; i < 3; i++ ) {
59  if ( overflow_counts[mode][i].mask == ( long long ) 0 ) {
60  overflow_counts[mode][i].mask = overflow_vector;
61  overflow_counts[mode][i].count = 1;
62  return;
63  }
64  }
65 
66  /* Unknown entry!?! */
67 
68  total_unknown++;
69 }
void
Definition: iozone.c:18627
#define OVER_FMT
int i
Definition: fileop.c:140
long long mask
static int total_unknown
int TESTS_QUIET
Definition: test_utils.c:18
static ocount_t overflow_counts[3]
static void handler_batch ( int  EventSet,
void address,
long long  overflow_vector,
void context 
)
static

Definition at line 72 of file overflow_twoevents.c.

74 {
75  ( void ) EventSet; /*unused */
76  handler( 0, address, overflow_vector, context );
77 }
int EventSet
void
Definition: iozone.c:18627
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:20

Here is the call graph for this function:

Here is the caller graph for this function:

static void handler_interleaf ( int  EventSet,
void address,
long long  overflow_vector,
void context 
)
static

Definition at line 80 of file overflow_twoevents.c.

82 {
83  ( void ) EventSet; /*unused */
84  handler( 1, address, overflow_vector, context );
85 }
int EventSet
void
Definition: iozone.c:18627
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:20

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 89 of file overflow_twoevents.c.

90 {
91  int EventSet = PAPI_NULL;
92  long long ( values[3] )[2];
93  int retval;
94  int PAPI_event, k, idx[4];
96  int num_events1;
97  int threshold = THRESHOLD;
98  int quiet;
99 
100  /* Set TESTS_QUIET variable */
101  quiet=tests_quiet( argc, argv );
102 
104  if (retval != PAPI_VER_CURRENT ) {
105  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
106  }
107 
108  retval = PAPI_create_eventset( &EventSet );
109  if (retval != PAPI_OK ) {
110  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
111  }
112 
113  /* decide which of PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS to add,
114  depending on the availability and derived status of the event on
115  this platform */
116  if ( ( PAPI_event = find_nonderived_event( ) ) == 0 ) {
117  if (!quiet) printf("No events found!\n");
118  test_skip( __FILE__, __LINE__, "no PAPI_event", 0 );
119  }
120 
121  if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
122  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
123  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
124  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
125 
126  retval = PAPI_start( EventSet );
127  if ( retval != PAPI_OK )
128  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
129 
130  do_flops( NUM_FLOPS );
131 
132  if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
133  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
134 
135  /* Set both overflows after adding both events (batch) */
136  retval = PAPI_overflow( EventSet, PAPI_event, threshold, 0,
137  handler_batch );
138  if (retval != PAPI_OK ) {
139  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
140  }
141 
142  retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0,
143  handler_batch );
144  if (retval != PAPI_OK ) {
145  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
146  }
147 
148  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
149  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
150 
151  do_flops( NUM_FLOPS );
152 
153  retval = PAPI_stop( EventSet, values[1] );
154  if ( retval != PAPI_OK )
155  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
156 
157  num_events1 = 1;
158  retval =
159  PAPI_get_overflow_event_index( EventSet, 1, &idx[0], &num_events1 );
160  if ( retval != PAPI_OK ) {
161  printf( "PAPI_get_overflow_event_index error: %s\n",
162  PAPI_strerror( retval ) );
163  }
164 
165  num_events1 = 1;
166  retval =
167  PAPI_get_overflow_event_index( EventSet, 2, &idx[1], &num_events1 );
168  if ( retval != PAPI_OK ) {
169  printf( "PAPI_get_overflow_event_index error: %s\n",
170  PAPI_strerror( retval ) );
171  }
172 
173  if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK )
174  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
175 
176  /* Add each event and set its overflow (interleaved) */
177  if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
178  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
179  if ( ( retval =
180  PAPI_overflow( EventSet, PAPI_event, threshold, 0,
181  handler_interleaf ) ) != PAPI_OK )
182  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
183  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
184  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
185  if ( ( retval =
186  PAPI_overflow( EventSet, PAPI_TOT_CYC, threshold, 0,
187  handler_interleaf ) ) != PAPI_OK )
188  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
189 
190  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
191  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
192 
193  do_flops( NUM_FLOPS );
194 
195  if ( ( retval = PAPI_stop( EventSet, values[2] ) ) != PAPI_OK )
196  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
197 
198  num_events1 = 1;
199  retval =
200  PAPI_get_overflow_event_index( EventSet, 1, &idx[2], &num_events1 );
201  if ( retval != PAPI_OK ) {
202  printf( "PAPI_get_overflow_event_index error: %s\n",
203  PAPI_strerror( retval ) );
204  }
205 
206  num_events1 = 1;
207  retval = PAPI_get_overflow_event_index( EventSet, 2, &idx[3],
208  &num_events1 );
209  if ( retval != PAPI_OK ) {
210  printf( "PAPI_get_overflow_event_index error: %s\n",
211  PAPI_strerror( retval ) );
212  }
213 
214  if ( ( retval = PAPI_cleanup_eventset( EventSet ) ) != PAPI_OK )
215  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
216 
217  retval = PAPI_event_code_to_name( PAPI_event, event_name[0] );
218  if (retval != PAPI_OK ) {
219  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
220  }
221 
222  retval = PAPI_event_code_to_name( PAPI_TOT_CYC, event_name[1] );
223  if (retval != PAPI_OK ) {
224  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
225  }
226 
227  strcpy( event_name[2], "Unknown" );
228 
229  if (!TESTS_QUIET) {
230  printf( "Test case: Overflow dispatch of both events in set with 2 events.\n" );
231  printf( "---------------------------------------------------------------\n" );
232  printf( "Threshold for overflow is: %d\n", threshold );
233  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
234  printf( "-----------------------------------------------\n" );
235 
236  printf( "Test type : %18s%18s%18s\n", "1 (no overflow)", "2 (batch)",
237  "3 (interleaf)" );
238  printf( OUT_FMT, event_name[0], ( values[0] )[0], ( values[1] )[0],
239  ( values[2] )[0] );
240  printf( OUT_FMT, event_name[1], ( values[0] )[1], ( values[1] )[1],
241  ( values[2] )[1] );
242  printf( "\n" );
243 
244  printf( "Predicted overflows at event %-12s : %6d\n", event_name[0],
245  ( int ) ( ( values[0] )[0] / threshold ) );
246  printf( "Predicted overflows at event %-12s : %6d\n", event_name[1],
247  ( int ) ( ( values[0] )[1] / threshold ) );
248 
249  printf( "\nBatch overflows (add, add, over, over):\n" );
250  for ( k = 0; k < 2; k++ ) {
251  if ( overflow_counts[0][k].mask ) {
252  printf( VEC_FMT, ( long long ) overflow_counts[0][k].mask,
253  event_name[idx[k]], overflow_counts[0][k].count );
254  }
255  }
256 
257  printf( "\nInterleaved overflows (add, over, add, over):\n" );
258  for ( k = 0; k < 2; k++ ) {
259  if ( overflow_counts[1][k].mask )
260  printf( VEC_FMT,
261  ( long long ) overflow_counts[1][k].mask,
262  event_name[idx[k + 2]],
263  overflow_counts[1][k].count );
264  }
265 
266  printf( "\nCases 2+3 Unknown overflows: %d\n", total_unknown );
267  printf( "-----------------------------------------------\n" );
268  }
269 
270  if ( overflow_counts[0][0].count == 0 || overflow_counts[0][1].count == 0 )
271  test_fail( __FILE__, __LINE__, "a batch counter had no overflows", 1 );
272 
273  if ( overflow_counts[1][0].count == 0 || overflow_counts[1][1].count == 0 )
274  test_fail( __FILE__, __LINE__,
275  "an interleaved counter had no overflows", 1 );
276 
277  if ( total_unknown > 0 )
278  test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );
279 
280  test_pass( __FILE__ );
281 
282  return 0;
283 }
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 PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#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
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
static void handler_batch(int EventSet, void *address, long long overflow_vector, void *context)
int PAPI_library_init(int version)
Definition: papi.c:500
#define VEC_FMT
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
int k
Definition: iozone.c:19136
long long
Definition: iozone.c:19827
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define OUT_FMT
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
static int threshold
strcpy(filename, default_filename)
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
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
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
static void handler_interleaf(int EventSet, void *address, long long overflow_vector, void *context)
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int find_nonderived_event(void)
Definition: test_utils.c:98
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

Here is the call graph for this function:

Variable Documentation

ocount_t overflow_counts[2][3]
static
Initial value:
=
{ {{0, 0}, {0, 0}, {0, 0}}, {{0, 0}, {0, 0}, {0, 0}} }

Definition at line 33 of file overflow_twoevents.c.

int total_unknown = 0
static

Definition at line 35 of file overflow_twoevents.c.