PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
memory.c File Reference
Include dependency graph for memory.c:

Go to the source code of this file.

Macros

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

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

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

Definition at line 21 of file memory.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file memory.c.

26 {
27  int retval, i, j;
28  int EventSet = PAPI_NULL;
29  long long values[2];
30  const PAPI_hw_info_t *hwinfo = NULL;
31  char descr[PAPI_MAX_STR_LEN];
32  PAPI_event_info_t evinfo;
33  PAPI_mh_level_t *L;
34 
35 
36  const int eventlist[] = {
43 #if 0
84 #endif
85  0
86  };
87 
88  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
89 
90  if ( ( retval =
92  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
93 
94  if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL ) {
95  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
96  }
97 
98  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
99  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
100 
101  /* Extract and report the cache information */
102  L = ( PAPI_mh_level_t * ) ( hwinfo->mem_hierarchy.level );
103  for ( i = 0; i < hwinfo->mem_hierarchy.levels; i++ ) {
104  for ( j = 0; j < 2; j++ ) {
105  int tmp;
106 
107  tmp = PAPI_MH_CACHE_TYPE( L[i].cache[j].type );
108  if ( tmp == PAPI_MH_TYPE_UNIFIED ) {
109  if (!TESTS_QUIET) printf( "L%d Unified ", i + 1 );
110  } else if ( tmp == PAPI_MH_TYPE_DATA ) {
111  if (!TESTS_QUIET) printf( "L%d Data ", i + 1 );
112  } else if ( tmp == PAPI_MH_TYPE_INST ) {
113  if (!TESTS_QUIET) printf( "L%d Instruction ", i + 1 );
114  } else if ( tmp == PAPI_MH_TYPE_VECTOR ) {
115  if (!TESTS_QUIET) printf( "L%d Vector ", i + 1 );
116  } else if ( tmp == PAPI_MH_TYPE_TRACE ) {
117  if (!TESTS_QUIET) printf( "L%d Trace ", i + 1 );
118  } else if ( tmp == PAPI_MH_TYPE_EMPTY ) {
119  break;
120  } else {
121  test_fail( __FILE__, __LINE__,
122  "PAPI_get_hardware_info",
123  PAPI_EBUG );
124  }
125 
126  tmp = PAPI_MH_CACHE_WRITE_POLICY( L[i].cache[j].type );
127  if ( tmp == PAPI_MH_TYPE_WB ) {
128  if (!TESTS_QUIET) printf( "Write back " );
129  } else if ( tmp == PAPI_MH_TYPE_WT ) {
130  if (!TESTS_QUIET) printf( "Write through " );
131  } else {
132  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
133  PAPI_EBUG );
134  }
135 
136  tmp = PAPI_MH_CACHE_REPLACEMENT_POLICY( L[i].cache[j].type );
137  if ( tmp == PAPI_MH_TYPE_PSEUDO_LRU ) {
138  if (!TESTS_QUIET) printf( "Pseudo LRU policy " );
139  } else if ( tmp == PAPI_MH_TYPE_LRU ) {
140  if (!TESTS_QUIET) printf( "LRU policy " );
141  } else if ( tmp == PAPI_MH_TYPE_UNKNOWN ) {
142  if (!TESTS_QUIET) printf( "Unknown policy " );
143  } else {
144  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
145  PAPI_EBUG );
146  }
147 
148  if (!TESTS_QUIET) {
149  printf( "Cache:\n" );
150  if ( L[i].cache[j].type ) {
151  printf( " Total size: %dKB\n"
152  " Line size: %dB\n"
153  " Number of Lines: %d\n"
154  " Associativity: %d\n\n",
155  ( L[i].cache[j].size ) >> 10,
156  L[i].cache[j].line_size,
157  L[i].cache[j].num_lines,
158  L[i].cache[j].associativity );
159  }
160  }
161  }
162  }
163 
164  for ( i = 0; eventlist[i] != 0; i++ ) {
165  if (PAPI_event_code_to_name( eventlist[i], descr ) != PAPI_OK)
166  continue;
167  if ( PAPI_add_event( EventSet, eventlist[i] ) != PAPI_OK )
168  continue;
169 
170  if ( PAPI_get_event_info( eventlist[i], &evinfo ) != PAPI_OK )
171  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
172 
173  if (!TESTS_QUIET) {
174  printf( "\nEvent: %s\nShort: %s\nLong: %s\n\n",
175  evinfo.symbol, evinfo.short_descr,
176  evinfo.long_descr );
177  printf( " Bytes\t\tCold\t\tWarm\tPercent\n" );
178  }
179 
180  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
181  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
182 
183  for ( j = 512; j <= 16 * ( 1024 * 1024 ); j = j * 2 ) {
184  do_misses( 1, j );
185  do_flush( );
186 
187  if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
188  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
189 
190  do_misses( 1, j );
191 
192  if ( ( retval = PAPI_read( EventSet, &values[0] ) ) != PAPI_OK )
193  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
194  if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
195  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
196 
197  do_misses( 1, j );
198 
199  if ( ( retval = PAPI_read( EventSet, &values[1] ) ) != PAPI_OK )
200  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
201 
202  if (!TESTS_QUIET) {
203  printf( OUT_FMT, j,
204  values[0], values[1],
205  ( ( float ) values[1] /
206  ( float ) ( ( values[0] !=0 ) ?
207  values[0] : 1 ) * 100.0 ) );
208  }
209  }
210 
211  if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK )
212  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
213 
214  if ( ( retval =
215  PAPI_remove_event( EventSet, eventlist[i] ) ) != PAPI_OK )
216  test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
217  }
218 
219  if ( ( retval = PAPI_destroy_eventset( &EventSet ) ) != PAPI_OK )
220  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
221 
222  test_pass( __FILE__ );
223 
224  return 0;
225 }
#define OUT_FMT
Definition: memory.c:21
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_L2_DCW
int levels
Definition: papi.h:774
#define PAPI_L2_TCH
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_L1_ICR
#define PAPI_L2_TCM
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
Hardware info structure.
Definition: papi.h:780
int PAPI_reset(int EventSet)
Definition: papi.c:2459
#define PAPI_L1_DCM
#define PAPI_MH_TYPE_INST
Definition: papi.h:730
#define PAPI_MEM_RCY
#define PAPI_LST_INS
PAPI_mh_info_t mem_hierarchy
Definition: papi.h:799
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1758
#define PAPI_L1_TCM
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_L1_TCR
#define PAPI_L1_LDM
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:969
#define PAPI_MH_TYPE_WB
Definition: papi.h:737
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
#define PAPI_L1_TCH
int EventSet
#define PAPI_EBUG
Definition: papi.h:259
return PAPI_OK
Definition: linux-nvml.c:497
#define PAPI_L1_DCA
#define PAPI_MH_TYPE_UNKNOWN
Definition: papi.h:739
#define PAPI_MH_TYPE_PSEUDO_LRU
Definition: papi.h:741
#define PAPI_MH_TYPE_LRU
Definition: papi.h:740
int int argc
Definition: iozone.c:1609
#define PAPI_MH_TYPE_TRACE
Definition: papi.h:733
#define PAPI_MH_TYPE_DATA
Definition: papi.h:731
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
#define PAPI_MH_CACHE_WRITE_POLICY(a)
Definition: papi.h:738
#define PAPI_MH_CACHE_REPLACEMENT_POLICY(a)
Definition: papi.h:742
char ** argv
Definition: iozone.c:1610
#define PAPI_L1_DCR
#define PAPI_L1_ICW
#define PAPI_L2_TCW
#define PAPI_L1_ICH
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
#define PAPI_L2_TCA
char *long long size
Definition: iozone.c:12023
#define PAPI_L1_ICA
#define PAPI_LD_INS
#define PAPI_L2_ICR
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Definition: papi.h:775
void do_misses(int n, int bytes)
Definition: do_loops.c:120
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:967
#define PAPI_L2_DCR
#define PAPI_L2_ICW
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define PAPI_L1_ICM
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
#define PAPI_L2_DCM
#define PAPI_L1_TCW
#define PAPI_CSR_TOT
void do_flush(void)
Definition: do_loops.c:172
#define PAPI_MEM_SCY
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
#define PAPI_L1_DCW
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_L2_TCR
#define PAPI_L1_TCA
#define PAPI_L1_STM
#define PAPI_MH_TYPE_UNIFIED
Definition: papi.h:734
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
#define PAPI_L2_LDM
#define PAPI_L2_DCH
#define PAPI_MH_TYPE_EMPTY
Definition: papi.h:729
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_MH_TYPE_WT
Definition: papi.h:736
#define PAPI_L2_ICA
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define PAPI_SR_INS
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
#define PAPI_L2_DCA
#define PAPI_VER_CURRENT
Definition: papi.h:225
#define PAPI_MH_TYPE_VECTOR
Definition: papi.h:732
#define PAPI_L1_DCH
#define PAPI_L2_ICM
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:735
#define PAPI_L2_STM
#define PAPI_L2_ICH
#define PAPI_MEM_WCY

Here is the call graph for this function: