PAPI  5.3.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 * CVS: $Id$
4 * Author: min@cs.utk.edu
5 * Min Zhou
6 */
7 
8 /* This file performs the following test: overflow dispatch on 2 counters. */
9 
10 #include "papi_test.h"
11 
12 #define OVER_FMT "handler(%d) Overflow at %p! vector=0x%llx\n"
13 #define OUT_FMT "%-12s : %16lld%16lld\n"
14 #define INDEX_FMT "Overflows vector 0x%llx: \n"
15 
16 typedef struct
17 {
18  long long mask;
19  int count;
20 } ocount_t;
21 
22 /* there are three possible vectors, one counter overflows, the other
23  counter overflows, both overflow */
24 ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} };
25 int total_unknown = 0;
26 
27 void
28 handler( int EventSet, void *address, long long overflow_vector, void *context )
29 {
30  int i;
31 
32  ( void ) context;
33 
34  if ( !TESTS_QUIET ) {
35  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
36  }
37 
38  /* Look for the overflow_vector entry */
39 
40  for ( i = 0; i < 3; i++ ) {
41  if ( overflow_counts[i].mask == overflow_vector ) {
42  overflow_counts[i].count++;
43  return;
44  }
45  }
46 
47  /* Didn't find it so add it. */
48 
49  for ( i = 0; i < 3; i++ ) {
50  if ( overflow_counts[i].mask == ( long long ) 0 ) {
51  overflow_counts[i].mask = overflow_vector;
52  overflow_counts[i].count = 1;
53  return;
54  }
55  }
56 
57  /* Unknown entry!?! */
58 
59  total_unknown++;
60 }
61 
62 int
63 main( int argc, char **argv )
64 {
65  int EventSet = PAPI_NULL;
66  long long ( values[3] )[2];
67  int retval;
68  int PAPI_event, k, i;
70  int index_array[2], number;
71  int num_events1, mask1;
72 
73  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
74 
76  if ( retval != PAPI_VER_CURRENT )
77  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
78 
79  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
80  PAPI_TOT_INS, depends on the availability of the event on the
81  platform */
82  EventSet =
83  add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 );
84 
85  retval = PAPI_start( EventSet );
86  if ( retval != PAPI_OK )
87  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
88 
90 
91  retval = PAPI_stop( EventSet, values[0] );
92  if ( retval != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
94 
95  retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler );
96  if ( retval != PAPI_OK )
97  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
98  retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, THRESHOLD, 0, handler );
99  if ( retval != PAPI_OK )
100  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
101 
102  retval = PAPI_start( EventSet );
103  if ( retval != PAPI_OK )
104  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
105 
106  do_flops( NUM_FLOPS );
107 
108  retval = PAPI_stop( EventSet, values[1] );
109  if ( retval != PAPI_OK )
110  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
111 
112  if ( ( retval =
113  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
114  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
115 
116  printf
117  ( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
118  printf
119  ( "---------------------------------------------------------------\n" );
120  printf( "Threshold for overflow is: %d\n", THRESHOLD );
121  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
122  printf( "-----------------------------------------------\n" );
123 
124  printf( "Test type : %16d%16d\n", 1, 2 );
125  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
126  printf( OUT_FMT, event_name, ( values[0] )[1], ( values[1] )[1] );
127 
128  if ( overflow_counts[0].count == 0 && overflow_counts[1].count == 0 )
129  test_fail( __FILE__, __LINE__, "one counter had no overflows", 1 );
130 
131  for ( k = 0; k < 3; k++ ) {
132  if ( overflow_counts[k].mask ) {
133  number = 2;
134  retval = PAPI_get_overflow_event_index( EventSet,
135  overflow_counts[k].mask,
136  index_array, &number );
137  if ( retval != PAPI_OK )
138  test_fail( __FILE__, __LINE__,
139  "PAPI_get_overflow_event_index", retval );
140  printf( INDEX_FMT, ( long long ) overflow_counts[k].mask );
141  printf( " counts: %d ", overflow_counts[k].count );
142  for ( i = 0; i < number; i++ )
143  printf( " Event Index %d ", index_array[i] );
144  printf( "\n" );
145  }
146  }
147  printf( "Case 2 %s Overflows: %d\n", "Unknown", total_unknown );
148  printf( "-----------------------------------------------\n" );
149 
150  if ( total_unknown > 0 )
151  test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 );
152 
153  retval = PAPI_cleanup_eventset( EventSet );
154  if ( retval != PAPI_OK )
155  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
156 
157  test_pass( __FILE__, NULL, 0 );
158  exit( 1 );
159 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define NUM_FLOPS
int mask1
Definition: zero_fork.c:41
int PAPI_event[2]
Definition: data_range.c:24
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int num_events1
Definition: zero_fork.c:42
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4655
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
#define INDEX_FMT
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
#define OUT_FMT
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
long long mask
#define PAPI_TOT_CYC
Definition: fpapi.h:194
int k
Definition: iozone.c:19136
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
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:16
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
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:6378
int EventSet
int total_unknown
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:723
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define THRESHOLD
Definition: earprofile.c:31
ocount_t overflow_counts[3]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()