Re: [Patch v6 14/20] perf/x86/amd: Refresh LBR stack in PMI only when LBR users are active
From: Mi, Dapeng
Date: Thu Nov 12 2026 - 05:13:25 EST
On 11/6/2026 12:32 PM, Dapeng Mi wrote:
> 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;
> }
>
This patch is actually unnecessary since amd_pmu_lbr_read() internally
checks cpuc->lbr_users and would early return if cpuc->lbr_users is 0.
Would drop this patch in next version. Thanks.