mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/5] perf/core: add AUX buffer kernel-consumer API
@ 2026-10-09 15:59 Kunwu Chan
  2026-10-09 15:59 ` [PATCH v2 1/5] perf/core: add AUX buffer ownership for kernel events Kunwu Chan
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Kunwu Chan @ 2026-10-09 15:59 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung
  Cc: sj, corbet, skhan, rdunlap, mark.rutland, alexander.shishkin,
	jolsa, irogers, adrian.hunter, james.clark, akpm, lianux.mm,
	kunwu.chan, linux-doc, linux-kernel, linux-perf-users,
	linux-kselftest

ARM SPE and other tracing PMUs write records directly to perf AUX
buffers.  Unlike ordinary sampling PMUs, they do not necessarily
generate a perf_event_overflow() callback for each record.  A kernel
consumer therefore needs to drain the AUX buffer directly.

Userspace allocates AUX buffers through perf_event_open() and mmap().
Kernel consumers created through perf_event_create_kernel_counter()
currently lack an equivalent interface.

This series adds perf-core APIs for kernel consumers to allocate and
release AUX buffers, read the producer head, copy trace data, and
advance the consumer tail.  The APIs keep perf's internal page layout
private and follow the existing non-overwrite AUX ring-buffer
protocol.  Setup and release serialize buffer attachment and
detachment through event->mmap_mutex; consumers must quiesce before
releasing the buffer.

Patches 1-2 add the ownership, lifecycle, and access APIs.  Patches
3-5 add KUnit tests, a userspace AUX regression test, and a selftest
script.  The first consumer is a DAMON ARM SPE backend, but this
series is independent of DAMON and adds no consumer-specific policy
to perf.

Testing
=======

The series builds cleanly at each step.

arm64 (Kunpeng 920, 256 CPUs, SPEv1.1): built and booted the Image
from this series.  KUnit: pass:39 fail:0 skip:0.  The arm_spe_0
userspace regression test passed, and the AUX head advanced under
live SPE traffic.  Selftest script: 92 passed, 0 failed, 2 skipped.
perf record with arm_spe_0 captured data; dmesg showed no warnings.

x86_64 (vmlinux build, qemu/kvm): KUnit pass:39 fail:0 skip:0,
including KASAN and lockdep (PROVE_LOCKING); 15 repeated boots
produced no splats.  The Intel PT userspace regression test passed.

Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>

Changes since v1 [2]:

- Fix double-release in KUnit error cleanup and make the coexistence
  test cleanup failure-safe.
- Make failure-sensitive userspace test outcomes report SKIP rather
  than PASS, read the AUX head after event disable to observe flushed
  trace data, and pass the PMU name from the script to the C test.
- Fix the selftest script exit-status handling, remove the
  /usr/src/linux fallback, and handle Intel PT event modifiers.
- Remove an unnecessary smp_rmb() from the tail update path.

Changes since RFC [1]:

- Serialize AUX teardown under event->mmap_mutex and fix lifetime
  handling around ring_buffer_attach().
- Improve KUnit cleanup and concurrent-release coverage.
- Extend userspace and selftest coverage.
- Document AUX lifecycle, ordering, and cursor validation.

[1] https://lore.kernel.org/linux-perf-users/20260814144927.489172-1-kunwu.chan@linux.dev/
[2] https://lore.kernel.org/all/20261004173458.837842-1-kunwu.chan@gmail.com/


Kunwu Chan (3):
  perf/core: add AUX buffer ownership for kernel events
  perf/core: add AUX ring accessors for kernel consumers
  selftests/perf_events: add AUX kernel API selftest script

Lian Wang (2):
  perf/core: add KUnit tests for AUX kernel-consumer API
  selftests/perf_events: add userspace AUX regression test

 .../userspace-api/perf_ring_buffer.rst        |   62 +-
 include/linux/perf_event.h                    |   18 +
 kernel/events/Makefile                        |    1 +
 kernel/events/aux_kernel_test.c               | 1172 +++++++++++++++++
 kernel/events/core.c                          |  164 +++
 kernel/events/internal.h                      |    6 +
 kernel/events/ring_buffer.c                   |  212 ++-
 lib/Kconfig.debug                             |   14 +
 tools/testing/selftests/perf_events/Makefile  |    2 +
 .../selftests/perf_events/aux_kernel.sh       |  635 +++++++++
 .../perf_events/aux_kernel_usermode.c         |  645 +++++++++
 tools/testing/selftests/perf_events/config    |    2 +
 12 files changed, 2928 insertions(+), 5 deletions(-)
 create mode 100644 kernel/events/aux_kernel_test.c
 create mode 100755 tools/testing/selftests/perf_events/aux_kernel.sh
 create mode 100644 tools/testing/selftests/perf_events/aux_kernel_usermode.c


base-commit: 6350de8671b94afb7691d110f63bcda42f658a69
-- 
2.43.0


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

end of thread, other threads:[~2026-10-09 16:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09 15:59 [PATCH v2 0/5] perf/core: add AUX buffer kernel-consumer API Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 1/5] perf/core: add AUX buffer ownership for kernel events Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 2/5] perf/core: add AUX ring accessors for kernel consumers Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 3/5] perf/core: add KUnit tests for AUX kernel-consumer API Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 4/5] selftests/perf_events: add userspace AUX regression test Kunwu Chan
2026-10-09 15:59 ` [PATCH v2 5/5] selftests/perf_events: add AUX kernel API selftest script Kunwu Chan

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

all inboxes | Powered by JetHome®