PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
9
13 int size;
15 int ways;
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(
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
78long 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
94long 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
110long 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}
volatile int result
static int check_if_cache_info_available(void)
Definition: cache_helper.c:21
const PAPI_hw_info_t * hw_info
Definition: cache_helper.c:8
long long get_cachesize(int type)
Definition: cache_helper.c:78
long long get_linesize(int type)
Definition: cache_helper.c:110
long long get_entries(int type)
Definition: cache_helper.c:94
static struct cache_info_t cache_info[MAX_CACHE]
Definition: cache_helper.c:19
#define L1I_CACHE
Definition: cache_helper.h:1
#define MAX_CACHE
Definition: cache_helper.h:5
#define L3_CACHE
Definition: cache_helper.h:4
#define L2_CACHE
Definition: cache_helper.h:3
#define L1D_CACHE
Definition: cache_helper.h:2
get information about the system hardware
uint16_t type
Return codes and api definitions.
#define PAPI_MH_TYPE_DATA
Definition: papi.h:720
#define PAPI_MH_CACHE_REPLACEMENT_POLICY(a)
Definition: papi.h:732
#define PAPI_MH_CACHE_TYPE(a)
Definition: papi.h:724
#define PAPI_MH_TYPE_INST
Definition: papi.h:719
#define PAPI_MH_TYPE_EMPTY
Definition: papi.h:718
#define PAPI_MH_CACHE_WRITE_POLICY(a)
Definition: papi.h:727
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
PAPI_mh_cache_info_t cache[PAPI_MH_MAX_LEVELS]
Definition: papi.h:762