PAPI  5.7.0.0
cache_helper.c
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include "cache_helper.h"
4 
5 #include "papi.h"
6 #include "papi_test.h"
7 
8 const PAPI_hw_info_t *hw_info=NULL;
9 
10 struct cache_info_t {
11  int wpolicy;
12  int replace;
13  int size;
14  int entries;
15  int ways;
16  int linesize;
17 };
18 
20 
22 
23  int cache_type,level,j;
24 
25  /* Get PAPI Hardware Info */
27  if (hw_info==NULL) {
28  return -1;
29  }
30 
31  /* Iterate down the levels (L1, L2, L3) */
32  for(level=0;level<hw_info->mem_hierarchy.levels;level++) {
33  for(j=0;j<2;j++) {
34  cache_type=PAPI_MH_CACHE_TYPE(
35  hw_info->mem_hierarchy.level[level].cache[j].type);
36  if (cache_type==PAPI_MH_TYPE_EMPTY) continue;
37 
38  if (level==0) {
39  if (cache_type==PAPI_MH_TYPE_DATA) {
46  }
47  else if (cache_type==PAPI_MH_TYPE_INST) {
54  }
55  }
56  else if (level==1) {
63  }
64  else if (level==2) {
71  }
72 
73  }
74  }
75  return 0;
76 }
77 
78 long long get_cachesize(int type) {
79 
80  int result;
81 
83  if (result<0) return result;
84 
85  if (type>=MAX_CACHE) {
86  printf("Errror!\n");
87  return -1;
88  }
89 
90  return cache_info[type].size;
91 }
92 
93 
94 long long get_entries(int type) {
95 
96  int result;
97 
99  if (result<0) return result;
100 
101  if (type>=MAX_CACHE) {
102  printf("Errror!\n");
103  return -1;
104  }
105 
106  return cache_info[type].entries;
107 }
108 
109 
110 long long get_linesize(int type) {
111 
112  int result;
113 
115  if (result<0) return result;
116 
117  if (type>=MAX_CACHE) {
118  printf("Errror!\n");
119  return -1;
120  }
121 
122  return cache_info[type].linesize;
123 }
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 L3_CACHE
Definition: cache_helper.h:4
Return codes and api definitions.
#define PAPI_MH_TYPE_DATA
Definition: papi.h:732
#define L2_CACHE
Definition: cache_helper.h:3
#define PAPI_MH_CACHE_WRITE_POLICY(a)
Definition: papi.h:739
#define PAPI_MH_CACHE_REPLACEMENT_POLICY(a)
Definition: papi.h:743
static int check_if_cache_info_available(void)
Definition: cache_helper.c:21
long long get_linesize(int type)
Definition: cache_helper.c:110
#define L1D_CACHE
Definition: cache_helper.h:2
long long get_cachesize(int type)
Definition: cache_helper.c:78
PAPI_mh_cache_info_t cache[PAPI_MH_MAX_LEVELS]
Definition: papi.h:769
static struct cache_info_t cache_info[MAX_CACHE]
Definition: cache_helper.c:19
#define MAX_CACHE
Definition: cache_helper.h:5
#define PAPI_MH_TYPE_EMPTY
Definition: papi.h:730
const PAPI_hw_info_t * hw_info
Definition: cache_helper.c:8
long long get_entries(int type)
Definition: cache_helper.c:94
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
#define L1I_CACHE
Definition: cache_helper.h:1
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:736