PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
overflow.c File Reference
Include dependency graph for overflow.c:

Go to the source code of this file.

Macros

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"
 
#define OUT_FMT   "%-12s : %16lld%16lld\n"
 

Functions

void handler (int EventSet, void *address, long long overflow_vector, void *context)
 
int main (int argc, char **argv)
 

Variables

static int total = 0
 

Macro Definition Documentation

#define OUT_FMT   "%-12s : %16lld%16lld\n"

Definition at line 31 of file overflow.c.

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"

Definition at line 30 of file overflow.c.

Function Documentation

void handler ( int  EventSet,
void address,
long long  overflow_vector,
void context 
)

Definition at line 37 of file overflow.c.

38 {
39  ( void ) context;
40 
41  if ( !TESTS_QUIET ) {
42  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
43  }
44  total++;
45 }
int EventSet
void
Definition: iozone.c:18627
#define OVER_FMT
Definition: overflow.c:30
int TESTS_QUIET
Definition: test_utils.c:18
static int total
Definition: rapl_overflow.c:9
int main ( int  argc,
char **  argv 
)

Definition at line 48 of file overflow.c.

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 */
70  hw_info = PAPI_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 */
79  EventSet = add_two_nonderived_events( &num_events, &PAPI_event, &mask );
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 ) {
91  mythreshold = THRESHOLD;
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 */
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  /* 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 */
115  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
116  if ( retval != PAPI_OK ) {
117  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
118  }
119 
120  /* Start overflow run */
121  retval = PAPI_start( EventSet );
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 );
132  retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
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 
155  retval = PAPI_cleanup_eventset( EventSet );
156  if ( retval != PAPI_OK )
157  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
158 
159  retval = PAPI_destroy_eventset( &EventSet );
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 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_event[2]
Definition: data_range.c:30
off64_t max
Definition: libasync.c:331
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:780
#define PAPI_FP_OPS
#define OVR_TOLERANCE
Definition: do_loops.h:14
#define PAPI_NULL
Definition: papi.h:292
static int num_events
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
static double
Definition: fileop.c:1281
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
long long
Definition: iozone.c:19827
#define OUT_FMT
Definition: overflow.c:31
#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:20
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 do_flops(int n)
Definition: multiplex.c:23
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
static int total
Definition: rapl_overflow.c:9
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:796
int
Definition: iozone.c:18528
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:646
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
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:225
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
#define PAPI_FP_INS

Here is the call graph for this function:

Variable Documentation

int total = 0
static

Definition at line 33 of file overflow.c.