memory.c File Reference

Include dependency graph for memory.c:

Go to the source code of this file.

Defines

#define OUT_FMT   "%12d\t%12lld\t%12lld\t%.2f\n"

Functions

int main (int argc, char **argv)

Define Documentation

#define OUT_FMT   "%12d\t%12lld\t%12lld\t%.2f\n"

Definition at line 15 of file memory.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 19 of file memory.c.

00020 {
00021     int retval, i, j;
00022     int EventSet = PAPI_NULL;
00023     long long values[2];
00024     const PAPI_hw_info_t *hwinfo = NULL;
00025     char descr[PAPI_MAX_STR_LEN];
00026     PAPI_event_info_t evinfo;
00027     PAPI_mh_level_t *L;
00028 
00029 
00030     const int eventlist[] = {
00031         PAPI_L1_DCA,
00032         PAPI_L1_DCM,
00033         PAPI_L1_DCH,
00034         PAPI_L2_DCA,
00035         PAPI_L2_DCM,
00036         PAPI_L2_DCH,
00037 #if 0
00038         PAPI_L1_LDM,
00039         PAPI_L1_STM,
00040         PAPI_L1_DCR,
00041         PAPI_L1_DCW,
00042         PAPI_L1_ICM,
00043         PAPI_L1_TCM,
00044         PAPI_LD_INS,
00045         PAPI_SR_INS,
00046         PAPI_LST_INS,
00047         PAPI_L2_DCR,
00048         PAPI_L2_DCW,
00049         PAPI_CSR_TOT,
00050         PAPI_MEM_SCY,
00051         PAPI_MEM_RCY,
00052         PAPI_MEM_WCY,
00053         PAPI_L1_ICH,
00054         PAPI_L1_ICA,
00055         PAPI_L1_ICR,
00056         PAPI_L1_ICW,
00057         PAPI_L1_TCH,
00058         PAPI_L1_TCA,
00059         PAPI_L1_TCR,
00060         PAPI_L1_TCW,
00061         PAPI_L2_DCM,
00062         PAPI_L2_ICM,
00063         PAPI_L2_TCM,
00064         PAPI_L2_LDM,
00065         PAPI_L2_STM,
00066         PAPI_L2_DCH,
00067         PAPI_L2_DCA,
00068         PAPI_L2_DCR,
00069         PAPI_L2_DCW,
00070         PAPI_L2_ICH,
00071         PAPI_L2_ICA,
00072         PAPI_L2_ICR,
00073         PAPI_L2_ICW,
00074         PAPI_L2_TCH,
00075         PAPI_L2_TCA,
00076         PAPI_L2_TCR,
00077         PAPI_L2_TCW,
00078 #endif
00079         0
00080     };
00081 
00082     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00083 
00084     if ( ( retval =
00085            PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
00086         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00087 
00088     if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL ) {
00089         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00090     }
00091 
00092     if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
00093         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00094 
00095     /* Extract and report the cache information */
00096     L = ( PAPI_mh_level_t * ) ( hwinfo->mem_hierarchy.level );
00097     for ( i = 0; i < hwinfo->mem_hierarchy.levels; i++ ) {
00098         for ( j = 0; j < 2; j++ ) {
00099             int tmp;
00100 
00101             tmp = PAPI_MH_CACHE_TYPE( L[i].cache[j].type );
00102             if ( tmp == PAPI_MH_TYPE_UNIFIED ) {
00103                 printf( "L%d Unified ", i + 1 );
00104             } else if ( tmp == PAPI_MH_TYPE_DATA ) {
00105                 printf( "L%d Data ", i + 1 );
00106             } else if ( tmp == PAPI_MH_TYPE_INST ) {
00107                 printf( "L%d Instruction ", i + 1 );
00108             } else if ( tmp == PAPI_MH_TYPE_VECTOR ) {
00109                 printf( "L%d Vector ", i + 1 );
00110             } else if ( tmp == PAPI_MH_TYPE_TRACE ) {
00111                 printf( "L%d Trace ", i + 1 );
00112             } else if ( tmp == PAPI_MH_TYPE_EMPTY ) {
00113                 break;
00114             } else {
00115                 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
00116                            PAPI_EBUG );
00117             }
00118 
00119             tmp = PAPI_MH_CACHE_WRITE_POLICY( L[i].cache[j].type );
00120             if ( tmp == PAPI_MH_TYPE_WB ) {
00121                 printf( "Write back " );
00122             } else if ( tmp == PAPI_MH_TYPE_WT ) {
00123                 printf( "Write through " );
00124             } else {
00125                 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
00126                            PAPI_EBUG );
00127             }
00128 
00129             tmp = PAPI_MH_CACHE_REPLACEMENT_POLICY( L[i].cache[j].type );
00130             if ( tmp == PAPI_MH_TYPE_PSEUDO_LRU ) {
00131                 printf( "Pseudo LRU policy " );
00132             } else if ( tmp == PAPI_MH_TYPE_LRU ) {
00133                 printf( "LRU policy " );
00134             } else if ( tmp == PAPI_MH_TYPE_UNKNOWN ) {
00135                 printf( "Unknown policy " );
00136             } else {
00137                 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
00138                            PAPI_EBUG );
00139             }
00140 
00141             printf( "Cache:\n" );
00142             if ( L[i].cache[j].type ) {
00143                 printf
00144                     ( "  Total size: %dKB\n  Line size: %dB\n  Number of Lines: %d\n  Associativity: %d\n\n",
00145                       ( L[i].cache[j].size ) >> 10, L[i].cache[j].line_size,
00146                       L[i].cache[j].num_lines, L[i].cache[j].associativity );
00147             }
00148         }
00149     }
00150 
00151     for ( i = 0; eventlist[i] != 0; i++ ) {
00152             if (PAPI_event_code_to_name( eventlist[i], descr ) != PAPI_OK)
00153                continue;
00154         if ( PAPI_add_event( EventSet, eventlist[i] ) != PAPI_OK )
00155            continue;
00156 
00157         if ( PAPI_get_event_info( eventlist[i], &evinfo ) != PAPI_OK )
00158             test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
00159 
00160         printf( "\nEvent: %s\nShort: %s\nLong: %s\n\n",
00161                 evinfo.symbol, evinfo.short_descr, evinfo.long_descr );
00162         printf( "       Bytes\t\tCold\t\tWarm\tPercent\n" );
00163 
00164         if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00165             test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00166 
00167         for ( j = 512; j <= 16 * ( 1024 * 1024 ); j = j * 2 ) {
00168             do_misses( 1, j );
00169             do_flush(  );
00170 
00171             if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
00172                 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
00173 
00174             do_misses( 1, j );
00175 
00176             if ( ( retval = PAPI_read( EventSet, &values[0] ) ) != PAPI_OK )
00177                 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
00178             if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
00179                 test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
00180 
00181             do_misses( 1, j );
00182 
00183             if ( ( retval = PAPI_read( EventSet, &values[1] ) ) != PAPI_OK )
00184                 test_fail( __FILE__, __LINE__, "PAPI_read", retval );
00185 
00186             printf( OUT_FMT, j, values[0], values[1],
00187                     ( ( float ) values[1] /
00188                       ( float ) ( ( values[0] !=
00189                                     0 ) ? values[0] : 1 ) * 100.0 ) );
00190         }
00191 
00192         if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK )
00193             test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00194 
00195         if ( ( retval =
00196                PAPI_remove_event( EventSet, eventlist[i] ) ) != PAPI_OK )
00197             test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
00198     }
00199 
00200     if ( ( retval = PAPI_destroy_eventset( &EventSet ) ) != PAPI_OK )
00201         test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
00202 
00203     test_pass( __FILE__, NULL, 0 );
00204 
00205     exit( 1 );
00206 }

Here is the call graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1