* [PATCH] perf/x86/amd: Avoid double-decrementing n_pair on failed transactions
@ 2026-11-09 11:19 Zhao Gongyi
2026-11-11 6:54 ` Hang Zhengyang
0 siblings, 1 reply; 2+ messages in thread
From: Zhao Gongyi @ 2026-11-09 11:19 UTC (permalink / raw)
To: peterz, mingo
Cc: acme, namhyung, mark.rutland, alexander.shishkin, jolsa, irogers,
adrian.hunter, james.clark, tglx, bp, dave.hansen, x86, hpa,
linux-perf-users, linux-kernel
On a failed PERF_PMU_TXN_ADD commit, x86_schedule_events() releases
constraints for newly added pair events. The AMD put callback decrements
n_pair, and x86_pmu_cancel_txn() then subtracts n_txn_pair for the same
events. This undercounts active pairs and overstates the GP counter budget
for later scheduling.
Leave transaction rollback to x86_pmu_cancel_txn(). Keep the AMD
decrement for constraint releases outside transactions.
Fixes: 871a93b0aad6 ("perf/x86: Fix n_pair for cancelled txn")
Signed-off-by: Zhao Gongyi <zhaogongyi@bytedance.com>
---
arch/x86/events/amd/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 49b6b8fce..3363cfd3b 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -1251,7 +1251,8 @@ static void amd_put_event_constraints_f17h(struct cpu_hw_events *cpuc,
{
struct hw_perf_event *hwc = &event->hw;
- if (is_counter_pair(hwc))
+ if (is_counter_pair(hwc) &&
+ !(cpuc->txn_flags & PERF_PMU_TXN_ADD))
--cpuc->n_pair;
}
base-commit: f5a78ecccd98a04c47cea1cd63c2a2fdce8a4b48
--
2.39.5 (Apple Git-154)
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] perf/x86/amd: Avoid double-decrementing n_pair on failed transactions
2026-11-09 11:19 [PATCH] perf/x86/amd: Avoid double-decrementing n_pair on failed transactions Zhao Gongyi
@ 2026-11-11 6:54 ` Hang Zhengyang
0 siblings, 0 replies; 2+ messages in thread
From: Hang Zhengyang @ 2026-11-11 6:54 UTC (permalink / raw)
To: Zhao Gongyi
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, james.clark, tglx, bp,
dave.hansen, x86, hpa, linux-perf-users, linux-kernel
On Mon, 9 Nov 2026 19:19:09 +0800, Zhao Gongyi wrote:
> On a failed PERF_PMU_TXN_ADD commit, x86_schedule_events() releases
> constraints for newly added pair events. The AMD put callback decrements
> n_pair, and x86_pmu_cancel_txn() then subtracts n_txn_pair for the same
> events.
Reproduced in a KVM guest on a Zen 3 host (Ryzen 7 PRO 5850U), kernel
7.3-rc6, with a trace_printk() in x86_schedule_events() and
x86_pmu_cancel_txn(). With four pinned cycles events on CPU 0, each
failed attempt to add a pinned '{fp_ret_sse_avx_ops.all,cycles}' group
leaves n_pair one lower: -1, -2, -3, so gpmax goes 5, 6, 7 on 6
counters. With this patch n_pair is back to 0 after each attempt and
gpmax stays 5.
Tested-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
To reproduce:
perf stat -C 0 -e '{cycles,cycles,cycles,cycles}:D' -- sleep 4 &
# three times:
perf stat -C 0 -e '{fp_ret_sse_avx_ops.all,cycles}:D' -- taskset -c 0 <workload>
(Analysis and testing done with an AI assistant; I reproduced the
n_pair drift.)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-11 6:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 11:19 [PATCH] perf/x86/amd: Avoid double-decrementing n_pair on failed transactions Zhao Gongyi
2026-11-11 6:54 ` Hang Zhengyang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®