53 long long sz = 0, lck = 0, res = 0, shr = 0, stk = 0, txt = 0, dat =
54 0, dum = 0, lib = 0, hwm = 0;
56 sprintf( fn,
"/proc/%ld/status", (
long ) getpid( ) );
65 if ( strspn(
tmp,
"VmSize:" ) == strlen(
"VmSize:" ) ) {
66 sscanf(
tmp + strlen(
"VmSize:" ),
"%lld", &
sz );
70 if ( strspn(
tmp,
"VmHWM:" ) == strlen(
"VmHWM:" ) ) {
71 sscanf(
tmp + strlen(
"VmHWM:" ),
"%lld", &hwm );
75 if ( strspn(
tmp,
"VmLck:" ) == strlen(
"VmLck:" ) ) {
76 sscanf(
tmp + strlen(
"VmLck:" ),
"%lld", &lck );
80 if ( strspn(
tmp,
"VmRSS:" ) == strlen(
"VmRSS:" ) ) {
81 sscanf(
tmp + strlen(
"VmRSS:" ),
"%lld", &res );
85 if ( strspn(
tmp,
"VmData:" ) == strlen(
"VmData:" ) ) {
86 sscanf(
tmp + strlen(
"VmData:" ),
"%lld", &dat );
90 if ( strspn(
tmp,
"VmStk:" ) == strlen(
"VmStk:" ) ) {
91 sscanf(
tmp + strlen(
"VmStk:" ),
"%lld", &stk );
95 if ( strspn(
tmp,
"VmExe:" ) == strlen(
"VmExe:" ) ) {
96 sscanf(
tmp + strlen(
"VmExe:" ),
"%lld", &txt );
100 if ( strspn(
tmp,
"VmLib:" ) == strlen(
"VmLib:" ) ) {
101 sscanf(
tmp + strlen(
"VmLib:" ),
"%lld", &lib );
108 sprintf( fn,
"/proc/%ld/statm", (
long ) getpid( ) );
109 f = fopen( fn,
"r" );
115 fscanf(
f,
"%lld %lld %lld %lld %lld %lld %lld", &dum, &dum, &shr, &dum,
134 #if defined(__i386__)||defined(__x86_64__) 146 PAPIERROR(
"Unknown vendor in memory information call for x86." );
153 #if defined(__ia64__) 155 get_number(
char *
buf )
157 char numbers[] =
"0123456789";
161 tmp = strpbrk(
buf, numbers );
164 while ( isdigit( *end ) )
176 fline( FILE *
fp,
char *rline )
183 memset( rline,
'\0', 1024 );
190 while ( isspace(
c ) ||
c ==
'\n' ||
c ==
'\r' );
199 if (
c ==
'\n' ||
c ==
'\r' )
215 int clevel = 0, cindex = -1;
221 f = fopen(
"/proc/pal/cpu0/cache_info",
"r" );
224 PAPIERROR(
"fopen(/proc/pal/cpu0/cache_info) returned < 0" );
228 while ( !feof(
f ) ) {
230 if (
buf[0] ==
'\0' )
232 if ( !strncmp(
buf,
"Data Cache", 10 ) ) {
234 clevel = get_number(
buf );
236 }
else if ( !strncmp(
buf,
"Instruction Cache", 17 ) ) {
238 clevel = get_number(
buf );
240 }
else if ( !strncmp(
buf,
"Data/Instruction Cache", 22 ) ) {
242 clevel = get_number(
buf );
245 if ( ( clevel == 0 || clevel > 3 ) && cindex >= 0 ) {
247 (
"Cache type could not be recognized, please send /proc/pal/cpu0/cache_info" );
251 if ( !strncmp(
buf,
"Size", 4 ) ) {
252 num = get_number(
buf );
254 }
else if ( !strncmp(
buf,
"Associativity", 13 ) ) {
255 num = get_number(
buf );
257 }
else if ( !strncmp(
buf,
"Line size", 9 ) ) {
258 num = get_number(
buf );
268 f = fopen(
"/proc/pal/cpu0/vm_info",
"r" );
273 while ( !feof(
f ) ) {
275 if (
buf[0] ==
'\0' )
277 if ( !strncmp(
buf,
"Data Translation", 16 ) ) {
279 clevel = get_number(
buf );
281 }
else if ( !strncmp(
buf,
"Instruction Translation", 23 ) ) {
283 clevel = get_number(
buf );
286 if ( ( clevel == 0 || clevel > 2 ) && cindex >= 0 ) {
288 (
"TLB type could not be recognized, send /proc/pal/cpu0/vm_info" );
292 if ( !strncmp(
buf,
"Number of entries", 17 ) ) {
293 num = get_number(
buf );
295 }
else if ( !strncmp(
buf,
"Associativity", 13 ) ) {
296 num = get_number(
buf );
306 for ( j = 0; j < 2; j++ ) {
316 #if defined(__powerpc__) 460 .num_entries = 64, .page_size = 0, .associativity = 2 }
463 .num_entries = 64, .page_size = 0,
464 .associativity = SHRT_MAX }
469 .size = 32768, .line_size = 128, .num_lines = 64,
473 .size = 32768, .line_size = 128, .num_lines = 32,
481 .page_size = -1, .associativity = -1 }
484 .page_size = -1, .associativity = -1 }
489 .size = 524288, .line_size = 128, .num_lines = 256,
493 .num_lines = -1, .associativity = -1 }
500 .page_size = -1, .associativity = -1 }
503 .page_size = -1, .associativity = -1 }
508 .size = 4194304, .line_size = 128, .num_lines = 4096,
512 .num_lines = -1, .associativity = -1 }
526 .num_entries = 72, .page_size = 0,
527 .associativity = SHRT_MAX }
530 .num_entries = 48, .page_size = 0,
531 .associativity = SHRT_MAX }
536 .size = 32768, .line_size = 128, .num_lines = 64,
540 .size = 65536, .line_size = 128, .num_lines = 512,
548 .page_size = 0, .associativity = 4 }
551 .page_size = -1, .associativity = -1 }
556 .size = 262144, .line_size = 128, .num_lines = 256,
560 .num_lines = -1, .associativity = -1 }
567 .page_size = -1, .associativity = -1 }
570 .page_size = -1, .associativity = -1 }
575 .size = 8388608, .line_size = 128, .num_lines = 65536,
579 .num_lines = -1, .associativity = -1 }
587 #define SPRN_PVR 0x11F 588 #define PVR_PROCESSOR_SHIFT 16 594 asm(
"mfspr %0,%1":
"=r"( pvr ):
"i"( SPRN_PVR ) );
602 unsigned int pvr = mfpvr( ) >> PVR_PROCESSOR_SHIFT;
638 for ( cache_level = 0; cache_level < sys_mh_inf.
levels; cache_level++ ) {
639 sys_mh_level = sys_mh_inf.
level[cache_level];
641 for ( cache_idx = 0; cache_idx < 2; cache_idx++ ) {
644 int type = curr_tlb.
type;
646 level[cache_level].
tlb[cache_idx].
type = type;
653 for ( cache_idx = 0; cache_idx < 2; cache_idx++ ) {
656 int type = curr_cache.
type;
658 level[cache_level].
cache[cache_idx].
type = type;
676 #if defined(__sparc__) 678 sparc_sysfs_cpu_attr(
char *
name,
char **result )
680 const char *path_base =
"/sys/devices/system/cpu/";
685 sys_cpu = opendir( path_base );
689 while ( ( cpu = readdir( sys_cpu ) ) != NULL ) {
692 if ( strncmp(
"cpu", cpu->d_name, 3 ) )
694 strcpy( path_buf, path_base );
695 strcat( path_buf, cpu->d_name );
696 strcat( path_buf,
"/" );
697 strcat( path_buf,
name );
699 fd =
open( path_buf, O_RDONLY );
703 if (
read(
fd, val_buf, 32 ) < 0 )
707 *result = strdup( val_buf );
716 sparc_cpu_attr(
char *
name,
unsigned long long *
val )
721 r = sparc_sysfs_cpu_attr(
name, &
buf );
725 sscanf(
buf,
"%llu",
val );
741 while ( fgets( line, 256,
f ) != NULL ) {
742 if ( strstr( line, search_str ) != NULL ) {
744 for (
s = line; *
s && ( *
s !=
':' ); ++
s );
770 f = fopen(
"/proc/cpuinfo",
"r" );
781 t = strchr(
s + 2,
'\n' );
808 sparc_cpu_attr(
"l1_icache_size", &
cache_size );
816 sparc_cpu_attr(
"l1_dcache_size", &
cache_size );
824 sparc_cpu_attr(
"l2_cache_size", &
cache_size );
835 case PFMLIB_SPARC_ULTRA12_PMU:
837 tlb[0].num_entries = 64;
838 tlb[0].associativity = SHRT_MAX;
840 tlb[1].num_entries = 64;
841 tlb[1].associativity = SHRT_MAX;
844 case PFMLIB_SPARC_ULTRA3_PMU:
845 case PFMLIB_SPARC_ULTRA3I_PMU:
846 case PFMLIB_SPARC_ULTRA3PLUS_PMU:
847 case PFMLIB_SPARC_ULTRA4PLUS_PMU:
853 tlb[0].num_entries = 16;
854 tlb[0].associativity = SHRT_MAX;
856 tlb[1].num_entries = 16;
857 tlb[1].associativity = SHRT_MAX;
859 tlb[2].num_entries = 1024;
860 tlb[2].associativity = 2;
862 tlb[3].num_entries = 128;
863 tlb[3].associativity = 2;
866 case PFMLIB_SPARC_NIAGARA1:
872 tlb[0].num_entries = 64;
873 tlb[0].associativity = SHRT_MAX;
875 tlb[1].num_entries = 64;
876 tlb[1].associativity = SHRT_MAX;
879 case PFMLIB_SPARC_NIAGARA2:
885 tlb[0].num_entries = 64;
886 tlb[0].associativity = SHRT_MAX;
888 tlb[1].num_entries = 128;
889 tlb[1].associativity = SHRT_MAX;
903 int type=0,level,result;
904 int size,line_size,associativity,sets;
907 char filename[BUFSIZ],type_string[BUFSIZ];
910 int level_count=0,last_level=-1,level_index=0;
918 dir=opendir(
"/sys/devices/system/cpu/cpu0/cache");
920 goto unrecoverable_error;
927 if (strncmp(d->d_name,
"index", 5))
continue;
929 MEMDBG(
"Found %s\n",d->d_name);
935 "/sys/devices/system/cpu/cpu0/cache/%s/level",
939 MEMDBG(
"Cannot open level.\n");
940 goto unrecoverable_error;
943 result=fscanf(
fff,
"%d",&level);
946 MEMDBG(
"Could not read cache level\n");
947 goto unrecoverable_error;
953 if (level!=last_level) {
961 MEMDBG(
"Exceeded maximum levels %d\n",
970 "/sys/devices/system/cpu/cpu0/cache/%s/type",d->d_name);
973 MEMDBG(
"Cannot open type\n");
974 goto unrecoverable_error;
976 result=fscanf(
fff,
"%s",type_string);
979 MEMDBG(
"Could not read cache type\n");
980 goto unrecoverable_error;
982 if (!strcmp(type_string,
"Data")) {
985 if (!strcmp(type_string,
"Instruction")) {
988 if (!strcmp(type_string,
"Unified")) {
991 L[level_index].
cache[level_count].
type=type;
997 "/sys/devices/system/cpu/cpu0/cache/%s/size",d->d_name);
1000 MEMDBG(
"Cannot open size\n");
1001 goto unrecoverable_error;
1003 result=fscanf(
fff,
"%d",&size);
1006 MEMDBG(
"Could not read cache size\n");
1007 goto unrecoverable_error;
1011 L[level_index].
cache[level_count].
size=size*1024;
1017 "/sys/devices/system/cpu/cpu0/cache/%s/coherency_line_size",
1021 MEMDBG(
"Cannot open linesize\n");
1022 goto unrecoverable_error;
1024 result=fscanf(
fff,
"%d",&line_size);
1027 MEMDBG(
"Could not read cache line-size\n");
1028 goto unrecoverable_error;
1037 "/sys/devices/system/cpu/cpu0/cache/%s/ways_of_associativity",
1041 MEMDBG(
"Cannot open associativity\n");
1042 goto unrecoverable_error;
1044 result=fscanf(
fff,
"%d",&associativity);
1047 MEMDBG(
"Could not read cache associativity\n");
1048 goto unrecoverable_error;
1056 "/sys/devices/system/cpu/cpu0/cache/%s/number_of_sets",
1060 MEMDBG(
"Cannot open sets\n");
1061 goto unrecoverable_error;
1063 result=fscanf(
fff,
"%d",&sets);
1067 MEMDBG(
"Could not read cache sets\n");
1068 goto unrecoverable_error;
1073 if (((size*1024)/line_size/associativity)!=sets) {
1074 MEMDBG(
"Warning! sets %d != expected %d\n",
1075 sets,((size*1024)/line_size/associativity));
1078 MEMDBG(
"\tL%d %s cache\n",level,type_string);
1079 MEMDBG(
"\t%d kilobytes\n",size);
1080 MEMDBG(
"\t%d byte linesize\n",line_size);
1081 MEMDBG(
"\t%d-way associative\n",associativity);
1082 MEMDBG(
"\t%d lines\n",sets);
1083 MEMDBG(
"\tUnknown inclusivity\n");
1084 MEMDBG(
"\tUnknown replacement algorithm\n");
1085 MEMDBG(
"\tUnknown if victim cache\n");
1087 if (level>max_level) max_level=level;
1090 MEMDBG(
"Exceeded maximum cache level %d\n",
1100 unrecoverable_error:
1115 #if defined(__i386__)||defined(__x86_64__) 1116 x86_get_memory_info( hwinfo );
1117 #elif defined(__ia64__) 1118 ia64_get_memory_info( hwinfo );
1119 #elif defined(__powerpc__) 1120 ppc64_get_memory_info( hwinfo );
1121 #elif defined(__sparc__) 1122 sparc_get_memory_info( hwinfo );
1123 #elif defined(__arm__) 1124 #warning "WARNING! linux_get_memory_info() does nothing on ARM32!" 1138 unsigned long t_index = 0, d_index = 0, b_index = 0, counting = 1;
1141 unsigned long begin = 0, end = 0, size = 0, inode = 0, foo = 0;
1145 memset( fname, 0x0,
sizeof ( fname ) );
1146 memset(
buf, 0x0,
sizeof (
buf ) );
1147 memset( perm, 0x0,
sizeof ( perm ) );
1148 memset( dev, 0x0,
sizeof ( dev ) );
1149 memset( mapname, 0x0,
sizeof ( mapname ) );
1150 memset( lastmapname, 0x0,
sizeof ( lastmapname ) );
1152 sprintf( fname,
"/proc/%ld/maps", (
long ) mdi->
pid );
1153 f = fopen( fname,
"r" );
1156 PAPIERROR(
"fopen(%s) returned < 0", fname );
1161 while ( !feof(
f ) ) {
1162 begin = end = size = inode = foo = 0;
1163 if ( fgets(
buf,
sizeof (
buf ),
f ) == 0 )
1166 if ( strlen( mapname ) )
1167 strcpy( lastmapname, mapname );
1169 lastmapname[0] =
'\0';
1172 sscanf(
buf,
"%lx-%lx %4s %lx %s %ld %s", &
begin, &end, perm, &foo, dev,
1181 if ( ( perm[2] ==
'x' ) && ( perm[0] ==
'r' ) && ( inode != 0 ) ) {
1190 }
else if ( ( perm[0] ==
'r' ) && ( perm[1] ==
'w' ) &&
1195 mapname ) == 0 ) ) {
1201 }
else if ( ( perm[0] ==
'r' ) && ( perm[1] ==
'w' ) &&
1206 lastmapname ) == 0 ) ) {
1213 }
else if ( !counting ) {
1214 if ( ( perm[2] ==
'x' ) && ( perm[0] ==
'r' ) && ( inode != 0 ) ) {
1222 }
else if ( ( perm[0] ==
'r' ) && ( perm[1] ==
'w' ) &&
1227 && ( t_index > 0 ) &&
1228 (
tmp[t_index - 1].data_start == 0 ) ) {
1232 }
else if ( ( perm[0] ==
'r' ) && ( perm[1] ==
'w' ) &&
1234 if ( ( t_index > 0 ) && (
tmp[t_index - 1].bss_start == 0 ) ) {
1250 if (
tmp == NULL ) {
1251 PAPIERROR(
"Error allocating shared library address map" );
ssize_t read(int fd, void *buf, size_t count)
unsigned long cache_line_size
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
#define PAPI_MH_TYPE_INST
PAPI_mh_info_t mem_hierarchy
static char * search_cpu_info(FILE *f, char *search_str, char *line)
static int _perfmon2_pfm_pmu_type
char filename[MAXNAMESIZE]
#define PAPI_MH_TYPE_PSEUDO_LRU
#define PAPI_MH_MAX_LEVELS
PAPI_shlib_info_t shlib_info
Return codes and api definitions.
#define PAPI_MH_TYPE_DATA
int _linux_update_shlib_info(papi_mdi_t *mdi)
int open(const char *pathname, int flags, mode_t mode)
int _x86_cache_info(PAPI_mh_info_t *mh_info)
int _linux_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
A pointer to the following is passed to PAPI_get_dmem_info()
PAPI_address_map_t address_info
#define PAPI_HUGE_STR_LEN
char model_string[PAPI_MAX_STR_LEN]
get the executable's address space info
void PAPIERROR(char *format,...)
#define MEMDBG(format, args...)
int _linux_get_dmem_info(PAPI_dmem_info_t *d)
mh for mem hierarchy maybe?
char vendor_string[PAPI_MAX_STR_LEN]
#define PAPI_VENDOR_INTEL
PAPI_mh_cache_info_t cache[PAPI_MH_MAX_LEVELS]
int generic_get_memory_info(PAPI_hw_info_t *hw_info)
#define PAPI_MH_TYPE_UNIFIED
PAPI_mh_tlb_info_t tlb[PAPI_MH_MAX_LEVELS]
#define PAPI_MH_TYPE_EMPTY
char fullname[PAPI_HUGE_STR_LEN]
static const PAPI_hw_info_t * hw_info
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
#define papi_calloc(a, b)
#define PAPI_MAX_MEM_HIERARCHY_LEVELS
long long high_water_mark