PAPI  5.0.1.0
native.c
Go to the documentation of this file.
00001 /*
00002 * File:     native.c
00003 * Mods:     Maynard Johnson
00004 *       maynardj@us.ibm.com
00005 */
00006 
00007 /*
00008    This test defines an array of native event names, either at compile time
00009    or at run time (some x86 platforms). It then:
00010    - add the table of events to an event set;
00011    - starts counting
00012    - does a little work
00013    - stops counting;
00014    - reports the results.
00015 */
00016 
00017 #include "papi_test.h"
00018 
00019 static int EventSet = PAPI_NULL;
00020 extern int TESTS_QUIET;                /* Declared in test_utils.c */
00021 
00022 
00023 #if (defined(PPC32))
00024    /* Select 4 events common to both ppc750 and ppc7450 */
00025 static char *native_name[] = { "CPU_CLK", "FLOPS", "TOT_INS", "BR_MSP", NULL
00026 };
00027 
00028 #elif defined(_POWER4) || defined(_PPC970)
00029    /* arbitrarily code events from group 28: pm_fpu3 - Floating point events by unit */
00030 static char *native_name[] =
00031     { "PM_FPU0_FDIV", "PM_FPU1_FDIV", "PM_FPU0_FRSP_FCONV",
00032 "PM_FPU1_FRSP_FCONV",
00033     "PM_FPU0_FMA", "PM_FPU1_FMA", "PM_INST_CMPL", "PM_CYC", NULL
00034 };
00035 
00036 #elif defined(_POWER5p)
00037 /* arbitrarily code events from group 33: pm_fpustall - Floating Point Unit stalls */
00038 static char *native_name[] =
00039     { "PM_FPU_FULL_CYC", "PM_CMPLU_STALL_FDIV", "PM_CMPLU_STALL_FPU",
00040     "PM_RUN_INST_CMPL", "PM_RUN_CYC", NULL
00041 };
00042 
00043 
00044 #elif defined(_POWER5)
00045    /* arbitrarily code events from group 78: pm_fpu1 - Floating Point events */
00046 static char *native_name[] =
00047     { "PM_FPU_FDIV", "PM_FPU_FMA", "PM_FPU_FMOV_FEST", "PM_FPU_FEST",
00048     "PM_INST_CMPL", "PM_RUN_CYC", NULL
00049 };
00050 
00051 #elif defined(POWER3)
00052 static char *native_name[] =
00053     { "PM_IC_MISS", "PM_FPU1_CMPL", "PM_LD_MISS_L1", "PM_LD_CMPL",
00054     "PM_FPU0_CMPL", "PM_CYC", "PM_TLB_MISS", NULL
00055 };
00056 
00057 #elif defined(__ia64__)
00058 #ifdef ITANIUM2
00059 static char *native_name[] =
00060     { "CPU_CYCLES", "L1I_READS", "L1D_READS_SET0", "IA64_INST_RETIRED", NULL
00061 };
00062 #else
00063 static char *native_name[] =
00064     { "DEPENDENCY_SCOREBOARD_CYCLE", "DEPENDENCY_ALL_CYCLE",
00065     "UNSTALLED_BACKEND_CYCLE", "MEMORY_CYCLE", NULL
00066 };
00067 #endif
00068 
00069 #elif ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
00070 static char *p3_native_name[] = { "DATA_MEM_REFS", "DCU_LINES_IN", NULL };
00071 static char *core_native_name[] = { "UnhltCore_Cycles", "Instr_Retired", NULL };
00072 static char *k7_native_name[] =
00073     { "TOT_CYC", "IC_MISSES", "DC_ACCESSES", "DC_MISSES", NULL };
00074 //   static char *k8_native_name[] = { "FP_ADD_PIPE", "FP_MULT_PIPE", "FP_ST_PIPE", "FP_NONE_RET", NULL };
00075 static char *k8_native_name[] =
00076     { "DISPATCHED_FPU:OPS_ADD", "DISPATCHED_FPU:OPS_MULTIPLY",
00077 "DISPATCHED_FPU:OPS_STORE", "CYCLES_NO_FPU_OPS_RETIRED", NULL };
00078 static char *p4_native_name[] =
00079     { "retired_mispred_branch_type:CONDITIONAL", "resource_stall:SBFULL",
00080     "tc_ms_xfer:CISC", "instr_retired:BOGUSNTAG:BOGUSTAG",
00081         "BSQ_cache_reference:RD_2ndL_HITS", NULL
00082 };
00083 static char **native_name = p3_native_name;
00084 
00085 #elif defined(mips) && defined(sgi)
00086 static char *native_name[] = { "Primary_instruction_cache_misses",
00087     "Primary_data_cache_misses", NULL
00088 };
00089 #elif defined(mips) && defined(linux)
00090 static char *native_name[] = { "CYCLES", NULL };
00091 #elif defined(sun) && defined(sparc)
00092 static char *native_name[] = { "Cycle_cnt", "Instr_cnt", NULL };
00093 
00094 #elif defined(_BGL)
00095 static char *native_name[] =
00096     { "BGL_UPC_PU0_PREF_STREAM_HIT", "BGL_PAPI_TIMEBASE",
00097 "BGL_UPC_PU1_PREF_STREAM_HIT", NULL };
00098 
00099 #elif defined(__bgp__)
00100 static char *native_name[] =
00101     { "PNE_BGP_PU0_JPIPE_LOGICAL_OPS", "PNE_BGP_PU0_JPIPE_LOGICAL_OPS",
00102 "PNE_BGP_PU2_IPIPE_INSTRUCTIONS", NULL };
00103 
00104 #else
00105 #error "Architecture not supported in test file."
00106 #endif
00107 
00108 
00109 int
00110 main( int argc, char **argv )
00111 {
00112     int i, retval, native;
00113     const PAPI_hw_info_t *hwinfo;
00114     long long values[8];
00115 
00116     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00117 
00118     if ( ( retval =
00119            PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
00120         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00121 
00122     if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
00123         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00124 
00125     if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
00126         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC );
00127 
00128     printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model );
00129 
00130 #if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
00131     if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) {
00132         native_name = p4_native_name;
00133     } else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) {
00134         native_name = k7_native_name;
00135     } else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) {
00136         native_name = k8_native_name;
00137     } else if ( !strncmp( hwinfo->model_string, "Intel Core", 17 ) ||
00138                 !strncmp( hwinfo->model_string, "Intel Core 2", 17 ) ) {
00139         native_name = core_native_name;
00140     }
00141 #endif
00142 
00143     for ( i = 0; native_name[i] != NULL; i++ ) {
00144         retval = PAPI_event_name_to_code( native_name[i], &native );
00145         if ( retval != PAPI_OK )
00146             test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
00147         printf( "Adding %s\n", native_name[i] );
00148         if ( ( retval = PAPI_add_event( EventSet, native ) ) != PAPI_OK )
00149             test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00150     }
00151 
00152     if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00153         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00154 
00155     do_both( 1000 );
00156 
00157     if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
00158         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00159 
00160     if ( !TESTS_QUIET ) {
00161         for ( i = 0; native_name[i] != NULL; i++ ) {
00162             fprintf( stderr, "%-40s: ", native_name[i] );
00163             fprintf( stderr, LLDFMT, values[i] );
00164             fprintf( stderr, "\n" );
00165         }
00166     }
00167 
00168     retval = PAPI_cleanup_eventset( EventSet );
00169     if ( retval != PAPI_OK )
00170         test_fail( __FILE__, __LINE__, "PAPI_cleanup", retval );
00171     retval = PAPI_destroy_eventset( &EventSet );
00172     if ( retval != PAPI_OK )
00173         test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
00174 
00175     test_pass( __FILE__, NULL, 0 );
00176     exit( 0 );
00177 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines