Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode
@ 2024-12-24 10:44 James Clark
  2024-12-24 10:44 ` [PATCH v2 1/5] " James Clark
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: James Clark @ 2024-12-24 10:44 UTC (permalink / raw)
  To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
	mark.rutland
  Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

Discard mode (Armv8.6) is a way to enable SPE related PMU events without
the overhead of recording any data. Add a format option, tests and docs
for it.

In theory we could make the driver drop calls to allocate the aux buffer
when discard mode is enabled. This would give a small memory saving,
but I think there is potential to interfere with any tools that don't
expect this so I left the aux allocation untouched. Even old tools that
don't know about discard mode will be able to use it because we publish
the format option. Not allocating the aux buffer will have to be added
to tools which I've done in Perf.

Tested on the FVP with SAMPLE_FEED_OP (0x812D):

 $ perf stat -e armv8_pmuv3/event=0x812D/ -- true

 Performance counter stats for 'true':

                 0      armv8_pmuv3/event=0x812D/  
 
 $ perf record -e arm_spe/discard/ -a -N -B --no-bpf-event -o - > /dev/null &
 $ perf stat -e armv8_pmuv3/event=0x812D/ -- true
 
  Performance counter stats for 'true':

             17350      armv8_pmuv3/event=0x812D/ 

Changes since v1:
  * Add a new section and some clarifications about the PMU events to
    the docs. (Ian)

James Clark (5):
  perf: arm_spe: Add format option for discard mode
  perf tool: arm-spe: Pull out functions for aux buffer and tracking
    setup
  perf tool: arm-spe: Don't allocate buffer or tracking event in discard
    mode
  perf test: arm_spe: Add test for discard mode
  perf docs: arm_spe: Document new discard mode

 drivers/perf/arm_spe_pmu.c                | 23 ++++++
 tools/perf/Documentation/perf-arm-spe.txt | 26 +++++++
 tools/perf/arch/arm64/util/arm-spe.c      | 90 +++++++++++++++--------
 tools/perf/tests/shell/test_arm_spe.sh    | 30 ++++++++
 4 files changed, 137 insertions(+), 32 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/5] perf: arm_spe: Add format option for discard mode
  2024-12-24 10:44 [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode James Clark
@ 2024-12-24 10:44 ` James Clark
  2025-01-07 17:39   ` Will Deacon
  2024-12-24 10:44 ` [PATCH v2 2/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup James Clark
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: James Clark @ 2024-12-24 10:44 UTC (permalink / raw)
  To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
	mark.rutland
  Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

FEAT_SPEv1p2 (optional from Armv8.6) adds a discard mode that allows all
SPE data to be discarded rather than written to memory. Add a format
bit for this mode.

If the mode isn't supported, the format bit isn't published and attempts
to use it will result in -EOPNOTSUPP. Allocating an aux buffer is still
allowed even though it won't be written to so that old tools continue to
work, but updated tools can choose to skip this step.

Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
 drivers/perf/arm_spe_pmu.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index fd5b78732603..9aaf3f98e6f5 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -193,6 +193,9 @@ static const struct attribute_group arm_spe_pmu_cap_group = {
 #define ATTR_CFG_FLD_store_filter_CFG		config	/* PMSFCR_EL1.ST */
 #define ATTR_CFG_FLD_store_filter_LO		34
 #define ATTR_CFG_FLD_store_filter_HI		34
+#define ATTR_CFG_FLD_discard_CFG		config	/* PMBLIMITR_EL1.FM = DISCARD */
+#define ATTR_CFG_FLD_discard_LO			35
+#define ATTR_CFG_FLD_discard_HI			35
 
 #define ATTR_CFG_FLD_event_filter_CFG		config1	/* PMSEVFR_EL1 */
 #define ATTR_CFG_FLD_event_filter_LO		0
@@ -216,6 +219,7 @@ GEN_PMU_FORMAT_ATTR(store_filter);
 GEN_PMU_FORMAT_ATTR(event_filter);
 GEN_PMU_FORMAT_ATTR(inv_event_filter);
 GEN_PMU_FORMAT_ATTR(min_latency);
+GEN_PMU_FORMAT_ATTR(discard);
 
 static struct attribute *arm_spe_pmu_formats_attr[] = {
 	&format_attr_ts_enable.attr,
@@ -228,9 +232,15 @@ static struct attribute *arm_spe_pmu_formats_attr[] = {
 	&format_attr_event_filter.attr,
 	&format_attr_inv_event_filter.attr,
 	&format_attr_min_latency.attr,
+	&format_attr_discard.attr,
 	NULL,
 };
 
+static bool discard_unsupported(struct arm_spe_pmu *spe_pmu)
+{
+	return spe_pmu->pmsver < ID_AA64DFR0_EL1_PMSVer_V1P2;
+}
+
 static umode_t arm_spe_pmu_format_attr_is_visible(struct kobject *kobj,
 						  struct attribute *attr,
 						  int unused)
@@ -238,6 +248,9 @@ static umode_t arm_spe_pmu_format_attr_is_visible(struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct arm_spe_pmu *spe_pmu = dev_get_drvdata(dev);
 
+	if (attr == &format_attr_discard.attr && discard_unsupported(spe_pmu))
+		return 0;
+
 	if (attr == &format_attr_inv_event_filter.attr && !(spe_pmu->features & SPE_PMU_FEAT_INV_FILT_EVT))
 		return 0;
 
@@ -502,6 +515,12 @@ static void arm_spe_perf_aux_output_begin(struct perf_output_handle *handle,
 	u64 base, limit;
 	struct arm_spe_pmu_buf *buf;
 
+	if (ATTR_CFG_GET_FLD(&event->attr, discard)) {
+		limit = FIELD_PREP(PMBLIMITR_EL1_FM, PMBLIMITR_EL1_FM_DISCARD);
+		limit |= PMBLIMITR_EL1_E;
+		goto out_write_limit;
+	}
+
 	/* Start a new aux session */
 	buf = perf_aux_output_begin(handle, event);
 	if (!buf) {
@@ -743,6 +762,10 @@ static int arm_spe_pmu_event_init(struct perf_event *event)
 	    !(spe_pmu->features & SPE_PMU_FEAT_FILT_LAT))
 		return -EOPNOTSUPP;
 
+	if (ATTR_CFG_GET_FLD(&event->attr, discard) &&
+	    discard_unsupported(spe_pmu))
+		return -EOPNOTSUPP;
+
 	set_spe_event_has_cx(event);
 	reg = arm_spe_event_to_pmscr(event);
 	if (reg & (PMSCR_EL1_PA | PMSCR_EL1_PCT))
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup
  2024-12-24 10:44 [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode James Clark
  2024-12-24 10:44 ` [PATCH v2 1/5] " James Clark
@ 2024-12-24 10:44 ` James Clark
  2024-12-24 10:44 ` [PATCH v2 3/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode James Clark
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: James Clark @ 2024-12-24 10:44 UTC (permalink / raw)
  To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
	mark.rutland
  Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

These won't be used in the next commit in discard mode, so put them in
their own functions. No functional changes intended.

Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/arch/arm64/util/arm-spe.c | 83 +++++++++++++++++-----------
 1 file changed, 51 insertions(+), 32 deletions(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 22b19dcc6beb..1b543855f206 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -274,33 +274,9 @@ static void arm_spe_setup_evsel(struct evsel *evsel, struct perf_cpu_map *cpus)
 		evsel__set_sample_bit(evsel, PHYS_ADDR);
 }
 
-static int arm_spe_recording_options(struct auxtrace_record *itr,
-				     struct evlist *evlist,
-				     struct record_opts *opts)
+static int arm_spe_setup_aux_buffer(struct record_opts *opts)
 {
-	struct arm_spe_recording *sper =
-			container_of(itr, struct arm_spe_recording, itr);
-	struct evsel *evsel, *tmp;
-	struct perf_cpu_map *cpus = evlist->core.user_requested_cpus;
 	bool privileged = perf_event_paranoid_check(-1);
-	struct evsel *tracking_evsel;
-	int err;
-
-	sper->evlist = evlist;
-
-	evlist__for_each_entry(evlist, evsel) {
-		if (evsel__is_aux_event(evsel)) {
-			if (!strstarts(evsel->pmu->name, ARM_SPE_PMU_NAME)) {
-				pr_err("Found unexpected auxtrace event: %s\n",
-				       evsel->pmu->name);
-				return -EINVAL;
-			}
-			opts->full_auxtrace = true;
-		}
-	}
-
-	if (!opts->full_auxtrace)
-		return 0;
 
 	/*
 	 * we are in snapshot mode.
@@ -330,6 +306,9 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 			pr_err("Failed to calculate default snapshot size and/or AUX area tracing mmap pages\n");
 			return -EINVAL;
 		}
+
+		pr_debug2("%sx snapshot size: %zu\n", ARM_SPE_PMU_NAME,
+			  opts->auxtrace_snapshot_size);
 	}
 
 	/* We are in full trace mode but '-m,xyz' wasn't specified */
@@ -355,14 +334,15 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 		}
 	}
 
-	if (opts->auxtrace_snapshot_mode)
-		pr_debug2("%sx snapshot size: %zu\n", ARM_SPE_PMU_NAME,
-			  opts->auxtrace_snapshot_size);
+	return 0;
+}
 
-	evlist__for_each_entry_safe(evlist, tmp, evsel) {
-		if (evsel__is_aux_event(evsel))
-			arm_spe_setup_evsel(evsel, cpus);
-	}
+static int arm_spe_setup_tracking_event(struct evlist *evlist,
+					struct record_opts *opts)
+{
+	int err;
+	struct evsel *tracking_evsel;
+	struct perf_cpu_map *cpus = evlist->core.user_requested_cpus;
 
 	/* Add dummy event to keep tracking */
 	err = parse_event(evlist, "dummy:u");
@@ -388,6 +368,45 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 	return 0;
 }
 
+static int arm_spe_recording_options(struct auxtrace_record *itr,
+				     struct evlist *evlist,
+				     struct record_opts *opts)
+{
+	struct arm_spe_recording *sper =
+			container_of(itr, struct arm_spe_recording, itr);
+	struct evsel *evsel, *tmp;
+	struct perf_cpu_map *cpus = evlist->core.user_requested_cpus;
+
+	int err;
+
+	sper->evlist = evlist;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel__is_aux_event(evsel)) {
+			if (!strstarts(evsel->pmu->name, ARM_SPE_PMU_NAME)) {
+				pr_err("Found unexpected auxtrace event: %s\n",
+				       evsel->pmu->name);
+				return -EINVAL;
+			}
+			opts->full_auxtrace = true;
+		}
+	}
+
+	if (!opts->full_auxtrace)
+		return 0;
+
+	evlist__for_each_entry_safe(evlist, tmp, evsel) {
+		if (evsel__is_aux_event(evsel))
+			arm_spe_setup_evsel(evsel, cpus);
+	}
+
+	err = arm_spe_setup_aux_buffer(opts);
+	if (err)
+		return err;
+
+	return arm_spe_setup_tracking_event(evlist, opts);
+}
+
 static int arm_spe_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
 					 struct record_opts *opts,
 					 const char *str)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode
  2024-12-24 10:44 [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode James Clark
  2024-12-24 10:44 ` [PATCH v2 1/5] " James Clark
  2024-12-24 10:44 ` [PATCH v2 2/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup James Clark
@ 2024-12-24 10:44 ` James Clark
  2024-12-24 10:44 ` [PATCH v2 4/5] perf test: arm_spe: Add test for " James Clark
  2024-12-24 10:44 ` [PATCH v2 5/5] perf docs: arm_spe: Document new " James Clark
  4 siblings, 0 replies; 8+ messages in thread
From: James Clark @ 2024-12-24 10:44 UTC (permalink / raw)
  To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
	mark.rutland
  Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

The buffer will never be written to so don't bother allocating it. The
tracking event is also not required.

Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/arch/arm64/util/arm-spe.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 1b543855f206..4301181b8e45 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -376,7 +376,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 			container_of(itr, struct arm_spe_recording, itr);
 	struct evsel *evsel, *tmp;
 	struct perf_cpu_map *cpus = evlist->core.user_requested_cpus;
-
+	bool discard = false;
 	int err;
 
 	sper->evlist = evlist;
@@ -396,10 +396,17 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
 		return 0;
 
 	evlist__for_each_entry_safe(evlist, tmp, evsel) {
-		if (evsel__is_aux_event(evsel))
+		if (evsel__is_aux_event(evsel)) {
 			arm_spe_setup_evsel(evsel, cpus);
+			if (evsel->core.attr.config &
+			    perf_pmu__format_bits(evsel->pmu, "discard"))
+				discard = true;
+		}
 	}
 
+	if (discard)
+		return 0;
+
 	err = arm_spe_setup_aux_buffer(opts);
 	if (err)
 		return err;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/5] perf test: arm_spe: Add test for discard mode
  2024-12-24 10:44 [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode James Clark
                   ` (2 preceding siblings ...)
  2024-12-24 10:44 ` [PATCH v2 3/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode James Clark
@ 2024-12-24 10:44 ` James Clark
  2024-12-24 10:44 ` [PATCH v2 5/5] perf docs: arm_spe: Document new " James Clark
  4 siblings, 0 replies; 8+ messages in thread
From: James Clark @ 2024-12-24 10:44 UTC (permalink / raw)
  To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
	mark.rutland
  Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

Add a test that checks that there were no AUX or AUXTRACE events
recorded when discard mode is used.

Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/tests/shell/test_arm_spe.sh | 30 ++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/tools/perf/tests/shell/test_arm_spe.sh b/tools/perf/tests/shell/test_arm_spe.sh
index 3258368634f7..a69aab70dd8a 100755
--- a/tools/perf/tests/shell/test_arm_spe.sh
+++ b/tools/perf/tests/shell/test_arm_spe.sh
@@ -107,7 +107,37 @@ arm_spe_system_wide_test() {
 	arm_spe_report "SPE system-wide testing" $err
 }
 
+arm_spe_discard_test() {
+	echo "SPE discard mode"
+
+	for f in /sys/bus/event_source/devices/arm_spe_*; do
+		if [ -e "$f/format/discard" ]; then
+			cpu=$(cut -c -1 "$f/cpumask")
+			break
+		fi
+	done
+
+	if [ -z $cpu ]; then
+		arm_spe_report "SPE discard mode not present" 2
+		return
+	fi
+
+	# Test can use wildcard SPE instance and Perf will only open the event
+	# on instances that have that format flag. But make sure the target
+	# runs on an instance with discard mode otherwise we're not testing
+	# anything.
+	perf record -o ${perfdata} -e arm_spe/discard/ -N -B --no-bpf-event \
+		-- taskset --cpu-list $cpu true
+
+	if perf report -i ${perfdata} --stats | grep 'AUX events\|AUXTRACE events'; then
+		arm_spe_report "SPE discard mode found unexpected data" 1
+	else
+		arm_spe_report "SPE discard mode" 0
+	fi
+}
+
 arm_spe_snapshot_test
 arm_spe_system_wide_test
+arm_spe_discard_test
 
 exit $glb_err
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/5] perf docs: arm_spe: Document new discard mode
  2024-12-24 10:44 [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode James Clark
                   ` (3 preceding siblings ...)
  2024-12-24 10:44 ` [PATCH v2 4/5] perf test: arm_spe: Add test for " James Clark
@ 2024-12-24 10:44 ` James Clark
  4 siblings, 0 replies; 8+ messages in thread
From: James Clark @ 2024-12-24 10:44 UTC (permalink / raw)
  To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
	mark.rutland
  Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

Document the flag along with PMU events to hint what it's used for and
give an example with other useful options to get minimal output.

Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
 tools/perf/Documentation/perf-arm-spe.txt | 26 +++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/perf/Documentation/perf-arm-spe.txt b/tools/perf/Documentation/perf-arm-spe.txt
index de2b0b479249..37afade4f1b2 100644
--- a/tools/perf/Documentation/perf-arm-spe.txt
+++ b/tools/perf/Documentation/perf-arm-spe.txt
@@ -150,6 +150,7 @@ arm_spe/load_filter=1,min_latency=10/'
   pct_enable=1        - collect physical timestamp instead of virtual timestamp (PMSCR.PCT) - requires privilege
   store_filter=1      - collect stores only (PMSFCR.ST)
   ts_enable=1         - enable timestamping with value of generic timer (PMSCR.TS)
+  discard=1           - enable SPE PMU events but don't collect sample data - see 'Discard mode' (PMBLIMITR.FM = DISCARD)
 
 +++*+++ Latency is the total latency from the point at which sampling started on that instruction, rather
 than only the execution latency.
@@ -220,6 +221,31 @@ Common errors
 
    Increase sampling interval (see above)
 
+PMU events
+~~~~~~~~~~
+
+SPE has events that can be counted on core PMUs. These are prefixed with
+SAMPLE_, for example SAMPLE_POP, SAMPLE_FEED, SAMPLE_COLLISION and
+SAMPLE_FEED_BR.
+
+These events will only count when an SPE event is running on the same core that
+the PMU event is opened on, otherwise they read as 0. There are various ways to
+ensure that the PMU event and SPE event are scheduled together depending on the
+way the event is opened. For example opening both events as per-process events
+on the same process, although it's not guaranteed that the PMU event is enabled
+first when context switching. For that reason it may be better to open the PMU
+event as a systemwide event and then open SPE on the process of interest.
+
+Discard mode
+~~~~~~~~~~~~
+
+SPE related (SAMPLE_* etc) core PMU events can be used without the overhead of
+collecting sample data if discard mode is supported (optional from Armv8.6).
+First run a system wide SPE session (or on the core of interest) using options
+to minimize output. Then run perf stat:
+
+  perf record -e arm_spe/discard/ -a -N -B --no-bpf-event -o - > /dev/null &
+  perf stat -e SAMPLE_FEED_LD
 
 SEE ALSO
 --------
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/5] perf: arm_spe: Add format option for discard mode
  2024-12-24 10:44 ` [PATCH v2 1/5] " James Clark
@ 2025-01-07 17:39   ` Will Deacon
  2025-01-08 10:08     ` James Clark
  0 siblings, 1 reply; 8+ messages in thread
From: Will Deacon @ 2025-01-07 17:39 UTC (permalink / raw)
  To: James Clark
  Cc: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun,
	mark.rutland, robh, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf

On Tue, Dec 24, 2024 at 10:44:08AM +0000, James Clark wrote:
> FEAT_SPEv1p2 (optional from Armv8.6) adds a discard mode that allows all
> SPE data to be discarded rather than written to memory. Add a format
> bit for this mode.
> 
> If the mode isn't supported, the format bit isn't published and attempts
> to use it will result in -EOPNOTSUPP. Allocating an aux buffer is still
> allowed even though it won't be written to so that old tools continue to
> work, but updated tools can choose to skip this step.
> 
> Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
> Signed-off-by: James Clark <james.clark@linaro.org>
> ---
>  drivers/perf/arm_spe_pmu.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
> index fd5b78732603..9aaf3f98e6f5 100644
> --- a/drivers/perf/arm_spe_pmu.c
> +++ b/drivers/perf/arm_spe_pmu.c
> @@ -193,6 +193,9 @@ static const struct attribute_group arm_spe_pmu_cap_group = {
>  #define ATTR_CFG_FLD_store_filter_CFG		config	/* PMSFCR_EL1.ST */
>  #define ATTR_CFG_FLD_store_filter_LO		34
>  #define ATTR_CFG_FLD_store_filter_HI		34
> +#define ATTR_CFG_FLD_discard_CFG		config	/* PMBLIMITR_EL1.FM = DISCARD */
> +#define ATTR_CFG_FLD_discard_LO			35
> +#define ATTR_CFG_FLD_discard_HI			35
>  
>  #define ATTR_CFG_FLD_event_filter_CFG		config1	/* PMSEVFR_EL1 */
>  #define ATTR_CFG_FLD_event_filter_LO		0
> @@ -216,6 +219,7 @@ GEN_PMU_FORMAT_ATTR(store_filter);
>  GEN_PMU_FORMAT_ATTR(event_filter);
>  GEN_PMU_FORMAT_ATTR(inv_event_filter);
>  GEN_PMU_FORMAT_ATTR(min_latency);
> +GEN_PMU_FORMAT_ATTR(discard);
>  
>  static struct attribute *arm_spe_pmu_formats_attr[] = {
>  	&format_attr_ts_enable.attr,
> @@ -228,9 +232,15 @@ static struct attribute *arm_spe_pmu_formats_attr[] = {
>  	&format_attr_event_filter.attr,
>  	&format_attr_inv_event_filter.attr,
>  	&format_attr_min_latency.attr,
> +	&format_attr_discard.attr,
>  	NULL,
>  };
>  
> +static bool discard_unsupported(struct arm_spe_pmu *spe_pmu)
> +{
> +	return spe_pmu->pmsver < ID_AA64DFR0_EL1_PMSVer_V1P2;
> +}

Why not add a new SPE_PMU_FEAT_* for this and handle it in a similar
way to other optional hardware features?

Will


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/5] perf: arm_spe: Add format option for discard mode
  2025-01-07 17:39   ` Will Deacon
@ 2025-01-08 10:08     ` James Clark
  0 siblings, 0 replies; 8+ messages in thread
From: James Clark @ 2025-01-08 10:08 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun,
	mark.rutland, robh, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Alexander Shishkin,
	Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
	Leo Yan, Graham Woodward, linux-kernel, bpf



On 07/01/2025 5:39 pm, Will Deacon wrote:
> On Tue, Dec 24, 2024 at 10:44:08AM +0000, James Clark wrote:
>> FEAT_SPEv1p2 (optional from Armv8.6) adds a discard mode that allows all
>> SPE data to be discarded rather than written to memory. Add a format
>> bit for this mode.
>>
>> If the mode isn't supported, the format bit isn't published and attempts
>> to use it will result in -EOPNOTSUPP. Allocating an aux buffer is still
>> allowed even though it won't be written to so that old tools continue to
>> work, but updated tools can choose to skip this step.
>>
>> Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
>> Signed-off-by: James Clark <james.clark@linaro.org>
>> ---
>>   drivers/perf/arm_spe_pmu.c | 23 +++++++++++++++++++++++
>>   1 file changed, 23 insertions(+)
>>
>> diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
>> index fd5b78732603..9aaf3f98e6f5 100644
>> --- a/drivers/perf/arm_spe_pmu.c
>> +++ b/drivers/perf/arm_spe_pmu.c
>> @@ -193,6 +193,9 @@ static const struct attribute_group arm_spe_pmu_cap_group = {
>>   #define ATTR_CFG_FLD_store_filter_CFG		config	/* PMSFCR_EL1.ST */
>>   #define ATTR_CFG_FLD_store_filter_LO		34
>>   #define ATTR_CFG_FLD_store_filter_HI		34
>> +#define ATTR_CFG_FLD_discard_CFG		config	/* PMBLIMITR_EL1.FM = DISCARD */
>> +#define ATTR_CFG_FLD_discard_LO			35
>> +#define ATTR_CFG_FLD_discard_HI			35
>>   
>>   #define ATTR_CFG_FLD_event_filter_CFG		config1	/* PMSEVFR_EL1 */
>>   #define ATTR_CFG_FLD_event_filter_LO		0
>> @@ -216,6 +219,7 @@ GEN_PMU_FORMAT_ATTR(store_filter);
>>   GEN_PMU_FORMAT_ATTR(event_filter);
>>   GEN_PMU_FORMAT_ATTR(inv_event_filter);
>>   GEN_PMU_FORMAT_ATTR(min_latency);
>> +GEN_PMU_FORMAT_ATTR(discard);
>>   
>>   static struct attribute *arm_spe_pmu_formats_attr[] = {
>>   	&format_attr_ts_enable.attr,
>> @@ -228,9 +232,15 @@ static struct attribute *arm_spe_pmu_formats_attr[] = {
>>   	&format_attr_event_filter.attr,
>>   	&format_attr_inv_event_filter.attr,
>>   	&format_attr_min_latency.attr,
>> +	&format_attr_discard.attr,
>>   	NULL,
>>   };
>>   
>> +static bool discard_unsupported(struct arm_spe_pmu *spe_pmu)
>> +{
>> +	return spe_pmu->pmsver < ID_AA64DFR0_EL1_PMSVer_V1P2;
>> +}
> 
> Why not add a new SPE_PMU_FEAT_* for this and handle it in a similar
> way to other optional hardware features?
> 
> Will

Hmmm good point, I'm not sure why I didn't do it that way. Possibly 
because it's only based off pmsver which is already saved, whereas the 
other feats are based off reading PMSIDR which is thrown away. But I can 
add SPE_PMU_FEAT_DISCARD.

Thanks
James




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-01-08 10:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-24 10:44 [PATCH v2 0/5] perf: arm_spe: Add format option for discard mode James Clark
2024-12-24 10:44 ` [PATCH v2 1/5] " James Clark
2025-01-07 17:39   ` Will Deacon
2025-01-08 10:08     ` James Clark
2024-12-24 10:44 ` [PATCH v2 2/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup James Clark
2024-12-24 10:44 ` [PATCH v2 3/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode James Clark
2024-12-24 10:44 ` [PATCH v2 4/5] perf test: arm_spe: Add test for " James Clark
2024-12-24 10:44 ` [PATCH v2 5/5] perf docs: arm_spe: Document new " James Clark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox