PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow.c
Go to the documentation of this file.
1 /*
2 * File: overflow.c
3 * CVS: $Id$
4 * Author: Philip Mucci
5 * mucci@cs.utk.edu
6 * Mods: <your name here>
7 * <your email address>
8 */
9 
10 /* This file performs the following test: overflow dispatch
11 
12  The Eventset contains:
13  + PAPI_TOT_CYC
14  + PAPI_FP_INS (overflow monitor)
15 
16  - Start eventset 1
17  - Do flops
18  - Stop and measure eventset 1
19  - Set up overflow on eventset 1
20  - Start eventset 1
21  - Do flops
22  - Stop eventset 1
23 */
24 
25 #include "papi_test.h"
26 
27 #define OVER_FMT "handler(%d ) Overflow at %p! bit=%#llx \n"
28 #define OUT_FMT "%-12s : %16lld%16lld\n"
29 
30 static int total = 0; /* total overflows */
31 
32 
33 void
34 handler( int EventSet, void *address, long long overflow_vector, void *context )
35 {
36  ( void ) context;
37 
38  if ( !TESTS_QUIET ) {
39  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
40  }
41  total++;
42 }
43 
44 int
45 main( int argc, char **argv )
46 {
47  int EventSet = PAPI_NULL;
48  long long ( values[2] )[2];
49  long long min, max;
50  int num_flops = NUM_FLOPS, retval;
52  char event_name1[PAPI_MAX_STR_LEN];
53  const PAPI_hw_info_t *hw_info = NULL;
54  int num_events, mask;
55 
56  /* Set TESTS_QUIET variable */
57  tests_quiet( argc, argv );
58 
59  /* Init PAPI */
61  if ( retval != PAPI_VER_CURRENT )
62  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
63 
64  /* Get hardware info */
65  hw_info = PAPI_get_hardware_info( );
66  if ( hw_info == NULL )
67  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
68 
69  /* add PAPI_TOT_CYC and one of the events in */
70  /* PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, */
71  /* depending on the availability of the event on */
72  /* the platform */
73  EventSet =
74  add_two_nonderived_events( &num_events, &PAPI_event, &mask );
75 
76  printf("Using %#x for the overflow event\n",PAPI_event);
77 
78  if ( PAPI_event == PAPI_FP_INS ) {
79  mythreshold = THRESHOLD;
80  }
81  else {
82 #if defined(linux)
83  mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
84 #else
85  mythreshold = THRESHOLD * 2;
86 #endif
87  }
88 
89  /* Start the run calibration run */
90  retval = PAPI_start( EventSet );
91  if ( retval != PAPI_OK )
92  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
93 
95 
96  /* stop the calibration run */
97  retval = PAPI_stop( EventSet, values[0] );
98  if ( retval != PAPI_OK )
99  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
100 
101 
102  /* set up overflow handler */
103  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
104  if ( retval != PAPI_OK ) {
105  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
106  }
107 
108  /* Start overflow run */
109  retval = PAPI_start( EventSet );
110  if ( retval != PAPI_OK ) {
111  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
112  }
113 
114  do_flops( num_flops );
115 
116  /* stop overflow run */
117  retval = PAPI_stop( EventSet, values[1] );
118  if ( retval != PAPI_OK )
119  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
120  retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
121  if ( retval != PAPI_OK )
122  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
123 
124  if ( !TESTS_QUIET ) {
125  if ( ( retval =
126  PAPI_event_code_to_name( PAPI_event, event_name1 ) ) != PAPI_OK )
127  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
128 
129  printf
130  ( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" );
131  printf
132  ( "---------------------------------------------------------------\n" );
133  printf( "Threshold for overflow is: %d\n", mythreshold );
134  printf( "Using %d iterations of c += a*b\n", num_flops );
135  printf( "-----------------------------------------------\n" );
136 
137  printf( "Test type : %16d%16d\n", 1, 2 );
138  printf( OUT_FMT, event_name1, ( values[0] )[1], ( values[1] )[1] );
139  printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] );
140  printf( "Overflows : %16s%16d\n", "", total );
141  printf( "-----------------------------------------------\n" );
142  }
143 
144  retval = PAPI_cleanup_eventset( EventSet );
145  if ( retval != PAPI_OK )
146  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
147 
148  retval = PAPI_destroy_eventset( &EventSet );
149  if ( retval != PAPI_OK )
150  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
151 
152  if ( !TESTS_QUIET ) {
153  printf( "Verification:\n" );
154 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
155  num_flops *= 2;
156 #endif
157  if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) {
158  printf( "Row 1 approximately equals %d %d\n", num_flops,
159  num_flops );
160  }
161  printf( "Column 1 approximately equals column 2\n" );
162  printf( "Row 3 approximately equals %u +- %u %%\n",
163  ( unsigned ) ( ( values[0] )[1] / ( long long ) mythreshold ),
164  ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
165  }
166 /*
167  min = (long long)((values[0])[1]*(1.0-TOLERANCE));
168  max = (long long)((values[0])[1]*(1.0+TOLERANCE));
169  if ( (values[0])[1] > max || (values[0])[1] < min )
170  test_fail(__FILE__, __LINE__, event_name, 1);
171 */
172 
173  min =
174  ( long long ) ( ( ( double ) values[0][1] * ( 1.0 - OVR_TOLERANCE ) ) /
175  ( double ) mythreshold );
176  max =
177  ( long long ) ( ( ( double ) values[0][1] * ( 1.0 + OVR_TOLERANCE ) ) /
178  ( double ) mythreshold );
179  printf( "Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) \n", total,
180  max, total, min );
181  if ( total > max || total < min )
182  test_fail( __FILE__, __LINE__, "Overflows", 1 );
183 
184  test_pass( __FILE__, NULL, 0 );
185  exit( 1 );
186 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int PAPI_event[2]
Definition: data_range.c:24
off64_t max
Definition: libasync.c:331
Hardware info structure.
Definition: papi.h:777
#define PAPI_FP_OPS
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
int num_events
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4714
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
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
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
long long
Definition: iozone.c:19827
#define OUT_FMT
Definition: overflow.c:28
#define min(x, y)
Definition: darwin-common.h:4
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:2834
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
void do_flops(int n)
Definition: multiplex.c:23
#define OVER_FMT
Definition: overflow.c:27
static int total
Definition: rapl_overflow.c:5
int cpu_max_mhz
Definition: papi.h:793
int
Definition: iozone.c:18528
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:723
long long mythreshold
int PAPI_start(int EventSet)
Definition: papi.c:2053
#define THRESHOLD
Definition: earprofile.c:31
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6111
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
#define PAPI_FP_INS
#define OVR_TOLERANCE
Definition: test_utils.h:14