PAPI 7.1.0.0
Loading...
Searching...
No Matches
overflow_twoevents.c
Go to the documentation of this file.
1/*
2* File: overflow_twoevents.c
3* Author: min@cs.utk.edu
4* Min Zhou
5* Mods: Philip Mucci
6* mucci@cs.utk.edu
7*/
8
9/* This file performs the following test: overflow dispatch on 2 counters. */
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "papi.h"
16#include "papi_test.h"
17
18#include "do_loops.h"
19
20#define OVER_FMT "handler(%d) Overflow at %p! vector=%#llx\n"
21#define OUT_FMT "%-12s : %18lld%18lld%18lld\n"
22#define VEC_FMT " at vector %#llx, event %-12s : %6d\n"
23
24typedef struct
25{
26 long long mask;
27 int count;
28} ocount_t;
29
30/* there are two experiments: batch and interleaf; for each experiment there
31 are three possible vectors, one counter overflows, the other
32 counter overflows, both overflow */
34 { {{0, 0}, {0, 0}, {0, 0}}, {{0, 0}, {0, 0}, {0, 0}} };
35static int total_unknown = 0;
36
37static void
38handler( int mode, void *address, long long overflow_vector, void *context )
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
69}
70
71static void
72handler_batch( int EventSet, void *address, long long overflow_vector,
73 void *context )
74{
75 ( void ) EventSet; /*unused */
76 handler( 0, address, overflow_vector, context );
77}
78
79static void
80handler_interleaf( int EventSet, void *address, long long overflow_vector,
81 void *context )
82{
83 ( void ) EventSet; /*unused */
84 handler( 1, address, overflow_vector, context );
85}
86
87
88int
89main( int argc, char **argv )
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
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
122 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
124 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
125
127 if ( retval != PAPI_OK )
128 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
129
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) */
138 if (retval != PAPI_OK ) {
139 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
140 }
141
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
152
154 if ( retval != PAPI_OK )
155 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
156
157 num_events1 = 1;
158 retval =
160 if ( retval != PAPI_OK ) {
161 printf( "PAPI_get_overflow_event_index error: %s\n",
163 }
164
165 num_events1 = 1;
166 retval =
168 if ( retval != PAPI_OK ) {
169 printf( "PAPI_get_overflow_event_index error: %s\n",
171 }
172
174 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
175
176 /* Add each event and set its overflow (interleaved) */
178 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
179 if ( ( retval =
182 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
184 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
185 if ( ( retval =
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
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 =
201 if ( retval != PAPI_OK ) {
202 printf( "PAPI_get_overflow_event_index error: %s\n",
204 }
205
206 num_events1 = 1;
208 &num_events1 );
209 if ( retval != PAPI_OK ) {
210 printf( "PAPI_get_overflow_event_index error: %s\n",
212 }
213
215 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
216
218 if (retval != PAPI_OK ) {
219 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
220 }
221
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}
284
int i
static long count
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Convert a numeric hardware event code to a name.
converts an overflow vector into an array of indexes to overflowing events
initialize the PAPI library.
Set up an event set to begin registering overflows.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Returns a string describing the PAPI error code.
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int threshold
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
#define VEC_FMT
#define OVER_FMT
static ocount_t overflow_counts[2][3]
static void handler(int mode, void *address, long long overflow_vector, void *context)
static int total_unknown
#define OUT_FMT
static void handler_interleaf(int EventSet, void *address, long long overflow_vector, void *context)
static void handler_batch(int EventSet, void *address, long long overflow_vector, void *context)
Return codes and api definitions.
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int find_nonderived_event(void)
Definition: test_utils.c:98
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
long long int long long
Definition: sde_internal.h:85
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
long long mask
int num_events1
Definition: zero_fork.c:49
int retval
Definition: zero_fork.c:53