PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
33static int total = 0; /* total overflows */
34
35
36void
37handler( 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
48int
49main( 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;
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
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 */
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++ ) {
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);
129 }
130 }
131#else
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
141 if ( retval != PAPI_OK ) {
142 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
143 }
144
145 do_flops( num_flops );
146
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
162 mythreshold, 0, handler );
163 if ( retval != PAPI_OK ) {
164 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
165 }
166
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 */
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",
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)],
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
284 if ( retval != PAPI_OK )
285 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
286
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}
double tmp
int i
const char * names[NUM_EVENTS]
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
Empty and destroy an EventSet.
Empty and destroy an EventSet.
Convert a numeric hardware event code to a name.
returns the component index for the named component
get information about the system hardware
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.
static long long mythreshold
#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_MAX_STR_LEN
Definition: f90papi.h:77
char events[MAX_EVENTS][BUFSIZ]
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
#define OVER_FMT
static int total
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int enum_add_native_events(int *num_events, int **evtcodes, int need_interrupts, int no_software_events, int cidx)
Definition: test_utils.c:709
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
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:547
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
if(file==NULL) goto out
int quiet
Definition: rapl_overflow.c:19
char error_string[PAPI_MAX_STR_LEN]
Definition: roc_common.c:17
const char * name
Definition: rocs.c:225
int
Definition: sde_internal.h:89
long long int long long
Definition: sde_internal.h:85
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
Hardware info structure.
Definition: papi.h:774
int cpu_max_mhz
Definition: papi.h:790
int retval
Definition: zero_fork.c:53