PAPI  5.7.0.0
overflow.c
Go to the documentation of this file.
1 /*
2 * File: overflow.c
3 * Author: Philip Mucci
4 * mucci@cs.utk.edu
5 */
6 
7 /* This file performs the following test: overflow dispatch
8 
9  The Eventset contains:
10  + PAPI_TOT_CYC
11  + PAPI_FP_INS (overflow monitor)
12 
13  - Start eventset 1
14  - Do flops
15  - Stop and measure eventset 1
16  - Set up overflow on eventset 1
17  - Start eventset 1
18  - Do flops
19  - Stop eventset 1
20 */
21 
22 #include <stdio.h>
23 #include <stdlib.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 
33 static int total = 0; /* total overflows */
34 
35 
36 void
37 handler( int EventSet, void *address, long long overflow_vector, void *context )
38 {
39  ( void ) context;
40 
41  if ( !TESTS_QUIET ) {
42  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
43  }
44  total++;
45 }
46 
47 int
48 main( int argc, char **argv )
49 {
50  int EventSet = PAPI_NULL;
51  long long ( values[2] )[2];
52  long long min, max;
53  int num_flops = NUM_FLOPS, retval;
55  char event_name1[PAPI_MAX_STR_LEN];
56  const PAPI_hw_info_t *hw_info = NULL;
57  int num_events, mask;
58  int quiet;
59 
60  /* Set TESTS_QUIET variable */
61  quiet = tests_quiet( argc, argv );
62 
63  /* Init PAPI */
65  if ( retval != PAPI_VER_CURRENT ) {
66  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
67  }
68 
69  /* Get hardware info */
71  if ( hw_info == NULL ) {
72  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
73  }
74 
75  /* add PAPI_TOT_CYC and one of the events in */
76  /* PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, */
77  /* depending on the availability of the event on */
78  /* the platform */
80 
81  if (num_events==0) {
82  if (!quiet) printf("Trouble adding event!\n");
83  test_skip(__FILE__,__LINE__,"Event add",1);
84  }
85 
86  if (!quiet) {
87  printf("Using %#x for the overflow event\n",PAPI_event);
88  }
89 
90  if ( PAPI_event == PAPI_FP_INS ) {
92  }
93  else {
94 #if defined(linux)
95  mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
96 #else
97  mythreshold = THRESHOLD * 2;
98 #endif
99  }
100 
101  /* Start the run calibration run */
103  if ( retval != PAPI_OK )
104  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
105 
106  do_flops( NUM_FLOPS );
107 
108  /* stop the calibration run */
109  retval = PAPI_stop( EventSet, values[0] );
110  if ( retval != PAPI_OK )
111  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
112 
113 
114  /* set up overflow handler */
116  if ( retval != PAPI_OK ) {
117  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
118  }
119 
120  /* Start overflow run */
122  if ( retval != PAPI_OK ) {
123  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
124  }
125 
126  do_flops( num_flops );
127 
128  /* stop overflow run */
129  retval = PAPI_stop( EventSet, values[1] );
130  if ( retval != PAPI_OK )
131  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
133  if ( retval != PAPI_OK )
134  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
135 
136  if ( !TESTS_QUIET ) {
137  retval = PAPI_event_code_to_name( PAPI_event, event_name1 );
138  if (retval != PAPI_OK ) {
139  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
140  }
141 
142  printf( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
143  printf( "---------------------------------------------------------------\n" );
144  printf( "Threshold for overflow is: %d\n", mythreshold );
145  printf( "Using %d iterations of c += a*b\n", num_flops );
146  printf( "-----------------------------------------------\n" );
147 
148  printf( "Test type : %16d%16d\n", 1, 2 );
149  printf( OUT_FMT, event_name1, ( values[0] )[1], ( values[1] )[1] );
150  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
151  printf( "Overflows : %16s%16d\n", "", total );
152  printf( "-----------------------------------------------\n" );
153  }
154 
156  if ( retval != PAPI_OK )
157  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
158 
160  if ( retval != PAPI_OK )
161  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
162 
163  if ( !TESTS_QUIET ) {
164  printf( "Verification:\n" );
165 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
166  num_flops *= 2;
167 #endif
168  if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) {
169  printf( "Row 1 approximately equals %d %d\n", num_flops,
170  num_flops );
171  }
172  printf( "Column 1 approximately equals column 2\n" );
173  printf( "Row 3 approximately equals %u +- %u %%\n",
174  ( unsigned ) ( ( values[0] )[1] / ( long long ) mythreshold ),
175  ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
176  }
177 /*
178  min = (long long)((values[0])[1]*(1.0-TOLERANCE));
179  max = (long long)((values[0])[1]*(1.0+TOLERANCE));
180  if ( (values[0])[1] > max || (values[0])[1] < min )
181  test_fail(__FILE__, __LINE__, event_name, 1);
182 */
183 
184  min =
185  ( long long ) ( ( ( double ) values[0][1] * ( 1.0 - OVR_TOLERANCE ) ) /
186  ( double ) mythreshold );
187  max =
188  ( long long ) ( ( ( double ) values[0][1] * ( 1.0 + OVR_TOLERANCE ) ) /
189  ( double ) mythreshold );
190  if (!quiet) {
191  printf( "Overflows: total(%d) > max(%lld) || "
192  "total(%d) < min(%lld) \n", total, max, total, min );
193  }
194  if ( total > max || total < min ) {
195  test_fail( __FILE__, __LINE__, "Overflows", 1 );
196  }
197 
198  test_pass( __FILE__ );
199  return 0;
200 
201 }
#define PAPI_OK
Definition: fpapi.h:105
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
Hardware info structure.
Definition: papi.h:781
#define OVR_TOLERANCE
Definition: do_loops.h:14
static int num_events
#define PAPI_FP_OPS
Definition: fpapi.h:238
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
int retval
Definition: zero_fork.c:53
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
static int total
Definition: overflow.c:33
#define PAPI_NULL
Definition: fpapi.h:13
#define OUT_FMT
Definition: overflow.c:31
#define min(x, y)
Definition: darwin-common.h:4
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: overflow.c:37
void do_flops(int n)
Definition: multiplex.c:23
#define OVER_FMT
Definition: overflow.c:30
int TESTS_QUIET
Definition: test_utils.c:18
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
int cpu_max_mhz
Definition: papi.h:797
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:648
static long long mythreshold
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define THRESHOLD
Definition: earprofile.c:37
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
int main(int argc, char **argv)
Definition: overflow.c:48
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
#define PAPI_FP_INS
Definition: fpapi.h:188
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43