PAPI  5.0.1.0
p4_lst_ins.c
Go to the documentation of this file.
00001 /* This code demonstrates the behavior of PAPI_LD_INS, PAPI_SR_INS and PAPI_LST_INS
00002     on a Pentium 4 processor. Because of the way these events are implemented in
00003     hardware, LD and SR cannot be counted in the presence of either of the other 
00004     two events. 
00005 */
00006 
00007 #include "papi_test.h"
00008 
00009 extern int TESTS_QUIET;                /* Declared in test_utils.c */
00010 extern unsigned char PENTIUM4;
00011 
00012 int
00013 main( int argc, char **argv )
00014 {
00015     int retval, num_tests = 6, tmp;
00016     long long **values;
00017     int EventSet = PAPI_NULL;
00018     const PAPI_hw_info_t *hw_info;
00019 
00020     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00021 
00022     retval = PAPI_library_init( PAPI_VER_CURRENT );
00023     if ( retval != PAPI_VER_CURRENT )
00024         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00025 
00026     if ( !PENTIUM4 )
00027         test_skip( __FILE__, __LINE__,
00028                    "This test is intended only for Pentium 4.", 1 );
00029 
00030     hw_info = PAPI_get_hardware_info(  );
00031     if ( hw_info == NULL )
00032         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00033 
00034     retval = PAPI_create_eventset( &EventSet );
00035     if ( retval != PAPI_OK )
00036         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00037 
00038     values = allocate_test_space( num_tests, 2 );
00039 
00040 /* First test: just PAPI_LD_INS */
00041     retval = PAPI_add_event( EventSet, PAPI_LD_INS );
00042     if ( retval != PAPI_OK )
00043         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval );
00044 
00045     retval = PAPI_start( EventSet );
00046     if ( retval != PAPI_OK )
00047         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00048 
00049     do_flops( NUM_FLOPS / 10 );
00050 
00051     retval = PAPI_stop( EventSet, values[0] );
00052     if ( retval != PAPI_OK )
00053         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00054 
00055     retval = PAPI_remove_event( EventSet, PAPI_LD_INS );
00056     if ( retval != PAPI_OK )
00057         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS",
00058                    retval );
00059 
00060 /* Second test: just PAPI_SR_INS */
00061     retval = PAPI_add_event( EventSet, PAPI_SR_INS );
00062     if ( retval != PAPI_OK )
00063         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval );
00064 
00065     retval = PAPI_start( EventSet );
00066     if ( retval != PAPI_OK )
00067         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00068 
00069     do_flops( NUM_FLOPS / 10 );
00070 
00071     retval = PAPI_stop( EventSet, values[1] );
00072     if ( retval != PAPI_OK )
00073         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00074 
00075     retval = PAPI_remove_event( EventSet, PAPI_SR_INS );
00076     if ( retval != PAPI_OK )
00077         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS",
00078                    retval );
00079 
00080 /* Third test: just PAPI_LST_INS */
00081     retval = PAPI_add_event( EventSet, PAPI_LST_INS );
00082     if ( retval != PAPI_OK )
00083         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_LST_INS", retval );
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 / 10 );
00090 
00091     retval = PAPI_stop( EventSet, values[2] );
00092     if ( retval != PAPI_OK )
00093         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00094 
00095 /* Fourth test: PAPI_LST_INS and PAPI_LD_INS */
00096     retval = PAPI_add_event( EventSet, PAPI_LD_INS );
00097     if ( retval != PAPI_OK )
00098         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval );
00099 
00100     retval = PAPI_start( EventSet );
00101     if ( retval != PAPI_OK )
00102         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00103 
00104     do_flops( NUM_FLOPS / 10 );
00105 
00106     retval = PAPI_stop( EventSet, values[3] );
00107     if ( retval != PAPI_OK )
00108         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00109 
00110     retval = PAPI_remove_event( EventSet, PAPI_LD_INS );
00111     if ( retval != PAPI_OK )
00112         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS",
00113                    retval );
00114 
00115 /* Fifth test: PAPI_LST_INS and PAPI_SR_INS */
00116     retval = PAPI_add_event( EventSet, PAPI_SR_INS );
00117     if ( retval != PAPI_OK )
00118         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval );
00119 
00120     retval = PAPI_start( EventSet );
00121     if ( retval != PAPI_OK )
00122         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00123 
00124     do_flops( NUM_FLOPS / 10 );
00125 
00126     retval = PAPI_stop( EventSet, values[4] );
00127     if ( retval != PAPI_OK )
00128         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00129 
00130     retval = PAPI_remove_event( EventSet, PAPI_SR_INS );
00131     if ( retval != PAPI_OK )
00132         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS",
00133                    retval );
00134 
00135     retval = PAPI_remove_event( EventSet, PAPI_LST_INS );
00136     if ( retval != PAPI_OK )
00137         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_LST_INS",
00138                    retval );
00139 
00140 /* Sixth test: PAPI_LD_INS and PAPI_SR_INS */
00141     retval = PAPI_add_event( EventSet, PAPI_LD_INS );
00142     if ( retval != PAPI_OK )
00143         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval );
00144 
00145     retval = PAPI_add_event( EventSet, PAPI_SR_INS );
00146     if ( retval != PAPI_OK )
00147         test_fail( __FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval );
00148 
00149     retval = PAPI_start( EventSet );
00150     if ( retval != PAPI_OK )
00151         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00152 
00153     do_flops( NUM_FLOPS / 10 );
00154 
00155     retval = PAPI_stop( EventSet, values[5] );
00156     if ( retval != PAPI_OK )
00157         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00158 
00159     retval = PAPI_remove_event( EventSet, PAPI_LD_INS );
00160     if ( retval != PAPI_OK )
00161         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS",
00162                    retval );
00163 
00164     retval = PAPI_remove_event( EventSet, PAPI_SR_INS );
00165     if ( retval != PAPI_OK )
00166         test_fail( __FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS",
00167                    retval );
00168 
00169 
00170 
00171     if ( !TESTS_QUIET ) {
00172         printf( "Pentium 4 Load / Store tests.\n" );
00173         printf
00174             ( "These PAPI events are counted by setting a tag at the front of the pipeline,\n" );
00175         printf
00176             ( "and counting tags at the back of the pipeline. All the tags are the same 'color'\n" );
00177         printf
00178             ( "and can't be distinguished from each other. Therefore, PAPI_LD_INS and PAPI_SR_INS\n" );
00179         printf
00180             ( "cannot be counted with the other two events, or the answer will always == PAPI_LST_INS.\n" );
00181         printf
00182             ( "-------------------------------------------------------------------------------------------\n" );
00183         tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
00184         printf( "Default domain is: %d (%s)\n", tmp,
00185                 stringify_all_domains( tmp ) );
00186         tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
00187         printf( "Default granularity is: %d (%s)\n", tmp,
00188                 stringify_granularity( tmp ) );
00189         printf( "Using %d iterations of c += a*b\n", NUM_FLOPS / 10 );
00190         printf
00191             ( "-------------------------------------------------------------------------------------------\n" );
00192 
00193         printf
00194             ( "Test:                1            2            3            4            5            6\n" );
00195         printf( "%s %12lld %12s %12s %12lld %12s %12lld\n", "PAPI_LD_INS: ",
00196                 ( values[0] )[0], "------", "------", ( values[3] )[1],
00197                 "------", ( values[5] )[0] );
00198         printf( "%s %12s %12lld %12s %12s %12lld %12lld\n", "PAPI_SR_INS: ",
00199                 "------", ( values[1] )[0], "------", "------",
00200                 ( values[4] )[1], ( values[5] )[1] );
00201         printf( "%s %12s %12s %12lld %12lld %12lld %12s\n", "PAPI_LST_INS:",
00202                 "------", "------", ( values[2] )[0], ( values[3] )[0],
00203                 ( values[4] )[0], "------" );
00204         printf
00205             ( "-------------------------------------------------------------------------------------------\n" );
00206 
00207         printf( "Test 1: PAPI_LD_INS only.\n" );
00208         printf( "Test 2: PAPI_SR_INS only.\n" );
00209         printf( "Test 3: PAPI_LST_INS only.\n" );
00210         printf( "Test 4: PAPI_LD_INS and PAPI_LST_INS.\n" );
00211         printf( "Test 5: PAPI_SR_INS and PAPI_LST_INS.\n" );
00212         printf( "Test 6: PAPI_LD_INS and PAPI_SR_INS.\n" );
00213         printf
00214             ( "Verification: Values within each column should be the same.\n" );
00215         printf( "              R3C3 ~= (R1C1 + R2C2) ~= all other entries.\n" );
00216     }
00217 
00218     test_pass( __FILE__, values, num_tests );
00219     exit( 1 );
00220 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines