Linux Perf Users
 help / color / mirror / Atom feed
From: Oancea Catalin <john3@mailbox.org>
To: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	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,
	Dapeng Mi <dapeng1.mi@linux.intel.com>
Subject: Re: [PATCH] perf/x86/amd/core: Handle overflows of counters stopped by a throttle
Date: Tue,  1 Dec 2026 18:28:58 +0200	[thread overview]
Message-ID: <20261201162858.43478-1-john3@mailbox.org> (raw)
In-Reply-To: <dc8cf79a-18c5-42c4-9075-895253e47032@amd.com>

Hi Ravi,

thanks for the review.

On Tue, 1 Dec 2026 16:26:09 +0530, Ravi Bangoria wrote:
>> The overflow of the sibling is not handled. Its period is not set up
>> again and its status bit stays set, because only the handled bits are
>> acknowledged.
>
> I assume Intel's PMI handler as well as generic x86_pmu_handle_irq()
> are also affected?

Yes, both. I have tested them now.

For the generic handler I booted the same KVM guest with
clearcpuid=perfmon_v2, so that amd_pmu_handle_irq() is used, on
v7.4-rc5-25-g19cc08c1a6a6. It has no status register to compare with,
so nothing warns, but the overflow of the sibling is skipped in the
same way. In an MSR trace of 8 seconds there are 493 NMIs which reload
counter 0, disable both event selects and do not touch counter 1, and
the next read of counter 1, with the counter still disabled, shows that
it had overflowed. With a debug print in the handler I counted 3574 and
1977 such counters in two runs of 8 seconds.

About half of them are picked up by a later NMI after the group is
unthrottled, since that handler goes by the counter values and the
counter still reads as overflowed. That sample is late and covers more
than one period. The other half are still pending when the task is
scheduled out.

The Intel handler I tested on an i7-14700T (bare metal, P-cores), same
commit plus a debug print in handle_pmi_common(). It skips the stopped
sibling too, and there it is worse: the status has already been acked,
so no later PMI finds the counter again. The unthrottle restarts it
with its old value and it does not sample until the event is scheduled
out and in again.

On bare metal the two periods of my reproducer (20000 and 20011) hardly
ever overflow in the same PMI: 0 skips in about 11000 throttles. With
both periods at 20000 it was 6575 skips in 8 seconds. But a few are
enough. A single task with a 20000/20011 group, pinned to one P-core,
run as uid 65534, got 16 skips in 3 seconds, and after each of them the
sibling delivered no samples for 13 to 605 ms. In three such runs the
sibling delivered 23%, 42% and 55% of the samples of the leader. Opened
as two independent events, both deliver the same number. The counts
stay right in all cases, it is the samples which are missing.

This patch only changes amd_pmu_v2_handle_irq(), where the warning is.
I can send patches for x86_pmu_handle_irq() and handle_pmi_common()
with the same approach, if that is how you want it fixed.

>> +		/* Stopped by a group throttle in an earlier iteration */
>
> Nit: Can this comment be more explicit:
>
> 		/*
> 		 * Group was throttled in an earlier iteration; re-arm the
> 		 * counter without delivering the sample.
> 		 */

Sure, I will use that in v2.

Thanks,
Catalin

      reply	other threads:[~2026-12-01 16:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 21:11 [PATCH] perf/x86/amd/core: Handle overflows of counters stopped by a throttle Oancea Catalin
2026-11-24 21:22 ` sashiko-bot
2026-12-01 10:56 ` Ravi Bangoria
2026-12-01 16:28   ` Oancea Catalin [this message]

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=20261201162858.43478-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