[Patch v7 13/24] perf/x86/intel: Always snapshot live hardware LBR state for BPF
From: Dapeng Mi
Date: Tue Nov 17 2026 - 22:24:41 EST
__intel_pmu_snapshot_branch_stack() is intended to capture the current
live hardware LBR state for the BPF path. However, that snapshot is
currently skipped when all LBR users are PEBS events.
BPF LBR snapshotting now uses its own dedicated LBR stack, so there is
no longer a risk of clobbering the shared default LBR stack. Move the
lbr_pebs_users check into the PMI handler, which is the only caller that
relies on it, so the BPF path always snapshots the live hardware LBR
state.
Fixes: c22ac2a3d4bd ("perf: Enable branch record for software events")
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/intel/core.c | 7 ++++++-
arch/x86/events/intel/lbr.c | 9 ---------
2 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index b560f2e96848..84b134bb91ee 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4072,7 +4072,12 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
loops = 0;
again:
- intel_pmu_lbr_read(cpu_lbr_stack(cpuc), cpuc->lbr_counters);
+ /*
+ * No need to read the LBR stack when all LBR users are PEBS events,
+ * since the PEBS handler updates it.
+ */
+ if (cpuc->lbr_users != cpuc->lbr_pebs_users)
+ intel_pmu_lbr_read(cpu_lbr_stack(cpuc), cpuc->lbr_counters);
/*
* Keep the LBR state frozen throughout PMI handling so that the PMI
diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index b60719adcc1c..6c7123c1f9ae 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -1042,15 +1042,6 @@ void intel_pmu_lbr_read(struct perf_branch_stack *lbr_stack,
return;
}
- /*
- * Don't read when all LBRs users are using adaptive PEBS.
- *
- * This could be smarter and actually check the event,
- * but this simple approach seems to work for now.
- */
- if (cpuc->lbr_users == cpuc->lbr_pebs_users)
- return;
-
x86_pmu.lbr_read(cpuc, lbr_stack);
intel_pmu_lbr_filter(cpuc, lbr_stack, lbr_counters);
--
2.34.1