|
PAPI
5.0.1.0
|
00001 /* 00002 * File: overflow_one_and_read.c : based on overflow_twoevents.c 00003 * Mods: Philip Mucci 00004 * mucci@cs.utk.edu 00005 * Kevin London 00006 * london@cs.utk.edu 00007 */ 00008 00009 /* This file performs the following test: overflow dispatch on 1 counter. 00010 * In the handler read events. 00011 */ 00012 00013 #include "papi_test.h" 00014 00015 #define OVER_FMT "handler(%d) Overflow at %p! vector=0x%llx\n" 00016 #define OUT_FMT "%-12s : %16lld%16lld\n" 00017 00018 typedef struct 00019 { 00020 long long mask; 00021 int count; 00022 } ocount_t; 00023 00024 /* there are three possible vectors, one counter overflows, the other 00025 counter overflows, both overflow */ 00026 /*not used*/ ocount_t overflow_counts[3] = { {0, 0}, {0, 0}, {0, 0} }; 00027 /*not used*/ int total_unknown = 0; 00028 00029 /*added*/ long long dummyvalues[2]; 00030 00031 void 00032 handler( int EventSet, void *address, long long overflow_vector, void *context ) 00033 { 00034 int retval; 00035 00036 ( void ) context; 00037 00038 if ( !TESTS_QUIET ) { 00039 fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector ); 00040 } 00041 00042 if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK ) 00043 test_fail( __FILE__, __LINE__, "PAPI_read", retval ); 00044 00045 if ( !TESTS_QUIET ) { 00046 fprintf( stderr, TWO12, dummyvalues[0], dummyvalues[1], 00047 "(Reading counters)\n" ); 00048 } 00049 if ( dummyvalues[1] == 0 ) 00050 test_fail( __FILE__, __LINE__, "Total Cycles == 0", 1 ); 00051 } 00052 00053 int 00054 main( int argc, char **argv ) 00055 { 00056 int EventSet; 00057 long long **values = NULL; 00058 int retval; 00059 int PAPI_event; 00060 char event_name[PAPI_MAX_STR_LEN]; 00061 int num_events1, mask1; 00062 00063 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00064 00065 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00066 if ( retval != PAPI_VER_CURRENT ) 00067 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00068 00069 /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or 00070 PAPI_TOT_INS, depends on the availability of the event on the 00071 platform */ 00072 /* NOTE: Only adding one overflow on PAPI_event -- no overflow for PAPI_TOT_CYC*/ 00073 EventSet = 00074 add_two_nonderived_events( &num_events1, &PAPI_event, &mask1 ); 00075 00076 values = allocate_test_space( 2, num_events1 ); 00077 00078 if ( ( retval = 00079 PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) 00080 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00081 00082 retval = PAPI_start( EventSet ); 00083 if ( retval != PAPI_OK ) 00084 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00085 00086 do_flops( NUM_FLOPS ); 00087 00088 retval = PAPI_stop( EventSet, values[0] ); 00089 if ( retval != PAPI_OK ) 00090 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00091 00092 retval = PAPI_overflow( EventSet, PAPI_event, THRESHOLD, 0, handler ); 00093 if ( retval != PAPI_OK ) 00094 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00095 00096 retval = PAPI_start( EventSet ); 00097 if ( retval != PAPI_OK ) 00098 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00099 00100 do_flops( NUM_FLOPS ); 00101 00102 retval = PAPI_stop( EventSet, values[1] ); 00103 if ( retval != PAPI_OK ) 00104 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00105 00106 remove_test_events( &EventSet, mask1 ); 00107 00108 00109 if ( !TESTS_QUIET ) { 00110 printf 00111 ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" ); 00112 printf 00113 ( "---------------------------------------------------------------\n" ); 00114 printf( "Threshold for overflow is: %d\n", THRESHOLD ); 00115 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00116 printf( "-----------------------------------------------\n" ); 00117 00118 printf( "Test type : %16d%16d\n", 1, 2 ); 00119 printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] ); 00120 printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] ); 00121 } 00122 00123 test_pass( __FILE__, NULL, 0 ); 00124 exit( 1 ); 00125 }