PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
21typedef 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 */
29static ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} };
30static int total_unknown = 0;
31
32static void
33handler( 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 ) {
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;
58 return;
59 }
60 }
61
62 /* Unknown entry!?! */
63
65}
66
67int
68main( 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 */
91
92 if (num_events1==0) {
93 if (!quiet) printf("Trouble adding events\n");
94 test_skip(__FILE__,__LINE__,"Adding events",0);
95 }
96
98 if ( retval != PAPI_OK )
99 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
100
102
104 if ( retval != PAPI_OK )
105 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
106
108 if ( retval != PAPI_OK )
109 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
111 if ( retval != PAPI_OK )
112 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
113
115 if ( retval != PAPI_OK )
116 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
117
119
121 if ( retval != PAPI_OK )
122 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
123
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;
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
176 if ( retval != PAPI_OK ) {
177 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
178 }
179
180 test_pass( __FILE__ );
181
182 return 0;
183}
int i
static long count
Empty and destroy an 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.
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
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
#define OVER_FMT
static void handler(int EventSet, void *address, long long overflow_vector, void *context)
#define INDEX_FMT
static int total_unknown
static ocount_t overflow_counts[3]
#define OUT_FMT
Return codes and api definitions.
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:671
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 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 mask1
Definition: zero_fork.c:48
int retval
Definition: zero_fork.c:53