|
PAPI
5.3.0.0
|
00001 /* 00002 * File: all_native_events.c 00003 * Author: Haihang You 00004 * you@cs.utk.edu 00005 * Mods: <Your name here> 00006 * <Your email here> 00007 */ 00008 00009 /* This file hardware info and performs the following test: 00010 - Start and stop all native events. 00011 This is a good preliminary way to validate native event tables. 00012 In its current form this test also stresses the number of 00013 events sets the library can handle outstanding. 00014 */ 00015 00016 #include "papi_test.h" 00017 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00018 extern unsigned char PENTIUM4; 00019 00020 static int 00021 check_event( int event_code, char *name ) 00022 { 00023 int retval; 00024 long long values; 00025 int EventSet = PAPI_NULL; 00026 00027 /* Is there an issue with older machines? */ 00028 /* Disable for now, add back once we can reproduce */ 00029 // if ( PENTIUM4 ) { 00030 // if ( strcmp( name, "REPLAY_EVENT:BR_MSP" ) == 0 ) { 00031 // return 1; 00032 // } 00033 // } 00034 00035 retval = PAPI_create_eventset( &EventSet ); 00036 if ( retval != PAPI_OK ) 00037 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00038 00039 retval = PAPI_add_event( EventSet, event_code ); 00040 if ( retval != PAPI_OK ) { 00041 printf( "Error adding %s %d\n", name, retval ); 00042 return 0; 00043 } else { 00044 // printf( "Added %s successfully ", name ); 00045 } 00046 00047 retval = PAPI_start( EventSet ); 00048 if ( retval != PAPI_OK ) { 00049 PAPI_perror( "PAPI_start" ); 00050 } else { 00051 retval = PAPI_stop( EventSet, &values ); 00052 if ( retval != PAPI_OK ) { 00053 PAPI_perror( "PAPI_stop" ); 00054 return 0; 00055 } else { 00056 printf( "Added and Stopped %s successfully.\n", name ); 00057 } 00058 } 00059 00060 00061 retval=PAPI_cleanup_eventset( EventSet ); 00062 if (retval != PAPI_OK ) { 00063 test_warn( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval); 00064 } 00065 retval=PAPI_destroy_eventset( &EventSet ); 00066 if (retval != PAPI_OK ) { 00067 test_warn( __FILE__, __LINE__, "PAPI_destroy_eventset", retval); 00068 } 00069 return ( 1 ); 00070 } 00071 00072 int 00073 main( int argc, char **argv ) 00074 { 00075 00076 int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0; 00077 int retval; 00078 PAPI_event_info_t info, info1; 00079 const PAPI_hw_info_t *hwinfo = NULL; 00080 const PAPI_component_info_t* cmpinfo; 00081 char *Intel_i7; 00082 int event_code; 00083 int numcmp, cid; 00084 00085 /* Set TESTS_QUIET variable */ 00086 tests_quiet( argc, argv ); 00087 00088 /* Init PAPI library */ 00089 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00090 if ( retval != PAPI_VER_CURRENT ) { 00091 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00092 } 00093 00094 retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available " 00095 "native events and hardware " 00096 "information.\n", 00097 &hwinfo ); 00098 if ( retval != PAPI_OK ) { 00099 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00100 } 00101 00102 numcmp = PAPI_num_components( ); 00103 00104 /* we need a little exception processing if it's a Core i7 */ 00105 /* Unfortunately, this test never succeeds... */ 00106 Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" ); 00107 00108 /* Loop through all components */ 00109 for( cid = 0; cid < numcmp; cid++ ) { 00110 00111 00112 cmpinfo = PAPI_get_component_info( cid ); 00113 00114 if (cmpinfo == NULL) 00115 { 00116 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 ); 00117 } 00118 00119 if (cmpinfo->disabled) 00120 { 00121 printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description); 00122 printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason); 00123 continue; 00124 } 00125 00126 00127 00128 /* For platform independence, always ASK FOR the first event */ 00129 /* Don't just assume it'll be the first numeric value */ 00130 i = 0 | PAPI_NATIVE_MASK; 00131 retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid ); 00132 00133 do { 00134 retval = PAPI_get_event_info( i, &info ); 00135 00136 /* Skip OFFCORE and UNCORE events */ 00137 /* Adding them will fail currently */ 00138 if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) { 00139 if ( !strncmp( info.symbol, "UNC_", 4 ) ) { 00140 unc_count++; 00141 continue; 00142 } 00143 if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) { 00144 offcore_count++; 00145 continue; 00146 } 00147 } 00148 00149 /* Enumerate all umasks */ 00150 k = i; 00151 if ( PAPI_enum_cmp_event(&k, PAPI_NTV_ENUM_UMASKS, cid )==PAPI_OK ) { 00152 do { 00153 retval = PAPI_get_event_info( k, &info1 ); 00154 event_code = ( int ) info1.event_code; 00155 if ( check_event( event_code, info1.symbol ) ) { 00156 add_count++; 00157 } 00158 else { 00159 err_count++; 00160 } 00161 } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK ); 00162 } else { 00163 /* Event didn't have any umasks */ 00164 event_code = ( int ) info.event_code; 00165 if ( check_event( event_code, info.symbol ) ) { 00166 add_count++; 00167 } 00168 else { 00169 err_count++; 00170 } 00171 } 00172 00173 } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK ); 00174 00175 } 00176 printf( "\n\nSuccessfully found and added %d events " 00177 "(in %d eventsets).\n", 00178 add_count , add_count); 00179 00180 if ( err_count ) { 00181 printf( "Failed to add %d events.\n", err_count ); 00182 } 00183 00184 if (( unc_count ) || (offcore_count)) { 00185 char warning[BUFSIZ]; 00186 sprintf(warning,"%d Uncore and %d Offcore events were ignored", 00187 unc_count,offcore_count); 00188 test_warn( __FILE__, __LINE__, warning, 1 ); 00189 } 00190 00191 if ( add_count > 0 ) { 00192 test_pass( __FILE__, NULL, 0 ); 00193 } 00194 else { 00195 test_fail( __FILE__, __LINE__, "No events added", 1 ); 00196 } 00197 00198 exit( 1 ); 00199 }