[Patch v6 14/20] perf/x86/amd: Refresh LBR stack in PMI only when LBR users are active
From: Dapeng Mi
Date: Thu Nov 05 2026 - 23:44:41 EST
Refreshing the LBR stack in the PMI handler is unnecessary when no LBR
users are active. This adds avoidable overhead and hurts performance.
Limit the LBR stack refresh to the PMI path only when LBR users are
present.
Suggested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: "Sandipan Das <sandipan.das@xxxxxxx>"
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
---
arch/x86/events/amd/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 160102a46b18..f0425e369837 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -988,7 +988,8 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs)
/* Read branch records */
if (x86_pmu.lbr_nr) {
- amd_pmu_lbr_read();
+ if (cpuc->lbr_users > 0)
+ amd_pmu_lbr_read();
status &= ~GLOBAL_STATUS_LBRS_FROZEN;
}
--
2.34.1