Re: [PATCH] perf/x86/amd/lbr: Freeze LBR on PMI only when kernel branches are recorded
From: Ravi Bangoria
Date: Wed Nov 18 2026 - 23:42:30 EST
On 19-Nov-26 5:35 AM, Andrii Nakryiko wrote:
> On Fri, Nov 13, 2026 at 7:48 PM Ravi Bangoria <ravi.bangoria@xxxxxxx> wrote:
>>
>> On 23-Oct-26 6:11 PM, Puranjay Mohan wrote:
>>> On CPUs with X86_FEATURE_AMD_LBR_PMC_FREEZE the LBR is always frozen on
>>> PMI, so the branch stack ends before the IP and callchain, which are
>>> taken when the NMI is delivered. IBS rejects branch-stack events, so
>>> there is no precise alternative.
>>>
>>> The freeze only keeps the PMI handler's branches out of the stack, which
>>> matters only when branches into the kernel are recorded; without it the
>>> stack fills with the handler's own branches. A user-only filter does not
>>> record them, and parts without the feature are never frozen (see commit
>>> 598c2fafc06f ("perf/x86/amd/lbr: Use freeze based on availability")).
>>>
>>> Freeze unless the value written to LBR_SELECT, which is shared by all
>>> events on the CPU, suppresses branches into the kernel.
>>>
>>> With perf record -e ex_ret_brn_tkn:u -j any,u on a Zen 5 part running
>>> CPython, the function of the sampled IP differs from the function of
>>> LBR[0].to in 84.3% of samples with the freeze and in 0.1% without it.
>>>
>>> Signed-off-by: Puranjay Mohan <puranjay@xxxxxxxxxx>
>>
>> Reviewed-by: Ravi Bangoria <ravi.bangoria@xxxxxxx>
>>
>
> Thanks, Ravi!
>
> Do I understand correctly (from [0]) that we'll just stick to this
> patch and there is nothing from Puranjay's side to follow up on?
> Thanks!
>
> [0] https://lore.kernel.org/all/5cf60aaf-2ee4-482f-9054-dff823710431@xxxxxxx/
That's right.
Ravi