From: Oancea Catalin <john3@mailbox.org>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Thomas Gleixner <tglx@kernel.org>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Ravi Bangoria <ravi.bangoria@amd.com>,
Dapeng Mi <dapeng1.mi@linux.intel.com>
Subject: [PATCH v4 0/4] perf/x86: Handle overflows of counters stopped by a throttle
Date: Thu, 3 Dec 2026 13:39:18 +0200 [thread overview]
Message-ID: <20261203113922.77972-1-john3@mailbox.org> (raw)
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. It also
fixes a case in which a group is not unthrottled today.
v4:
- Patch 1 returns 1 instead of 0 for an event which is already
throttled. With 0, perf_swevent_overflow() did not leave its loop
when an NMI throttled the group under it, as the Sashiko review of
v3 pointed out. It reproduces with v3: a tracepoint event delivered
over 100 million samples in one go, with interrupts off for more
than 3 seconds (KVM guest).
- Patch 1 has a new changelog, as Dapeng asked. The test for the
point above showed that mainline already loses unthrottles when a
software event is in the group, so the changelog starts from that.
The comment in the code says both cases now.
- Patches 3 and 4 have Dapeng's Reviewed-by. Patches 2 to 4 are
unchanged.
- Tested again, on d06ce6f1eb5e.
v3: https://lore.kernel.org/all/20261203062703.15346-1-john3@mailbox.org/
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 d06ce6f1eb5e with perf_event_paranoid at 2:
- AMD Ryzen 9 7945HX, bare metal, as uid 65534: without the series
the PerfMonV2 handler warns in 2 of 2 boots; with it there is no
warning, on either handler. An MSR trace of two grouped cycles
events shows the stopped counter being handled in the same NMI in
all 822 cases with each handler, and never without the series.
perf record of that group gives 332080/332077 samples without and
385857/385857 with the series. The group of patch 1 (as root,
leader period 8000) gets 289 THROTTLE and 264 UNTHROTTLE records in
5 seconds without the series, 1273 of each with it.
- 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 28706
cases, and in all 20671 with the generic handler (booted with
clearcpuid=perfmon_v2); without the series in none of 6040.
- 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 389471 / 333850 317204 / 317204
cycles, E-core 386871 / 6211 387302 / 387302
instructions (leader on a
fixed counter), P-core 166259 / 382270 386034 / 386034
Also tested: PEBS events in the group and frequency mode. "perf test"
gives the same failures with and without the series.
- The group of patch 1 (cycles leader, tracepoint sibling, as root),
5 seconds on the Intel machine: 150 THROTTLE and 76 UNTHROTTLE
records without the series, 1317 of each with it.
The series is against mainline and applies to tip perf/urgent. On tip
perf/core patches 2 to 4 need their context adjusted (the declarations
of the sample data, and the PEBS drain lines in handle_pmi_common()).
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: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106
--
2.56.1
next reply other threads:[~2026-12-03 11:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 11:39 Oancea Catalin [this message]
2026-12-03 11:39 ` [PATCH v4 1/4] perf/core: Do not account overflows of a throttled event Oancea Catalin
2026-12-03 11:39 ` [PATCH v4 2/4] perf/x86/amd/core: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-12-03 13:42 ` Ravi Bangoria
2026-12-03 11:39 ` [PATCH v4 3/4] perf/x86: " Oancea Catalin
2026-12-03 11:39 ` [PATCH v4 4/4] perf/x86/intel: " Oancea Catalin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203113922.77972-1-john3@mailbox.org \
--to=john3@mailbox.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=dapeng1.mi@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®