PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mem_info.c
Go to the documentation of this file.
1 /*
2  * This file perfoms the following test: memory info
3  *
4  * Author: Kevin London
5  * london@cs.utk.edu
6  */
29 #include "papi_test.h"
30 extern int TESTS_QUIET; /*Declared in test_utils.c */
31 
32 int
33 main( int argc, char **argv )
34 {
35  const PAPI_hw_info_t *meminfo = NULL;
36  PAPI_mh_level_t *L;
37  int i, j, retval;
38 
39  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
41  if ( retval != PAPI_VER_CURRENT )
42  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43 
44  if ( ( meminfo = PAPI_get_hardware_info( ) ) == NULL )
45  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
46 
47  if ( !TESTS_QUIET ) {
48  printf( "Memory Cache and TLB Hierarchy Information.\n" );
49  printf
50  ( "------------------------------------------------------------------------\n" );
51  /* Extract and report the tlb and cache information */
52  L = ( PAPI_mh_level_t * ) & ( meminfo->mem_hierarchy.level[0] );
53  printf
54  ( "TLB Information.\n There may be multiple descriptors for each level of TLB\n" );
55  printf( " if multiple page sizes are supported.\n\n" );
56  /* Scan the TLB structures */
57  for ( i = 0; i < meminfo->mem_hierarchy.levels; i++ ) {
58  for ( j = 0; j < PAPI_MH_MAX_LEVELS; j++ ) {
59  switch ( PAPI_MH_CACHE_TYPE( L[i].tlb[j].type ) ) {
61  printf( "L%d Unified TLB:\n", i + 1 );
62  break;
63  case PAPI_MH_TYPE_DATA:
64  printf( "L%d Data TLB:\n", i + 1 );
65  break;
66  case PAPI_MH_TYPE_INST:
67  printf( "L%d Instruction TLB:\n", i + 1 );
68  break;
69  }
70  if ( L[i].tlb[j].type ) {
71  if ( L[i].tlb[j].page_size )
72  printf( " Page Size: %6d KB\n",
73  L[i].tlb[j].page_size >> 10 );
74  printf( " Number of Entries: %6d\n",
75  L[i].tlb[j].num_entries );
76  switch ( L[i].tlb[j].associativity ) {
77  case 0: /* undefined */
78  break;
79  case 1:
80  printf( " Associativity: Direct Mapped\n\n" );
81  break;
82  case SHRT_MAX:
83  printf( " Associativity: Full\n\n" );
84  break;
85  default:
86  printf( " Associativity: %6d\n\n",
87  L[i].tlb[j].associativity );
88  break;
89  }
90  }
91  }
92  }
93  /* Scan the Cache structures */
94  printf( "\nCache Information.\n\n" );
95  for ( i = 0; i < meminfo->mem_hierarchy.levels; i++ ) {
96  for ( j = 0; j < 2; j++ ) {
97  switch ( PAPI_MH_CACHE_TYPE( L[i].cache[j].type ) ) {
99  printf( "L%d Unified Cache:\n", i + 1 );
100  break;
101  case PAPI_MH_TYPE_DATA:
102  printf( "L%d Data Cache:\n", i + 1 );
103  break;
104  case PAPI_MH_TYPE_INST:
105  printf( "L%d Instruction Cache:\n", i + 1 );
106  break;
107  case PAPI_MH_TYPE_TRACE:
108  printf( "L%d Trace Buffer:\n", i + 1 );
109  break;
110  case PAPI_MH_TYPE_VECTOR:
111  printf( "L%d Vector Cache:\n", i + 1 );
112  break;
113  }
114  if ( L[i].cache[j].type ) {
115  printf
116  ( " Total size: %6d KB\n Line size: %6d B\n Number of Lines: %6d\n Associativity: %6d\n\n",
117  ( L[i].cache[j].size ) >> 10, L[i].cache[j].line_size,
118  L[i].cache[j].num_lines,
119  L[i].cache[j].associativity );
120  }
121  }
122  }
123  }
124  test_pass( __FILE__, NULL, 0 );
125  exit( 1 );
126 }
int levels
Definition: papi.h:769
Hardware info structure.
Definition: papi.h:775
#define PAPI_MH_TYPE_INST
Definition: papi.h:725
PAPI_mh_info_t mem_hierarchy
Definition: papi.h:794
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
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 TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
long long page_size
Definition: iozone.c:428
char *long long size
Definition: iozone.c:12023
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Definition: papi.h:770
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_MH_TYPE_UNIFIED
Definition: papi.h:729
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
#define PAPI_MH_TYPE_VECTOR
Definition: papi.h:727
#define PAPI_MH_MAX_LEVELS
Definition: fpapi.h:87
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:730