[PATCH v2 03/14] perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE

From: Leo Yan
Date: Tue Sep 01 2020 - 04:38:44 EST


The existed architectures which have supported perf memory profiling,
usually it contains two types of hardware events: load and store, so if
want to profile memory for both load and store operations, the tool will
use these two events at the same time. But this is not valid for aux
tracing event, the same event can be used with setting different
configurations for memory operation filtering, e.g the event can be used
to only trace memory load, or only memory store, or trace for both memory
load and store.

This patch introduces a new event PERF_MEM_EVENTS__LOAD_STORE, which is
used to support the event which can record both memory load and store
operations.

Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>
---
tools/perf/builtin-mem.c | 11 +++++++++--
tools/perf/util/mem-events.c | 9 ++++++++-
tools/perf/util/mem-events.h | 1 +
3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 070e0f1d3300..9fd730019e45 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -19,8 +19,9 @@
#include "util/symbol.h"
#include <linux/err.h>

-#define MEM_OPERATION_LOAD 0x1
-#define MEM_OPERATION_STORE 0x2
+#define MEM_OPERATION_LOAD 0x1
+#define MEM_OPERATION_STORE 0x2
+#define MEM_OPERATION_LOAD_STORE 0x4

struct perf_mem {
struct perf_tool tool;
@@ -97,6 +98,11 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
e->record = true;
}

+ if (mem->operation & MEM_OPERATION_LOAD_STORE) {
+ e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD_STORE);
+ e->record = true;
+ }
+
e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
if (e->record)
rec_argv[i++] = "-W";
@@ -329,6 +335,7 @@ struct mem_mode {
static const struct mem_mode mem_modes[]={
MEM_OPT("load", MEM_OPERATION_LOAD),
MEM_OPT("store", MEM_OPERATION_STORE),
+ MEM_OPT("ldst", MEM_OPERATION_LOAD_STORE),
MEM_END
};

diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 7a5a0d699e27..74449cf33a0e 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -20,6 +20,7 @@ unsigned int perf_mem_events__loads_ldlat = 30;
static struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
E("ldlat-loads", "cpu/mem-loads,ldlat=%u/P", "cpu/events/mem-loads"),
E("ldlat-stores", "cpu/mem-stores/P", "cpu/events/mem-stores"),
+ E(NULL, NULL, NULL),
};
#undef E

@@ -75,6 +76,9 @@ int perf_mem_events__parse(const char *str)
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
struct perf_mem_event *e = perf_mem_events__ptr(j);

+ if (!e->tag)
+ continue;
+
if (strstr(e->tag, tok))
e->record = found = true;
}
@@ -105,6 +109,9 @@ int perf_mem_events__init(void)
struct perf_mem_event *e = perf_mem_events__ptr(j);
struct stat st;

+ if (!e->sysfs_name)
+ continue;
+
scnprintf(path, PATH_MAX, "%s/devices/%s",
mnt, e->sysfs_name);

@@ -123,7 +130,7 @@ void perf_mem_events__list(void)
struct perf_mem_event *e = perf_mem_events__ptr(j);

fprintf(stderr, "%-13s%-*s%s\n",
- e->tag,
+ e->tag ? e->tag : "",
verbose > 0 ? 25 : 0,
verbose > 0 ? perf_mem_events__name(j) : "",
e->supported ? ": available" : "");
diff --git a/tools/perf/util/mem-events.h b/tools/perf/util/mem-events.h
index 726a9c8103e4..5ef178278909 100644
--- a/tools/perf/util/mem-events.h
+++ b/tools/perf/util/mem-events.h
@@ -28,6 +28,7 @@ struct mem_info {
enum {
PERF_MEM_EVENTS__LOAD,
PERF_MEM_EVENTS__STORE,
+ PERF_MEM_EVENTS__LOAD_STORE,
PERF_MEM_EVENTS__MAX,
};

--
2.20.1