xref: /openbmc/linux/tools/perf/arch/x86/util/mem-events.c (revision d9fd5a71)
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 
9 #define MEM_LOADS_AUX		0x8203
10 #define MEM_LOADS_AUX_NAME	"{cpu/mem-loads-aux/,cpu/mem-loads,ldlat=%u/pp}:S"
11 
12 bool is_mem_loads_aux_event(struct evsel *leader)
13 {
14 	if (!pmu_have_event("cpu", "mem-loads-aux"))
15 		return false;
16 
17 	return leader->core.attr.config == MEM_LOADS_AUX;
18 }
19 
20 char *perf_mem_events__name(int i)
21 {
22 	struct perf_mem_event *e = perf_mem_events__ptr(i);
23 
24 	if (!e)
25 		return NULL;
26 
27 	if (i == PERF_MEM_EVENTS__LOAD) {
28 		if (mem_loads_name__init)
29 			return mem_loads_name;
30 
31 		mem_loads_name__init = true;
32 
33 		if (pmu_have_event("cpu", "mem-loads-aux")) {
34 			scnprintf(mem_loads_name, sizeof(mem_loads_name),
35 				  MEM_LOADS_AUX_NAME, perf_mem_events__loads_ldlat);
36 		} else {
37 			scnprintf(mem_loads_name, sizeof(mem_loads_name),
38 				  e->name, perf_mem_events__loads_ldlat);
39 		}
40 		return mem_loads_name;
41 	}
42 
43 	return (char *)e->name;
44 }
45