PAPI 7.1.0.0
Loading...
Searching...
No Matches
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;
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;
73 printf( "L%d Data TLB:\n", i + 1 );
74 break;
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;
112 printf( "L%d Data Cache:\n", i + 1 );
113 break;
115 printf( "L%d Instruction Cache:\n", i + 1 );
116 break;
118 printf( "L%d Trace Buffer:\n", i + 1 );
119 break;
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 i
get information about the system hardware
initialize the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
uint16_t type
#define PAPI_MH_TYPE_DATA
Definition: papi.h:720
#define PAPI_MH_MAX_LEVELS
Definition: papi.h:739
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:724
#define PAPI_MH_TYPE_INST
Definition: papi.h:719
#define PAPI_MH_TYPE_VECTOR
Definition: papi.h:721
#define PAPI_MH_TYPE_TRACE
Definition: papi.h:722
#define PAPI_MH_TYPE_UNIFIED
Definition: papi.h:723
FILE * stderr
Hardware info structure.
Definition: papi.h:774
PAPI_mh_info_t mem_hierarchy
Definition: papi.h:793
int levels
Definition: papi.h:768
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Definition: papi.h:769
int retval
Definition: zero_fork.c:53