Skip to content

Commit 32ba156

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/lbr: Enable the branch type for the Arch LBR by default
On the platform with Arch LBR, the HW raw branch type encoding may leak to the perf tool when the SAVE_TYPE option is not set. In the intel_pmu_store_lbr(), the HW raw branch type is stored in lbr_entries[].type. If the SAVE_TYPE option is set, the lbr_entries[].type will be converted into the generic PERF_BR_* type in the intel_pmu_lbr_filter() and exposed to the user tools. But if the SAVE_TYPE option is NOT set by the user, the current perf kernel doesn't clear the field. The HW raw branch type leaks. There are two solutions to fix the issue for the Arch LBR. One is to clear the field if the SAVE_TYPE option is NOT set. The other solution is to unconditionally convert the branch type and expose the generic type to the user tools. The latter is implemented here, because - The branch type is valuable information. I don't see a case where you would not benefit from the branch type. (Stephane Eranian) - Not having the branch type DOES NOT save any space in the branch record (Stephane Eranian) - The Arch LBR HW can retrieve the common branch types from the LBR_INFO. It doesn't require the high overhead SW disassemble. Fixes: 47125db ("perf/x86/intel/lbr: Support Architectural LBR") Reported-by: Stephane Eranian <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 8924779 commit 32ba156

File tree

1 file changed

+8
-0
lines changed
  • arch/x86/events/intel

1 file changed

+8
-0
lines changed

arch/x86/events/intel/lbr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,14 @@ static int intel_pmu_setup_hw_lbr_filter(struct perf_event *event)
10971097

10981098
if (static_cpu_has(X86_FEATURE_ARCH_LBR)) {
10991099
reg->config = mask;
1100+
1101+
/*
1102+
* The Arch LBR HW can retrieve the common branch types
1103+
* from the LBR_INFO. It doesn't require the high overhead
1104+
* SW disassemble.
1105+
* Enable the branch type by default for the Arch LBR.
1106+
*/
1107+
reg->reg |= X86_BR_TYPE_SAVE;
11001108
return 0;
11011109
}
11021110

0 commit comments

Comments
 (0)