diff options
-rw-r--r-- | tools/perf/util/parse-events.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 06af2fadcd87..7939a21130d2 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c | |||
@@ -90,6 +90,34 @@ static char *hw_cache_result[][MAX_ALIASES] = { | |||
90 | { "Miss" }, | 90 | { "Miss" }, |
91 | }; | 91 | }; |
92 | 92 | ||
93 | #define C(x) PERF_COUNT_HW_CACHE_##x | ||
94 | #define CACHE_READ (1 << C(OP_READ)) | ||
95 | #define CACHE_WRITE (1 << C(OP_WRITE)) | ||
96 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) | ||
97 | #define COP(x) (1 << x) | ||
98 | |||
99 | /* | ||
100 | * cache operartion stat | ||
101 | * L1I : Read and prefetch only | ||
102 | * ITLB and BPU : Read-only | ||
103 | */ | ||
104 | static unsigned long hw_cache_stat[C(MAX)] = { | ||
105 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
106 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), | ||
107 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
108 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | ||
109 | [C(ITLB)] = (CACHE_READ), | ||
110 | [C(BPU)] = (CACHE_READ), | ||
111 | }; | ||
112 | |||
113 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) | ||
114 | { | ||
115 | if (hw_cache_stat[cache_type] & COP(cache_op)) | ||
116 | return 1; /* valid */ | ||
117 | else | ||
118 | return 0; /* invalid */ | ||
119 | } | ||
120 | |||
93 | char *event_name(int counter) | 121 | char *event_name(int counter) |
94 | { | 122 | { |
95 | u64 config = attrs[counter].config; | 123 | u64 config = attrs[counter].config; |
@@ -123,6 +151,8 @@ char *event_name(int counter) | |||
123 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) | 151 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
124 | return "unknown-ext-hardware-cache-result"; | 152 | return "unknown-ext-hardware-cache-result"; |
125 | 153 | ||
154 | if (!is_cache_op_valid(cache_type, cache_op)) | ||
155 | return "invalid-cache"; | ||
126 | sprintf(name, "%s-Cache-%s-%ses", | 156 | sprintf(name, "%s-Cache-%s-%ses", |
127 | hw_cache[cache_type][0], | 157 | hw_cache[cache_type][0], |
128 | hw_cache_op[cache_op][0], | 158 | hw_cache_op[cache_op][0], |
@@ -179,6 +209,9 @@ parse_generic_hw_symbols(const char *str, struct perf_counter_attr *attr) | |||
179 | if (cache_op == -1) | 209 | if (cache_op == -1) |
180 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; | 210 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; |
181 | 211 | ||
212 | if (!is_cache_op_valid(cache_type, cache_op)) | ||
213 | return -EINVAL; | ||
214 | |||
182 | cache_result = parse_aliases(str, hw_cache_result, | 215 | cache_result = parse_aliases(str, hw_cache_result, |
183 | PERF_COUNT_HW_CACHE_RESULT_MAX); | 216 | PERF_COUNT_HW_CACHE_RESULT_MAX); |
184 | /* | 217 | /* |