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

Go to the source code of this file.

Macros

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

Functions

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

Variables

static int total [MY_NUM_TESTS] = { 0, }
 
static int use_total = 0
 
static long long values [MY_NUM_TESTS] = { 0, }
 

Macro Definition Documentation

#define MY_NUM_TESTS   5

Definition at line 41 of file overflow_force_software.c.

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

Definition at line 38 of file overflow_force_software.c.

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

Definition at line 37 of file overflow_force_software.c.

#define SOFT_TOLERANCE   0.90

Definition at line 40 of file overflow_force_software.c.

Function Documentation

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

Definition at line 48 of file overflow_force_software.c.

49 {
50  ( void ) context;
51 
52  if ( !TESTS_QUIET ) {
53  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
54  }
55 
56  total[use_total]++;
57 }
static int use_total
void
Definition: iozone.c:18627
int TESTS_QUIET
Definition: test_utils.c:11
#define OVER_FMT
int EventSet
static int total
Definition: rapl_overflow.c:5
int main ( int  argc,
char **  argv 
)

Definition at line 60 of file overflow_force_software.c.

61 {
62  int EventSet = PAPI_NULL;
63  long long hard_min, hard_max, soft_min, soft_max;
64  int retval;
65  int PAPI_event = 0, mythreshold;
67  PAPI_option_t opt;
68  PAPI_event_info_t info;
69  PAPI_option_t itimer;
70  const PAPI_hw_info_t *hw_info = NULL;
71 
72  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
73 
75  if ( retval != PAPI_VER_CURRENT )
76  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
77 
78  /* query and set up the right instruction to monitor */
79  if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
80  if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
82  if ( info.count == 1 ||
83  !strcmp( info.derived, "DERIVED_CMPD" ) )
84  PAPI_event = PAPI_FP_INS;
85  }
86  }
87  if ( PAPI_event == 0 ) {
88  if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) {
90  if ( info.count == 1 ||
91  !strcmp( info.derived, "DERIVED_CMPD" ) )
92  PAPI_event = PAPI_FP_OPS;
93  }
94  }
95  if ( PAPI_event == 0 ) {
98  if ( info.count == 1 ||
99  !strcmp( info.derived, "DERIVED_CMPD" ) )
100  PAPI_event = PAPI_TOT_INS;
101  }
102  }
103 
104  if ( PAPI_event == 0 )
105  test_skip( __FILE__, __LINE__, "No suitable event for this test found!",
106  0 );
107 
108  hw_info = PAPI_get_hardware_info( );
109  if ( hw_info == NULL )
110  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
111 
112  if ( PAPI_event == PAPI_FP_INS )
114  else
115 #if defined(linux)
116  mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
117 #else
118  mythreshold = THRESHOLD * 2;
119 #endif
120 
121  retval = PAPI_create_eventset( &EventSet );
122  if ( retval != PAPI_OK )
123  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
124 
125  retval = PAPI_add_event( EventSet, PAPI_event );
126  if ( retval != PAPI_OK )
127  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
128 
129  retval = PAPI_get_opt( PAPI_COMPONENTINFO, &opt );
130  if ( retval != PAPI_OK )
131  test_skip( __FILE__, __LINE__,
132  "Platform does not support Hardware overflow", 0 );
133 
134  do_stuff( );
135 
136  /* Do reference count */
137 
138  retval = PAPI_start( EventSet );
139  if ( retval != PAPI_OK )
140  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
141 
142  do_stuff( );
143 
144  retval = PAPI_stop( EventSet, &values[use_total] );
145  if ( retval != PAPI_OK )
146  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
147  use_total++;
148 
149  /* Now do hardware overflow reference count */
150 
151  retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
152  if ( retval != PAPI_OK )
153  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
154 
155  retval = PAPI_start( EventSet );
156  if ( retval != PAPI_OK )
157  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
158 
159  do_stuff( );
160 
161  retval = PAPI_stop( EventSet, &values[use_total] );
162  if ( retval != PAPI_OK )
163  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
164  use_total++;
165 
166  retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
167  if ( retval != PAPI_OK )
168  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
169 
170  /* Now do software overflow reference count, uses SIGPROF */
171 
172  retval =
173  PAPI_overflow( EventSet, PAPI_event, mythreshold,
175  if ( retval != PAPI_OK )
176  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
177 
178  retval = PAPI_start( EventSet );
179  if ( retval != PAPI_OK )
180  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
181 
182  do_stuff( );
183 
184  retval = PAPI_stop( EventSet, &values[use_total] );
185  if ( retval != PAPI_OK )
186  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
187  use_total++;
188 
189  retval =
190  PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
191  handler );
192  if ( retval != PAPI_OK )
193  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
194 
195  /* Now do software overflow with SIGVTALRM */
196 
197  memset( &itimer, 0, sizeof ( itimer ) );
198  itimer.itimer.itimer_num = ITIMER_VIRTUAL;
199  itimer.itimer.itimer_sig = SIGVTALRM;
200 
201  if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK )
202  test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );
203 
204  retval =
205  PAPI_overflow( EventSet, PAPI_event, mythreshold,
207  if ( retval != PAPI_OK )
208  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
209 
210  retval = PAPI_start( EventSet );
211  if ( retval != PAPI_OK )
212  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
213 
214  do_stuff( );
215 
216  retval = PAPI_stop( EventSet, &values[use_total] );
217  if ( retval != PAPI_OK )
218  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
219  use_total++;
220 
221  retval =
222  PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
223  handler );
224  if ( retval != PAPI_OK )
225  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
226 
227  /* Now do software overflow with SIGALRM */
228 
229  memset( &itimer, 0, sizeof ( itimer ) );
230  itimer.itimer.itimer_num = ITIMER_REAL;
231  itimer.itimer.itimer_sig = SIGALRM;
232  if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK )
233  test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );
234 
235  retval =
236  PAPI_overflow( EventSet, PAPI_event, mythreshold,
238  if ( retval != PAPI_OK )
239  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
240 
241  retval = PAPI_start( EventSet );
242  if ( retval != PAPI_OK )
243  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
244 
245  do_stuff( );
246 
247  retval = PAPI_stop( EventSet, &values[use_total] );
248  if ( retval != PAPI_OK )
249  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
250  use_total++;
251 
252  retval =
253  PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
254  handler );
255  if ( retval != PAPI_OK )
256  test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
257 
258  if ( !TESTS_QUIET ) {
259  if ( ( retval =
260  PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
261  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
262 
263  printf
264  ( "Test case: Software overflow of various types with 1 event in set.\n" );
265  printf
266  ( "------------------------------------------------------------------------------\n" );
267  printf( "Threshold for overflow is: %d\n", mythreshold );
268  printf
269  ( "------------------------------------------------------------------------------\n" );
270 
271  printf( "Test type : %11s%13s%13s%13s%13s\n", "Reference", "Hardware",
272  "ITIMER_PROF", "ITIMER_VIRT", "ITIMER_REAL" );
273  printf( "%-12s: %11lld%13lld%13lld%13lld%13lld\n", info.symbol,
274  values[0], values[1], values[2], values[3], values[4] );
275  printf( "Overflows : %11d%13d%13d%13d%13d\n", total[0], total[1],
276  total[2], total[3], total[4] );
277  printf
278  ( "------------------------------------------------------------------------------\n" );
279 
280  printf( "Verification:\n" );
281 
282  printf
283  ( "Overflow in Column 2 greater than or equal to overflows in Columns 3, 4, 5\n" );
284  printf( "Overflow in Columns 3, 4, 5 greater than 0\n" );
285  }
286 
287  hard_min =
288  ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) /
289  ( double ) mythreshold );
290  hard_max =
291  ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) /
292  ( double ) mythreshold );
293  soft_min =
294  ( long long ) ( ( ( double ) values[0] * ( 1.0 - SOFT_TOLERANCE ) ) /
295  ( double ) mythreshold );
296  soft_max =
297  ( long long ) ( ( ( double ) values[0] * ( 1.0 + SOFT_TOLERANCE ) ) /
298  ( double ) mythreshold );
299 
300  if ( total[1] > hard_max || total[1] < hard_min )
301  test_fail( __FILE__, __LINE__, "Hardware Overflows outside limits", 1 );
302 
303  if ( total[2] > soft_max || total[3] > soft_max || total[4] > soft_max )
304  test_fail( __FILE__, __LINE__,
305  "Software Overflows exceed theoretical maximum", 1 );
306 
307  if ( total[2] < soft_min || total[3] < soft_min || total[4] < soft_min )
308  printf( "WARNING: Software Overflow occuring but suspiciously low\n" );
309 
310  if ( ( total[2] == 0 ) || ( total[3] == 0 ) || ( total[4] == 0 ) )
311  test_fail( __FILE__, __LINE__, "Software Overflows", 1 );
312 
313  test_pass( __FILE__, NULL, 0 );
314  exit( 1 );
315 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
unsigned int count
Definition: papi.h:982
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
int PAPI_event[2]
Definition: data_range.c:24
static int use_total
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_TOT_INS
Definition: fpapi.h:185
void do_stuff(void)
Definition: do_loops.c:249
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
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
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
test_pass(__FILE__, NULL, 0)
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3371
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
#define PAPI_COMPONENTINFO
Definition: fpapi.h:65
int PAPI_library_init(int version)
Definition: papi.c:495
Create a new empty PAPI EventSet.
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4041
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long
Definition: iozone.c:19827
#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
#define SOFT_TOLERANCE
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int PAPI_query_event(int EventCode)
Definition: papi.c:696
int EventSet
#define PAPI_OVERFLOW_FORCE_SW
Definition: papi.h:409
#define PAPI_DEF_ITIMER
Definition: papi.h:452
static int total
Definition: rapl_overflow.c:5
int cpu_max_mhz
Definition: papi.h:791
int
Definition: iozone.c:18528
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
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:990
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()
PAPI_itimer_option_t itimer
Definition: papi.h:855
#define OVR_TOLERANCE
Definition: test_utils.h:14

Here is the call graph for this function:

Variable Documentation

int total[MY_NUM_TESTS] = { 0, }
static

Definition at line 43 of file overflow_force_software.c.

int use_total = 0
static

Definition at line 44 of file overflow_force_software.c.

long long values[MY_NUM_TESTS] = { 0, }
static

Definition at line 45 of file overflow_force_software.c.