overflow_single_event.c File Reference

Include dependency graph for overflow_single_event.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%16lld\n"

Functions

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

Variables

static int total = 0

Define Documentation

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

Definition at line 28 of file overflow_single_event.c.

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

Definition at line 27 of file overflow_single_event.c.


Function Documentation

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

Definition at line 33 of file overflow_single_event.c.

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

int main ( int  argc,
char **  argv 
)

Definition at line 45 of file overflow_single_event.c.

00046 {
00047     int EventSet = PAPI_NULL;
00048     long long values[2] = { 0, 0 };
00049     long long min, max;
00050     int num_flops = NUM_FLOPS, retval;
00051     int PAPI_event = 0, 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 ( ( !strncmp( hw_info->model_string, "UltraSPARC", 10 ) &&
00066            !( strncmp( hw_info->vendor_string, "SUN", 3 ) ) ) ||
00067          ( !strncmp( hw_info->model_string, "AMD K7", 6 ) ) ||
00068          ( !strncmp( hw_info->vendor_string, "Cray", 4 ) ) ||
00069          ( strstr( hw_info->model_string, "POWER3" ) ) ) {
00070         /* query and set up the right instruction to monitor */
00071         if ( PAPI_query_event( PAPI_TOT_INS ) == PAPI_OK ) {
00072             PAPI_event = PAPI_TOT_INS;
00073         } else {
00074             test_fail( __FILE__, __LINE__,
00075                        "PAPI_TOT_INS not available on this Sun platform!", 0 );
00076         }
00077     } else {
00078         /* query and set up the right instruction to monitor */
00079         PAPI_event = find_nonderived_event( );
00080     }
00081 
00082     if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS ))
00083         mythreshold = THRESHOLD;
00084     else
00085 #if defined(linux)
00086         mythreshold = ( int ) hw_info->cpu_max_mhz * 20000;
00087 #else
00088         mythreshold = THRESHOLD * 2;
00089 #endif
00090 
00091     retval = PAPI_create_eventset( &EventSet );
00092     if ( retval != PAPI_OK )
00093         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00094 
00095     retval = PAPI_add_event( EventSet, PAPI_event );
00096     if ( retval != PAPI_OK )
00097         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00098 
00099     retval = PAPI_start( EventSet );
00100     if ( retval != PAPI_OK )
00101         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00102 
00103     do_flops( NUM_FLOPS );
00104 
00105     retval = PAPI_stop( EventSet, &values[0] );
00106     if ( retval != PAPI_OK )
00107         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00108 
00109     retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler );
00110     if ( retval != PAPI_OK )
00111         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00112 
00113     retval = PAPI_start( EventSet );
00114     if ( retval != PAPI_OK )
00115         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00116 
00117     do_flops( NUM_FLOPS );
00118 
00119     retval = PAPI_stop( EventSet, &values[1] );
00120     if ( retval != PAPI_OK )
00121         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00122 
00123 #if defined(linux) || defined(__ia64__) || defined(_POWER4)
00124     num_flops *= 2;
00125 #endif
00126 
00127     if ( !TESTS_QUIET ) {
00128         if ( ( retval =
00129                PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK )
00130             test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00131 
00132         printf
00133             ( "Test case: Overflow dispatch of 1st event in set with 1 event.\n" );
00134         printf
00135             ( "--------------------------------------------------------------\n" );
00136         printf( "Threshold for overflow is: %d\n", mythreshold );
00137         printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
00138         printf( "-----------------------------------------------\n" );
00139 
00140         printf( "Test type    : %16d%16d\n", 1, 2 );
00141         printf( OUT_FMT, event_name, values[0], values[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     printf("Column 1 approximately equals column 2\n");
00150 */
00151         printf( "Row 3 approximately equals %u +- %u %%\n",
00152                 ( unsigned ) ( ( values[0] ) / ( long long ) mythreshold ),
00153                 ( unsigned ) ( OVR_TOLERANCE * 100.0 ) );
00154 
00155     }
00156 
00157 /*
00158   min = (long long)(values[0]*(1.0-TOLERANCE));
00159   max = (long long)(values[0]*(1.0+TOLERANCE));
00160   if ( values[1] > max || values[1] < min )
00161     test_fail(__FILE__, __LINE__, event_name, 1);
00162 */
00163 
00164     min =
00165         ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) /
00166                         ( double ) mythreshold );
00167     max =
00168         ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) /
00169                         ( double ) mythreshold );
00170     if ( total > max || total < min )
00171         test_fail( __FILE__, __LINE__, "Overflows", 1 );
00172 
00173     test_pass( __FILE__, NULL, 0 );
00174     exit( 1 );
00175 }

Here is the call graph for this function:


Variable Documentation

int total = 0 [static]

Definition at line 30 of file overflow_single_event.c.


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1