overflow_force_software.c File Reference

Include dependency graph for overflow_force_software.c:

Go to the source code of this file.

Defines

#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, }

Define 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.

00049 {
00050     ( void ) context;
00051 
00052     if ( !TESTS_QUIET ) {
00053         fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
00054     }
00055 
00056     total[use_total]++;
00057 }

int main ( int  argc,
char **  argv 
)

Definition at line 60 of file overflow_force_software.c.

00061 {
00062     int EventSet = PAPI_NULL;
00063     long long hard_min, hard_max, soft_min, soft_max;
00064     int retval;
00065     int PAPI_event = 0, mythreshold;
00066     char event_name[PAPI_MAX_STR_LEN];
00067     PAPI_option_t opt;
00068     PAPI_event_info_t info;
00069     PAPI_option_t itimer;
00070     const PAPI_hw_info_t *hw_info = NULL;
00071 
00072     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00073 
00074     retval = PAPI_library_init( PAPI_VER_CURRENT );
00075     if ( retval != PAPI_VER_CURRENT )
00076         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00077 
00078     /* query and set up the right instruction to monitor */
00079     if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
00080         if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
00081             PAPI_get_event_info( PAPI_FP_INS, &info );
00082             if ( info.count == 1 || 
00083                              !strcmp( info.derived, "DERIVED_CMPD" ) )
00084                 PAPI_event = PAPI_FP_INS;
00085         }
00086     }
00087     if ( PAPI_event == 0 ) {
00088         if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) {
00089             PAPI_get_event_info( PAPI_FP_OPS, &info );
00090             if ( info.count == 1 || 
00091                              !strcmp( info.derived, "DERIVED_CMPD" ) )
00092                 PAPI_event = PAPI_FP_OPS;
00093         }
00094     }
00095     if ( PAPI_event == 0 ) {
00096         if ( PAPI_query_event( PAPI_TOT_INS ) == PAPI_OK ) {
00097             PAPI_get_event_info( PAPI_TOT_INS, &info );
00098             if ( info.count == 1 || 
00099                              !strcmp( info.derived, "DERIVED_CMPD" ) )
00100                 PAPI_event = PAPI_TOT_INS;
00101         }
00102     }
00103 
00104     if ( PAPI_event == 0 )
00105         test_skip( __FILE__, __LINE__, "No suitable event for this test found!",
00106                    0 );
00107 
00108     hw_info = PAPI_get_hardware_info(  );
00109     if ( hw_info == NULL )
00110         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00111 
00112     if ( PAPI_event == PAPI_FP_INS )
00113         mythreshold = THRESHOLD;
00114     else
00115 #if defined(linux)
00116         mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
00117 #else
00118         mythreshold = THRESHOLD * 2;
00119 #endif
00120 
00121     retval = PAPI_create_eventset( &EventSet );
00122     if ( retval != PAPI_OK )
00123         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00124 
00125     retval = PAPI_add_event( EventSet, PAPI_event );
00126     if ( retval != PAPI_OK )
00127         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00128 
00129     retval = PAPI_get_opt( PAPI_COMPONENTINFO, &opt );
00130     if ( retval != PAPI_OK )
00131         test_skip( __FILE__, __LINE__,
00132                    "Platform does not support Hardware overflow", 0 );
00133 
00134     do_stuff(  );
00135 
00136     /* Do reference count */
00137 
00138     retval = PAPI_start( EventSet );
00139     if ( retval != PAPI_OK )
00140         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00141 
00142     do_stuff(  );
00143 
00144     retval = PAPI_stop( EventSet, &values[use_total] );
00145     if ( retval != PAPI_OK )
00146         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00147     use_total++;
00148 
00149     /* Now do hardware overflow reference count */
00150 
00151     retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
00152     if ( retval != PAPI_OK )
00153         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00154 
00155     retval = PAPI_start( EventSet );
00156     if ( retval != PAPI_OK )
00157         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00158 
00159     do_stuff(  );
00160 
00161     retval = PAPI_stop( EventSet, &values[use_total] );
00162     if ( retval != PAPI_OK )
00163         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00164     use_total++;
00165 
00166     retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
00167     if ( retval != PAPI_OK )
00168         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00169 
00170     /* Now do software overflow reference count, uses SIGPROF */
00171 
00172     retval =
00173         PAPI_overflow( EventSet, PAPI_event, mythreshold,
00174                        PAPI_OVERFLOW_FORCE_SW, handler );
00175     if ( retval != PAPI_OK )
00176         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00177 
00178     retval = PAPI_start( EventSet );
00179     if ( retval != PAPI_OK )
00180         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00181 
00182     do_stuff(  );
00183 
00184     retval = PAPI_stop( EventSet, &values[use_total] );
00185     if ( retval != PAPI_OK )
00186         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00187     use_total++;
00188 
00189     retval =
00190         PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
00191                        handler );
00192     if ( retval != PAPI_OK )
00193         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00194 
00195     /* Now do software overflow with SIGVTALRM */
00196 
00197     memset( &itimer, 0, sizeof ( itimer ) );
00198     itimer.itimer.itimer_num = ITIMER_VIRTUAL;
00199     itimer.itimer.itimer_sig = SIGVTALRM;
00200 
00201     if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK )
00202         test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );
00203 
00204     retval =
00205         PAPI_overflow( EventSet, PAPI_event, mythreshold,
00206                        PAPI_OVERFLOW_FORCE_SW, handler );
00207     if ( retval != PAPI_OK )
00208         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00209 
00210     retval = PAPI_start( EventSet );
00211     if ( retval != PAPI_OK )
00212         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00213 
00214     do_stuff(  );
00215 
00216     retval = PAPI_stop( EventSet, &values[use_total] );
00217     if ( retval != PAPI_OK )
00218         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00219     use_total++;
00220 
00221     retval =
00222         PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
00223                        handler );
00224     if ( retval != PAPI_OK )
00225         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00226 
00227     /* Now do software overflow with SIGALRM */
00228 
00229     memset( &itimer, 0, sizeof ( itimer ) );
00230     itimer.itimer.itimer_num = ITIMER_REAL;
00231     itimer.itimer.itimer_sig = SIGALRM;
00232     if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK )
00233         test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval );
00234 
00235     retval =
00236         PAPI_overflow( EventSet, PAPI_event, mythreshold,
00237                        PAPI_OVERFLOW_FORCE_SW, handler );
00238     if ( retval != PAPI_OK )
00239         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00240 
00241     retval = PAPI_start( EventSet );
00242     if ( retval != PAPI_OK )
00243         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00244 
00245     do_stuff(  );
00246 
00247     retval = PAPI_stop( EventSet, &values[use_total] );
00248     if ( retval != PAPI_OK )
00249         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00250     use_total++;
00251 
00252     retval =
00253         PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW,
00254                        handler );
00255     if ( retval != PAPI_OK )
00256         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00257 
00258     if ( !TESTS_QUIET ) {
00259         if ( ( retval =
00260                PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
00261             test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00262 
00263         printf
00264             ( "Test case: Software overflow of various types with 1 event in set.\n" );
00265         printf
00266             ( "------------------------------------------------------------------------------\n" );
00267         printf( "Threshold for overflow is: %d\n", mythreshold );
00268         printf
00269             ( "------------------------------------------------------------------------------\n" );
00270 
00271         printf( "Test type   : %11s%13s%13s%13s%13s\n", "Reference", "Hardware",
00272                 "ITIMER_PROF", "ITIMER_VIRT", "ITIMER_REAL" );
00273         printf( "%-12s: %11lld%13lld%13lld%13lld%13lld\n", info.symbol,
00274                 values[0], values[1], values[2], values[3], values[4] );
00275         printf( "Overflows   : %11d%13d%13d%13d%13d\n", total[0], total[1],
00276                 total[2], total[3], total[4] );
00277         printf
00278             ( "------------------------------------------------------------------------------\n" );
00279 
00280         printf( "Verification:\n" );
00281 
00282         printf
00283             ( "Overflow in Column 2 greater than or equal to overflows in Columns 3, 4, 5\n" );
00284         printf( "Overflow in Columns 3, 4, 5 greater than 0\n" );
00285     }
00286 
00287     hard_min =
00288         ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) /
00289                         ( double ) mythreshold );
00290     hard_max =
00291         ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) /
00292                         ( double ) mythreshold );
00293     soft_min =
00294         ( long long ) ( ( ( double ) values[0] * ( 1.0 - SOFT_TOLERANCE ) ) /
00295                         ( double ) mythreshold );
00296     soft_max =
00297         ( long long ) ( ( ( double ) values[0] * ( 1.0 + SOFT_TOLERANCE ) ) /
00298                         ( double ) mythreshold );
00299     
00300     if ( total[1] > hard_max || total[1] < hard_min )
00301         test_fail( __FILE__, __LINE__, "Hardware Overflows outside limits", 1 );
00302 
00303     if ( total[2] > soft_max || total[3] > soft_max || total[4] > soft_max )
00304         test_fail( __FILE__, __LINE__,
00305                    "Software Overflows exceed theoretical maximum", 1 );
00306 
00307     if ( total[2] < soft_min || total[3] < soft_min || total[4] < soft_min )
00308         printf( "WARNING: Software Overflow occuring but suspiciously low\n" );
00309 
00310     if ( ( total[2] == 0 ) || ( total[3] == 0 ) || ( total[4] == 0 ) )
00311         test_fail( __FILE__, __LINE__, "Software Overflows", 1 );
00312 
00313     test_pass( __FILE__, NULL, 0 );
00314     exit( 1 );
00315 }

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.


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1