mm/damon/perf: add ARM SPE AUX backend
Subsystems (4)
cover mm/damon/perf: add ARM SPE AUX backend
From: Kunwu Chan <[email protected]>
This series adds an AUX trace-buffer backend to the DAMON perf observability framework, enabling ARM SPE (Statistical Profiling Extension) to deliver hardware-sampled access reports into DAMON's existing SPSC report ring.
Patch 2 touches drivers/perf/arm_spe_pmu.c to expose the PMU matcher. This change is tightly coupled with the DAMON AUX backend. ARM SPE PMU driver maintainers only need to review patch 2.
This series is based on the Ravi's hardware-sampled access reports branch [1], and depends on the perf AUX kernel-consumer RFC series [2]. The dependencies is not upstream yet, so this series remains RFC.
Why a dedicated AUX backend
---------------------------
ARM SPE and similar PMUs do not deliver samples through the standard perf overflow callback. Instead, they write trace data into an AUX buffer managed by the perf core. The AUX buffer is consumed from process context (kdamond) rather than from NMI, so the existing overflow-callback path in DAMON cannot be reused.
The backend model adds three operations to the damon_perf_event
lifecycle: init (allocate the AUX buffer), arm (position the consumer cursor), and drain (parse the SPE packet stream and publish reports). The backend is selected at event creation time by matching the PMU object via its event_init callback.
What the series adds
--------------------
Patch 1 introduces the backend operations table, the backend state fields in damon_perf_event, and the Kconfig options. ARM SPE must be built into the kernel; the KUnit test option is separate.
Patch 2 is the ARM SPE backend. It owns a per-CPU AUX buffer, decodes the SPE packet stream (the same encoding that perf's userspace arm-spe-decoder handles), resolves sampled CONTEXTIDR_EL1 values to tgids under RCU, and publishes synthesized access reports. The drain runs before the SPSC ring consumer on each monitoring interval, and a final drain after event disable ensures no records are lost. The backend also modifies the ARM SPE PMU driver to expose arm_spe_pmu_match() for PMU object matching.
Patch 3 adds byte-exact KUnit tests for the SPE record parser. The tests cover load and store records, timestamp terminators, multiple records in one window, PAD and ALIGNMENT packets at both odd and aligned positions, extended addresses, bad-packet resynchronization, truncated records, and records without a virtual address. A split- record test verifies that a record spanning two AUX snapshots leaves the tail unchanged until the terminating packet arrives.
Patch 4 adds a DAMON selftest for the AUX backend. It checks the backend integration, the required AUX-before-ring lifecycle ordering, runs the parser KUnit suite through debugfs, and on an ARM SPE system creates a live DAMON session with a controlled userspace target, verifying positive end-to-end pipeline counters and final enqueue/dequeue closure.
Testing
=======
Tested on Kunpeng 920 (256 CPUs, ARM SPE, kernel 7.1.0-rc5-mm-new-damon+):
ARM SPE KUnit (spe_parse_one_record):
16 passed, 0 failed, 0 skipped
(store record, load record with timestamp, two records, pad-wrapped,
alignment at odd/aligned positions, bad packet resync, record without address, events/source/counter, truncated record retained, truncated packet retained, extended address, invalid extended header, pad-only, empty window, split record across two snapshots)
AUX selftest (damon_perf_aux_test.sh arm_spe_0):
SUMMARY: 52 passed, 0 failed, 0 skipped (Overall PASS)
callback=58318, valid=58318, enqueue=43390, dequeue=43390,
match=34049, update=564
final ring closure: enqueue=43390 dequeue=43390Known limitations
=================
- AUX_BACKEND_MAX=4: the AUX backend registration table holds at most 4 backend types. This is a framework limit, not a per-PMU-instance cap.
- ARM SPE must be built into the kernel (ARM_SPE_PMU=y), not as a module, because the backend calls arm_spe_pmu_match() at initcall time.
- The AUX buffer is 2 pages (8 KiB). The SPE hardware pauses when the non-overwrite ring is full; the drain frees space and re-enables the event.
- CONTEXTIDR_EL1 carries the sampled task's pid, resolved to tgid under RCU. Records without a valid tgid are dropped.
- This series requires the perf AUX kernel API patches [2] to be applied first. These patches are not yet upstream and must be reviewed by the perf subsystem maintainers.
References
==========
Link [1]: https://github.com/damonitor/linux.git
branch: ravi_hw_sampled_access_reports_rfc_v1
commit: fd968106e5bfLink [2]: https://lore.kernel.org/all/[email protected]/
perf AUX kernel API PATCH Series:
- perf/core: add AUX buffer ownership for kernel events
- perf/core: add AUX ring accessors for kernel consumers
- perf/core: add KUnit tests for AUX kernel-consumer API
- selftests/perf_events: add userspace AUX regression test
- selftests/perf_events: add AUX kernel API selftest script
Kunwu Chan (2):
mm/damon/perf: introduce AUX backend interface and Kconfig mm/damon/perf: add AUX trace-buffer PMU backend for ARM SPE
Lian Wang (ProcessMission) (2):
mm/damon/perf: add KUnit tests for the SPE record parser selftests/damon: add DAMON perf AUX backend test
drivers/perf/arm_spe_pmu.c | 8 + include/linux/damon.h | 5 + include/linux/perf/arm_spe_pmu.h | 11 + mm/damon/Kconfig | 28 + mm/damon/core.c | 22 +- mm/damon/ops-common.h | 6 +- mm/damon/perf/Makefile | 5 + mm/damon/perf/aux_backend.c | 121 +++++ mm/damon/perf/aux_backend.h | 72 +++ mm/damon/perf/spe_backend.c | 479 ++++++++++++++++++ mm/damon/perf/spe_parser.h | 109 ++++ mm/damon/perf/spe_parser_test.c | 365 +++++++++++++ mm/damon/vaddr.c | 68 ++- tools/testing/selftests/damon/Makefile | 1 + .../selftests/damon/damon_perf_aux_test.sh | 414 +++++++++++++++ 15 files changed, 1704 insertions(+), 10 deletions(-) create mode 100644 include/linux/perf/arm_spe_pmu.h create mode 100644 mm/damon/perf/aux_backend.c create mode 100644 mm/damon/perf/aux_backend.h create mode 100644 mm/damon/perf/spe_backend.c create mode 100644 mm/damon/perf/spe_parser.h create mode 100644 mm/damon/perf/spe_parser_test.c create mode 100755 tools/testing/selftests/damon/damon_perf_aux_test.sh
Signature · 1 line
2.43.0
RFC PATCH 1/4 mm/damon/perf: introduce AUX backend interface and Kconfig
From: Kunwu Chan <[email protected]>
Add the backend operations used by AUX trace-buffer PMUs, backend state to damon_perf_event, and stubs for configurations without AUX support.
Add CONFIG_DAMON_PERF_AUX for the ARM SPE transport and a separate CONFIG_DAMON_PERF_SPE_KUNIT_TEST option. The current transport requires ARM SPE to be built into the kernel; it remains independent of the optional observability counters and tracepoints.
--- include/linux/damon.h | 5 +++ mm/damon/Kconfig | 28 +++++++++++++++ mm/damon/perf/aux_backend.h | 72 +++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 mm/damon/perf/aux_backend.h
include/linux/damon.h +5 -0
@@ -8,6 +8,7 @@#ifndef _DAMON_H_#define _DAMON_H_ +#include <linux/cpumask.h> #include <linux/math64.h> #include <linux/memcontrol.h> #include <linux/mutex.h>
@@ -127,6 +128,7 @@ struct damon_target {enum damon_report_source {DAMON_REPORT_SRC_PERF_OVERFLOW =0 ,/* overflow_handler (IBS, PEBS) */ DAMON_REPORT_SRC_PAGE_FAULT ,/* damon_report_page_fault() */ +DAMON_REPORT_SRC_PERF_AUX ,/* AUX trace-buffer backend */ };/**
@@ -538,6 +540,7 @@ struct damos_filter {struct damon_ctx ;struct damon_target_lookup ;struct damos ; +struct damon_perf_backend_ops ;/** * struct damos_walk_control - Control damos_walk().
@@ -1056,6 +1059,8 @@ struct damon_perf_event_attr {struct damon_perf_event {struct damon_perf_event_attr attr;void *priv; +const struct damon_perf_backend_ops *ops; +cpumask_t aux_cpumask;struct list_head list;struct hlist_node hlist_node;bool init_complete;
mm/damon/Kconfig +28 -0
@@ -149,4 +149,32 @@ config DAMON_PERF_OBSERVE If unsure, say N. + +config DAMON_PERF_AUX + bool "DAMON AUX trace-buffer backend support" + depends on DAMON + depends on PERF_EVENTS + depends on ARM_SPE_PMU=y + default n + help + Enable the functional AUX trace-buffer transport for DAMON perf + events. This provides backend selection and drain scheduling for + ARM SPE, which does not deliver samples through an overflow + callback. ARM SPE must be built into the kernel. + + This transport is independent of CONFIG_DAMON_PERF_OBSERVE. + + If unsure, say N. + +config DAMON_PERF_SPE_KUNIT_TEST + bool "Test the DAMON perf SPE parser" if !KUNIT_ALL_TESTS + depends on DAMON_PERF_AUX && KUNIT=y + default KUNIT_ALL_TESTS + help + Test the ARM SPE parser with byte-exact packet streams. The cases + cover valid records, truncation, alignment, error resynchronization + and consumed-length accounting. Results can be exposed through + debugfs when CONFIG_KUNIT_DEBUGFS is enabled. + + If unsure, say N. endmenu
mm/damon/perf/aux_backend.h new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 2/4 mm/damon/perf: add AUX trace-buffer PMU backend for ARM SPE
In reply to Kunwu ChanFrom: Kunwu Chan <[email protected]>
Add an ARM SPE backend that owns a per-CPU AUX buffer, drains its packet stream from kdamond process context, and publishes synthesized access reports through DAMON's existing SPSC report ring.
Drain AUX before consuming the SPSC ring on each monitoring interval. After disabling the events, run the same AUX-then-ring sequence once more so records finalized by perf_event_disable() are not lost.
Decode CONTEXTIDR_EL1 as a sampled tid and resolve its tgid under RCU. Drop records whose context is missing or stale instead of assigning them to an arbitrary DAMON target. Retain incomplete trailing records across drains, guarantee progress for aligned ALIGNMENT packets, and reject unsupported extended packet classes.
Match ARM SPE events by the PMU event_init callback, avoiding a fixed-size PMU registry and its device-lifetime problems. Roll back partially armed CPU events on failure and release per-CPU AUX state on all error paths.
This depends on the perf AUX kernel-consumer API series.
--- drivers/perf/arm_spe_pmu.c | 8 + include/linux/perf/arm_spe_pmu.h | 11 + mm/damon/core.c | 22 +- mm/damon/ops-common.h | 6 +- mm/damon/perf/Makefile | 5 + mm/damon/perf/aux_backend.c | 121 ++++++++ mm/damon/perf/spe_backend.c | 479 +++++++++++++++++++++++++++++++ mm/damon/perf/spe_parser.h | 109 +++++++ mm/damon/vaddr.c | 68 ++++- 9 files changed, 819 insertions(+), 10 deletions(-) create mode 100644 include/linux/perf/arm_spe_pmu.h create mode 100644 mm/damon/perf/aux_backend.c create mode 100644 mm/damon/perf/spe_backend.c create mode 100644 mm/damon/perf/spe_parser.h
drivers/perf/arm_spe_pmu.c +8 -0
@@ -27,6 +27,8 @@#include <linux/module.h> #include <linux/of.h> #include <linux/perf_event.h> +#include <linux/perf/arm_spe_pmu.h> +#include <linux/perf/arm_pmu.h> #include <linux/platform_device.h> #include <linux/printk.h>
@@ -1097,6 +1099,12 @@ static int arm_spe_pmu_perf_init(struct arm_spe_pmu *spe_pmu)return perf_pmu_register (&spe_pmu->pmu, name,-1 ); } +bool arm_spe_pmu_match (struct perf_event *perf_event) +{ +return perf_event->pmu->event_init == arm_spe_pmu_event_init; +} +EXPORT_SYMBOL_GPL (arm_spe_pmu_match); +static void arm_spe_pmu_perf_destroy (struct arm_spe_pmu *spe_pmu) {perf_pmu_unregister (&spe_pmu->pmu);
include/linux/perf/arm_spe_pmu.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_PERF_ARM_SPE_PMU_H +#define _LINUX_PERF_ARM_SPE_PMU_H + +#include <linux/types.h> + +struct perf_event ; + +bool arm_spe_pmu_match (struct perf_event *perf_event); + +#endif /* _LINUX_PERF_ARM_SPE_PMU_H */
mm/damon/core.c +17 -5
@@ -22,6 +22,7 @@/* for damon_get_folio() used by node eligible memory metrics */ #include "ops-common.h" #include "perf/perf.h" +#include "perf/aux_backend.h" #define CREATE_TRACE_POINTS #include <trace/events/damon.h>
@@ -1763,8 +1764,14 @@ static int damon_commit_perf_events(struct damon_ctx *dst,* the kdamond runs. Arm now if we are committing into a * running ctx whose substrate is already armed. */ -if (dst->perf_events_active) -damon_perf_event_arm (new_event); +if (dst->perf_events_active) { + err =damon_perf_event_arm (new_event); +if (err) { +damon_perf_cleanup (dst, new_event); +kfree (new_event); + goto out; + } + } }list_add_tail (&new_event->list, &dst->perf_events); }
@@ -4077,6 +4084,9 @@ static unsigned int kdamond_check_reported_accesses(struct damon_ctx *ctx)unsigned int i;unsigned int total_reports =0 , matched_reports =0 ; +/* AUX backends publish into the same ring consumed below. */ +damon_perf_aux_drain (ctx); + tbl =damon_build_target_lookup (ctx, &nr_targets);if (!tbl) { pr_warn_ratelimited(
@@ -4194,8 +4204,10 @@ static int kdamond_fn(void *data)struct damon_perf_event *event;WRITE_ONCE (ctx->perf_events_active, true); -list_for_each_entry (event, &ctx->perf_events, list) -damon_perf_event_arm (event); +list_for_each_entry (event, &ctx->perf_events, list) { +if (damon_perf_event_arm (event)) + goto done; + } }if (ctx->ops.init)
@@ -4323,7 +4335,7 @@ static int kdamond_fn(void *data)WRITE_ONCE (ctx->perf_events_active, false);list_for_each_entry (event, &ctx->perf_events, list)damon_perf_event_disarm (event); -/* Drain any in-flight reports queued before disarm took effect. */ +/* Final AUX drain and ring drain after perf_event_disable(). */ kdamond_check_reported_accesses (ctx); }damon_destroy_targets (ctx);
mm/damon/ops-common.h +4 -2
@@ -33,11 +33,12 @@ bool damos_ops_has_filter(struct damos *s);*/ struct damon_perf {struct perf_event *__percpu *event; +void *aux_priv; };int damon_perf_init (struct damon_ctx *ctx,struct damon_perf_event *event);void damon_perf_cleanup (struct damon_ctx *ctx,struct damon_perf_event *event); -void damon_perf_event_arm (struct damon_perf_event *event); +int damon_perf_event_arm (struct damon_perf_event *event);void damon_perf_event_disarm (struct damon_perf_event *event);#else /* !CONFIG_PERF_EVENTS */
@@ -53,8 +54,9 @@ static inline void damon_perf_cleanup(struct damon_ctx *ctx, { } -static inline void damon_perf_event_arm (struct damon_perf_event *event) +static inline int damon_perf_event_arm (struct damon_perf_event *event) { +return 0 ; }static inline void damon_perf_event_disarm (struct damon_perf_event *event)
mm/damon/perf/Makefile +5 -0
@@ -3,3 +3,8 @@ # Observability: per-CPU counters, tracepoints, debugfs perf_stats obj-$(CONFIG_DAMON_PERF_OBSERVE) += damon-perf.o damon-perf-objs := stats.o debugfs.o + +obj-$(CONFIG_DAMON_PERF_AUX) += damon-perf-aux.o +damon-perf-aux-objs := aux_backend.o spe_backend.o +damon-perf-aux-$(CONFIG_DAMON_PERF_SPE_KUNIT_TEST) += \ + spe_parser_test.o
mm/damon/perf/aux_backend.c new file +121 -0
121 lines not on this page · raw message
mm/damon/perf/spe_backend.c new file +479 -0
479 lines not on this page · raw message
mm/damon/perf/spe_parser.h new file +109 -0
109 lines not on this page · raw message
mm/damon/vaddr.c +65 -3
131 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 3/4 mm/damon/perf: add KUnit tests for the SPE record parser
In reply to Kunwu ChanFrom: "Lian Wang (ProcessMission)" <[email protected]>
Add byte-exact tests for load and store records, timestamp terminators, multiple records, PAD and ALIGNMENT packets, extended addresses, invalid extended headers, error resynchronization, and records without a virtual address.
Cover ALIGNMENT packets at both odd and already aligned stream offsets. Also verify that a record split across two AUX snapshots leaves the tail unchanged until the terminating packet becomes available.
--- mm/damon/perf/spe_parser_test.c | 365 ++++++++++++++++++++++++++++++++ 1 file changed, 365 insertions(+) create mode 100644 mm/damon/perf/spe_parser_test.c
mm/damon/perf/spe_parser_test.c new file +365 -0
@@ -0,0 +1,365 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* KUnit tests for the DAMON perf ARM SPE record parser. +* +* Each parameterized case feeds a byte-exact SPE packet stream (same +* encodings and decode order as tools/perf/util/arm-spe-decoder) into +* spe_parse_one_record() and verifies the synthesized records, the +* return values, and the aux_tail accounting. The loop mirrors +* spe_backend_drain() including the caller-side window shrink. +*/ + +#include <kunit/test.h> +#include <linux/slab.h> + +#include "spe_parser.h" + +/** +* struct spe_parse_case - One parser test case. +* @name: Parameter description (shown on failure). +* @stream: Byte-exact SPE packet stream. +* @len: @stream length. +* @exp_reports: Expected SPE_PARSE_REPORT count. +* @exp_skips: Expected SPE_PARSE_SKIP count. +* @exp_errors: Expected SPE_PARSE_ERROR count. +* @exp_tail: Expected st->aux_tail after the stream. +* @exp_va: Expected virtual address of the first REPORT record. +* @exp_tid: Expected tid of the first REPORT record. +* @exp_is_write: Expected access type of the first REPORT record. +*/ +struct spe_parse_case { +const char *name; +const u8 *stream; +size_t len; +unsigned int exp_reports; +unsigned int exp_skips; +unsigned int exp_errors; +unsigned long exp_tail; +unsigned long exp_va; +u32 exp_tid; +bool exp_is_write; +}; + +static const u8 stream_store[] = { +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: 64-bit EL1 tid=42 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x01 ,/* OP-TYPE: ST */ +0x01 ,/* END */ +}; + +static const u8 stream_ts_load[] = { +0xb2 ,0x00 ,0x20 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x2000 */ +0x49 ,0x00 ,/* OP-TYPE: load */ +0x71 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* TIMESTAMP end */ +}; + +static const u8 stream_two[] = { +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: 64-bit EL1 tid=42 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x01 ,/* OP-TYPE: ST */ +0x01 ,/* END */ +0xb2 ,0x00 ,0x20 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x2000 */ +0x49 ,0x00 ,/* OP-TYPE: load */ +0x01 ,/* END */ +}; + +static const u8 stream_pad[] = { +0x00 ,0x00 ,/* PAD prefix */ +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: 64-bit EL1 tid=42 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x01 ,/* OP-TYPE: ST */ +0x01 ,/* END */ +0x00 ,0x00 ,0x00 ,/* PAD padding */ +}; + +static const u8 stream_alignment[] = { +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: tid 42, pos 0-4 */ +0x20 ,0x00 ,/* ALIGNMENT at odd pos 5 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x00 ,/* OP-TYPE: load */ +0x01 ,/* END */ +}; + +static const u8 stream_alignment_aligned[] = { +0x20 ,0x00 ,/* ALIGNMENT at even pos 0 */ +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: 64-bit EL1 tid=42 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x00 ,/* OP-TYPE: load */ +0x01 ,/* END */ +}; + +static const u8 stream_bad[] = { +0xff ,/* unknown header */ +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: 64-bit EL1 tid=42 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x01 ,/* OP-TYPE: ST */ +0x01 ,/* END */ +}; + +static const u8 stream_skip[] = { +0x49 ,0x00 ,/* OP-TYPE: load */ +0x01 ,/* END, no address */ +}; + +static const u8 stream_other_pkts[] = { +0x42 ,0x05 ,/* EVENTS (width 1) */ +0x43 ,0x06 ,/* DATA-SOURCE (width 1) */ +0x98 ,0x00 ,0x00 ,/* COUNTER (width 2) */ +0xb2 ,0x00 ,0x30 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x3000 */ +0x49 ,0x00 ,/* OP-TYPE: load */ +0x01 ,/* END */ +}; + +static const u8 stream_truncated[] = { +0x66 ,0x2a ,0x00 ,0x00 ,0x00 ,/* CONTEXT: 64-bit EL1 tid=42 */ +0xb2 ,0x00 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x1000 */ +0x49 ,0x01 ,/* OP-TYPE: ST, no END */ +}; + +static const u8 stream_truncated_packet[] = { +0xb2 ,0x00 ,0x10 ,/* short 8-byte address */ +}; + +static const u8 stream_ext_addr[] = { +0x20 ,0xb2 ,/* EXTENDED ADDRESS, DATA_VIRT */ +0x00 ,0x40 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,/* VA 0x4000 */ +0x49 ,0x00 ,/* OP-TYPE: load */ +0x01 ,/* END */ +}; + +static const u8 stream_invalid_extended[] = { +0x20 ,0x42 ,0x00 ,/* invalid extended EVENTS */ +0x01 ,/* END after resync */ +}; + +static const u8 stream_pad_only[] = { +0x00 ,0x00 ,0x00 , +}; + +static const u8 stream_empty[] = {0x00 }; + +static const struct spe_parse_case spe_parse_cases[] = { + { + .name ="store record" , + .stream = stream_store, + .len =sizeof (stream_store), + .exp_reports =1 , + .exp_tail =17 , + .exp_va =0x1000 , + .exp_tid =42 , + .exp_is_write = true, + }, + { + .name ="load record with timestamp terminator" , + .stream = stream_ts_load, + .len =sizeof (stream_ts_load), + .exp_reports =1 , + .exp_tail =20 , + .exp_va =0x2000 , + .exp_tid =0 , + .exp_is_write = false, + }, + { + .name ="two records in one window" , + .stream = stream_two, + .len =sizeof (stream_two), + .exp_reports =2 , + .exp_tail =29 , + .exp_va =0x1000 , + .exp_tid =42 , + .exp_is_write = true, + }, + { + .name ="pad-wrapped record" , + .stream = stream_pad, + .len =sizeof (stream_pad), + .exp_reports =1 , + .exp_tail =22 , + .exp_va =0x1000 , + .exp_tid =42 , + .exp_is_write = true, + }, + { + .name ="alignment packet at odd position" , + .stream = stream_alignment, + .len =sizeof (stream_alignment), + .exp_reports =1 , + .exp_tail =19 , + .exp_va =0x1000 , + .exp_tid =42 , + .exp_is_write = false, + }, + { + .name ="alignment packet at aligned position" , + .stream = stream_alignment_aligned, + .len =sizeof (stream_alignment_aligned), + .exp_reports =1 , + .exp_tail =sizeof (stream_alignment_aligned), + .exp_va =0x1000 , + .exp_tid =42 , + .exp_is_write = false, + }, + { + .name ="bad packet resync" , + .stream = stream_bad, + .len =sizeof (stream_bad), + .exp_reports =1 , + .exp_errors =1 , + .exp_tail =18 , + .exp_va =0x1000 , + .exp_tid =42 , + .exp_is_write = true, + }, + { + .name ="record without address" , + .stream = stream_skip, + .len =sizeof (stream_skip), + .exp_skips =1 , + .exp_tail =3 , + }, + { + .name ="events/source/counter packets ignored" , + .stream = stream_other_pkts, + .len =sizeof (stream_other_pkts), + .exp_reports =1 , + .exp_tail =19 , + .exp_va =0x3000 , + .exp_is_write = false, + }, + { + .name ="truncated trailing record retained" , + .stream = stream_truncated, + .len =sizeof (stream_truncated), + .exp_tail =0 , + }, + { + .name ="truncated packet retained" , + .stream = stream_truncated_packet, + .len =sizeof (stream_truncated_packet), + .exp_tail =0 , + }, + { + .name ="extended address packet" , + .stream = stream_ext_addr, + .len =sizeof (stream_ext_addr), + .exp_reports =1 , + .exp_tail =13 , + .exp_va =0x4000 , + .exp_is_write = false, + }, + { + .name ="invalid extended header resync" , + .stream = stream_invalid_extended, + .len =sizeof (stream_invalid_extended), + .exp_skips =1 , + .exp_errors =1 , + .exp_tail =sizeof (stream_invalid_extended), + }, + { + .name ="pad-only window" , + .stream = stream_pad_only, + .len =sizeof (stream_pad_only), + .exp_tail =3 , + }, + { + .name ="empty window" , + .stream = stream_empty, + .len =0 , + .exp_tail =0 , + }, +}; + +KUNIT_ARRAY_PARAM_DESC (spe_parse, spe_parse_cases, name); + +static void spe_parse_case_test (struct kunit *test) +{ +const struct spe_parse_case *tc = test->param_value; +struct spe_parser_state st = {0 }; +struct spe_record rec; +u8 *buf; +unsigned int reports =0 , skips =0 , errors =0 , guard =0 ; +bool first_checked = false; + + buf =kunit_kmalloc (test, tc->len ?:1 ,GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, buf); +memcpy (buf, tc->stream, tc->len); + st.win = buf; + st.win_size = tc->len; + +while (guard++ <SPE_BUFFER_MAX_RECORDS ) { +unsigned long tail0 = st.aux_tail; +unsigned long consumed; +int ret =spe_parse_one_record (&st, &rec); + +if (ret ==SPE_PARSE_NEED_MORE ) +break ; + +/* caller-side window shrink, mirrors spe_backend_drain() */ + consumed = st.aux_tail - tail0; + st.win_size -= consumed; +memmove (st.win, st.win + consumed, st.win_size); + +switch (ret) { +case SPE_PARSE_REPORT : + reports++; +if (!first_checked) { +KUNIT_EXPECT_EQ (test, tc->exp_va, rec.va); +KUNIT_EXPECT_EQ (test, tc->exp_tid, rec.tid); +KUNIT_EXPECT_EQ (test, tc->exp_is_write, + rec.is_write); + first_checked = true; + } +break ; +case SPE_PARSE_SKIP : + skips++; +break ; +case SPE_PARSE_ERROR : + errors++; +break ; + } + } + +KUNIT_EXPECT_EQ (test, tc->exp_reports, reports); +KUNIT_EXPECT_EQ (test, tc->exp_skips, skips); +KUNIT_EXPECT_EQ (test, tc->exp_errors, errors); +KUNIT_EXPECT_EQ (test, tc->exp_tail, st.aux_tail); +KUNIT_EXPECT_EQ (test, tc->exp_tail, st.bytes); +KUNIT_EXPECT_EQ (test, tc->exp_reports, st.records); +} + +static void spe_split_record_test (struct kunit *test) +{ +struct spe_parser_state st = { + .win = (u8 *)stream_store, + .win_size =sizeof (stream_store) -1 , + }; +struct spe_record rec; +int ret; + + ret =spe_parse_one_record (&st, &rec); +KUNIT_ASSERT_EQ (test,SPE_PARSE_NEED_MORE , ret); +KUNIT_EXPECT_EQ (test,0UL , st.aux_tail); +KUNIT_EXPECT_EQ (test,0UL , st.bytes); + +/* The next AUX copy starts at the unchanged tail and includes END. */ + st.win_size =sizeof (stream_store); + ret =spe_parse_one_record (&st, &rec); +KUNIT_ASSERT_EQ (test,SPE_PARSE_REPORT , ret); +KUNIT_EXPECT_EQ (test, (unsigned long )sizeof (stream_store), + st.aux_tail); +KUNIT_EXPECT_EQ (test,0x1000UL , rec.va); +KUNIT_EXPECT_EQ (test,42U , rec.tid); +} + +static struct kunit_case spe_parser_test_cases[] = { +KUNIT_CASE_PARAM (spe_parse_case_test, spe_parse_gen_params), +KUNIT_CASE (spe_split_record_test), + {}, +}; + +static struct kunit_suite spe_parser_test_suite = { + .name ="damon_perf_spe_parser" , + .test_cases = spe_parser_test_cases, +}; + +kunit_test_suite (spe_parser_test_suite);
Signature · 1 line
2.43.0
RFC PATCH 4/4 selftests/damon: add DAMON perf AUX backend test
In reply to Kunwu ChanFrom: "Lian Wang (ProcessMission)" <[email protected]>
Register a DAMON kselftest for the ARM SPE AUX backend. When kernel sources are available, check the backend integration and the required AUX-before-ring lifecycle ordering. Independently run the SPE parser KUnit suite through debugfs when it is built.
On an ARM SPE system with no pre-existing kdamond, create one controlled userspace target and collect counter deltas from a five-second session. Stop the session explicitly, then verify positive end-to-end pipeline counters and final enqueue/dequeue closure. Use a private mktemp result directory and restore only the DAMON state created by this test.
This is a smoke and lifecycle test; full-ring pause/resume validation remains a separate hardware stress test.
--- tools/testing/selftests/damon/Makefile | 1 + .../selftests/damon/damon_perf_aux_test.sh | 414 ++++++++++++++++++ 2 files changed, 415 insertions(+) create mode 100755 tools/testing/selftests/damon/damon_perf_aux_test.sh
tools/testing/selftests/damon/Makefile +1 -0
@@ -24,4 +24,5 @@ TEST_PROGS += sysfs_no_op_commit_break.py EXTRA_CLEAN = __pycache__ TEST_PROGS += damon_perf_obs_test.sh +TEST_PROGS += damon_perf_aux_test.sh include ../lib.mk
tools/testing/selftests/damon/damon_perf_aux_test.sh new file +414 -0
414 lines not on this page · raw message
Signature · 1 line
2.43.0
SJ Park
maintainerHello Kunwu,
Quoted 6 lines · On Sun, 16 Aug 2026 22:22:17 +0800 Kunwu Chan <[email protected]> wrote:
From: Kunwu Chan <[email protected]>
This series adds an AUX trace-buffer backend to the DAMON perf observability framework, enabling ARM SPE (Statistical Profiling Extension) to deliver hardware-sampled access reports into DAMON's existing SPSC report ring.
Awesome. Thank you for making this. This will make DAMON be more useful on ARM machines.
Quoted 8 lines
Patch 2 touches
drivers/perf/arm_spe_pmu.cto expose the PMU matcher. This change is tightly coupled with the DAMON AUX backend. ARM SPE PMU driver maintainers only need to review patch 2.This series is based on the Ravi's hardware-sampled access reports branch [1], and depends on the perf AUX kernel-consumer RFC series [2]. The dependencies is not upstream yet, so this series remains RFC.
Unfortunately I haven't had a time to thoroughly read the dependent patches. I believe the basic idea of this patch series is aligned with the ongoing DAMON extension roadmap [1], though. That is, this series is supposed to be a part of the milestone 3. We are currently at the near end of milestone 1, and aim to complete milestone 2 by the time around next year's LSFMMBPF.
I will hold review of this series for now, and take more time on making milestones 1 and 2 for thier planned delivery timeline. Sorry for being a bottleneck of your work, and thanks in advance for your patience.
Please feel free to let me know if you have specific parts that need my review right now, though. Otherwise, please make sure this is aligned with the roadmap until we finish the milestone 2. I do want ARM SPE support of DAMON.
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
SJ
[...]
Hello SJ,
Quoted 7 lines · SJ Park
Hello Kunwu,
Quoted 2 lines · On Sun, 16 Aug 2026 22:22:17 +0800 Kunwu Chan <[email protected]> wrote:
From: Kunwu Chan <[email protected]>
Quoted 7 lines
Quoted 4 lines
This series adds an AUX trace-buffer backend to the DAMON perf observability framework, enabling ARM SPE (Statistical Profiling Extension) to deliver hardware-sampled access reports into DAMON's existing SPSC report ring.
Awesome. Thank you for making this. This will make DAMON be more useful on ARM machines.
Thanks for the feedback.
Quoted 10 lines
Quoted 9 lines
Patch 2 touches
drivers/perf/arm_spe_pmu.cto expose the PMU matcher. This change is tightly coupled with the DAMON AUX backend. ARM SPE PMU driver maintainers only need to review patch 2.This series is based on the Ravi's hardware-sampled access reports branch [1], and depends on the perf AUX kernel-consumer RFC series [2]. The dependencies is not upstream yet, so this series remains RFC.
Quoted 5 lines
Unfortunately I haven't had a time to thoroughly read the dependent patches. I believe the basic idea of this patch series is aligned with the ongoing DAMON extension roadmap [1], though. That is, this series is supposed to be a part of the milestone 3. We are currently at the near end of milestone 1, and aim to complete milestone 2 by the time around next year's LSFMMBPF.
One clarification on the architecture: the AUX backend is intended as a transport/front-end for damon_report_access(), rather than a separate reporting path. spe_submit() ultimately calls damon_report_access(&report), and the AUX path shares the same SPSC report ring and kdamond_check_reported_accesses() consumer with the existing overflow-callback path. The main difference is the producer
context: the overflow path enqueues from NMI context, while the AUX path enqueues from kdamond process context.
The perf AUX kernel-consumer API is still an upstream dependency, so there is no specific part that needs your review right now. The implementation is already functional and tested on Kunpeng 920, and I can rebase and resend once the dependency chain is ready and the relevant DAMON infrastructure has landed.
Separately, the DAMON perf observability framework (CONFIG_DAMON_PERF_OBSERVE) was developed in parallel with the AUX backend and is already implemented. It provides the observability infrastructure used by both the existing overflow path and the new AUX path, including per-CPU pipeline counters, debugfs statistics, and tracepoints. This work is independent of the AUX transport, and I will post it shortly as a standalone series.
Thanks,
Kunwu
Quoted 16 lines
I will hold review of this series for now, and take more time on making milestones 1 and 2 for thier planned delivery timeline. Sorry for being a bottleneck of your work, and thanks in advance for your patience.
Please feel free to let me know if you have specific parts that need my review right now, though. Otherwise, please make sure this is aligned with the roadmap until we finish the milestone 2. I do want ARM SPE support of DAMON.
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
SJ[...]