Re: [PATCH v6 0/3] arm64: Add BRBE support for bpf_get_branch_snapshot()
From: James Clark
Date: Fri Nov 27 2026 - 05:56:50 EST
On 26/11/2026 18:02, Leo Yan wrote:
On Thu, Nov 26, 2026 at 12:39:52PM +0000, James Clark wrote:
[...]
Mark, Will, you guys seems to be designated as maintainers for
drivers/perf/arm_brbe.c, can you please take a look and give your
feedback as well? This is important and useful feature for newer arm64
CPUs, it would be great to get access to this functionality that we
had on x86-64 side for a long while now. Please help get this upstream
or, if it's not in the right shape, guide Puranjay towards a better
implementation. Thank you!
...
+ Vladimir
Hi Mark, Will, Vladimir,
Any thoughts on this approach where NMIs need to be disabled? Alternatively
we could do something like track where the PMU interrupts and BPF snapshots
overlap and then discard the BRBE buffer and make sure they don't trample on
each other etc, but it looks like it would be significantly more
complicated.
Could we restrict bpf_get_branch_snapshot() on arm64 to a free-running
BRBE mode? On a given CPU, at least one active event would have to
request a branch stack, and every such event would have to be a
counting event.
This seems to fit in this series. The selftest opens a CPU-cycles event
with PERF_SAMPLE_BRANCH_STACK and sample_period = 0, then takes the
snapshot from an fexit program.
Counting events can still generate overflow interrupts for bookkeeping.
It requires to refactor the PMU driver to leave BRBCR_ELx.FZP clear so
an overflow doesn't freeze BRBE. The interrupt handler could service the
counters without touching BRBE and losing the branch records.
Thanks,
Leo
Yeah I think this is a pretty good idea. It looks like it would avoid having to disable NMIs. You only need a local_irq_save() to avoid new events from reconfiguring BRBE while taking a snapshot, and you don't have to disable the PMU counters either.
If any sampling BRBE event gets scheduled then the snapshots just start skipping and returning empty.