The 'perf mem' and 'perf c2c' tools are wrappers around 'perf record' with mem load/ store events. IBS tagged load/store sample provides most of the information needed for these tools. Wire in the "ibs_op//" event as mem-ldst event for AMD. There are some limitations though: Only load/store micro-ops provide mem/c2c information. Whereas, IBS does not have a way to choose a particular type of micro-op to tag. This results in many non-LS micro-ops being tagged which appear as N/A in the perf report. IBS, being an uncore pmu from kernel point of view[1], does not support per process monitoring. Thus, perf mem/c2c on AMD are currently supported in per-cpu mode only. Example: $ sudo perf mem record -- -c 10000 ^C[ perf record: Woken up 227 times to write data ] [ perf record: Captured and wrote 58.760 MB perf.data (836978 samples) ] $ sudo perf mem report -F mem,sample,snoop Samples: 836K of event 'ibs_op//', Event count (approx.): 8418762 Memory access Samples Snoop N/A 700620 N/A L1 hit 126675 N/A L2 hit 424 N/A L3 hit 664 HitM L3 hit 10 N/A Local RAM hit 2 N/A Remote RAM (1 hop) hit 8558 N/A Remote Cache (1 hop) hit 3 N/A Remote Cache (1 hop) hit 2 HitM Remote Cache (2 hops) hit 10 HitM Remote Cache (2 hops) hit 6 N/A Uncached hit 4 N/A $ [1]: https://lore.kernel.org/lkml/20220829113347.295-1-ravi.bangoria@amd.com Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ali Saidi <alisaidi@amazon.com> Cc: Ananth Narayan <ananth.narayan@amd.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Joe Mario <jmario@redhat.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Kim Phillips <kim.phillips@amd.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Santosh Shukla <santosh.shukla@amd.com> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: x86@kernel.org Link: https://lore.kernel.org/r/20221006153946.7816-6-ravi.bangoria@amd.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
108 lines
2.5 KiB
C
108 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include "util/pmu.h"
|
|
#include "util/env.h"
|
|
#include "map_symbol.h"
|
|
#include "mem-events.h"
|
|
#include "linux/string.h"
|
|
|
|
static char mem_loads_name[100];
|
|
static bool mem_loads_name__init;
|
|
static char mem_stores_name[100];
|
|
|
|
#define MEM_LOADS_AUX 0x8203
|
|
#define MEM_LOADS_AUX_NAME "{%s/mem-loads-aux/,%s/mem-loads,ldlat=%u/}:P"
|
|
|
|
#define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
|
|
|
|
static struct perf_mem_event perf_mem_events_intel[PERF_MEM_EVENTS__MAX] = {
|
|
E("ldlat-loads", "%s/mem-loads,ldlat=%u/P", "%s/events/mem-loads"),
|
|
E("ldlat-stores", "%s/mem-stores/P", "%s/events/mem-stores"),
|
|
E(NULL, NULL, NULL),
|
|
};
|
|
|
|
static struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
|
|
E(NULL, NULL, NULL),
|
|
E(NULL, NULL, NULL),
|
|
E("mem-ldst", "ibs_op//", "ibs_op"),
|
|
};
|
|
|
|
static int perf_mem_is_amd_cpu(void)
|
|
{
|
|
struct perf_env env = { .total_mem = 0, };
|
|
|
|
perf_env__cpuid(&env);
|
|
if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD"))
|
|
return 1;
|
|
return -1;
|
|
}
|
|
|
|
struct perf_mem_event *perf_mem_events__ptr(int i)
|
|
{
|
|
/* 0: Uninitialized, 1: Yes, -1: No */
|
|
static int is_amd;
|
|
|
|
if (i >= PERF_MEM_EVENTS__MAX)
|
|
return NULL;
|
|
|
|
if (!is_amd)
|
|
is_amd = perf_mem_is_amd_cpu();
|
|
|
|
if (is_amd == 1)
|
|
return &perf_mem_events_amd[i];
|
|
|
|
return &perf_mem_events_intel[i];
|
|
}
|
|
|
|
bool is_mem_loads_aux_event(struct evsel *leader)
|
|
{
|
|
if (perf_pmu__find("cpu")) {
|
|
if (!pmu_have_event("cpu", "mem-loads-aux"))
|
|
return false;
|
|
} else if (perf_pmu__find("cpu_core")) {
|
|
if (!pmu_have_event("cpu_core", "mem-loads-aux"))
|
|
return false;
|
|
}
|
|
|
|
return leader->core.attr.config == MEM_LOADS_AUX;
|
|
}
|
|
|
|
char *perf_mem_events__name(int i, char *pmu_name)
|
|
{
|
|
struct perf_mem_event *e = perf_mem_events__ptr(i);
|
|
|
|
if (!e)
|
|
return NULL;
|
|
|
|
if (i == PERF_MEM_EVENTS__LOAD) {
|
|
if (mem_loads_name__init && !pmu_name)
|
|
return mem_loads_name;
|
|
|
|
if (!pmu_name) {
|
|
mem_loads_name__init = true;
|
|
pmu_name = (char *)"cpu";
|
|
}
|
|
|
|
if (pmu_have_event(pmu_name, "mem-loads-aux")) {
|
|
scnprintf(mem_loads_name, sizeof(mem_loads_name),
|
|
MEM_LOADS_AUX_NAME, pmu_name, pmu_name,
|
|
perf_mem_events__loads_ldlat);
|
|
} else {
|
|
scnprintf(mem_loads_name, sizeof(mem_loads_name),
|
|
e->name, pmu_name,
|
|
perf_mem_events__loads_ldlat);
|
|
}
|
|
return mem_loads_name;
|
|
}
|
|
|
|
if (i == PERF_MEM_EVENTS__STORE) {
|
|
if (!pmu_name)
|
|
pmu_name = (char *)"cpu";
|
|
|
|
scnprintf(mem_stores_name, sizeof(mem_stores_name),
|
|
e->name, pmu_name);
|
|
return mem_stores_name;
|
|
}
|
|
|
|
return (char *)e->name;
|
|
}
|