Skip to content

Commit

Permalink
perf/x86/amd/lbr: Adjust LBR regardless of filtering
Browse files Browse the repository at this point in the history
In case of fused compare and taken branch instructions, the AMD LBR points to
the compare instruction instead of the branch. Users of LBR usually expects
the from address to point to a branch instruction. The kernel has code to
adjust the from address via get_branch_type_fused(). However this correction
is only applied when a branch filter is applied. That means that if no
filter is present, the quality of the data is lower.

Fix the problem by applying the adjustment regardless of the filter setting,
bringing the AMD LBR to the same level as other LBR implementations.

Fixes: 245268c ("perf/x86/amd/lbr: Use fusion-aware branch classifier")
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Sandipan Das <sandipan.das@amd.com>
Link: https://lore.kernel.org/r/20220928184043.408364-3-eranian@google.com
  • Loading branch information
Stephane Eranian authored and Peter Zijlstra committed Sep 29, 2022
1 parent 117ceeb commit 3f9a1b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions arch/x86/events/amd/lbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ static void amd_pmu_lbr_filter(void)
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
int br_sel = cpuc->br_sel, offset, type, i, j;
bool compress = false;
bool fused_only = false;
u64 from, to;

/* If sampling all branches, there is nothing to filter */
if (((br_sel & X86_BR_ALL) == X86_BR_ALL) &&
((br_sel & X86_BR_TYPE_SAVE) != X86_BR_TYPE_SAVE))
return;
fused_only = true;

for (i = 0; i < cpuc->lbr_stack.nr; i++) {
from = cpuc->lbr_entries[i].from;
Expand All @@ -116,8 +117,11 @@ static void amd_pmu_lbr_filter(void)
* fusion where it points to an instruction preceding the
* actual branch
*/
if (offset)
if (offset) {
cpuc->lbr_entries[i].from += offset;
if (fused_only)
continue;
}

/* If type does not correspond, then discard */
if (type == X86_BR_NONE || (br_sel & type) != type) {
Expand Down

0 comments on commit 3f9a1b3

Please sign in to comment.