Skip to contentSkip to conversation

perf mem/c2c: Support AUX trace

PATCH Superseded Leo Yan 4 participants 19 messages Oct 28, 2020 – Nov 2, 2020

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v3 cover perf mem/c2c: Support AUX trace

The patch set v2 [1] mixed the patches for support perf mem/c2c AUX trace and for enabling Arm SPE's memory event. To make easier reviewing, this patch set extracts the changes for perf mem/c2c AUX trace.

Patches 01, 02, 03 extend to support more flexible memory event name and introduce a new event type 'ldst' (besides the existed types 'load' and 'store').

Patch 04 is a minor refactoring to initailize memory event for recording but not for reporting.

Patches 05, 06 are to support AUX trace for "perf mem" and "perf c2c" tools.

Patch 07 enabled SPE memory events for Arm64 arch; patch 08 fixes the memory event name issue on PowerPC.

Patch 09 is to update documentation to reflect the latest changes.

This patch set has been applied clearly on the perf/core branch with the latest commit 7cf726a59435 ("Merge tag 'linux-kselftest-kunit-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest").

This patch set has been verified on x86 and Arm64.

On x86, below commands have been tested:

  # perf c2c record -e ldlat-loads  -- ~/false_sharing.exe 2
  # perf c2c record -e ldlat-stores  -- ~/false_sharing.exe 2
  # perf mem record -t load -- ~/false_sharing.exe 2
  # perf mem record -t store -- ~/false_sharing.exe 2
  # perf mem record -t ldst -- ~/false_sharing.exe 2
      `-> report failure due the type 'ldst' is not supported on x86
  # perf mem record -e ldlat-loads  -- ~/false_sharing.exe 2
  # perf mem record -e ldlat-stores  -- ~/false_sharing.exe 2

On Arm64, below commands have been tested:

  # perf c2c record -e spe-load  -- ~/false_sharing.exe 2
  # perf c2c record -e spe-store  -- ~/false_sharing.exe 2
  # perf c2c record -e spe-ldst  -- ~/false_sharing.exe 2
  # perf mem record -t load -- ~/false_sharing.exe 2
  # perf mem record -t store -- ~/false_sharing.exe 2
  # perf mem record -t ldst -- ~/false_sharing.exe 2
  # perf mem record -e spe-load  -- ~/false_sharing.exe 2
  # perf mem record -e spe-store  -- ~/false_sharing.exe 2
  # perf mem record -e spe-ldst  -- ~/false_sharing.exe 2

[1] https://lore.kernel.org/patchwork/cover/1298085/

Leo Yan (9):
perf mem: Search event name with more flexible path perf mem: Introduce weak function perf_mem_events__ptr() perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE perf mem: Only initialize memory event for recording perf mem: Support AUX trace
perf c2c: Support AUX trace
perf mem: Support Arm SPE events
perf mem: Return NULL for event 'ldst' on PowerPC perf mem: Document event type 'ldst'

Changes from v2:
* Patch 02 went back to use loops with PERF_MEM_EVENTS__MAX (Jiri);
* Patch 06 for "perf c2c" AUX trace is supported;
* Patch 08 for fixing memory event name on PowerPC.

Changes from v1:
* Refined patch 02 to use perf_mem_events__ptr() to return event pointer and check if pointer is NULL, and remove the condition checking for PERF_MEM_EVENTS__MAX; (James Clark)
* Added new itrace option 'M' for memory events;
* Added patch 14 to update documentation.

 tools/perf/Documentation/perf-mem.txt     |  6 ++-
 tools/perf/arch/arm64/util/Build          |  2 +-
 tools/perf/arch/arm64/util/mem-events.c   | 37 +++++++++++++++++
 tools/perf/arch/powerpc/util/mem-events.c |  6 ++-
 tools/perf/builtin-c2c.c                  | 22 +++++++---
 tools/perf/builtin-mem.c                  | 49 ++++++++++++++++-------
 tools/perf/util/mem-events.c              | 45 ++++++++++++++++-----
 tools/perf/util/mem-events.h              |  3 +-
 8 files changed, 133 insertions(+), 37 deletions(-)
 create mode 100644 tools/perf/arch/arm64/util/mem-events.c
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#1 lore raw

PATCH v3 1/9 perf mem: Search event name with more flexible path

Perf tool searches memory event name under the folder '/sys/devices/cpu/events/', this leads to the limitation for selection memory profiling event which must be under this folder. Thus it's impossible to use any other event as memory event which is not under this specific folder, e.g. Arm SPE hardware event is not located in '/sys/devices/cpu/events/' so it cannot be enabled for memory profiling.

This patch changes to search folder from '/sys/devices/cpu/events/' to '/sys/devices', so it give flexibility to find events which can be used for memory profiling.

---
 tools/perf/util/mem-events.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/mem-events.c +3 -3
index ea0af0bc4314..35c8d175a9d2 100644
@@ -18,8 +18,8 @@ unsigned int perf_mem_events__loads_ldlat = 30;
 #define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
 
 struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
-	E("ldlat-loads",	"cpu/mem-loads,ldlat=%u/P",	"mem-loads"),
-	E("ldlat-stores",	"cpu/mem-stores/P",		"mem-stores"),
+	E("ldlat-loads",	"cpu/mem-loads,ldlat=%u/P",	"cpu/events/mem-loads"),
+	E("ldlat-stores",	"cpu/mem-stores/P",		"cpu/events/mem-stores"),
 };
 #undef E
 
@@ -93,7 +93,7 @@ int perf_mem_events__init(void)
 		struct perf_mem_event *e = &perf_mem_events[j];
 		struct stat st;
 
-		scnprintf(path, PATH_MAX, "%s/devices/cpu/events/%s",
+		scnprintf(path, PATH_MAX, "%s/devices/%s",
 			  mnt, e->sysfs_name);
 
 		if (!stat(path, &st))
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#2 lore raw

PATCH v3 2/9 perf mem: Introduce weak function perf_mem_events__ptr()

In reply to Leo Yan

Different architectures might use different event or different event parameters for memory profiling, this patch introduces weak function perf_mem_events__ptr(), which allows to return back architecture specific memory event.

Since the variable 'perf_mem_events' can be only accessed by the function perf_mem_events__ptr(), marks the variable as 'static', this allows the architectures to define its own memory event array.

---
 tools/perf/builtin-c2c.c     | 18 ++++++++++++------
 tools/perf/builtin-mem.c     | 21 ++++++++++++++-------
 tools/perf/util/mem-events.c | 26 +++++++++++++++++++-------
 tools/perf/util/mem-events.h |  2 +-
 4 files changed, 46 insertions(+), 21 deletions(-)
tools/perf/builtin-c2c.c +12 -6
index d5bea5d3cd51..4d1a08e38233 100644
@@ -2867,6 +2867,7 @@ static int perf_c2c__record(int argc, const char **argv)
 	int ret;
 	bool all_user = false, all_kernel = false;
 	bool event_set = false;
+	struct perf_mem_event *e;
 	struct option options[] = {
 	OPT_CALLBACK('e', "event", &event_set, "event",
 		     "event selector. Use 'perf c2c record -e list' to list available events",
@@ -2894,11 +2895,15 @@ static int perf_c2c__record(int argc, const char **argv)
 	rec_argv[i++] = "record";
 
 	if (!event_set) {
-		perf_mem_events[PERF_MEM_EVENTS__LOAD].record  = true;
-		perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
+		e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
+		e->record = true;
+
+		e = perf_mem_events__ptr(PERF_MEM_EVENTS__STORE);
+		e->record = true;
 	}
 
-	if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
+	e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
+	if (e->record)
 		rec_argv[i++] = "-W";
 
 	rec_argv[i++] = "-d";
@@ -2906,12 +2911,13 @@ static int perf_c2c__record(int argc, const char **argv)
 	rec_argv[i++] = "--sample-cpu";
 
 	for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
-		if (!perf_mem_events[j].record)
+		e = perf_mem_events__ptr(j);
+		if (!e->record)
 			continue;
 
-		if (!perf_mem_events[j].supported) {
+		if (!e->supported) {
 			pr_err("failed: event '%s' not supported\n",
-			       perf_mem_events[j].name);
+			       perf_mem_events__name(j));
 			free(rec_argv);
 			return -1;
 		}
tools/perf/builtin-mem.c +14 -7
index 3523279af6af..9a7df8d01296 100644
@@ -64,6 +64,7 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 	const char **rec_argv;
 	int ret;
 	bool all_user = false, all_kernel = false;
+	struct perf_mem_event *e;
 	struct option options[] = {
 	OPT_CALLBACK('e', "event", &mem, "event",
 		     "event selector. use 'perf mem record -e list' to list available events",
@@ -86,13 +87,18 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 
 	rec_argv[i++] = "record";
 
-	if (mem->operation & MEM_OPERATION_LOAD)
-		perf_mem_events[PERF_MEM_EVENTS__LOAD].record = true;
+	if (mem->operation & MEM_OPERATION_LOAD) {
+		e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
+		e->record = true;
+	}
 
-	if (mem->operation & MEM_OPERATION_STORE)
-		perf_mem_events[PERF_MEM_EVENTS__STORE].record = true;
+	if (mem->operation & MEM_OPERATION_STORE) {
+		e = perf_mem_events__ptr(PERF_MEM_EVENTS__STORE);
+		e->record = true;
+	}
 
-	if (perf_mem_events[PERF_MEM_EVENTS__LOAD].record)
+	e = perf_mem_events__ptr(PERF_MEM_EVENTS__LOAD);
+	if (e->record)
 		rec_argv[i++] = "-W";
 
 	rec_argv[i++] = "-d";
@@ -101,10 +107,11 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 		rec_argv[i++] = "--phys-data";
 
 	for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
-		if (!perf_mem_events[j].record)
+		e = perf_mem_events__ptr(j);
+		if (!e->record)
 			continue;
 
-		if (!perf_mem_events[j].supported) {
+		if (!e->supported) {
 			pr_err("failed: event '%s' not supported\n",
 			       perf_mem_events__name(j));
 			free(rec_argv);
tools/perf/util/mem-events.c +19 -7
index 35c8d175a9d2..7a5a0d699e27 100644
@@ -17,7 +17,7 @@ unsigned int perf_mem_events__loads_ldlat = 30;
 
 #define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
 
-struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
+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"),
 };
@@ -28,19 +28,31 @@ struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
 static char mem_loads_name[100];
 static bool mem_loads_name__init;
 
+struct perf_mem_event * __weak perf_mem_events__ptr(int i)
+{
+	if (i >= PERF_MEM_EVENTS__MAX)
+		return NULL;
+
+	return &perf_mem_events[i];
+}
+
 char * __weak perf_mem_events__name(int i)
 {
+	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) {
 			mem_loads_name__init = true;
 			scnprintf(mem_loads_name, sizeof(mem_loads_name),
-				  perf_mem_events[i].name,
-				  perf_mem_events__loads_ldlat);
+				  e->name, perf_mem_events__loads_ldlat);
 		}
 		return mem_loads_name;
 	}
 
-	return (char *)perf_mem_events[i].name;
+	return (char *)e->name;
 }
 
 int perf_mem_events__parse(const char *str)
@@ -61,7 +73,7 @@ int perf_mem_events__parse(const char *str)
 
 	while (tok) {
 		for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
-			struct perf_mem_event *e = &perf_mem_events[j];
+			struct perf_mem_event *e = perf_mem_events__ptr(j);
 
 			if (strstr(e->tag, tok))
 				e->record = found = true;
@@ -90,7 +102,7 @@ int perf_mem_events__init(void)
 
 	for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
 		char path[PATH_MAX];
-		struct perf_mem_event *e = &perf_mem_events[j];
+		struct perf_mem_event *e = perf_mem_events__ptr(j);
 		struct stat st;
 
 		scnprintf(path, PATH_MAX, "%s/devices/%s",
@@ -108,7 +120,7 @@ void perf_mem_events__list(void)
 	int j;
 
 	for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
-		struct perf_mem_event *e = &perf_mem_events[j];
+		struct perf_mem_event *e = perf_mem_events__ptr(j);
 
 		fprintf(stderr, "%-13s%-*s%s\n",
 			e->tag,
tools/perf/util/mem-events.h +1 -1
index 904dad34f7f7..726a9c8103e4 100644
@@ -31,13 +31,13 @@ enum {
 	PERF_MEM_EVENTS__MAX,
 };
 
-extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
 extern unsigned int perf_mem_events__loads_ldlat;
 
 int perf_mem_events__parse(const char *str);
 int perf_mem_events__init(void);
 
 char *perf_mem_events__name(int i);
+struct perf_mem_event *perf_mem_events__ptr(int i);
 
 void perf_mem_events__list(void);
 
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#3 lore raw

PATCH v3 3/9 perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE

In reply to Leo Yan

On the architectures with perf memory profiling, two types of hardware events have been supported: load and store; if want to profile memory for both load and store operations, the tool will use these two events at the same time, the usage is:

  # perf mem record -t load,store -- uname

But this cannot be applied for AUX tracing event, the same PMU 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, thus a new type option "ldst" is added:

  # perf mem record -t ldst -- uname
---
 tools/perf/builtin-mem.c     | 13 ++++++++++---
 tools/perf/util/mem-events.c | 13 ++++++++++++-
 tools/perf/util/mem-events.h |  1 +
 3 files changed, 23 insertions(+), 4 deletions(-)
tools/perf/builtin-mem.c +10 -3
index 9a7df8d01296..31144f586e77 100644
@@ -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";
@@ -326,6 +332,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
 };
 
@@ -405,7 +412,7 @@ int cmd_mem(int argc, const char **argv)
 	};
 	const struct option mem_options[] = {
 	OPT_CALLBACK('t', "type", &mem.operation,
-		   "type", "memory operations(load,store) Default load,store",
+		   "type", "memory operations(load,store,ldst) Default load,store",
 		    parse_mem_ops),
 	OPT_BOOLEAN('D', "dump-raw-samples", &mem.dump_raw,
 		    "dump raw samples in ASCII"),
tools/perf/util/mem-events.c +12 -1
index 7a5a0d699e27..2e82b4e78f29 100644
@@ -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,13 @@ int perf_mem_events__init(void)
 		struct perf_mem_event *e = perf_mem_events__ptr(j);
 		struct stat st;
 
+		/*
+		 * If the event entry isn't valid, skip initialization
+		 * and "e->supported" will keep false.
+		 */
+		if (!e->tag)
+			continue;
+
 		scnprintf(path, PATH_MAX, "%s/devices/%s",
 			  mnt, e->sysfs_name);
 
@@ -123,7 +134,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" : "");
tools/perf/util/mem-events.h +1 -0
index 726a9c8103e4..5ef178278909 100644
@@ -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,
 };
 
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw

Re: [PATCH v3 3/9] perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE

On Wed, Oct 28, 2020 at 02:38:07PM +0800, Leo Yan wrote:

SNIP

Quoted 13 lines
tools/perf/util/mem-events.c +7 -0
 		struct stat st;
 
+		/*
+		 * If the event entry isn't valid, skip initialization
+		 * and "e->supported" will keep false.
+		 */
+		if (!e->tag)
+			continue;
+
 		scnprintf(path, PATH_MAX, "%s/devices/%s",
 			  mnt, e->sysfs_name);

tools/perf/util/mem-events.c void perf_mem_events__list(void) · line 137

Quoted 5 lines
tools/perf/util/mem-events.c +1 -1
@@ -123,7 +134,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 : "",

nit, could be: e->tag ?: "",

jirka

Quoted 18 lines
tools/perf/util/mem-events.c +0 -0
 			verbose > 0 ? 25 : 0,
 			verbose > 0 ? perf_mem_events__name(j) : "",
 			e->supported ? ": available" : "");
tools/perf/util/mem-events.h +1 -0
index 726a9c8103e4..5ef178278909 100644
@@ -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,
 };
 
Signature · 1 line
2.17.1
author
#5 lore raw

Re: [PATCH v3 3/9] perf mem: Support new memory event PERF_MEM_EVENTS__LOAD_STORE

Quoted 16 lines · Jiri Olsa

On Wed, Oct 28, 2020 at 02:38:07PM +0800, Leo Yan wrote:

SNIP

Quoted 12 lines
tools/perf/util/mem-events.c +7 -0
 		struct stat st;
 
+		/*
+		 * If the event entry isn't valid, skip initialization
+		 * and "e->supported" will keep false.
+		 */
+		if (!e->tag)
+			continue;
+
 		scnprintf(path, PATH_MAX, "%s/devices/%s",
 			  mnt, e->sysfs_name);
Quoted 8 lines

tools/perf/util/mem-events.c void perf_mem_events__list(void) · line 137

Quoted 6 lines
tools/perf/util/mem-events.c +1 -1
@@ -123,7 +134,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 : "",

nit, could be: e->tag ?: "",

Will do.

Thanks,
Leo

Quoted 19 lines
Quoted 18 lines
tools/perf/util/mem-events.c +0 -0
 			verbose > 0 ? 25 : 0,
 			verbose > 0 ? perf_mem_events__name(j) : "",
 			e->supported ? ": available" : "");
tools/perf/util/mem-events.h +1 -0
index 726a9c8103e4..5ef178278909 100644
@@ -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,
 };
 
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH v3 4/9 perf mem: Only initialize memory event for recording

In reply to Leo Yan

It's needless to initialize memory events for reporting, this patch moves memory event initialization for only recording. Furthermore, the change allows to parse perf data on cross platforms, e.g. perf tool can report result properly even the machine doesn't support the memory events.

---
 tools/perf/builtin-mem.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-mem.c +5 -5
index 31144f586e77..f3dc2d2b879c 100644
@@ -78,6 +78,11 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
 	OPT_END()
 	};
 
+	if (perf_mem_events__init()) {
+		pr_err("failed: memory events not supported\n");
+		return -1;
+	}
+
 	argc = parse_options(argc, argv, options, record_mem_usage,
 			     PARSE_OPT_KEEP_UNKNOWN);
 
@@ -436,11 +441,6 @@ int cmd_mem(int argc, const char **argv)
 		NULL
 	};
 
-	if (perf_mem_events__init()) {
-		pr_err("failed: memory events not supported\n");
-		return -1;
-	}
-
 	argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
 					mem_usage, PARSE_OPT_KEEP_UNKNOWN);
 
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer Acked-by on v3 4/9
#7 lore raw

Re: [PATCH v3 4/9] perf mem: Only initialize memory event for recording

Quoted 8 lines · Leo Yan

It's needless to initialize memory events for reporting, this patch moves memory event initialization for only recording. Furthermore, the change allows to parse perf data on cross platforms, e.g. perf tool can report result properly even the machine doesn't support the memory events.

Thanks,
Ian

Quoted 35 lines
---
 tools/perf/builtin-mem.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-mem.c +5 -6
index 31144f586e77..f3dc2d2b879c 100644
@@ -78,6 +78,11 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
        OPT_END()
        };
 
+       if (perf_mem_events__init()) {
+               pr_err("failed: memory events not supported\n");
+               return -1;
+       }
+
        argc = parse_options(argc, argv, options, record_mem_usage,
                             PARSE_OPT_KEEP_UNKNOWN);
 
@@ -436,11 +441,6 @@ int cmd_mem(int argc, const char **argv)
                NULL
        };
 
-       if (perf_mem_events__init()) {
-               pr_err("failed: memory events not supported\n");
-               return -1;
-       }
-
        argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
                                        mem_usage, PARSE_OPT_KEEP_UNKNOWN);
 
--

2.17.1

author
#8 lore raw

PATCH v3 5/9 perf mem: Support AUX trace

In reply to Leo Yan

Perf memory tool doesn't support AUX trace data so it cannot receive the hardware tracing data. On Arm64, although it doesn't support PMU events for memory load and store, but Arm SPE is a good candidate for memory profiling, the hardware tracer can record memory accessing operations with affiliated information (e.g. physical address and virtual address for accessing, cache levels, TLB walking, latency, etc).

To allow "perf mem" tool to support AUX trace, this patches adds the AUX callbacks for session structure.

---
 tools/perf/builtin-mem.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/builtin-mem.c +5 -0
index f3dc2d2b879c..87c6074e405e 100644
@@ -7,6 +7,7 @@
 #include "perf.h"
 
 #include <subcmd/parse-options.h>
+#include "util/auxtrace.h"
 #include "util/trace-event.h"
 #include "util/tool.h"
 #include "util/session.h"
@@ -405,8 +406,12 @@ int cmd_mem(int argc, const char **argv)
 			.comm		= perf_event__process_comm,
 			.lost		= perf_event__process_lost,
 			.fork		= perf_event__process_fork,
+			.attr		= perf_event__process_attr,
 			.build_id	= perf_event__process_build_id,
 			.namespaces	= perf_event__process_namespaces,
+			.auxtrace_info  = perf_event__process_auxtrace_info,
+			.auxtrace       = perf_event__process_auxtrace,
+			.auxtrace_error = perf_event__process_auxtrace_error,
 			.ordered_events	= true,
 		},
 		.input_name		 = "perf.data",
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#9 lore raw

PATCH v3 6/9 perf c2c: Support AUX trace

In reply to Leo Yan

This patches adds the AUX callbacks in session structure, so support AUX trace for "perf c2c" tool.

---
 tools/perf/builtin-c2c.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/builtin-c2c.c +4 -0
index 4d1a08e38233..24f4af997aab 100644
@@ -369,6 +369,10 @@ static struct perf_c2c c2c = {
 		.exit		= perf_event__process_exit,
 		.fork		= perf_event__process_fork,
 		.lost		= perf_event__process_lost,
+		.attr		= perf_event__process_attr,
+		.auxtrace_info  = perf_event__process_auxtrace_info,
+		.auxtrace       = perf_event__process_auxtrace,
+		.auxtrace_error = perf_event__process_auxtrace_error,
 		.ordered_events	= true,
 		.ordering_requires_timestamps = true,
 	},
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#10 lore raw

Re: [PATCH v3 6/9] perf c2c: Support AUX trace

Quoted 13 lines · Leo Yan

This patches adds the AUX callbacks in session structure, so support AUX trace for "perf c2c" tool.

---
 tools/perf/builtin-c2c.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/builtin-c2c.c +0 -0
index 4d1a08e38233..24f4af997aab 100644

tools/perf/builtin-c2c.c static struct perf_c2c c2c = { · line 375

Quoted 7 lines
tools/perf/builtin-c2c.c +4 -0
@@ -369,6 +369,10 @@ static struct perf_c2c c2c = {
 		.exit		= perf_event__process_exit,
 		.fork		= perf_event__process_fork,
 		.lost		= perf_event__process_lost,
+		.attr		= perf_event__process_attr,
+		.auxtrace_info  = perf_event__process_auxtrace_info,
+		.auxtrace       = perf_event__process_auxtrace,
+		.auxtrace_error = perf_event__process_auxtrace_error,

so this will process aux data, but don't you have to say which events you want to synthesize?

like in script/report via --itrace option?

aybe arm differs from x86 in this, and it's happening in the background.. I have no idea ;-)

jirka

Quoted 6 lines
tools/perf/builtin-c2c.c +0 -0
 		.ordered_events	= true,
 		.ordering_requires_timestamps = true,
 	},
Signature · 1 line
2.17.1
author
#11 lore raw

Re: [PATCH v3 6/9] perf c2c: Support AUX trace

Hi Jiri,

Quoted 25 lines · Jiri Olsa
Quoted 13 lines · Leo Yan

This patches adds the AUX callbacks in session structure, so support AUX trace for "perf c2c" tool.

---
 tools/perf/builtin-c2c.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/builtin-c2c.c +0 -0
index 4d1a08e38233..24f4af997aab 100644

tools/perf/builtin-c2c.c static struct perf_c2c c2c = { · line 375

Quoted 7 lines
tools/perf/builtin-c2c.c +4 -0
@@ -369,6 +369,10 @@ static struct perf_c2c c2c = {
 		.exit		= perf_event__process_exit,
 		.fork		= perf_event__process_fork,
 		.lost		= perf_event__process_lost,
+		.attr		= perf_event__process_attr,
+		.auxtrace_info  = perf_event__process_auxtrace_info,
+		.auxtrace       = perf_event__process_auxtrace,
+		.auxtrace_error = perf_event__process_auxtrace_error,

so this will process aux data, but don't you have to say which events you want to synthesize?

Quoted 1 line

like in script/report via --itrace option?

Indeed, we need to assign "session->itrace_synth_opts", otherwise, the tool cannot output synthesized samples.

I tried to keep this patch set as small as possible, for easier reviewing.

Comparing to the previous patch set, I moved out the patch "perf
auxtrace: Add option '-M' for memory events" [1] from this patch set, at the end my purpose is to introduce the itrace option '-M' to synthesize memory event; and "perf c2c" tool can use memory event for output result. Thus "perf c2c" needs to add itrace_synth_opts:

  struct itrace_synth_opts itrace_synth_opts = {
          .set = true,
          .mem = true,            /* Memory samples */
          .default_no_sample = true,
  };
Quoted 2 lines

aybe arm differs from x86 in this, and it's happening in the background.. I have no idea ;-)

There should have no any difference between archs for 'itrace' behaviour.

Since I moved the patch "perf auxtrace: Add option '-M' for memory events" out from this patch set, thus I also left out the code for adding itrace_synth_opts. This introduced confusion for reviewing the change (sorry!), I will add back the patch "perf auxtrace: Add option '-M' for memory events" and add itrace_synth_opts for perf mem/c2c in next patch set.

Thanks,
Leo

[1] https://lore.kernel.org/patchwork/patch/1298072/

#12 lore raw

Re: [PATCH v3 6/9] perf c2c: Support AUX trace

Quoted 54 lines · Leo Yan

Hi Jiri,

Quoted 25 lines · Jiri Olsa
Quoted 13 lines · Leo Yan

This patches adds the AUX callbacks in session structure, so support AUX trace for "perf c2c" tool.

---
 tools/perf/builtin-c2c.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/builtin-c2c.c +0 -0
index 4d1a08e38233..24f4af997aab 100644

tools/perf/builtin-c2c.c static struct perf_c2c c2c = { · line 375

Quoted 7 lines
tools/perf/builtin-c2c.c +4 -0
@@ -369,6 +369,10 @@ static struct perf_c2c c2c = {
 		.exit		= perf_event__process_exit,
 		.fork		= perf_event__process_fork,
 		.lost		= perf_event__process_lost,
+		.attr		= perf_event__process_attr,
+		.auxtrace_info  = perf_event__process_auxtrace_info,
+		.auxtrace       = perf_event__process_auxtrace,
+		.auxtrace_error = perf_event__process_auxtrace_error,

so this will process aux data, but don't you have to say which events you want to synthesize?

Quoted 1 line

like in script/report via --itrace option?

Indeed, we need to assign "session->itrace_synth_opts", otherwise, the tool cannot output synthesized samples.

I tried to keep this patch set as small as possible, for easier reviewing.

Comparing to the previous patch set, I moved out the patch "perf
auxtrace: Add option '-M' for memory events" [1] from this patch set, at the end my purpose is to introduce the itrace option '-M' to synthesize memory event; and "perf c2c" tool can use memory event for output result. Thus "perf c2c" needs to add itrace_synth_opts:

  struct itrace_synth_opts itrace_synth_opts = {
          .set = true,
          .mem = true,            /* Memory samples */
          .default_no_sample = true,
  };
Quoted 2 lines

aybe arm differs from x86 in this, and it's happening in the background.. I have no idea ;-)

There should have no any difference between archs for 'itrace' behaviour.

Quoted 6 lines

Since I moved the patch "perf auxtrace: Add option '-M' for memory events" out from this patch set, thus I also left out the code for adding itrace_synth_opts. This introduced confusion for reviewing the change (sorry!), I will add back the patch "perf auxtrace: Add option '-M' for memory events" and add itrace_synth_opts for perf mem/c2c in next patch set.

ok either way works for me, I just wanted to understand ;-)

thanks,
jirka

author
#13 lore raw

PATCH v3 7/9 perf mem: Support Arm SPE events

In reply to Leo Yan

This patch adds Arm SPE events for perf memory profiling:

'spe-load': event for only recording memory load ops; 'spe-store': event for only recording memory store ops; 'spe-ldst': event for recording memory load and store ops.

---
 tools/perf/arch/arm64/util/Build        |  2 +-
 tools/perf/arch/arm64/util/mem-events.c | 37 +++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/arch/arm64/util/mem-events.c
tools/perf/arch/arm64/util/Build +1 -1
index b53294d74b01..cf6d7e799f33 100644
@@ -9,4 +9,4 @@ perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 perf-$(CONFIG_AUXTRACE) += ../../arm/util/pmu.o \
 			      ../../arm/util/auxtrace.o \
 			      ../../arm/util/cs-etm.o \
-			      arm-spe.o
+			      arm-spe.o mem-events.o
tools/perf/arch/arm64/util/mem-events.c new file +37 -0
new file mode 100644
index 000000000000..2a2497372671
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "map_symbol.h"
+#include "mem-events.h"
+
+#define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
+
+static struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
+	E("spe-load",	"arm_spe_0/ts_enable=1,load_filter=1,store_filter=0,min_latency=%u/",	"arm_spe_0"),
+	E("spe-store",	"arm_spe_0/ts_enable=1,load_filter=0,store_filter=1/",			"arm_spe_0"),
+	E("spe-ldst",	"arm_spe_0/ts_enable=1,load_filter=1,store_filter=1,min_latency=%u/",	"arm_spe_0"),
+};
+
+static char mem_ev_name[100];
+
+struct perf_mem_event *perf_mem_events__ptr(int i)
+{
+	if (i >= PERF_MEM_EVENTS__MAX)
+		return NULL;
+
+	return &perf_mem_events[i];
+}
+
+char *perf_mem_events__name(int i)
+{
+	struct perf_mem_event *e = perf_mem_events__ptr(i);
+
+	if (i >= PERF_MEM_EVENTS__MAX)
+		return NULL;
+
+	if (i == PERF_MEM_EVENTS__LOAD || i == PERF_MEM_EVENTS__LOAD_STORE)
+		scnprintf(mem_ev_name, sizeof(mem_ev_name),
+			  e->name, perf_mem_events__loads_ldlat);
+	else /* PERF_MEM_EVENTS__STORE */
+		scnprintf(mem_ev_name, sizeof(mem_ev_name), e->name);
+
+	return mem_ev_name;
+}
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#14 lore raw

PATCH v3 8/9 perf mem: Return NULL for event 'ldst' on PowerPC

In reply to Leo Yan

If user specifies event type "ldst", PowerPC's perf_mem_events__name() will wrongly return the store event name "cpu/mem-stores/".

This patch changes to return NULL for the event "ldst" on PowerPC.

---
 tools/perf/arch/powerpc/util/mem-events.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/arch/powerpc/util/mem-events.c +4 -2
index 07fb5e049488..90c5a0760685 100644
@@ -7,6 +7,8 @@ char *perf_mem_events__name(int i)
 {
 	if (i == PERF_MEM_EVENTS__LOAD)
 		return (char *) "cpu/mem-loads/";
-
-	return (char *) "cpu/mem-stores/";
+	else if (i == PERF_MEM_EVENTS__STORE)
+		return (char *) "cpu/mem-stores/";
+	else
+		return NULL;
 }
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#15 lore raw

Re: [PATCH v3 8/9] perf mem: Return NULL for event 'ldst' on PowerPC

[+ Maddy]

Quoted 29 lines · Leo Yan

If user specifies event type "ldst", PowerPC's perf_mem_events__name() will wrongly return the store event name "cpu/mem-stores/".

This patch changes to return NULL for the event "ldst" on PowerPC.

---
 tools/perf/arch/powerpc/util/mem-events.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/arch/powerpc/util/mem-events.c +4 -2
index 07fb5e049488..90c5a0760685 100644
@@ -7,6 +7,8 @@ char *perf_mem_events__name(int i)
 {
 	if (i == PERF_MEM_EVENTS__LOAD)
 		return (char *) "cpu/mem-loads/";
-
-	return (char *) "cpu/mem-stores/";
+	else if (i == PERF_MEM_EVENTS__STORE)
+		return (char *) "cpu/mem-stores/";
+	else
+		return NULL;
 }
Signature · 1 line
2.17.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#16 lore raw

PATCH v3 9/9 perf mem: Document event type 'ldst'

In reply to Leo Yan

The event type 'ldst' is added for recording both load and store memory operations, this patch documents for the new event type.

---
 tools/perf/Documentation/perf-mem.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-mem.txt +5 -1
index 199ea0f0a6c0..c50ef37dba72 100644
@@ -38,7 +38,11 @@ OPTIONS
 
 -t::
 --type=<type>::
-	Select the memory operation type: load or store (default: load,store)
+	Select the memory operation type: load, store, ldst (default: load,store).
+	The type 'ldst' means the single event can record both for load and store
+	operations; Intel and PowerPC support the types 'load' and 'store' but
+	'ldst' cannot be used; on Arm64, it uses Arm SPE as memory events and
+	user needs to specify one of these three types.
 
 -D::
 --dump-raw-samples::
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer
#17 lore raw

Re: [PATCH v3 9/9] perf mem: Document event type 'ldst'

Quoted 14 lines · Leo Yan

The event type 'ldst' is added for recording both load and store memory operations, this patch documents for the new event type.

---
 tools/perf/Documentation/perf-mem.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-mem.txt +0 -0
index 199ea0f0a6c0..c50ef37dba72 100644

tools/perf/Documentation/perf-mem.txt OPTIONS · line 45

Quoted 9 lines
tools/perf/Documentation/perf-mem.txt +5 -1
@@ -38,7 +38,11 @@ OPTIONS
 
 -t::
 --type=<type>::
-       Select the memory operation type: load or store (default: load,store)
+       Select the memory operation type: load, store, ldst (default: load,store).
+       The type 'ldst' means the single event can record both for load and store
+       operations; Intel and PowerPC support the types 'load' and 'store' but
+       'ldst' cannot be used; on Arm64, it uses Arm SPE as memory events and
+       user needs to specify one of these three types.

Naive question, could the type remain load,store for mem record and the tool internally change it to ldst for ARM SPE?

Thanks,
Ian

Quoted 6 lines
tools/perf/Documentation/perf-mem.txt +0 -1
 -D::
 --dump-raw-samples::
 
--

2.17.1

author
#18 lore raw

Re: [PATCH v3 9/9] perf mem: Document event type 'ldst'

Hi Ian,

Quoted 16 lines · Ian Rogers
Quoted 15 lines · Leo Yan

The event type 'ldst' is added for recording both load and store memory operations, this patch documents for the new event type.

---
 tools/perf/Documentation/perf-mem.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-mem.txt +0 -0
index 199ea0f0a6c0..c50ef37dba72 100644
@@ -38,7 +38,11 @@ OPTIONS
 
Quoted 11 lines

tools/perf/Documentation/perf-mem.txt OPTIONS · line 45

Quoted 8 lines
tools/perf/Documentation/perf-mem.txt +5 -1
 -t::
 --type=<type>::
-       Select the memory operation type: load or store (default: load,store)
+       Select the memory operation type: load, store, ldst (default: load,store).
+       The type 'ldst' means the single event can record both for load and store
+       operations; Intel and PowerPC support the types 'load' and 'store' but
+       'ldst' cannot be used; on Arm64, it uses Arm SPE as memory events and
+       user needs to specify one of these three types.

Naive question, could the type remain load,store for mem record and the tool internally change it to ldst for ARM SPE?

Good point. I understand you are suggesting to avoid complex options for usage, looked again at the code, my conclusion is it's feabile to convert 'load,store' to Arm SPE's ldst type.

If find any block issue when I experiment this idea, will come back to update it; otherwise, I will apply the suggestion in next spin.

Thanks for suggestion,
Leo