Re: [Patch v2 4/9] perf/x86/intel: Fallback to sw branch type decoding if no hw decoding

From: Mi, Dapeng

Date: Tue Jun 09 2026 - 21:54:17 EST



On 6/9/2026 10:49 PM, Peter Zijlstra wrote:
> On Tue, Jun 09, 2026 at 01:02:17PM +0800, Dapeng Mi wrote:
>> intel_pmu_lbr_filter() currently assumes Arch LBR provides hardware
>> branch-type decoding and skips software decoding on that path.
>>
>> However, Arch LBR may not always expose branch-type information. In
>> that case, treating entries as hardware-decoded can misclassify sampled
>> branches (for example, defaulting to JCC), which breaks branch-type
>> filtering results.
>>
>> Fix this by using software branch-type decoding when hardware
>> branch-type decoding is unavailable (that is, when x86_lbr_type is not
>> enabled). This keeps branch classification and filtering behavior
>> correct across Arch LBR configurations.
>>
>> Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
>> ---
>> arch/x86/events/intel/lbr.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
>> index 72f2adcda7c6..d4c0ed85e1fb 100644
>> --- a/arch/x86/events/intel/lbr.c
>> +++ b/arch/x86/events/intel/lbr.c
>> @@ -1232,6 +1232,7 @@ intel_pmu_lbr_filter(struct cpu_hw_events *cpuc)
>> * OTHER_BRANCH branch type still rely on software decoding.
>> */
>> if (static_cpu_has(X86_FEATURE_ARCH_LBR) &&
>> + static_branch_likely(&x86_lbr_type) &&
>> type <= ARCH_LBR_BR_TYPE_KNOWN_MAX) {
>> to_plm = kernel_ip(to) ? X86_BR_KERNEL : X86_BR_USER;
>> type = arch_lbr_br_type_map[type] | to_plm;
> Now you have two static branches in concert. Best to make sure
> x86_lbr_type covers both conditions, no?

Oh, yes. Actually x86_lbr_type would be enabled only when there is
arch-LBR, so it's unnecessary to check static_cpu_has(X86_FEATURE_ARCH_LBR)
again. static_cpu_has(X86_FEATURE_ARCH_LBR) could be simply removed. Thanks.


>