overflow2.c File Reference

Include dependency graph for overflow2.c:

Go to the source code of this file.

Defines

#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

int total = 0
int TESTS_QUIET

Define Documentation

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

Definition at line 28 of file overflow2.c.

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

Definition at line 27 of file overflow2.c.


Function Documentation

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

Definition at line 34 of file overflow2.c.

00035 {
00036     ( void ) context;
00037 
00038     if ( !TESTS_QUIET ) {
00039         fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector );
00040     }
00041     total++;
00042 }

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file overflow2.c.

00046 {
00047     int EventSet = PAPI_NULL;
00048     long long ( values[2] )[2];
00049     long long min, max;
00050     int num_flops, retval;
00051     int PAPI_event, mythreshold;
00052     char event_name[PAPI_MAX_STR_LEN];
00053     const PAPI_hw_info_t *hw_info = NULL;
00054 
00055     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00056 
00057     retval = PAPI_library_init( PAPI_VER_CURRENT );
00058     if ( retval != PAPI_VER_CURRENT )
00059         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00060 
00061     hw_info = PAPI_get_hardware_info(  );
00062     if ( hw_info == NULL )
00063         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00064 
00065 #if defined(POWER3) || defined(__sparc__)
00066     PAPI_event = PAPI_TOT_INS;
00067 #else
00068     /* query and set up the right instruction to monitor */
00069     PAPI_event = find_nonderived_event( );
00070 #endif
00071 
00072     if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS ))
00073         mythreshold = THRESHOLD;
00074     else
00075 #if defined(linux)
00076         mythreshold = ( int ) hw_info->cpu_max_mhz * 10000 * 2;
00077 #else
00078         mythreshold = THRESHOLD * 2;
00079 #endif
00080 
00081     retval = PAPI_create_eventset( &EventSet );
00082     if ( retval != PAPI_OK )
00083         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00084 
00085     retval = PAPI_add_event( EventSet, PAPI_event );
00086     if ( retval != PAPI_OK )
00087         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00088 
00089     retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
00090     if ( retval != PAPI_OK )
00091         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00092 
00093     retval = PAPI_start( EventSet );
00094     if ( retval != PAPI_OK )
00095         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00096 
00097     do_flops( NUM_FLOPS );
00098 
00099     retval = PAPI_stop( EventSet, values[0] );
00100     if ( retval != PAPI_OK )
00101         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00102 
00103     retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
00104     if ( retval != PAPI_OK )
00105         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00106 
00107     retval = PAPI_start( EventSet );
00108     if ( retval != PAPI_OK )
00109         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00110 
00111     do_flops( NUM_FLOPS );
00112 
00113     retval = PAPI_stop( EventSet, values[1] );
00114     if ( retval != PAPI_OK )
00115         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00116 
00117     retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler );
00118     if ( retval != PAPI_OK )
00119         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00120 
00121     num_flops = NUM_FLOPS;
00122 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
00123     num_flops *= 2;
00124 #endif
00125 
00126     if ( !TESTS_QUIET ) {
00127         if ( ( retval =
00128                PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
00129             test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00130 
00131         printf
00132             ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" );
00133         printf
00134             ( "---------------------------------------------------------------\n" );
00135         printf( "Threshold for overflow is: %d\n", mythreshold );
00136         printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
00137         printf( "-----------------------------------------------\n" );
00138 
00139         printf( "Test type    : %16d%16d\n", 1, 2 );
00140         printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] );
00141         printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] );
00142         printf( "Overflows    : %16s%16d\n", "", total );
00143         printf( "-----------------------------------------------\n" );
00144 
00145         printf( "Verification:\n" );
00146 /*
00147     if (PAPI_event == PAPI_FP_INS)
00148         printf("Row 1 approximately equals %d %d\n", num_flops, num_flops);
00149 */
00150         /* Note that the second run prints output on stdout. On some systems
00151          * this is costly. PAPI_TOT_INS or PAPI_TOT_CYC are likely to be _very_
00152          * different between the two runs.
00153          * printf("Column 1 approximately equals column 2\n"); 
00154          */
00155         printf( "Row 3 approximately equals %u +- %u %%\n",
00156                 ( unsigned ) ( ( values[0] )[0] / ( long long ) mythreshold ),
00157                 ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
00158     }
00159 /*
00160   min = (long long)((values[0])[0]*(1.0-TOLERANCE));
00161   max = (long long)((values[0])[0]*(1.0+TOLERANCE));
00162   if ( (values[1])[0] > max || (values[1])[0] < min )
00163     test_fail(__FILE__, __LINE__, event_name, 1);
00164 */
00165 
00166     min =
00167         ( long long ) ( ( ( double ) values[0][0] * ( 1.0 - OVR_TOLERANCE ) ) /
00168                         ( double ) mythreshold );
00169     max =
00170         ( long long ) ( ( ( double ) values[0][0] * ( 1.0 + OVR_TOLERANCE ) ) /
00171                         ( double ) mythreshold );
00172     if ( total > max || total < min )
00173         test_fail( __FILE__, __LINE__, "Overflows", 1 );
00174 
00175     test_pass( __FILE__, NULL, 0 );
00176     exit( 1 );
00177 }

Here is the call graph for this function:


Variable Documentation

Definition at line 11 of file test_utils.c.

int total = 0

Definition at line 30 of file overflow2.c.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1