Skip to contentSkip to conversation

perf tools: Add ARM Statistical Profiling Extensions (SPE) support

PATCH Superseded Kim Phillips 1 participant 1 message Oct 27, 2017

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 perf tools: Add ARM Statistical Profiling Extensions (SPE) support

'perf record' and 'perf report --dump-raw-trace' supported in this release.

Example usage:

$ ./perf record -e arm_spe_0/ts_enable=1,pa_enable=1/ \
		dd if=/dev/zero of=/dev/null count=10000

perf report --dump-raw-trace

Note that the perf.data file is portable, so the report can be run on another architecture host if necessary.

Output will contain raw SPE data and its textual representation, such as:

0x550 [0x30]: PERF_RECORD_AUXTRACE size: 0xc408 offset: 0 ref: 0x30005619 idx: 3 tid: 2109 cpu: 3 .
. ... ARM SPE data: size 50184 bytes

.  00000000:  49 00                                           LD
.  00000002:  b2 00 9c 7b 7a 00 80 ff ff                      VA 0xffff80007a7b9c00
.  0000000b:  9a 00 00                                        LAT 0 XLAT
.  0000000e:  42 16                                           EV RETIRED L1D-ACCESS TLB-ACCESS
.  00000010:  b0 b0 c9 15 08 00 00 ff ff                      PC 0xff00000815c9b0 el3 ns=1
.  00000019:  98 00 00                                        LAT 0 TOT
.  0000001c:  71 00 20 fa fd 16 00 00 00                      TS 98750308352
.  00000025:  49 01                                           ST
.  00000027:  b2 60 bc 0c 0f 00 00 ff ff                      VA 0xffff00000f0cbc60
.  00000030:  9a 00 00                                        LAT 0 XLAT
.  00000033:  42 16                                           EV RETIRED L1D-ACCESS TLB-ACCESS
.  00000035:  b0 48 cc 15 08 00 00 ff ff                      PC 0xff00000815cc48 el3 ns=1
.  0000003e:  98 00 00                                        LAT 0 TOT
.  00000041:  71 00 20 fa fd 16 00 00 00                      TS 98750308352
.  0000004a:  48 00                                           INSN-OTHER
.  0000004c:  42 02                                           EV RETIRED
.  0000004e:  b0 ac 47 0c 08 00 00 ff ff                      PC 0xff0000080c47ac el3 ns=1
.  00000057:  98 00 00                                        LAT 0 TOT
.  0000005a:  71 00 20 fa fd 16 00 00 00                      TS 98750308352
.  00000063:  49 00                                           LD
.  00000065:  b2 18 48 e5 7a 00 80 ff ff                      VA 0xffff80007ae54818
.  0000006e:  9a 00 00                                        LAT 0 XLAT
.  00000071:  42 16                                           EV RETIRED L1D-ACCESS TLB-ACCESS
.  00000073:  b0 08 f8 15 08 00 00 ff ff                      PC 0xff00000815f808 el3 ns=1
.  0000007c:  98 00 00                                        LAT 0 TOT
.  0000007f:  71 00 20 fa fd 16 00 00 00                      TS 98750308352

...

Other release notes:

- applies to acme's perf/{core,urgent} branches, likely elsewhere

- Report is self-contained within the tool. Record requires Will's SPE driver:

http://lists.infradead.org/pipermail/linux-arm-kernel/2017-October/536221.html

- the intel-bts implementation was used as a starting point; its min/default/max buffer sizes and power of 2 pages granularity need to be revisited for ARM SPE

- multiple SPE clusters/domains not supported

- snapshot support (record -S), and conversion to native perf events (e.g., via 'perf inject --itrace'), are also not supported

- technically both cs-etm and spe can be used simultaneously, however disabled for simplicity in this release

---
v3: trying to address comments from v2:

- despite adding a find_all_arm_spe_pmus() function to scan for all arm_spe_<n> device instances, in order to ensure auxtrace_record__init successfully matches the evsel type with the correct arm_spe_pmu type, I am still having trouble running in multi-SPE PPI (heterogeneous) environments (mmap fails with EOPNOTSUPP, as does running with --per-thread on homogeneous systems).

- arm_spe_reference: use gettime instead of direct cntvct register access

- spe-decoder: add a comment for why SPE_EVENTS code sets packet->index.

- added arm_spe_pmu_default_config that accesses the driver caps/min_interval and sets the default sampling period to it. This way users don't have to specify -c explicitly. Also set is_uncore to false.

- set more sampling bits in the arm_spe and its tracking evsel. Still unsure if too liberal, and not sure whether it needs another context switch tracking evsel. Comments welcome!

v2: mostly addressing Mark Rutland's comments as much as possible without his feedback to my feedback:

- decoder refactored with a get_payload, not extended to with-ext_len ones like get_addr, named the constants

- 0x-ified %x output formats, but decided to not sign extend the addresses in the raw dump, rather do so if necessary in the synthesis stage:
SPE implementations differ in this area, and raw dump should reflect that.

