* [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode
@ 2025-01-08 14:27 James Clark
0 siblings, 0 replies; 11+ messages in thread
From: James Clark @ 2025-01-08 14:27 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, Michael Petlan, Veronika Molnarova,
Athira Rajeev, Thomas Richter, 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 v2:
* Use existing SPE_PMU_FEAT_* mechanism (Will)
Changes since v1:
* Add a new section and some clarifications about the PMU events to
the docs. (Ian)
Applies to v6.13-rc6
James Clark (5):
perf: arm_spe: Add format option for discard mode
perf docs: arm_spe: Document new 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
drivers/perf/arm_spe_pmu.c | 22 ++++++
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, 136 insertions(+), 32 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode
@ 2025-01-08 14:28 James Clark
2025-01-08 14:28 ` [PATCH v3 1/5] " James Clark
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: James Clark @ 2025-01-08 14:28 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
mark.rutland, namhyung, acme
Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward, Michael Petlan,
Veronika Molnarova, Thomas Richter, Athira Rajeev, 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 v2:
* Use existing SPE_PMU_FEAT_* mechanism (Will)
Changes since v1:
* Add a new section and some clarifications about the PMU events to
the docs. (Ian)
Applies to v6.13-rc6
James Clark (5):
perf: arm_spe: Add format option for discard mode
perf docs: arm_spe: Document new 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
drivers/perf/arm_spe_pmu.c | 22 ++++++
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, 136 insertions(+), 32 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/5] perf: arm_spe: Add format option for discard mode
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
@ 2025-01-08 14:28 ` James Clark
2025-01-08 20:16 ` Yeo Reum Yun
2025-01-08 14:28 ` [PATCH v3 2/5] perf docs: arm_spe: Document new " James Clark
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: James Clark @ 2025-01-08 14:28 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
mark.rutland, namhyung, acme
Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward, Michael Petlan,
Veronika Molnarova, Athira Rajeev, Thomas Richter, 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.
Signed-off-by: James Clark <james.clark@linaro.org>
---
drivers/perf/arm_spe_pmu.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index fd5b78732603..f5e6878db9d6 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -85,6 +85,7 @@ struct arm_spe_pmu {
#define SPE_PMU_FEAT_LDS (1UL << 4)
#define SPE_PMU_FEAT_ERND (1UL << 5)
#define SPE_PMU_FEAT_INV_FILT_EVT (1UL << 6)
+#define SPE_PMU_FEAT_DISCARD (1UL << 7)
#define SPE_PMU_FEAT_DEV_PROBED (1UL << 63)
u64 features;
@@ -193,6 +194,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 +220,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,6 +233,7 @@ 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,
};
@@ -238,6 +244,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 && !(spe_pmu->features & SPE_PMU_FEAT_DISCARD))
+ return 0;
+
if (attr == &format_attr_inv_event_filter.attr && !(spe_pmu->features & SPE_PMU_FEAT_INV_FILT_EVT))
return 0;
@@ -502,6 +511,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 +758,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) &&
+ !(spe_pmu->features & SPE_PMU_FEAT_DISCARD))
+ return -EOPNOTSUPP;
+
set_spe_event_has_cx(event);
reg = arm_spe_event_to_pmscr(event);
if (reg & (PMSCR_EL1_PA | PMSCR_EL1_PCT))
@@ -1027,6 +1046,9 @@ static void __arm_spe_pmu_dev_probe(void *info)
if (FIELD_GET(PMSIDR_EL1_ERND, reg))
spe_pmu->features |= SPE_PMU_FEAT_ERND;
+ if (spe_pmu->pmsver >= ID_AA64DFR0_EL1_PMSVer_V1P2)
+ spe_pmu->features |= SPE_PMU_FEAT_DISCARD;
+
/* This field has a spaced out encoding, so just use a look-up */
fld = FIELD_GET(PMSIDR_EL1_INTERVAL, reg);
switch (fld) {
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/5] perf docs: arm_spe: Document new discard mode
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
2025-01-08 14:28 ` [PATCH v3 1/5] " James Clark
@ 2025-01-08 14:28 ` James Clark
2025-01-08 14:28 ` [PATCH v3 3/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup James Clark
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: James Clark @ 2025-01-08 14:28 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
mark.rutland, namhyung, acme
Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward,
Veronika Molnarova, Michael Petlan, Athira Rajeev, Thomas Richter,
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] 11+ messages in thread
* [PATCH v3 3/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
2025-01-08 14:28 ` [PATCH v3 1/5] " James Clark
2025-01-08 14:28 ` [PATCH v3 2/5] perf docs: arm_spe: Document new " James Clark
@ 2025-01-08 14:28 ` James Clark
2025-01-08 14:28 ` [PATCH v3 4/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode James Clark
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: James Clark @ 2025-01-08 14:28 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
mark.rutland, namhyung, acme
Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward, Michael Petlan,
Veronika Molnarova, Athira Rajeev, Thomas Richter, 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] 11+ messages in thread
* [PATCH v3 4/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
` (2 preceding siblings ...)
2025-01-08 14:28 ` [PATCH v3 3/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup James Clark
@ 2025-01-08 14:28 ` James Clark
2025-01-08 14:29 ` [PATCH v3 5/5] perf test: arm_spe: Add test for " James Clark
2025-01-10 16:22 ` [PATCH v3 0/5] perf: arm_spe: Add format option " Will Deacon
5 siblings, 0 replies; 11+ messages in thread
From: James Clark @ 2025-01-08 14:28 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
mark.rutland, namhyung, acme
Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward,
Veronika Molnarova, Michael Petlan, Thomas Richter, Athira Rajeev,
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] 11+ messages in thread
* [PATCH v3 5/5] perf test: arm_spe: Add test for discard mode
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
` (3 preceding siblings ...)
2025-01-08 14:28 ` [PATCH v3 4/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode James Clark
@ 2025-01-08 14:29 ` James Clark
2025-01-10 16:22 ` [PATCH v3 0/5] perf: arm_spe: Add format option " Will Deacon
5 siblings, 0 replies; 11+ messages in thread
From: James Clark @ 2025-01-08 14:29 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun, will,
mark.rutland, namhyung, acme
Cc: robh, James Clark, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward,
Veronika Molnarova, Michael Petlan, Thomas Richter, Athira Rajeev,
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] 11+ messages in thread
* Re: [PATCH v3 1/5] perf: arm_spe: Add format option for discard mode
2025-01-08 14:28 ` [PATCH v3 1/5] " James Clark
@ 2025-01-08 20:16 ` Yeo Reum Yun
0 siblings, 0 replies; 11+ messages in thread
From: Yeo Reum Yun @ 2025-01-08 20:16 UTC (permalink / raw)
To: James Clark, linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, irogers@google.com,
will@kernel.org, Mark Rutland, namhyung@kernel.org,
acme@kernel.org
Cc: robh@kernel.org, Peter Zijlstra, Ingo Molnar, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Liang, Kan, John Garry, Mike Leach,
Leo Yan, Graham Woodward, Michael Petlan, Veronika Molnarova,
Athira Rajeev, Thomas Richter, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org
Reviewd-by: Yeoreum Yun <yeoreum.yun@arm.com>
________________________________________
From: James Clark <james.clark@linaro.org>
Sent: 08 January 2025 14:28
To: linux-arm-kernel@lists.infradead.org; linux-perf-users@vger.kernel.org; irogers@google.com; Yeo Reum Yun; will@kernel.org; Mark Rutland; namhyung@kernel.org; acme@kernel.org
Cc: robh@kernel.org; James Clark; Peter Zijlstra; Ingo Molnar; Alexander Shishkin; Jiri Olsa; Adrian Hunter; Liang, Kan; John Garry; Mike Leach; Leo Yan; Graham Woodward; Michael Petlan; Veronika Molnarova; Athira Rajeev; Thomas Richter; linux-kernel@vger.kernel.org; bpf@vger.kernel.org
Subject: [PATCH v3 1/5] perf: arm_spe: Add format option for discard mode
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.
Signed-off-by: James Clark <james.clark@linaro.org>
---
drivers/perf/arm_spe_pmu.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c
index fd5b78732603..f5e6878db9d6 100644
--- a/drivers/perf/arm_spe_pmu.c
+++ b/drivers/perf/arm_spe_pmu.c
@@ -85,6 +85,7 @@ struct arm_spe_pmu {
#define SPE_PMU_FEAT_LDS (1UL << 4)
#define SPE_PMU_FEAT_ERND (1UL << 5)
#define SPE_PMU_FEAT_INV_FILT_EVT (1UL << 6)
+#define SPE_PMU_FEAT_DISCARD (1UL << 7)
#define SPE_PMU_FEAT_DEV_PROBED (1UL << 63)
u64 features;
@@ -193,6 +194,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 +220,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,6 +233,7 @@ 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,
};
@@ -238,6 +244,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 && !(spe_pmu->features & SPE_PMU_FEAT_DISCARD))
+ return 0;
+
if (attr == &format_attr_inv_event_filter.attr && !(spe_pmu->features & SPE_PMU_FEAT_INV_FILT_EVT))
return 0;
@@ -502,6 +511,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 +758,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) &&
+ !(spe_pmu->features & SPE_PMU_FEAT_DISCARD))
+ return -EOPNOTSUPP;
+
set_spe_event_has_cx(event);
reg = arm_spe_event_to_pmscr(event);
if (reg & (PMSCR_EL1_PA | PMSCR_EL1_PCT))
@@ -1027,6 +1046,9 @@ static void __arm_spe_pmu_dev_probe(void *info)
if (FIELD_GET(PMSIDR_EL1_ERND, reg))
spe_pmu->features |= SPE_PMU_FEAT_ERND;
+ if (spe_pmu->pmsver >= ID_AA64DFR0_EL1_PMSVer_V1P2)
+ spe_pmu->features |= SPE_PMU_FEAT_DISCARD;
+
/* This field has a spaced out encoding, so just use a look-up */
fld = FIELD_GET(PMSIDR_EL1_INTERVAL, reg);
switch (fld) {
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
` (4 preceding siblings ...)
2025-01-08 14:29 ` [PATCH v3 5/5] perf test: arm_spe: Add test for " James Clark
@ 2025-01-10 16:22 ` Will Deacon
2025-01-13 14:33 ` James Clark
2025-01-13 14:45 ` Arnaldo Carvalho de Melo
5 siblings, 2 replies; 11+ messages in thread
From: Will Deacon @ 2025-01-10 16:22 UTC (permalink / raw)
To: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun,
mark.rutland, namhyung, acme, James Clark
Cc: catalin.marinas, kernel-team, Will Deacon, robh, Peter Zijlstra,
Ingo Molnar, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Liang, Kan, John Garry, Mike Leach, Leo Yan, Graham Woodward,
Michael Petlan, Veronika Molnarova, Thomas Richter, Athira Rajeev,
linux-kernel, bpf
On Wed, 08 Jan 2025 14:28:55 +0000, James Clark wrote:
> 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.
>
> [...]
Applied driver and docs patches to will (for-next/perf), thanks!
[1/5] perf: arm_spe: Add format option for discard mode
https://git.kernel.org/will/c/d28d95bc63cb
[2/5] perf docs: arm_spe: Document new discard mode
https://git.kernel.org/will/c/ba113ecad81a
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode
2025-01-10 16:22 ` [PATCH v3 0/5] perf: arm_spe: Add format option " Will Deacon
@ 2025-01-13 14:33 ` James Clark
2025-01-13 14:45 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 11+ messages in thread
From: James Clark @ 2025-01-13 14:33 UTC (permalink / raw)
To: Will Deacon, namhyung, acme
Cc: catalin.marinas, kernel-team, robh, Peter Zijlstra, Ingo Molnar,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Liang, Kan,
John Garry, Mike Leach, Leo Yan, Graham Woodward, Michael Petlan,
Veronika Molnarova, Thomas Richter, Athira Rajeev, linux-kernel,
bpf, linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun,
mark.rutland
On 10/01/2025 4:22 pm, Will Deacon wrote:
> On Wed, 08 Jan 2025 14:28:55 +0000, James Clark wrote:
>> 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.
>>
>> [...]
>
> Applied driver and docs patches to will (for-next/perf), thanks!
>
> [1/5] perf: arm_spe: Add format option for discard mode
> https://git.kernel.org/will/c/d28d95bc63cb
> [2/5] perf docs: arm_spe: Document new discard mode
> https://git.kernel.org/will/c/ba113ecad81a
>
> Cheers,
Thanks Will. Arnaldo and Namhyung, are you ok to take the Perf changes now?
Thanks
James
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode
2025-01-10 16:22 ` [PATCH v3 0/5] perf: arm_spe: Add format option " Will Deacon
2025-01-13 14:33 ` James Clark
@ 2025-01-13 14:45 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 11+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-01-13 14:45 UTC (permalink / raw)
To: Will Deacon
Cc: linux-arm-kernel, linux-perf-users, irogers, yeoreum.yun,
mark.rutland, namhyung, James Clark, catalin.marinas, kernel-team,
robh, Peter Zijlstra, Ingo Molnar, Alexander Shishkin, Jiri Olsa,
Adrian Hunter, Liang, Kan, John Garry, Mike Leach, Leo Yan,
Graham Woodward, Michael Petlan, Veronika Molnarova,
Thomas Richter, Athira Rajeev, linux-kernel, bpf
On Fri, Jan 10, 2025 at 04:22:48PM +0000, Will Deacon wrote:
> On Wed, 08 Jan 2025 14:28:55 +0000, James Clark wrote:
> > 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.
> >
> > [...]
>
> Applied driver and docs patches to will (for-next/perf), thanks!
Picked the rest and added it to perf-tools-next,
Thanks,
- Arnaldo
> [1/5] perf: arm_spe: Add format option for discard mode
> https://git.kernel.org/will/c/d28d95bc63cb
> [2/5] perf docs: arm_spe: Document new discard mode
> https://git.kernel.org/will/c/ba113ecad81a
>
> Cheers,
> --
> Will
>
> https://fixes.arm64.dev
> https://next.arm64.dev
> https://will.arm64.dev
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-01-13 14:47 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 14:28 [PATCH v3 0/5] perf: arm_spe: Add format option for discard mode James Clark
2025-01-08 14:28 ` [PATCH v3 1/5] " James Clark
2025-01-08 20:16 ` Yeo Reum Yun
2025-01-08 14:28 ` [PATCH v3 2/5] perf docs: arm_spe: Document new " James Clark
2025-01-08 14:28 ` [PATCH v3 3/5] perf tool: arm-spe: Pull out functions for aux buffer and tracking setup James Clark
2025-01-08 14:28 ` [PATCH v3 4/5] perf tool: arm-spe: Don't allocate buffer or tracking event in discard mode James Clark
2025-01-08 14:29 ` [PATCH v3 5/5] perf test: arm_spe: Add test for " James Clark
2025-01-10 16:22 ` [PATCH v3 0/5] perf: arm_spe: Add format option " Will Deacon
2025-01-13 14:33 ` James Clark
2025-01-13 14:45 ` Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2025-01-08 14:27 James Clark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).