1 // SPDX-License-Identifier: GPL-2.0
4 #include "map_symbol.h"
5 #include "mem-events.h"
6 #include "linux/string.h"
9 static char mem_loads_name[100];
10 static bool mem_loads_name__init;
11 static char mem_stores_name[100];
13 #define MEM_LOADS_AUX 0x8203
14 #define MEM_LOADS_AUX_NAME "{%s/mem-loads-aux/,%s/mem-loads,ldlat=%u/}:P"
16 #define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
18 static struct perf_mem_event perf_mem_events_intel[PERF_MEM_EVENTS__MAX] = {
19 E("ldlat-loads", "%s/mem-loads,ldlat=%u/P", "%s/events/mem-loads"),
20 E("ldlat-stores", "%s/mem-stores/P", "%s/events/mem-stores"),
24 static struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
27 E("mem-ldst", "ibs_op//", "ibs_op"),
30 struct perf_mem_event *perf_mem_events__ptr(int i)
32 if (i >= PERF_MEM_EVENTS__MAX)
35 if (x86__is_amd_cpu())
36 return &perf_mem_events_amd[i];
38 return &perf_mem_events_intel[i];
41 bool is_mem_loads_aux_event(struct evsel *leader)
43 if (perf_pmu__find("cpu")) {
44 if (!pmu_have_event("cpu", "mem-loads-aux"))
46 } else if (perf_pmu__find("cpu_core")) {
47 if (!pmu_have_event("cpu_core", "mem-loads-aux"))
51 return leader->core.attr.config == MEM_LOADS_AUX;
54 char *perf_mem_events__name(int i, char *pmu_name)
56 struct perf_mem_event *e = perf_mem_events__ptr(i);
61 if (i == PERF_MEM_EVENTS__LOAD) {
62 if (mem_loads_name__init && !pmu_name)
63 return mem_loads_name;
66 mem_loads_name__init = true;
67 pmu_name = (char *)"cpu";
70 if (pmu_have_event(pmu_name, "mem-loads-aux")) {
71 scnprintf(mem_loads_name, sizeof(mem_loads_name),
72 MEM_LOADS_AUX_NAME, pmu_name, pmu_name,
73 perf_mem_events__loads_ldlat);
75 scnprintf(mem_loads_name, sizeof(mem_loads_name),
77 perf_mem_events__loads_ldlat);
79 return mem_loads_name;
82 if (i == PERF_MEM_EVENTS__STORE) {
84 pmu_name = (char *)"cpu";
86 scnprintf(mem_stores_name, sizeof(mem_stores_name),
88 return mem_stores_name;
91 return (char *)e->name;