52 char fn[PATH_MAX],
tmp[PATH_MAX];
55 long long sz = 0, lck = 0, res = 0, shr = 0, stk = 0, txt = 0, dat =
56 0, dum = 0, lib = 0, hwm = 0;
58 sprintf( fn,
"/proc/%ld/status", (
long ) getpid( ) );
65 if ( fgets(
tmp, PATH_MAX,
f ) == NULL )
67 if ( strspn(
tmp,
"VmSize:" ) == strlen(
"VmSize:" ) ) {
68 sscanf(
tmp + strlen(
"VmSize:" ),
"%lld", &sz );
72 if ( strspn(
tmp,
"VmHWM:" ) == strlen(
"VmHWM:" ) ) {
73 sscanf(
tmp + strlen(
"VmHWM:" ),
"%lld", &hwm );
77 if ( strspn(
tmp,
"VmLck:" ) == strlen(
"VmLck:" ) ) {
78 sscanf(
tmp + strlen(
"VmLck:" ),
"%lld", &lck );
82 if ( strspn(
tmp,
"VmRSS:" ) == strlen(
"VmRSS:" ) ) {
83 sscanf(
tmp + strlen(
"VmRSS:" ),
"%lld", &res );
87 if ( strspn(
tmp,
"VmData:" ) == strlen(
"VmData:" ) ) {
88 sscanf(
tmp + strlen(
"VmData:" ),
"%lld", &dat );
92 if ( strspn(
tmp,
"VmStk:" ) == strlen(
"VmStk:" ) ) {
93 sscanf(
tmp + strlen(
"VmStk:" ),
"%lld", &stk );
97 if ( strspn(
tmp,
"VmExe:" ) == strlen(
"VmExe:" ) ) {
98 sscanf(
tmp + strlen(
"VmExe:" ),
"%lld", &txt );
102 if ( strspn(
tmp,
"VmLib:" ) == strlen(
"VmLib:" ) ) {
103 sscanf(
tmp + strlen(
"VmLib:" ),
"%lld", &lib );
110 sprintf( fn,
"/proc/%ld/statm", (
long ) getpid( ) );
111 f = fopen( fn,
"r" );
117 fscanf(
f,
"%lld %lld %lld %lld %lld %lld %lld", &dum, &dum, &shr, &dum,
120 PAPIERROR(
"fscanf(7 items): %d\n", ret );
136#if defined(__i386__)||defined(__x86_64__)
148 PAPIERROR(
"Unknown vendor in memory information call for x86." );
157get_number(
char *
buf )
159 char numbers[] =
"0123456789";
163 tmp = strpbrk(
buf, numbers );
166 while ( isdigit( *end ) )
178fline( FILE *
fp,
char *rline )
185 memset( rline,
'\0', 1024 );
192 while ( isspace(
c ) ||
c ==
'\n' ||
c ==
'\r' );
201 if (
c ==
'\n' ||
c ==
'\r' )
217 int clevel = 0, cindex = -1;
223 f = fopen(
"/proc/pal/cpu0/cache_info",
"r" );
226 PAPIERROR(
"fopen(/proc/pal/cpu0/cache_info) returned < 0" );
230 while ( !feof(
f ) ) {
232 if (
buf[0] ==
'\0' )
234 if ( !strncmp(
buf,
"Data Cache", 10 ) ) {
238 }
else if ( !strncmp(
buf,
"Instruction Cache", 17 ) ) {
242 }
else if ( !strncmp(
buf,
"Data/Instruction Cache", 22 ) ) {
249 (
"Cache type could not be recognized, please send /proc/pal/cpu0/cache_info" );
253 if ( !strncmp(
buf,
"Size", 4 ) ) {
254 num = get_number(
buf );
256 }
else if ( !strncmp(
buf,
"Associativity", 13 ) ) {
257 num = get_number(
buf );
259 }
else if ( !strncmp(
buf,
"Line size", 9 ) ) {
260 num = get_number(
buf );
270 f = fopen(
"/proc/pal/cpu0/vm_info",
"r" );
275 while ( !feof(
f ) ) {
277 if (
buf[0] ==
'\0' )
279 if ( !strncmp(
buf,
"Data Translation", 16 ) ) {
283 }
else if ( !strncmp(
buf,
"Instruction Translation", 23 ) ) {
290 (
"TLB type could not be recognized, send /proc/pal/cpu0/vm_info" );
294 if ( !strncmp(
buf,
"Number of entries", 17 ) ) {
295 num = get_number(
buf );
297 }
else if ( !strncmp(
buf,
"Associativity", 13 ) ) {
298 num = get_number(
buf );
308 for ( j = 0; j < 2; j++ ) {
318#if defined(__powerpc__)
462 .num_entries = 64, .page_size = 0, .associativity = 2 }
465 .num_entries = 64, .page_size = 0,
466 .associativity = SHRT_MAX }
471 .size = 32768, .line_size = 128, .num_lines = 64,
475 .size = 32768, .line_size = 128, .num_lines = 32,
483 .page_size = -1, .associativity = -1 }
486 .page_size = -1, .associativity = -1 }
491 .size = 524288, .line_size = 128, .num_lines = 256,
495 .num_lines = -1, .associativity = -1 }
502 .page_size = -1, .associativity = -1 }
505 .page_size = -1, .associativity = -1 }
510 .size = 4194304, .line_size = 128, .num_lines = 4096,
514 .num_lines = -1, .associativity = -1 }
528 .num_entries = 72, .page_size = 0,
529 .associativity = SHRT_MAX }
532 .num_entries = 48, .page_size = 0,
533 .associativity = SHRT_MAX }
538 .size = 32768, .line_size = 128, .num_lines = 64,
542 .size = 65536, .line_size = 128, .num_lines = 512,
550 .page_size = 0, .associativity = 4 }
553 .page_size = -1, .associativity = -1 }
558 .size = 262144, .line_size = 128, .num_lines = 256,
562 .num_lines = -1, .associativity = -1 }
569 .page_size = -1, .associativity = -1 }
572 .page_size = -1, .associativity = -1 }
577 .size = 8388608, .line_size = 128, .num_lines = 65536,
581 .num_lines = -1, .associativity = -1 }
595 .num_entries = 64, .page_size = 0,
596 .associativity = SHRT_MAX }
599 .num_entries = 64, .page_size = 0,
600 .associativity = SHRT_MAX }
605 .size = 32768, .line_size = 128, .num_lines = 256,
609 .size = 32768, .line_size = 128, .num_lines = 256,
617 .page_size = 0, .associativity = 4 }
620 .page_size = -1, .associativity = -1 }
625 .size = 524288, .line_size = 128, .num_lines = 4096,
629 .num_lines = -1, .associativity = -1 }
636 .page_size = -1, .associativity = -1 }
639 .page_size = -1, .associativity = -1 }
644 .size = 10485760, .line_size = 128, .num_lines = 81920,
645 .associativity = 20 }
648 .num_lines = -1, .associativity = -1 }
662 .num_entries = 64, .page_size = 0,
663 .associativity = SHRT_MAX }
666 .num_entries = 64, .page_size = 0,
667 .associativity = SHRT_MAX }
672 .size = 49152, .line_size = 128, .num_lines = 384,
676 .size = 32768, .line_size = 128, .num_lines = 256,
684 .page_size = 0, .associativity = 4 }
687 .page_size = -1, .associativity = -1 }
692 .size = 1048576, .line_size = 128, .num_lines = 8192,
696 .num_lines = -1, .associativity = -1 }
703 .page_size = -1, .associativity = -1 }
706 .page_size = -1, .associativity = -1 }
711 .size = 4194304, .line_size = 128, .num_lines = 32768,
712 .associativity = 16 }
715 .num_lines = -1, .associativity = -1 }
723#define SPRN_PVR 0x11F
724#define PVR_PROCESSOR_SHIFT 16
730 asm(
"mfspr %0,%1":
"=r"( pvr ):
"i"(
SPRN_PVR ) );
780 for ( cache_level = 0; cache_level < sys_mh_inf.
levels; cache_level++ ) {
781 sys_mh_level = sys_mh_inf.
level[cache_level];
783 for ( cache_idx = 0; cache_idx < 2; cache_idx++ ) {
795 for ( cache_idx = 0; cache_idx < 2; cache_idx++ ) {
818#if defined(__sparc__)
820sparc_sysfs_cpu_attr(
char *
name,
char **
result )
822 const char *path_base =
"/sys/devices/system/cpu/";
823 char path_buf[PATH_MAX];
827 sys_cpu = opendir( path_base );
831 while ( ( cpu = readdir( sys_cpu ) ) != NULL ) {
834 if ( strncmp(
"cpu", cpu->d_name, 3 ) )
836 strcpy( path_buf, path_base );
837 strcat( path_buf, cpu->d_name );
838 strcat( path_buf,
"/" );
839 strcat( path_buf,
name );
841 fd =
open( path_buf, O_RDONLY );
845 if (
read( fd, val_buf, 32 ) < 0 )
849 *
result = strdup( val_buf );
858sparc_cpu_attr(
char *
name,
unsigned long long *val )
863 r = sparc_sysfs_cpu_attr(
name, &
buf );
867 sscanf(
buf,
"%llu", val );
883 while ( fgets( line, 256,
f ) != NULL ) {
884 if ( strstr( line, search_str ) != NULL ) {
886 for (
s = line; *
s && ( *
s !=
':' ); ++
s );
900 unsigned long long cache_size, cache_line_size;
912 f = fopen(
"/proc/cpuinfo",
"r" );
923 t = strchr(
s + 2,
'\n' );
950 sparc_cpu_attr(
"l1_icache_size", &cache_size );
951 sparc_cpu_attr(
"l1_icache_line_size", &cache_line_size );
958 sparc_cpu_attr(
"l1_dcache_size", &cache_size );
959 sparc_cpu_attr(
"l1_dcache_line_size", &cache_line_size );
966 sparc_cpu_attr(
"l2_cache_size", &cache_size );
967 sparc_cpu_attr(
"l2_cache_line_size", &cache_line_size );
979 tlb[0].num_entries = 64;
980 tlb[0].associativity = SHRT_MAX;
982 tlb[1].num_entries = 64;
983 tlb[1].associativity = SHRT_MAX;
995 tlb[0].num_entries = 16;
996 tlb[0].associativity = SHRT_MAX;
998 tlb[1].num_entries = 16;
999 tlb[1].associativity = SHRT_MAX;
1001 tlb[2].num_entries = 1024;
1002 tlb[2].associativity = 2;
1004 tlb[3].num_entries = 128;
1005 tlb[3].associativity = 2;
1008 case PFMLIB_SPARC_NIAGARA1:
1014 tlb[0].num_entries = 64;
1015 tlb[0].associativity = SHRT_MAX;
1017 tlb[1].num_entries = 64;
1018 tlb[1].associativity = SHRT_MAX;
1021 case PFMLIB_SPARC_NIAGARA2:
1027 tlb[0].num_entries = 64;
1028 tlb[0].associativity = SHRT_MAX;
1030 tlb[1].num_entries = 128;
1031 tlb[1].associativity = SHRT_MAX;
1040#if defined(__aarch64__)
1048 .num_entries = 16, .page_size = 65536,
1049 .associativity = SHRT_MAX }
1052 .num_entries = 16, .page_size = 65536,
1053 .associativity = SHRT_MAX }
1058 .size = 65536, .line_size = 256, .num_lines = 64,
1059 .associativity = 4 }
1062 .size = 65536, .line_size = 256, .num_lines = 64,
1063 .associativity = 4 }
1070 .page_size = 65536, .associativity = 4 }
1073 .page_size = 65536, .associativity = 4 }
1078 .size = 8388608, .line_size = 256, .num_lines = 2048,
1079 .associativity = 16 }
1082 .num_lines = -1, .associativity = -1 }
1090#define IMPLEMENTER_FUJITSU 0x46
1091#define PARTNUM_FUJITSU_A64FX 0x001
1096 unsigned int implementer, partnum;
1102 switch ( implementer ) {
1103 case IMPLEMENTER_FUJITSU:
1104 switch ( partnum ) {
1105 case PARTNUM_FUJITSU_A64FX:
1118 if ( index != -1 ) {
1125 for ( cache_level = 0; cache_level < sys_mh_inf.
levels; cache_level++ ) {
1126 sys_mh_level = sys_mh_inf.
level[cache_level];
1128 for ( cache_idx = 0; cache_idx < 2; cache_idx++ ) {
1140 for ( cache_idx = 0; cache_idx < 2; cache_idx++ ) {
1168 int size,line_size,associativity,sets;
1169 int write_policy,allocation_policy;
1172 char filename[BUFSIZ],type_string[BUFSIZ];
1174 char write_policy_string[BUFSIZ],allocation_policy_string[BUFSIZ];
1177 int level_count,level_index;
1185 dir=opendir(
"/sys/devices/system/cpu/cpu0/cache");
1187 goto unrecoverable_error;
1200 if (strncmp(d->d_name,
"index", 5))
continue;
1202 MEMDBG(
"Found %s\n",d->d_name);
1208 "/sys/devices/system/cpu/cpu0/cache/%s/level",
1210 fff=fopen(filename,
"r");
1212 MEMDBG(
"Cannot open level.\n");
1213 goto unrecoverable_error;
1219 MEMDBG(
"Could not read cache level\n");
1220 goto unrecoverable_error;
1224 level_index=level-1;
1235 MEMDBG(
"Exceeded maximum levels %d\n",
1244 "/sys/devices/system/cpu/cpu0/cache/%s/type",d->d_name);
1245 fff=fopen(filename,
"r");
1247 MEMDBG(
"Cannot open type\n");
1248 goto unrecoverable_error;
1250 str_result=fgets(type_string, BUFSIZ,
fff);
1252 if (str_result==NULL) {
1253 MEMDBG(
"Could not read cache type\n");
1254 goto unrecoverable_error;
1256 if (!strcmp(type_string,
"Data")) {
1259 if (!strcmp(type_string,
"Instruction")) {
1262 if (!strcmp(type_string,
"Unified")) {
1271 "/sys/devices/system/cpu/cpu0/cache/%s/write_policy",d->d_name);
1272 fff=fopen(filename,
"r");
1274 MEMDBG(
"Cannot open write_policy\n");
1275 goto get_allocation_policy;
1277 str_result=fgets(write_policy_string, BUFSIZ,
fff);
1279 if (str_result==NULL) {
1280 MEMDBG(
"Could not read cache write_policy\n");
1281 goto get_allocation_policy;
1283 if (!strcmp(write_policy_string,
"WriteThrough")) {
1286 if (!strcmp(write_policy_string,
"WriteBack")) {
1290get_allocation_policy:
1295 allocation_policy=0;
1297 "/sys/devices/system/cpu/cpu0/cache/%s/allocation_policy",d->d_name);
1298 fff=fopen(filename,
"r");
1300 MEMDBG(
"Cannot open allocation_policy\n");
1303 str_result=fgets(allocation_policy_string, BUFSIZ,
fff);
1305 if (str_result==NULL) {
1306 MEMDBG(
"Could not read cache allocation_policy\n");
1309 if (!strcmp(allocation_policy_string,
"ReadAllocate")) {
1312 if (!strcmp(allocation_policy_string,
"WriteAllocate")) {
1315 if (!strcmp(allocation_policy_string,
"ReadWriteAllocate")) {
1320 L[level_index].
cache[level_count].
type=
type | write_policy | allocation_policy;
1326 "/sys/devices/system/cpu/cpu0/cache/%s/size",d->d_name);
1327 fff=fopen(filename,
"r");
1329 MEMDBG(
"Cannot open size\n");
1330 goto unrecoverable_error;
1335 MEMDBG(
"Could not read cache size\n");
1336 goto unrecoverable_error;
1340 L[level_index].
cache[level_count].
size=size*1024;
1348 "/sys/devices/system/cpu/cpu0/cache/%s/coherency_line_size",
1350 fff=fopen(filename,
"r");
1352 MEMDBG(
"Cannot open linesize\n");
1358 MEMDBG(
"Could not read cache line-size\n");
1371 "/sys/devices/system/cpu/cpu0/cache/%s/ways_of_associativity",
1373 fff=fopen(filename,
"r");
1375 MEMDBG(
"Cannot open associativity\n");
1381 MEMDBG(
"Could not read cache associativity\n");
1394 "/sys/devices/system/cpu/cpu0/cache/%s/number_of_sets",
1396 fff=fopen(filename,
"r");
1398 MEMDBG(
"Cannot open sets\n");
1405 MEMDBG(
"Could not read cache sets\n");
1413 if ((line_size!=0) && (associativity!=0)) {
1414 if (((size*1024)/line_size/associativity)!=sets) {
1415 MEMDBG(
"Warning! sets %d != expected %d\n",
1416 sets,((size*1024)/line_size/associativity));
1420 MEMDBG(
"\tL%d %s cache\n",level,type_string);
1421 MEMDBG(
"\t%d kilobytes\n",size);
1422 MEMDBG(
"\t%d byte linesize\n",line_size);
1423 MEMDBG(
"\t%d-way associative\n",associativity);
1424 MEMDBG(
"\t%d lines\n",sets);
1425 MEMDBG(
"\tUnknown inclusivity\n");
1426 MEMDBG(
"\tUnknown replacement algorithm\n");
1427 MEMDBG(
"\tUnknown if victim cache\n");
1429 if (level>max_level) max_level=level;
1432 MEMDBG(
"Exceeded maximum cache level %d\n",
1459#if defined(__i386__)||defined(__x86_64__)
1460 x86_get_memory_info( hwinfo );
1461#elif defined(__ia64__)
1462 ia64_get_memory_info( hwinfo );
1463#elif defined(__powerpc__)
1464 ppc64_get_memory_info( hwinfo );
1465#elif defined(__sparc__)
1466 sparc_get_memory_info( hwinfo );
1467#elif defined(__arm__)
1468 #warning "WARNING! linux_get_memory_info() does nothing on ARM32!"
1470#elif defined(__aarch64__)
1471 aarch64_get_memory_info( hwinfo );
1484 unsigned long t_index = 0, d_index = 0, b_index = 0, counting = 1;
1487 unsigned long begin = 0, end = 0, size = 0, inode = 0, foo = 0;
1491 memset( fname, 0x0,
sizeof ( fname ) );
1492 memset(
buf, 0x0,
sizeof (
buf ) );
1493 memset(
perm, 0x0,
sizeof (
perm ) );
1494 memset( dev, 0x0,
sizeof ( dev ) );
1495 memset( mapname, 0x0,
sizeof ( mapname ) );
1496 memset( lastmapname, 0x0,
sizeof ( lastmapname ) );
1498 sprintf( fname,
"/proc/%ld/maps", (
long ) mdi->
pid );
1499 f = fopen( fname,
"r" );
1502 PAPIERROR(
"fopen(%s) returned < 0", fname );
1507 while ( !feof(
f ) ) {
1508 begin = end = size = inode = foo = 0;
1509 if ( fgets(
buf,
sizeof (
buf ),
f ) == 0 )
1512 if ( strlen( mapname ) )
1513 strcpy( lastmapname, mapname );
1515 lastmapname[0] =
'\0';
1518 sscanf(
buf,
"%lx-%lx %4s %lx %s %ld %s", &begin, &end,
perm, &foo, dev,
1527 if ( (
perm[2] ==
'x' ) && (
perm[0] ==
'r' ) && ( inode != 0 ) ) {
1533 (
vptr_t ) ( begin + size );
1536 }
else if ( (
perm[0] ==
'r' ) && (
perm[1] ==
'w' ) &&
1541 mapname ) == 0 ) ) {
1545 (
vptr_t ) ( begin + size );
1547 }
else if ( (
perm[0] ==
'r' ) && (
perm[1] ==
'w' ) &&
1552 lastmapname ) == 0 ) ) {
1556 (
vptr_t ) ( begin + size );
1559 }
else if ( !counting ) {
1560 if ( (
perm[2] ==
'x' ) && (
perm[0] ==
'r' ) && ( inode != 0 ) ) {
1564 tmp[t_index - 1].text_start = (
vptr_t ) begin;
1565 tmp[t_index - 1].text_end = (
vptr_t ) ( begin + size );
1569 }
else if ( (
perm[0] ==
'r' ) && (
perm[1] ==
'w' ) &&
1574 && ( t_index > 0 ) &&
1575 (
tmp[t_index - 1].data_start == 0 ) ) {
1576 tmp[t_index - 1].data_start = (
vptr_t ) begin;
1577 tmp[t_index - 1].data_end = (
vptr_t ) ( begin + size );
1579 }
else if ( (
perm[0] ==
'r' ) && (
perm[1] ==
'w' ) &&
1581 if ( ( t_index > 0 ) && (
tmp[t_index - 1].bss_start == 0 ) ) {
1582 tmp[t_index - 1].bss_start = (
vptr_t ) begin;
1583 tmp[t_index - 1].bss_end = (
vptr_t ) ( begin + size );
1597 if (
tmp == NULL ) {
1598 PAPIERROR(
"Error allocating shared library address map" );
int open(const char *pathname, int flags, mode_t mode)
ssize_t read(int fd, void *buf, size_t count)
static const PAPI_hw_info_t * hw_info
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
#define PAPI_VENDOR_INTEL
#define PAPI_MAX_MEM_HIERARCHY_LEVELS
#define PAPI_HUGE_STR_LEN
static double c[MATRIX_SIZE][MATRIX_SIZE]
int _linux_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
int generic_get_memory_info(PAPI_hw_info_t *hw_info)
int _linux_update_shlib_info(papi_mdi_t *mdi)
int _linux_get_dmem_info(PAPI_dmem_info_t *d)
static _sysdetect_cache_level_info_t clevel[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Return codes and api definitions.
#define PAPI_MH_TYPE_DATA
#define PAPI_MH_TYPE_RW_ALLOC
#define PAPI_MH_MAX_LEVELS
#define PAPI_MH_TYPE_PSEUDO_LRU
#define PAPI_MH_TYPE_FIFO
#define PAPI_MH_TYPE_WR_ALLOC
#define PAPI_MH_TYPE_RD_ALLOC
#define PAPI_MH_TYPE_INST
#define PAPI_MH_TYPE_EMPTY
#define PAPI_MH_TYPE_UNIFIED
#define MEMDBG(format, args...)
int fclose(FILE *__stream)
void PAPIERROR(char *format,...)
#define papi_calloc(a, b)
static char * search_cpu_info(FILE *f, char *search_str, char *line)
static int _perfmon2_pfm_pmu_type
#define PFMLIB_SPARC_ULTRA3I_PMU
#define PFMLIB_SPARC_ULTRA12_PMU
#define PFMLIB_SPARC_ULTRA3PLUS_PMU
#define PFMLIB_SPARC_ULTRA3_PMU
#define PFMLIB_SPARC_ULTRA4PLUS_PMU
static unsigned int mfpvr(void)
#define PVR_PROCESSOR_SHIFT
get the executable's address space info
A pointer to the following is passed to PAPI_get_dmem_info()
long long high_water_mark
char fullname[PAPI_HUGE_STR_LEN]
PAPI_address_map_t address_info
char vendor_string[PAPI_MAX_STR_LEN]
PAPI_mh_info_t mem_hierarchy
char model_string[PAPI_MAX_STR_LEN]
mh for mem hierarchy maybe?
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
PAPI_mh_tlb_info_t tlb[PAPI_MH_MAX_LEVELS]
PAPI_mh_cache_info_t cache[PAPI_MH_MAX_LEVELS]
PAPI_shlib_info_t shlib_info
int _x86_cache_info(PAPI_mh_info_t *mh_info)