Skip to content

powerpc/perf: Add HTM PMU driver and perf AUX support

Athira Rajeev linux-perf-users linuxppc-dev 4 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest6 patches 0 repliesNew
  2. v46 patches 0 repliesSuperseded
  3. v36 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v26 patches6 repliesSuperseded

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro dataarch/powerpc/perf/Makefile arch/powerpc/perf/htm-perf.c+518 -10 replies
2/6powerpc/perf: Reject duplicate HTM target reservationsarch/powerpc/perf/htm-perf.c+38 -40 replies
3/6powerpc/perf: Add AUX buffer management to capture HTM trace dataarch/powerpc/perf/htm-perf.c+370 -10 replies
4/6powerpc/perf: Capture the HTM memory configuration as part of perf dataarch/powerpc/perf/htm-perf.c+206 -40 replies
5/6docs: ABI: sysfs-bus-event_source-devices-htm: Document sysfs event format entries for htm pmuDocumentation/ABI/testing/sysfs-bus-event_source-devices-htm+36 -00 replies
6/6powerpc/perf/htm: Add documentation for Hardware Trace Macro PMUDocumentation/arch/powerpc/htm.rst+155 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH V5 0/6] powerpc/perf: Add HTM PMU driver and perf AUX support

Overview:
The Hardware Trace Macro (HTM) on POWER systems provides hardware-level bus-trace data for a specific node/chip/core target within a logical partition. It is accessed via the H_HTM hypervisor call and traces continuously at node, chip, or core scope independent of task scheduling.

This series adds a new "htm" PMU driver under arch/powerpc/perf/ that exposes HTM trace collection via the standard perf interface using the perf AUX buffer infrastructure, together with ABI and RST documentation.

Patch overview:
Patch 1 introduces the core HTM PMU driver (htm-perf.c). The event configuration encodes the trace target as a 28-bit value in perf_event_attr.config:

bits 0-3: htm_type (HTM_CORE=2, HTM_NEST=1, HTM_LLAT=3)
bits 4-11: nodeindex
bits 12-19: nodalchipindex
bits 20-27: coreindexonchip

The PMU lifecycle maps to H_HTM_OP_CONFIGURE/DECONFIGURE at add/del time and H_HTM_OP_START/STOP at start/stop time. Context-switch callbacks (PERF_EF_RELOAD / PERF_EF_UPDATE) are intentionally ignored because HTM traces the hardware scope, not individual tasks. Tracing state is kept in event->pmu_private (HTM_TRACING_ACTIVE / HTM_TRACING_INACTIVE) as the authoritative source, with event->hw.state kept in sync as a hint for the perf core.

Patch 2 adds duplicate-reservation protection. When 'perf record -a' is used, perf opens system-wide events on all CPUs in parallel. Without driver-side tracking, concurrent opens for the same HTM target (node, chip, core, type) can race and issue duplicate H_HTM_OP_CONFIGURE flows. A global reserved-targets list is added; htm_event_init() rejects any open that matches an already-reserved tuple, while different targets can still be opened simultaneously on different CPUs.

Patch 3 adds AUX ring-buffer support so that high-volume trace data can be streamed into a perf AUX buffer. The driver opts into PERF_PMU_CAP_AUX_NO_SG | PERF_PMU_CAP_AUX_PREFER_LARGE to request physically contiguous allocations, which H_HTM_OP_DUMP_DATA requires. A page-by-page physical-continuity scan is performed before each dump to detect and bound any fragmentation gaps, preventing silent memory corruption. event->count is set to the number of 128-byte HTM trace records written on a successful dump, 1 when the AUX buffer is temporarily full but the hypervisor stream is intact, and 0 when the stream is exhausted or a hard error occurs; the perf tool uses this as a drain signal to decide whether another read pass is needed before closing the event.

Patch 4 adds system memory configuration capture. After writing trace data to the AUX buffer, htm_event_read() calls H_HTM_OP_DUMP_SYSMEM_CONF and emits the returned physical-to-logical address mapping records as PERF_SAMPLE_RAW data. Keeping trace data in the AUX stream and memory configuration in raw samples allows each to be decoded independently in userspace.

Patch 5 adds ABI documentation for the sysfs entries under /sys/bus/event_source/devices/htm/, covering the format attribute (config bit layout) and the events attribute group.

Patch 6 extends Documentation/arch/powerpc/htm.rst with a new section on the perf interface: event syntax, required options, the two output files (htm.bin.nX.pX.cX.tX and translation.nX.pX.cX.tX), and how to pass them to htmdecode for trace decoding.

Usage example:
Collect HTM trace data from two simultaneous chip targets:

  # perf record -m,256                                          \
      -e htm/nodalchipindex=2,nodeindex=0,htm_type=1,cpu=8/    \
      -e htm/nodalchipindex=1,nodeindex=0,htm_type=1,cpu=9/    \
      -a -- sleep 10
  # perf report

Output files written by perf report:

  htm.bin.n0.p2.c0.t1       raw HTM bus-trace, chip 2
  htm.bin.n0.p1.c0.t1       raw HTM bus-trace, chip 1
  translation.n0.p2.c0.t1   memory config records, chip 2
  translation.n0.p1.c0.t1   memory config records, chip 1

The htm.bin.* files can then be decoded with htmdecoder to produce trace output.

Testing:
Tested on POWER11 with two simultaneous HTM targets. Both htm.bin.* and translation.* files are produced correctly.

  # perf record -C 9 -m,256 \
      -e htm/nodalchipindex=2,nodeindex=0,htm_type=1/ -a sleep 3
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 256.277 MB perf.data ]
  # perf record -m,512 \
  -e htm/htm_type=3,nodalchipindex=1,nodeindex=0,coreindexonchip=6,cpu=8/ \
  -e htm/htm_nest,nodalchipindex=1,nodeindex=0,cpu=16/ -a sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 514.095 MB perf.data ]

Athira Rajeev (6):
powerpc/perf: Add HTM PMU driver to expose Hardware Trace Macro data powerpc/perf: Reject duplicate HTM target reservations powerpc/perf: Add AUX buffer management to capture HTM trace data powerpc/perf: Capture the HTM memory configuration as part of perf
data
docs: ABI: sysfs-bus-event_source-devices-htm: Document sysfs event
format entries for htm pmu
powerpc/perf/htm: Add documentation for Hardware Trace Macro PMU

 .../sysfs-bus-event_source-devices-htm        |   36 +
 Documentation/arch/powerpc/htm.rst            |  158 ++-
 arch/powerpc/perf/Makefile                    |    2 +-
 arch/powerpc/perf/htm-perf.c                  | 1122 +++++++++++++++++
 4 files changed, 1314 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-event_source-devices-htm
 create mode 100644 arch/powerpc/perf/htm-perf.c
Signature · 1 line
2.53.0