10 #include <linux/kernel.h> 18 #define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s } 21 E(
"ldlat-loads",
"cpu/mem-loads,ldlat=%u/P",
"mem-loads"),
22 E(
"ldlat-stores",
"cpu/mem-stores/P",
"mem-stores"),
37 perf_mem_events[i].
name,
43 return (
char *)perf_mem_events[i].
name;
48 char *tok, *saveptr = NULL;
54 buf =
malloc(strlen(str) + 1);
60 tok = strtok_r((
char *)buf,
",", &saveptr);
66 if (strstr(e->
tag, tok))
70 tok = strtok_r(NULL,
",", &saveptr);
78 pr_err(
"failed: event '%s' not found, use '-e list' to get list of available events\n", str);
84 const char *mnt = sysfs__mount();
96 scnprintf(path,
PATH_MAX,
"%s/devices/cpu/events/%s",
103 return found ? 0 : -ENOENT;
119 u64
m = PERF_MEM_TLB_NA;
128 hit = m & PERF_MEM_TLB_HIT;
129 miss = m & PERF_MEM_TLB_MISS;
132 m &= ~(PERF_MEM_TLB_HIT|PERF_MEM_TLB_MISS);
134 for (i = 0; m && i < ARRAY_SIZE(tlb_access); i++, m >>= 1) {
141 l += scnprintf(out + l, sz - l,
tlb_access[i]);
144 l += scnprintf(out, sz - l,
"N/A");
146 l += scnprintf(out + l, sz - l,
" hit");
148 l += scnprintf(out + l, sz - l,
" miss");
162 "Remote RAM (1 hop)",
163 "Remote RAM (2 hops)",
164 "Remote Cache (1 hop)",
165 "Remote Cache (2 hops)",
171 [PERF_MEM_LVLNUM_ANY_CACHE] =
"Any cache",
172 [PERF_MEM_LVLNUM_LFB] =
"LFB",
173 [PERF_MEM_LVLNUM_RAM] =
"RAM",
174 [PERF_MEM_LVLNUM_PMEM] =
"PMEM",
175 [PERF_MEM_LVLNUM_NA] =
"N/A",
181 u64
m = PERF_MEM_LVL_NA;
191 hit = m & PERF_MEM_LVL_HIT;
192 miss = m & PERF_MEM_LVL_MISS;
195 m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS);
198 if (mem_info && mem_info->
data_src.mem_remote) {
199 strcat(out,
"Remote ");
204 for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) {
211 l += scnprintf(out + l, sz - l,
mem_lvl[i]);
214 if (mem_info && mem_info->
data_src.mem_lvl_num) {
215 int lvl = mem_info->
data_src.mem_lvl_num;
221 l += scnprintf(out + l, sz - l,
mem_lvlnum[lvl]);
223 l += scnprintf(out + l, sz - l,
"L%d", lvl);
227 l += scnprintf(out + l, sz - l,
"N/A");
229 l += scnprintf(out + l, sz - l,
" hit");
231 l += scnprintf(out + l, sz - l,
" miss");
247 u64
m = PERF_MEM_SNOOP_NA;
255 for (i = 0; m && i < ARRAY_SIZE(snoop_access); i++, m >>= 1) {
265 (mem_info->
data_src.mem_snoopx & PERF_MEM_SNOOPX_FWD)) {
270 l += scnprintf(out + l, sz - l,
"Fwd");
274 l += scnprintf(out, sz - l,
"N/A");
281 u64 mask = PERF_MEM_LOCK_NA;
287 if (mask & PERF_MEM_LOCK_NA)
288 l = scnprintf(out, sz,
"N/A");
289 else if (mask & PERF_MEM_LOCK_LOCKED)
290 l = scnprintf(out, sz,
"Yes");
292 l = scnprintf(out, sz,
"No");
302 i += scnprintf(out + i, sz - i,
"|SNP ");
304 i += scnprintf(out + i, sz - i,
"|TLB ");
306 i += scnprintf(out + i, sz - i,
"|LCK ");
314 union perf_mem_data_src *data_src = &mi->
data_src;
316 u64 op = data_src->mem_op;
317 u64 lvl = data_src->mem_lvl;
318 u64 snoop = data_src->mem_snoop;
319 u64 lock = data_src->mem_lock;
324 bool mrem = data_src->mem_remote;
327 #define HITM_INC(__f) \ 333 #define P(a, b) PERF_MEM_##a##_##b 337 if (lock &
P(LOCK, LOCKED)) stats->
locks++;
339 if (op &
P(OP, LOAD)) {
348 if (lvl &
P(LVL, HIT)) {
350 if (lvl &
P(LVL, IO)) stats->
ld_io++;
351 if (lvl &
P(LVL, LFB)) stats->
ld_fbhit++;
352 if (lvl &
P(LVL, L1 )) stats->
ld_l1hit++;
353 if (lvl &
P(LVL, L2 )) stats->
ld_l2hit++;
354 if (lvl &
P(LVL, L3 )) {
355 if (snoop &
P(SNOOP, HITM))
361 if (lvl &
P(LVL, LOC_RAM)) {
363 if (snoop &
P(SNOOP, HIT))
369 if ((lvl &
P(LVL, REM_RAM1)) ||
370 (lvl &
P(LVL, REM_RAM2)) ||
373 if (snoop &
P(SNOOP, HIT))
380 if ((lvl &
P(LVL, REM_CCE1)) ||
381 (lvl &
P(LVL, REM_CCE2)) ||
383 if (snoop &
P(SNOOP, HIT))
385 else if (snoop &
P(SNOOP, HITM))
389 if ((lvl &
P(LVL, MISS)))
392 }
else if (op &
P(OP, STORE)) {
401 if (lvl &
P(LVL, HIT)) {
403 if (lvl &
P(LVL, L1 )) stats->
st_l1hit++;
405 if (lvl &
P(LVL, MISS))
static const char *const mem_lvl[]
int perf_mem_events__init(void)
struct addr_map_symbol daddr
unsigned int perf_mem_events__loads_ldlat
int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
char * perf_mem_events__name(int i)
int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
static const char *const snoop_access[]
static int str(yyscan_t scanner, int token)
union perf_mem_data_src data_src
int perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
static bool mem_loads_name__init
int perf_script__meminfo_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
static const char *const mem_lvlnum[]
int perf_mem_events__parse(const char *str)
static char mem_loads_name[100]
struct addr_map_symbol iaddr
static const char *const tlb_access[]
int c2c_decode_stats(struct c2c_stats *stats, struct mem_info *mi)
struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX]
void c2c_add_stats(struct c2c_stats *stats, struct c2c_stats *add)