- CPU mask / new record behaviour bisected to commit e3ba76deef23064 "perf
tools: Force uncore events to system wide monitoring". Waiting to hear back on why driver can't do system wide monitoring, even across PPIs, by e.g., sharing the SPE interrupts in one handler (SPE's don't differ in this record regard).

- addressed off-list comment from M. Williams:
"Instruction Type" packet was renamed as "Operation Type".
so in the spe packet decoder: INSN_TYPE -> OP_TYPE

- do_get_packet fixed to handle excessive, successive PADding from a new source of raw SPE data, so instead of:

	.  000011ae:  00                                              PAD
	.  000011af:  00                                              PAD
	.  000011b0:  00                                              PAD
	.  000011b1:  00                                              PAD
	.  000011b2:  00                                              PAD
	.  000011b3:  00                                              PAD
	.  000011b4:  00                                              PAD
	.  000011b5:  00                                              PAD
	.  000011b6:  00                                              PAD

we now get:

	.  000011ae:  00 00 00 00 00 00 00 00 00                      PAD

- fixed 52 00 00 decoded with an empty events clause, adding 'EV' for all events clauses now. parser writers can detect for empty event clauses by finding nothing after it.

 tools/perf/arch/arm/util/auxtrace.c   |  75 +++++-
 tools/perf/arch/arm/util/pmu.c        |   5 +-
 tools/perf/arch/arm64/util/Build      |   3 +-
 tools/perf/arch/arm64/util/arm-spe.c  | 235 +++++++++++++++++
 tools/perf/util/Build                 |   2 +
 tools/perf/util/arm-spe-pkt-decoder.c | 472 ++++++++++++++++++++++++++++++++++
 tools/perf/util/arm-spe-pkt-decoder.h |  52 ++++
 tools/perf/util/arm-spe.c             | 318 +++++++++++++++++++++++
 tools/perf/util/arm-spe.h             |  42 +++
 tools/perf/util/auxtrace.c            |   3 +
 tools/perf/util/auxtrace.h            |   1 +
 11 files changed, 1200 insertions(+), 8 deletions(-)
 create mode 100644 tools/perf/arch/arm64/util/arm-spe.c
 create mode 100644 tools/perf/util/arm-spe-pkt-decoder.c
 create mode 100644 tools/perf/util/arm-spe-pkt-decoder.h
 create mode 100644 tools/perf/util/arm-spe.c
 create mode 100644 tools/perf/util/arm-spe.h
tools/perf/arch/arm/util/auxtrace.c +69 -6
index 8edf2cb71564..8e7c1ad18224 100644
@@ -22,6 +22,42 @@
 #include "../../util/evlist.h"
 #include "../../util/pmu.h"
 #include "cs-etm.h"
+#include "arm-spe.h"
+
+static struct perf_pmu **find_all_arm_spe_pmus(int *nr_spes, int *err)
+{
+	struct perf_pmu **arm_spe_pmus = NULL;
+	int ret, i, nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
+	/* arm_spe_xxxxxxxxx\0 */
+	char arm_spe_pmu_name[sizeof(ARM_SPE_PMU_NAME) + 10];
+
+	arm_spe_pmus = zalloc(sizeof(struct perf_pmu *) * nr_cpus);
+	if (!arm_spe_pmus) {
+		pr_err("spes alloc failed\n");
+		*err = -ENOMEM;
+		return NULL;
+	}
+
+	for (i = 0; i < nr_cpus; i++) {
+		ret = sprintf(arm_spe_pmu_name, "%s%d", ARM_SPE_PMU_NAME, i);
+		if (ret < 0) {
+			pr_err("sprintf failed\n");
+			*err = -ENOMEM;
+			return NULL;
+		}
+
+		arm_spe_pmus[*nr_spes] = perf_pmu__find(arm_spe_pmu_name);
+		if (arm_spe_pmus[*nr_spes]) {
+			pr_debug2("%s %d: arm_spe_pmu %d type %d name %s\n",
+				 __func__, __LINE__, *nr_spes,
+				 arm_spe_pmus[*nr_spes]->type,
+				 arm_spe_pmus[*nr_spes]->name);
+			(*nr_spes)++;
+		}
+	}
+
+	return arm_spe_pmus;
+}
 
 struct auxtrace_record
 *auxtrace_record__init(struct perf_evlist *evlist, int *err)
@@ -29,22 +65,49 @@ struct auxtrace_record
 	struct perf_pmu	*cs_etm_pmu;
 	struct perf_evsel *evsel;
 	bool found_etm = false;
+	bool found_spe = false;
+	static struct perf_pmu **arm_spe_pmus = NULL;
+	static int nr_spes = 0;
+	int i;
+
+	if (!evlist)
+		return NULL;
 
 	cs_etm_pmu = perf_pmu__find(CORESIGHT_ETM_PMU_NAME);
 
