PAPI  5.3.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 15 of file memory.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 19 of file memory.c.

20 {
21  int retval, i, j;
22  int EventSet = PAPI_NULL;
23  long long values[2];
24  const PAPI_hw_info_t *hwinfo = NULL;
25  char descr[PAPI_MAX_STR_LEN];
26  PAPI_event_info_t evinfo;
27  PAPI_mh_level_t *L;
28 
29 
30  const int eventlist[] = {
37 #if 0
78 #endif
79  0
80  };
81 
82  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
83 
84  if ( ( retval =
86  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
87 
88  if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL ) {
89  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
90  }
91 
92  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
94 
95  /* Extract and report the cache information */
96  L = ( PAPI_mh_level_t * ) ( hwinfo->mem_hierarchy.level );
97  for ( i = 0; i < hwinfo->mem_hierarchy.levels; i++ ) {
98  for ( j = 0; j < 2; j++ ) {
99  int tmp;
100 
101  tmp = PAPI_MH_CACHE_TYPE( L[i].cache[j].type );
102  if ( tmp == PAPI_MH_TYPE_UNIFIED ) {
103  printf( "L%d Unified ", i + 1 );
104  } else if ( tmp == PAPI_MH_TYPE_DATA ) {
105  printf( "L%d Data ", i + 1 );
106  } else if ( tmp == PAPI_MH_TYPE_INST ) {
107  printf( "L%d Instruction ", i + 1 );
108  } else if ( tmp == PAPI_MH_TYPE_VECTOR ) {
109  printf( "L%d Vector ", i + 1 );
110  } else if ( tmp == PAPI_MH_TYPE_TRACE ) {
111  printf( "L%d Trace ", i + 1 );
112  } else if ( tmp == PAPI_MH_TYPE_EMPTY ) {
113  break;
114  } else {
115  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
116  PAPI_EBUG );
117  }
118 
119  tmp = PAPI_MH_CACHE_WRITE_POLICY( L[i].cache[j].type );
120  if ( tmp == PAPI_MH_TYPE_WB ) {
121  printf( "Write back " );
122  } else if ( tmp == PAPI_MH_TYPE_WT ) {
123  printf( "Write through " );
124  } else {
125  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
126  PAPI_EBUG );
127  }
128 
129  tmp = PAPI_MH_CACHE_REPLACEMENT_POLICY( L[i].cache[j].type );
130  if ( tmp == PAPI_MH_TYPE_PSEUDO_LRU ) {
131  printf( "Pseudo LRU policy " );
132  } else if ( tmp == PAPI_MH_TYPE_LRU ) {
133  printf( "LRU policy " );
134  } else if ( tmp == PAPI_MH_TYPE_UNKNOWN ) {
135  printf( "Unknown policy " );
136  } else {
137  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info",
138  PAPI_EBUG );
139  }
140 
141  printf( "Cache:\n" );
142  if ( L[i].cache[j].type ) {
143  printf
144  ( " Total size: %dKB\n Line size: %dB\n Number of Lines: %d\n Associativity: %d\n\n",
145  ( L[i].cache[j].size ) >> 10, L[i].cache[j].line_size,
146  L[i].cache[j].num_lines, L[i].cache[j].associativity );
147  }
148  }
149  }
150 
151  for ( i = 0; eventlist[i] != 0; i++ ) {
152  if (PAPI_event_code_to_name( eventlist[i], descr ) != PAPI_OK)
153  continue;
154  if ( PAPI_add_event( EventSet, eventlist[i] ) != PAPI_OK )
155  continue;
156 
157  if ( PAPI_get_event_info( eventlist[i], &evinfo ) != PAPI_OK )
158  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
159 
160  printf( "\nEvent: %s\nShort: %s\nLong: %s\n\n",
161  evinfo.symbol, evinfo.short_descr, evinfo.long_descr );
162  printf( " Bytes\t\tCold\t\tWarm\tPercent\n" );
163 
164  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
165  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
166 
167  for ( j = 512; j <= 16 * ( 1024 * 1024 ); j = j * 2 ) {
168  do_misses( 1, j );
169  do_flush( );
170 
171  if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
172  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
173 
174  do_misses( 1, j );
175 
176  if ( ( retval = PAPI_read( EventSet, &values[0] ) ) != PAPI_OK )
177  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
178  if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
179  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
180 
181  do_misses( 1, j );
182 
183  if ( ( retval = PAPI_read( EventSet, &values[1] ) ) != PAPI_OK )
184  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
185 
186  printf( OUT_FMT, j, values[0], values[1],
187  ( ( float ) values[1] /
188  ( float ) ( ( values[0] !=
189  0 ) ? values[0] : 1 ) * 100.0 ) );
190  }
191 
192  if ( ( retval = PAPI_stop( EventSet, NULL ) ) != PAPI_OK )
193  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
194 
195  if ( ( retval =
196  PAPI_remove_event( EventSet, eventlist[i] ) ) != PAPI_OK )
197  test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
198  }
199 
200  if ( ( retval = PAPI_destroy_eventset( &EventSet ) ) != PAPI_OK )
201  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
202 
203  test_pass( __FILE__, NULL, 0 );
204 
205  exit( 1 );
206 }
#define OUT_FMT
Definition: memory.c:15
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define PAPI_L1_TCW
Definition: fpapi.h:229
#define PAPI_L2_TCM
Definition: fpapi.h:142
#define PAPI_LD_INS
Definition: fpapi.h:188
int levels
Definition: papi.h:769
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
Hardware info structure.
Definition: papi.h:775
int PAPI_reset(int EventSet)
Definition: papi.c:2370
#define PAPI_L2_TCW
Definition: fpapi.h:230
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MH_TYPE_INST
Definition: papi.h:725
#define PAPI_L1_ICA
Definition: fpapi.h:211
#define PAPI_L1_ICM
Definition: fpapi.h:136
PAPI_mh_info_t mem_hierarchy
Definition: papi.h:794
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1692
#define PAPI_L1_TCM
Definition: fpapi.h:141
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
#define PAPI_MH_TYPE_WB
Definition: papi.h:732
#define PAPI_L1_DCW
Definition: fpapi.h:205
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
#define PAPI_L1_ICH
Definition: fpapi.h:208
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_L2_DCH
Definition: fpapi.h:198
tests_quiet(argc, argv)
#define PAPI_LST_INS
Definition: fpapi.h:195
#define PAPI_MH_TYPE_UNKNOWN
Definition: papi.h:734
#define PAPI_MH_TYPE_PSEUDO_LRU
Definition: papi.h:736
#define printf
Definition: papi_test.h:125
#define PAPI_MH_TYPE_LRU
Definition: papi.h:735
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
#define PAPI_MH_TYPE_TRACE
Definition: papi.h:728
#define PAPI_MH_TYPE_DATA
Definition: papi.h:726
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:841
#define PAPI_L1_ICR
Definition: fpapi.h:214
#define PAPI_MH_CACHE_WRITE_POLICY(a)
Definition: papi.h:733
#define PAPI_MH_CACHE_REPLACEMENT_POLICY(a)
Definition: papi.h:737
#define PAPI_L1_DCR
Definition: fpapi.h:202
char ** argv
Definition: iozone.c:1610
#define PAPI_L2_DCW
Definition: fpapi.h:206
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_SR_INS
Definition: fpapi.h:189
#define PAPI_L2_ICW
Definition: fpapi.h:218
#define PAPI_L2_DCM
Definition: fpapi.h:137
#define PAPI_MEM_WCY
Definition: fpapi.h:171
char *long long size
Definition: iozone.c:12023
#define PAPI_L1_TCA
Definition: fpapi.h:223
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Definition: papi.h:770
void do_misses(int n, int bytes)
Definition: do_loops.c:113
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:962
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_L1_ICW
Definition: fpapi.h:217
#define PAPI_L1_DCH
Definition: fpapi.h:197
#define PAPI_L2_DCA
Definition: fpapi.h:200
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
#define PAPI_L1_TCH
Definition: fpapi.h:220
#define PAPI_MEM_SCY
Definition: fpapi.h:169
#define PAPI_MEM_RCY
Definition: fpapi.h:170
int EventSet
void do_flush(void)
Definition: do_loops.c:165
#define PAPI_L2_DCR
Definition: fpapi.h:203
#define PAPI_EBUG
Definition: fpapi.h:111
#define PAPI_L2_TCR
Definition: fpapi.h:227
#define PAPI_L1_DCM
Definition: fpapi.h:135
#define PAPI_L2_STM
Definition: fpapi.h:161
#define PAPI_L2_TCH
Definition: fpapi.h:221
#define PAPI_MH_TYPE_UNIFIED
Definition: papi.h:729
#define PAPI_L1_TCR
Definition: fpapi.h:226
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
#define PAPI_L1_STM
Definition: fpapi.h:159
#define PAPI_MH_TYPE_EMPTY
Definition: papi.h:724
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2469
#define PAPI_L2_ICM
Definition: fpapi.h:138
#define PAPI_L1_LDM
Definition: fpapi.h:158
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define PAPI_MH_TYPE_WT
Definition: papi.h:731
#define PAPI_L2_TCA
Definition: fpapi.h:224
long j
Definition: iozone.c:19135
#define PAPI_L2_ICR
Definition: fpapi.h:215
#define PAPI_CSR_TOT
Definition: fpapi.h:168
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
#define PAPI_L1_DCA
Definition: fpapi.h:199
#define PAPI_L2_LDM
Definition: fpapi.h:160
void exit()
#define PAPI_MH_TYPE_VECTOR
Definition: papi.h:727
#define PAPI_L2_ICH
Definition: fpapi.h:209
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:730
#define PAPI_L2_ICA
Definition: fpapi.h:212

Here is the call graph for this function: