|
PAPI
5.0.1.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 char *Intel_i7; 00081 int event_code; 00082 int numcmp, cid; 00083 00084 /* Set TESTS_QUIET variable */ 00085 tests_quiet( argc, argv ); 00086 00087 /* Init PAPI library */ 00088 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00089 if ( retval != PAPI_VER_CURRENT ) { 00090 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00091 } 00092 00093 retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available " 00094 "native events and hardware " 00095 "information.\n", 00096 &hwinfo ); 00097 if ( retval != PAPI_OK ) { 00098 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00099 } 00100 00101 numcmp = PAPI_num_components( ); 00102 00103 /* we need a little exception processing if it's a Core i7 */ 00104 /* Unfortunately, this test never succeeds... */ 00105 Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" ); 00106 00107 /* Loop through all components */ 00108 for( cid = 0; cid < numcmp; cid++ ) { 00109 00110 if ( PAPI_get_component_info( cid ) == NULL ) { 00111 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 ); 00112 } 00113 00114 /* For platform independence, always ASK FOR the first event */ 00115 /* Don't just assume it'll be the first numeric value */ 00116 i = 0 | PAPI_NATIVE_MASK; 00117 retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid ); 00118 00119 do { 00120 retval = PAPI_get_event_info( i, &info ); 00121 00122 /* Skip OFFCORE and UNCORE events */ 00123 /* Adding them will fail currently */ 00124 if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) { 00125 if ( !strncmp( info.symbol, "UNC_", 4 ) ) { 00126 unc_count++; 00127 continue; 00128 } 00129 if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) { 00130 offcore_count++; 00131 continue; 00132 } 00133 } 00134 00135 /* Enumerate all umasks */ 00136 k = i; 00137 if ( PAPI_enum_cmp_event(&k, PAPI_NTV_ENUM_UMASKS, cid )==PAPI_OK ) { 00138 do { 00139 retval = PAPI_get_event_info( k, &info1 ); 00140 event_code = ( int ) info1.event_code; 00141 if ( check_event( event_code, info1.symbol ) ) { 00142 add_count++; 00143 } 00144 else { 00145 err_count++; 00146 } 00147 } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK ); 00148 } else { 00149 /* Event didn't have any umasks */ 00150 event_code = ( int ) info.event_code; 00151 if ( check_event( event_code, info.symbol ) ) { 00152 add_count++; 00153 } 00154 else { 00155 err_count++; 00156 } 00157 } 00158 00159 } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK ); 00160 00161 } 00162 printf( "\n\nSuccessfully found and added %d events " 00163 "(in %d eventsets).\n", 00164 add_count , add_count); 00165 00166 if ( err_count ) { 00167 printf( "Failed to add %d events.\n", err_count ); 00168 } 00169 00170 if (( unc_count ) || (offcore_count)) { 00171 char warning[BUFSIZ]; 00172 sprintf(warning,"%d Uncore and %d Offcore events were ignored", 00173 unc_count,offcore_count); 00174 test_warn( __FILE__, __LINE__, warning, 1 ); 00175 } 00176 00177 if ( add_count > 0 ) { 00178 test_pass( __FILE__, NULL, 0 ); 00179 } 00180 else { 00181 test_fail( __FILE__, __LINE__, "No events added", 1 ); 00182 } 00183 00184 exit( 1 ); 00185 }