|
PAPI
5.0.1.0
|
00001 /* 00002 * File: overflow_index.c 00003 * CVS: $Id$ 00004 * Author: min@cs.utk.edu 00005 * Min Zhou 00006 */ 00007 00008 /* This file performs the following test: overflow dispatch on 2 counters. */ 00009 00010 #include "papi_test.h" 00011 00012 #define OVER_FMT "handler(%d) Overflow at %p! vector=0x%llx\n" 00013 #define OUT_FMT "%-12s : %16lld%16lld\n" 00014 #define INDEX_FMT "Overflows vector 0x%llx: \n" 00015 00016 typedef struct 00017 { 00018 long long mask; 00019 int count; 00020 } ocount_t; 00021 00022 /* there are three possible vectors, one counter overflows, the other 00023 counter overflows, both overflow */ 00024 ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} }; 00025 int total_unknown = 0; 00026 00027 void 00028 handler( int EventSet, void *address, long long overflow_vector, void *context ) 00029 { 00030 int i; 00031 00032 ( void ) context; 00033 00034 if ( !TESTS_QUIET ) { 00035 fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector ); 00036 } 00037 00038 /* Look for the overflow_vector entry */ 00039 00040 for ( i = 0; i < 3; i++ ) { 00041 if ( overflow_counts[i].mask == overflow_vector ) { 00042 overflow_counts[i].count++; 00043 return; 00044 } 00045 } 00046 00047 /* Didn't find it so add it. */ 00048 00049 for ( i = 0; i < 3; i++ ) { 00050 if ( overflow_counts[i].mask == ( long long ) 0 ) { 00051 overflow_counts[i].mask = overflow_vector; 00052 overflow_counts[i].count = 1; 00053 return; 00054 } 00055 } 00056 00057 /* Unknown entry!?! */ 00058 00059 total_unknown++; 00060 } 00061 00062 int 00063 main( int argc, char **argv ) 00064 { 00065 int EventSet = PAPI_NULL; 00066 long long ( values[3] )[2]; 00067 int retval; 00068 int PAPI_event, k, i; 00069 char event_name[PAPI_MAX_STR_LEN]; 00070 int index_array[2], number; 00071 int num_events1, mask1; 00072 00073 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00074 00075 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00076 if ( retval != PAPI_VER_CURRENT ) 00077 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00078 00079 /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or 00080 PAPI_TOT_INS, depends on the availability of the event on the 00081 platform */ 00082 EventSet = 00083 add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 ); 00084 00085 retval = PAPI_start( EventSet ); 00086 if ( retval != PAPI_OK ) 00087 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00088 00089 do_flops( NUM_FLOPS ); 00090 00091 retval = PAPI_stop( EventSet, values[0] ); 00092 if ( retval != PAPI_OK ) 00093 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00094 00095 retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler ); 00096 if ( retval != PAPI_OK ) 00097 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00098 retval = PAPI_overflow( EventSet, PAPI_TOT_CYC, THRESHOLD, 0, handler ); 00099 if ( retval != PAPI_OK ) 00100 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00101 00102 retval = PAPI_start( EventSet ); 00103 if ( retval != PAPI_OK ) 00104 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00105 00106 do_flops( NUM_FLOPS ); 00107 00108 retval = PAPI_stop( EventSet, values[1] ); 00109 if ( retval != PAPI_OK ) 00110 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00111 00112 if ( ( retval = 00113 PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) 00114 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00115 00116 printf 00117 ( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" ); 00118 printf 00119 ( "---------------------------------------------------------------\n" ); 00120 printf( "Threshold for overflow is: %d\n", THRESHOLD ); 00121 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00122 printf( "-----------------------------------------------\n" ); 00123 00124 printf( "Test type : %16d%16d\n", 1, 2 ); 00125 printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] ); 00126 printf( OUT_FMT, event_name, ( values[0] )[1], ( values[1] )[1] ); 00127 00128 if ( overflow_counts[0].count == 0 && overflow_counts[1].count == 0 ) 00129 test_fail( __FILE__, __LINE__, "one counter had no overflows", 1 ); 00130 00131 for ( k = 0; k < 3; k++ ) { 00132 if ( overflow_counts[k].mask ) { 00133 number = 2; 00134 retval = PAPI_get_overflow_event_index( EventSet, 00135 overflow_counts[k].mask, 00136 index_array, &number ); 00137 if ( retval != PAPI_OK ) 00138 test_fail( __FILE__, __LINE__, 00139 "PAPI_get_overflow_event_index", retval ); 00140 printf( INDEX_FMT, ( long long ) overflow_counts[k].mask ); 00141 printf( " counts: %d ", overflow_counts[k].count ); 00142 for ( i = 0; i < number; i++ ) 00143 printf( " Event Index %d ", index_array[i] ); 00144 printf( "\n" ); 00145 } 00146 } 00147 printf( "Case 2 %s Overflows: %d\n", "Unknown", total_unknown ); 00148 printf( "-----------------------------------------------\n" ); 00149 00150 if ( total_unknown > 0 ) 00151 test_fail( __FILE__, __LINE__, "Unknown counter had overflows", 1 ); 00152 00153 retval = PAPI_cleanup_eventset( EventSet ); 00154 if ( retval != PAPI_OK ) 00155 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00156 00157 test_pass( __FILE__, NULL, 0 ); 00158 exit( 1 ); 00159 }