[PATCH v4 3/4] perf/x86: Handle overflows of counters stopped by a throttle
From: Oancea Catalin
Date: Thu Dec 03 2026 - 06:39:57 EST
x86_pmu_handle_irq() tests cpuc->active_mask while it walks the
counters. When perf_event_overflow() throttles a group, the other
events of the group are stopped and the loop skips them, also when
they have overflowed in the same NMI.
The period of such a counter is not set up again. The counter is
restarted as it is when the group is unthrottled, so the overflow is
noticed by a later NMI of another counter, or not at all when the
event is scheduled out first.
Take a copy of active_mask before the loop and walk the counters which
were active on entry, as in amd_pmu_v2_handle_irq().
An AI coding assistant (Claude Code) was used in the analysis and in
writing the patch.
Fixes: 9734e25fbf5a ("perf: Fix the throttle logic for a group")
Signed-off-by: Oancea Catalin <john3@xxxxxxxxxxx>
Reviewed-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
Tested with the reproducer of patch 2 on the same AMD machine and in
the guest, booted with clearcpuid=perfmon_v2 so that
amd_pmu_handle_irq() is used. I have no other hardware which uses
this handler.
arch/x86/events/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 4e344fb1ae3e..b4f956c5ca1c 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2157,6 +2157,7 @@ void x86_pmu_update_perf_regs(struct perf_event *event,
int x86_pmu_handle_irq(struct pt_regs *regs)
{
+ DECLARE_BITMAP(active, X86_PMC_IDX_MAX);
struct perf_sample_data data;
struct cpu_hw_events *cpuc;
struct perf_event *event;
@@ -2176,8 +2177,15 @@ int x86_pmu_handle_irq(struct pt_regs *regs)
*/
apic_write(APIC_LVTPC, APIC_DM_NMI);
+ /*
+ * perf_event_overflow() can throttle and thereby stop the whole group.
+ * Walk the counters which are active now, so that a pending overflow
+ * of a sibling stopped that way is still handled.
+ */
+ bitmap_copy(active, cpuc->active_mask, X86_PMC_IDX_MAX);
+
for_each_set_bit(idx, x86_pmu.cntr_mask, X86_PMC_IDX_MAX) {
- if (!test_bit(idx, cpuc->active_mask))
+ if (!test_bit(idx, active))
continue;
event = cpuc->events[idx];
--
2.56.1