PAPI 7.1.0.0
Loading...
Searching...
No Matches
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

◆ MY_NUM_TESTS

#define MY_NUM_TESTS   5

Definition at line 48 of file overflow_force_software.c.

◆ OUT_FMT

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

Definition at line 45 of file overflow_force_software.c.

◆ OVER_FMT

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

Definition at line 44 of file overflow_force_software.c.

◆ SOFT_TOLERANCE

#define SOFT_TOLERANCE   0.90

Definition at line 47 of file overflow_force_software.c.

Function Documentation

◆ handler()

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
64}
static int EventSet
Definition: init_fini.c:8
int TESTS_QUIET
Definition: test_utils.c:18
#define OVER_FMT
static int total[MY_NUM_TESTS]
static int use_total
FILE * stderr
Here is the caller graph for this function:

◆ main()

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;
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 */
89 if ( info.count == 1 ||
90 !strcmp( info.derived, "DERIVED_CMPD" ) )
92 }
93 }
94 if ( PAPI_event == 0 ) {
97 if ( info.count == 1 ||
98 !strcmp( info.derived, "DERIVED_CMPD" ) )
100 }
101 }
102 if ( PAPI_event == 0 ) {
105 if ( info.count == 1 ||
106 !strcmp( info.derived, "DERIVED_CMPD" ) )
108 }
109 }
110
111 if ( PAPI_event == 0 )
112 test_skip( __FILE__, __LINE__, "No suitable event for this test found!",
113 0 );
114
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
126#endif
127
129 if ( retval != PAPI_OK )
130 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
131
133 if ( retval != PAPI_OK )
134 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
135
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
146 if ( retval != PAPI_OK )
147 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
148
149 do_stuff( );
150
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
159 if ( retval != PAPI_OK )
160 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
161
163 if ( retval != PAPI_OK )
164 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
165
166 do_stuff( );
167
169 if ( retval != PAPI_OK )
170 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
171 use_total++;
172
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 =
182 if ( retval != PAPI_OK )
183 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
184
186 if ( retval != PAPI_OK )
187 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
188
189 do_stuff( );
190
192 if ( retval != PAPI_OK )
193 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
194 use_total++;
195
196 retval =
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 =
214 if ( retval != PAPI_OK )
215 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
216
218 if ( retval != PAPI_OK )
219 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
220
221 do_stuff( );
222
224 if ( retval != PAPI_OK )
225 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
226 use_total++;
227
228 retval =
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 =
245 if ( retval != PAPI_OK )
246 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
247
249 if ( retval != PAPI_OK )
250 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
251
252 do_stuff( );
253
255 if ( retval != PAPI_OK )
256 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
257 use_total++;
258
259 retval =
261 handler );
262 if ( retval != PAPI_OK )
263 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
264
265 if ( !TESTS_QUIET ) {
266 if ( ( retval =
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 occurring 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}
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a numeric hardware event code to a name.
Get the event's name and description info.
get information about the system hardware
Get PAPI library or event set options.
initialize the PAPI library.
Set up an event set to begin registering overflows.
Query if PAPI event exists.
Set PAPI library or event set options.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static long long mythreshold
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
void do_stuff(void)
Definition: do_loops.c:256
#define OVR_TOLERANCE
Definition: do_loops.h:14
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_OVERFLOW_FORCE_SW
Definition: f90papi.h:131
#define PAPI_FP_INS
Definition: f90papi.h:366
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_FP_OPS
Definition: f90papi.h:319
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_COMPONENTINFO
Definition: f90papi.h:75
#define PAPI_DEF_ITIMER
Definition: papi.h:462
static long long values[MY_NUM_TESTS]
#define SOFT_TOLERANCE
void handler(int EventSet, void *address, long long overflow_vector, void *context)
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int
Definition: sde_internal.h:89
long long int long long
Definition: sde_internal.h:85
unsigned int count
Definition: papi.h:981
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:989
Hardware info structure.
Definition: papi.h:774
int cpu_max_mhz
Definition: papi.h:790
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
PAPI_itimer_option_t itimer
Definition: papi.h:854
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

Variable Documentation

◆ total

int total[MY_NUM_TESTS] = { 0, }
static

Definition at line 50 of file overflow_force_software.c.

◆ use_total

int use_total = 0
static

Definition at line 51 of file overflow_force_software.c.

◆ values

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

Definition at line 52 of file overflow_force_software.c.