Skip to content

Commit 58074a0

Browse files
robherringwilldeacon
authored andcommitted
perf: arm_pmuv3: Add support for the Branch Record Buffer Extension (BRBE)
The ARMv9.2 architecture introduces the optional Branch Record Buffer Extension (BRBE), which records information about branches as they are executed into set of branch record registers. BRBE is similar to x86's Last Branch Record (LBR) and PowerPC's Branch History Rolling Buffer (BHRB). BRBE supports filtering by exception level and can filter just the source or target address if excluded to avoid leaking privileged addresses. The h/w filter would be sufficient except when there are multiple events with disjoint filtering requirements. In this case, BRBE is configured with a union of all the events' desired branches, and then the recorded branches are filtered based on each event's filter. For example, with one event capturing kernel events and another event capturing user events, BRBE will be configured to capture both kernel and user branches. When handling event overflow, the branch records have to be filtered by software to only include kernel or user branch addresses for that event. In contrast, x86 simply configures LBR using the last installed event which seems broken. It is possible on x86 to configure branch filter such that no branches are ever recorded (e.g. -j save_type). For BRBE, events with a configuration that will result in no samples are rejected. Recording branches in KVM guests is not supported like x86. However, perf on x86 allows requesting branch recording in guests. The guest events are recorded, but the resulting branches are all from the host. For BRBE, events with branch recording and "exclude_host" set are rejected. Requiring "exclude_guest" to be set did not work. The default for the perf tool does set "exclude_guest" if no exception level options are specified. However, specifying kernel or user events defaults to including both host and guest. In this case, only host branches are recorded. BRBE can support some additional exception branch types compared to x86. On x86, all exceptions other than syscalls are recorded as IRQ. With BRBE, it is possible to better categorize these exceptions. One limitation relative to x86 is we cannot distinguish a syscall return from other exception returns. So all exception returns are recorded as ERET type. The FIQ branch type is omitted as the only FIQ user is Apple platforms which don't support BRBE. The debug branch types are omitted as there is no clear need for them. BRBE records are invalidated whenever events are reconfigured, a new task is scheduled in, or after recording is paused (and the records have been recorded for the event). The architecture allows branch records to be invalidated by the PE under implementation defined conditions. It is expected that these conditions are rare. Cc: Catalin Marinas <catalin.marinas@arm.com> Co-developed-by: Anshuman Khandual <anshuman.khandual@arm.com> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> Co-developed-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Mark Rutland <mark.rutland@arm.com> Tested-by: James Clark <james.clark@linaro.org> Signed-off-by: Rob Herring (Arm) <robh@kernel.org> tested-by: Adam Young <admiyo@os.amperecomputing.com> Acked-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20250611-arm-brbe-v19-v23-4-e7775563036e@kernel.org [will: Fix sparse warnings about mixed declarations and code. Fix C99 comment syntax.] Signed-off-by: Will Deacon <will@kernel.org>
1 parent d7567e9 commit 58074a0

7 files changed

Lines changed: 990 additions & 5 deletions

File tree

drivers/perf/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ config ARM_SPE_PMU
223223
Extension, which provides periodic sampling of operations in
224224
the CPU pipeline and reports this via the perf AUX interface.
225225

226+
config ARM64_BRBE
227+
bool "Enable support for branch stack sampling using FEAT_BRBE"
228+
depends on ARM_PMUV3 && ARM64
229+
default y
230+
help
231+
Enable perf support for Branch Record Buffer Extension (BRBE) which
232+
records all branches taken in an execution path. This supports some
233+
branch types and privilege based filtering. It captures additional
234+
relevant information such as cycle count, misprediction and branch
235+
type, branch privilege level etc.
236+
226237
config ARM_DMC620_PMU
227238
tristate "Enable PMU support for the ARM DMC-620 memory controller"
228239
depends on (ARM64 && ACPI) || COMPILE_TEST

drivers/perf/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ obj-$(CONFIG_STARFIVE_STARLINK_PMU) += starfive_starlink_pmu.o
2323
obj-$(CONFIG_THUNDERX2_PMU) += thunderx2_pmu.o
2424
obj-$(CONFIG_XGENE_PMU) += xgene_pmu.o
2525
obj-$(CONFIG_ARM_SPE_PMU) += arm_spe_pmu.o
26+
obj-$(CONFIG_ARM64_BRBE) += arm_brbe.o
2627
obj-$(CONFIG_ARM_DMC620_PMU) += arm_dmc620_pmu.o
2728
obj-$(CONFIG_MARVELL_CN10K_TAD_PMU) += marvell_cn10k_tad_pmu.o
2829
obj-$(CONFIG_MARVELL_CN10K_DDR_PMU) += marvell_cn10k_ddr_pmu.o

0 commit comments

Comments
 (0)