PAPI  5.3.2.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 28 of file overflow.c.

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

Definition at line 27 of file overflow.c.

Function Documentation

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

Definition at line 34 of file overflow.c.

35 {
36  ( void ) context;
37 
38  if ( !TESTS_QUIET ) {
39  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
40  }
41  total++;
42 }
void
Definition: iozone.c:18627
int TESTS_QUIET
Definition: test_utils.c:11
int EventSet
#define OVER_FMT
Definition: overflow.c:27
static int total
Definition: rapl_overflow.c:5
int main ( int  argc,
char **  argv 
)

Definition at line 45 of file overflow.c.

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:2232
#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:775
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int num_events
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_FP_OPS
Definition: fpapi.h:237
tests_quiet(argc, argv)
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4668
#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:495
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long
Definition: iozone.c:19827
#define OUT_FMT
Definition: overflow.c:28
#define min(x, y)
Definition: darwin-common.h:4
#define PAPI_FP_INS
Definition: fpapi.h:187
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:2805
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
void do_flops(int n)
Definition: multiplex.c:23
int EventSet
static int total
Definition: rapl_overflow.c:5
int cpu_max_mhz
Definition: papi.h:791
int
Definition: iozone.c:18528
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
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:2026
#define THRESHOLD
Definition: earprofile.c:31
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
void exit()
#define OVR_TOLERANCE
Definition: test_utils.h:14

Here is the call graph for this function:

Variable Documentation

int total = 0
static

Definition at line 30 of file overflow.c.