-	if (evlist) {
-		evlist__for_each_entry(evlist, evsel) {
-			if (cs_etm_pmu &&
-			    evsel->attr.type == cs_etm_pmu->type)
-				found_etm = true;
+	if (!arm_spe_pmus)
+		arm_spe_pmus = find_all_arm_spe_pmus(&nr_spes, err);
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (cs_etm_pmu &&
+		    evsel->attr.type == cs_etm_pmu->type)
+			found_etm = true;
+
+		if (!nr_spes)
+			continue;
+
+		for (i = 0; i < nr_spes; i++) {
+			if (evsel->attr.type == arm_spe_pmus[i]->type) {
+				found_spe = true;
+				break;
+			}
 		}
 	}
 
+	if (found_etm && found_spe) {
+		pr_err("Concurrent ARM Coresight ETM and SPE operation not currently supported\n");
+		*err = -EOPNOTSUPP;
+		return NULL;
+	}
+
 	if (found_etm)
 		return cs_etm_record_init(err);
 
+	if (found_spe)
+		return arm_spe_recording_init(err, arm_spe_pmus[i]);
+
 	/*
-	 * Clear 'err' even if we haven't found a cs_etm event - that way perf
+	 * Clear 'err' even if we haven't found an event - that way perf
 	 * record can still be used even if tracers aren't present.  The NULL
 	 * return value will take care of telling the infrastructure HW tracing
 	 * isn't available.
tools/perf/arch/arm/util/pmu.c +4 -1
index 98d67399a0d6..4c06a25ae6b1 100644
@@ -20,6 +20,7 @@
 #include <linux/perf_event.h>
 
 #include "cs-etm.h"
+#include "arm-spe.h"
 #include "../../util/pmu.h"
 
 struct perf_event_attr
@@ -30,7 +31,9 @@ struct perf_event_attr
 		/* add ETM default config here */
 		pmu->selectable = true;
 		pmu->set_drv_config = cs_etm_set_drv_config;
-	}
+	} else
+		if (strstarts(pmu->name, ARM_SPE_PMU_NAME))
+			return arm_spe_pmu_default_config(pmu);
 #endif
 	return NULL;
 }
tools/perf/arch/arm64/util/Build +2 -1
index 8dee4aa31a68..a80a53f89cf2 100644
@@ -5,4 +5,5 @@ libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
 
 libperf-$(CONFIG_AUXTRACE) += ../../arm/util/pmu.o \
 			      ../../arm/util/auxtrace.o \
-			      ../../arm/util/cs-etm.o
+			      ../../arm/util/cs-etm.o \
+			      arm-spe.o
tools/perf/arch/arm64/util/arm-spe.c new file +235 -0

235 lines not on this page · raw message

tools/perf/util/Build +2 -0
index 94518c1bf8b6..e6cb696359a2 100644
@@ -83,6 +83,8 @@ libperf-$(CONFIG_AUXTRACE) += auxtrace.o
 libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
 libperf-$(CONFIG_AUXTRACE) += intel-pt.o
 libperf-$(CONFIG_AUXTRACE) += intel-bts.o
+libperf-$(CONFIG_AUXTRACE) += arm-spe.o
+libperf-$(CONFIG_AUXTRACE) += arm-spe-pkt-decoder.o
 libperf-y += parse-branch-options.o
 libperf-y += dump-insn.o
 libperf-y += parse-regs-options.o
tools/perf/util/arm-spe-pkt-decoder.c new file +472 -0

472 lines not on this page · raw message

tools/perf/util/arm-spe-pkt-decoder.h new file +52 -0

52 lines not on this page · raw message

tools/perf/util/arm-spe.c new file +318 -0

318 lines not on this page · raw message

tools/perf/util/arm-spe.h new file +42 -0

42 lines not on this page · raw message

tools/perf/util/auxtrace.c +3 -0
index 5547457566a7..92da3981a761 100644
@@ -57,6 +57,7 @@
 
 #include "intel-pt.h"
 #include "intel-bts.h"
+#include "arm-spe.h"
 
 #include "sane_ctype.h"
 #include "symbol/kallsyms.h"
@@ -913,6 +914,8 @@ int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,
 		return intel_pt_process_auxtrace_info(event, session);
 	case PERF_AUXTRACE_INTEL_BTS:
 		return intel_bts_process_auxtrace_info(event, session);
+	case PERF_AUXTRACE_ARM_SPE:
+		return arm_spe_process_auxtrace_info(event, session);
 	case PERF_AUXTRACE_CS_ETM:
 	case PERF_AUXTRACE_UNKNOWN:
 	default:
tools/perf/util/auxtrace.h +1 -0
index 33b5e6cdf38c..fa1c8deffac4 100644
@@ -43,6 +43,7 @@ enum auxtrace_type {
 	PERF_AUXTRACE_INTEL_PT,
 	PERF_AUXTRACE_INTEL_BTS,
 	PERF_AUXTRACE_CS_ETM,
+	PERF_AUXTRACE_ARM_SPE,
 };
 
 enum itrace_period_type {
Signature · 1 line
2.14.2