PAPI  5.7.0.0
papi_mem_info.c File Reference
Include dependency graph for papi_mem_info.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 37 of file papi_mem_info.c.

38 {
39  const PAPI_hw_info_t *meminfo = NULL;
40  PAPI_mh_level_t *L;
41  int i, j, retval;
42 
43  (void)argc;
44  (void)argv;
45 
47  if ( retval != PAPI_VER_CURRENT ) {
48  fprintf(stderr,"Error! PAPI_library_init\n");
49  return retval;
50  }
51 
52  meminfo = PAPI_get_hardware_info( );
53  if (meminfo == NULL ) {
54  fprintf(stderr,"Error! PAPI_get_hardware_info");
55  return 2;
56  }
57 
58  printf( "Memory Cache and TLB Hierarchy Information.\n" );
59  printf( "------------------------------------------------------------------------\n" );
60 
61  /* Extract and report the tlb and cache information */
62  L = ( PAPI_mh_level_t * ) & ( meminfo->mem_hierarchy.level[0] );
63  printf( "TLB Information.\n There may be multiple descriptors for each level of TLB\n" );
64  printf( " if multiple page sizes are supported.\n\n" );
65  /* Scan the TLB structures */
66  for ( i = 0; i < meminfo->mem_hierarchy.levels; i++ ) {
67  for ( j = 0; j < PAPI_MH_MAX_LEVELS; j++ ) {
68  switch ( PAPI_MH_CACHE_TYPE( L[i].tlb[j].type ) ) {
70  printf( "L%d Unified TLB:\n", i + 1 );
71  break;
72  case PAPI_MH_TYPE_DATA:
73  printf( "L%d Data TLB:\n", i + 1 );
74  break;
75  case PAPI_MH_TYPE_INST:
76  printf( "L%d Instruction TLB:\n", i + 1 );
77  break;
78  }
79  if ( L[i].tlb[j].type ) {
80  if ( L[i].tlb[j].page_size )
81  printf( " Page Size: %6d KB\n",
82  L[i].tlb[j].page_size >> 10 );
83  printf( " Number of Entries: %6d\n",
84  L[i].tlb[j].num_entries );
85  switch ( L[i].tlb[j].associativity ) {
86  case 0: /* undefined */
87  break;
88  case 1:
89  printf( " Associativity: Direct Mapped\n\n" );
90  break;
91  case SHRT_MAX:
92  printf( " Associativity: Full\n\n" );
93  break;
94  default:
95  printf( " Associativity: %6d\n\n",
96  L[i].tlb[j].associativity );
97  break;
98  }
99  }
100  }
101  }
102 
103  /* Scan the Cache structures */
104  printf( "\nCache Information.\n\n" );
105  for ( i = 0; i < meminfo->mem_hierarchy.levels; i++ ) {
106  for ( j = 0; j < 2; j++ ) {
107  switch ( PAPI_MH_CACHE_TYPE( L[i].cache[j].type ) ) {
109  printf( "L%d Unified Cache:\n", i + 1 );
110  break;
111  case PAPI_MH_TYPE_DATA:
112  printf( "L%d Data Cache:\n", i + 1 );
113  break;
114  case PAPI_MH_TYPE_INST:
115  printf( "L%d Instruction Cache:\n", i + 1 );
116  break;
117  case PAPI_MH_TYPE_TRACE:
118  printf( "L%d Trace Buffer:\n", i + 1 );
119  break;
120  case PAPI_MH_TYPE_VECTOR:
121  printf( "L%d Vector Cache:\n", i + 1 );
122  break;
123  }
124  if ( L[i].cache[j].type ) {
125  printf( " Total size: %6d KB\n Line size: %6d B\n Number of Lines: %6d\n Associativity: %6d\n\n",
126  ( L[i].cache[j].size ) >> 10, L[i].cache[j].line_size,
127  L[i].cache[j].num_lines,
128  L[i].cache[j].associativity );
129  }
130  }
131  }
132 
133  return 0;
134 }
int levels
Definition: papi.h:775
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Definition: papi.h:776
Hardware info structure.
Definition: papi.h:781
#define PAPI_MH_TYPE_INST
Definition: papi.h:731
PAPI_mh_info_t mem_hierarchy
Definition: papi.h:800
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
#define PAPI_MH_MAX_LEVELS
Definition: fpapi.h:87
#define PAPI_MH_TYPE_TRACE
Definition: papi.h:734
#define PAPI_MH_TYPE_DATA
Definition: papi.h:732
int PAPI_library_init(int version)
Definition: papi.c:500
long long page_size
Definition: iozone.c:428
#define PAPI_MH_TYPE_UNIFIED
Definition: papi.h:735
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
#define PAPI_MH_TYPE_VECTOR
Definition: papi.h:733
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:736
int i
Definition: fileop.c:140
Here is the call graph for this function: