Skip to content

Commit 871a93b

Browse files
author
Peter Zijlstra
committed
perf/x86: Fix n_pair for cancelled txn
Kan reported that n_metric gets corrupted for cancelled transactions; a similar issue exists for n_pair for AMD's Large Increment thing. The problem was confirmed and confirmed fixed by Kim using: sudo perf stat -e "{cycles,cycles,cycles,cycles}:D" -a sleep 10 & # should succeed: sudo perf stat -e "{fp_ret_sse_avx_ops.all}:D" -a workload # should fail: sudo perf stat -e "{fp_ret_sse_avx_ops.all,fp_ret_sse_avx_ops.all,cycles}:D" -a workload # previously failed, now succeeds with this patch: sudo perf stat -e "{fp_ret_sse_avx_ops.all}:D" -a workload Fixes: 5738891 ("perf/x86/amd: Add support for Large Increment per Cycle Events") Reported-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Kim Phillips <kim.phillips@amd.com> Link: https://lkml.kernel.org/r/20201005082516.GG2628@hirez.programming.kicks-ass.net
1 parent 59d5396 commit 871a93b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

arch/x86/events/core.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,8 +1064,10 @@ static int collect_event(struct cpu_hw_events *cpuc, struct perf_event *event,
10641064
return -EINVAL;
10651065

10661066
cpuc->event_list[n] = event;
1067-
if (is_counter_pair(&event->hw))
1067+
if (is_counter_pair(&event->hw)) {
10681068
cpuc->n_pair++;
1069+
cpuc->n_txn_pair++;
1070+
}
10691071

10701072
return 0;
10711073
}
@@ -2006,6 +2008,7 @@ static void x86_pmu_start_txn(struct pmu *pmu, unsigned int txn_flags)
20062008

20072009
perf_pmu_disable(pmu);
20082010
__this_cpu_write(cpu_hw_events.n_txn, 0);
2011+
__this_cpu_write(cpu_hw_events.n_txn_pair, 0);
20092012
}
20102013

20112014
/*
@@ -2031,6 +2034,7 @@ static void x86_pmu_cancel_txn(struct pmu *pmu)
20312034
*/
20322035
__this_cpu_sub(cpu_hw_events.n_added, __this_cpu_read(cpu_hw_events.n_txn));
20332036
__this_cpu_sub(cpu_hw_events.n_events, __this_cpu_read(cpu_hw_events.n_txn));
2037+
__this_cpu_sub(cpu_hw_events.n_pair, __this_cpu_read(cpu_hw_events.n_txn_pair));
20342038
perf_pmu_enable(pmu);
20352039
}
20362040

arch/x86/events/perf_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ struct cpu_hw_events {
235235
they've never been enabled yet */
236236
int n_txn; /* the # last events in the below arrays;
237237
added in the current transaction */
238+
int n_txn_pair;
238239
int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */
239240
u64 tags[X86_PMC_IDX_MAX];
240241

0 commit comments

Comments
 (0)