PAPI  5.6.0.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 48 of file overflow_force_software.c.

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

Definition at line 45 of file overflow_force_software.c.

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

Definition at line 44 of file overflow_force_software.c.

#define SOFT_TOLERANCE   0.90

Definition at line 47 of file overflow_force_software.c.

Function Documentation

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

Definition at line 55 of file overflow_force_software.c.

56 {
57  ( void ) context;
58 
59  if ( !TESTS_QUIET ) {
60  fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
61  }
62 
63  total[use_total]++;
64 }
static int use_total
int EventSet
void
Definition: iozone.c:18627
#define OVER_FMT
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 67 of file overflow_force_software.c.

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

Here is the call graph for this function:

Variable Documentation

int total[MY_NUM_TESTS] = { 0, }
static

Definition at line 50 of file overflow_force_software.c.

int use_total = 0
static

Definition at line 51 of file overflow_force_software.c.

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

Definition at line 52 of file overflow_force_software.c.