1 // SPDX-License-Identifier: GPL-2.0 2 #include "util/pmu.h" 3 #include "map_symbol.h" 4 #include "mem-events.h" 5 6 static char mem_loads_name[100]; 7 static bool mem_loads_name__init; 8 static char mem_stores_name[100]; 9 10 #define MEM_LOADS_AUX 0x8203 11 #define MEM_LOADS_AUX_NAME "{%s/mem-loads-aux/,%s/mem-loads,ldlat=%u/}:P" 12 13 #define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s } 14 15 static struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = { 16 E("ldlat-loads", "%s/mem-loads,ldlat=%u/P", "%s/events/mem-loads"), 17 E("ldlat-stores", "%s/mem-stores/P", "%s/events/mem-stores"), 18 E(NULL, NULL, NULL), 19 }; 20 21 struct perf_mem_event *perf_mem_events__ptr(int i) 22 { 23 if (i >= PERF_MEM_EVENTS__MAX) 24 return NULL; 25 26 return &perf_mem_events[i]; 27 } 28 29 bool is_mem_loads_aux_event(struct evsel *leader) 30 { 31 if (perf_pmu__find("cpu")) { 32 if (!pmu_have_event("cpu", "mem-loads-aux")) 33 return false; 34 } else if (perf_pmu__find("cpu_core")) { 35 if (!pmu_have_event("cpu_core", "mem-loads-aux")) 36 return false; 37 } 38 39 return leader->core.attr.config == MEM_LOADS_AUX; 40 } 41 42 char *perf_mem_events__name(int i, char *pmu_name) 43 { 44 struct perf_mem_event *e = perf_mem_events__ptr(i); 45 46 if (!e) 47 return NULL; 48 49 if (i == PERF_MEM_EVENTS__LOAD) { 50 if (mem_loads_name__init && !pmu_name) 51 return mem_loads_name; 52 53 if (!pmu_name) { 54 mem_loads_name__init = true; 55 pmu_name = (char *)"cpu"; 56 } 57 58 if (pmu_have_event(pmu_name, "mem-loads-aux")) { 59 scnprintf(mem_loads_name, sizeof(mem_loads_name), 60 MEM_LOADS_AUX_NAME, pmu_name, pmu_name, 61 perf_mem_events__loads_ldlat); 62 } else { 63 scnprintf(mem_loads_name, sizeof(mem_loads_name), 64 e->name, pmu_name, 65 perf_mem_events__loads_ldlat); 66 } 67 return mem_loads_name; 68 } 69 70 if (i == PERF_MEM_EVENTS__STORE) { 71 if (!pmu_name) 72 pmu_name = (char *)"cpu"; 73 74 scnprintf(mem_stores_name, sizeof(mem_stores_name), 75 e->name, pmu_name); 76 return mem_stores_name; 77 } 78 79 return (char *)e->name; 80 } 81