mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/4] perf/x86: Handle overflows of counters stopped by a throttle
@ 2026-12-03  6:26 Oancea Catalin
  2026-12-03  6:27 ` [PATCH v3 1/4] perf/core: Do not account overflows of a throttled event Oancea Catalin
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Oancea Catalin @ 2026-12-03  6:26 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim
  Cc: Kan Liang, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, James Clark, Thomas Gleixner,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	linux-perf-users, linux-kernel, Ravi Bangoria, Dapeng Mi

Since 9734e25fbf5a ("perf: Fix the throttle logic for a group") a
throttle stops the whole group, from inside the PMU interrupt handler.
The x86 handlers test cpuc->active_mask while they walk the counters,
so they skip a group member which was just stopped, also when its
overflow is pending in the same interrupt:

 - amd_pmu_v2_handle_irq() warns "New overflows for inactive PMCs";
 - x86_pmu_handle_irq() notices the overflow in a later NMI, or never;
 - handle_pmi_common() does not set the period up again, and the event
   stops sampling until it is scheduled in again.

Patches 2 to 4 make the three handlers walk the counters which were
active on entry, so that such an overflow is handled like any other.
Patch 1 is needed for that: the overflow of an event which is already
throttled must not go through the throttle accounting again.

v3:
 - The stopped counter gets its sample now. Dapeng Mi asked why it did
   not: the sample made the group leader lose its throttled mark.
   Patch 1 (new) takes care of that.
 - Patches 3 and 4 are new. Dapeng asked for the Intel handler to be
   fixed in the same way, and the generic handler has the same loop.
 - Patch 2 is the v2 patch without the second active_mask test, with
   a shorter changelog.
 - Tested again, on 3f963696da44.

v2: https://lore.kernel.org/all/20261201163432.44692-1-john3@mailbox.org/
v1: https://lore.kernel.org/all/20261124211146.61378-1-john3@mailbox.org/

Tested on 3f963696da44 with perf_event_paranoid at 2:

 - AMD Ryzen 9 7945HX, bare metal, as uid 65534: without the series
   the PerfMonV2 handler warns 3 and 14 seconds into the reproducer
   (two boots); with it there is no warning in two boots. perf record
   of two grouped cycles events gives 355996/355991 samples without
   and 393090/393090 with the series.
 - The same CPU as a KVM host, guest with KASAN and lockdep, as root
   and as uid 65534. PerfMonV2 handler: the warning shows in 3 of 3
   boots without the series and in 0 of 6 with it. An MSR trace shows
   the stopped counter being handled in the same NMI in all 29122
   cases, and in all 25120 with the generic handler (booted with
   clearcpuid=perfmon_v2); without the series in none of 3887.
 - Intel, on a Core i7-14700T, as an unprivileged user. Samples of two
   grouped events with period 20000 in 4 seconds, without and with the
   series:
     cycles, P-core                  349634 /  60173   337035 / 337035
     cycles, E-core                  387674 / 112846   388066 / 388066
     instructions (leader on a
     fixed counter), P-core          133650 / 383265   389577 / 389577
   Also tested: PEBS events in the group and frequency mode. "perf test"
   gives the same failures with and without the series.

knc_pmu_handle_irq(), p4_pmu_handle_irq() and zhaoxin_pmu_handle_irq()
have the same loop. I have no such hardware and did not change them.

Oancea Catalin (4):
  perf/core: Do not account overflows of a throttled event
  perf/x86/amd/core: Handle overflows of counters stopped by a throttle
  perf/x86: Handle overflows of counters stopped by a throttle
  perf/x86/intel: Handle overflows of counters stopped by a throttle

 arch/x86/events/amd/core.c   | 10 +++++++++-
 arch/x86/events/core.c       | 10 +++++++++-
 arch/x86/events/intel/core.c | 11 ++++++++++-
 kernel/events/core.c         |  9 +++++++++
 4 files changed, 37 insertions(+), 3 deletions(-)


base-commit: 3f963696da4447986959d4a25c2ed69433ca3665
-- 
2.56.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-03  9:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03  6:26 [PATCH v3 0/4] perf/x86: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-03  6:27 ` [PATCH v3 1/4] perf/core: Do not account overflows of a throttled event Oancea Catalin
2026-12-03  8:59   ` Mi, Dapeng
2026-12-03  6:27 ` [PATCH v3 2/4] perf/x86/amd/core: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-03  6:27 ` [PATCH v3 3/4] perf/x86: " Oancea Catalin
2026-12-03  9:03   ` Mi, Dapeng
2026-12-03  6:27 ` [PATCH v3 4/4] perf/x86/intel: " Oancea Catalin
2026-12-03  9:08   ` Mi, Dapeng

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®