mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Oancea Catalin <john3@mailbox.org>,
	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>
Subject: Re: [PATCH v3 1/4] perf/core: Do not account overflows of a throttled event
Date: Thu, 3 Dec 2026 16:59:32 +0800	[thread overview]
Message-ID: <2c1bb759-0808-4bee-a60a-022141097aca@linux.intel.com> (raw)
In-Reply-To: <20261203062703.15346-2-john3@mailbox.org>


On 12/3/2026 2:27 PM, Oancea Catalin wrote:
> A throttle marks every event of the group with hw.interrupts ==
> MAX_INTERRUPTS and stops it. The tick unthrottles the group when it
> finds that mark on the group leader.
>
> __perf_event_account_interrupt() counts the overflow of an event which
> is already throttled like any other. This overwrites the mark, and if
> the event is the leader, the group stays stopped until it is scheduled
> in again.

I'm fine with the code change, but the change log is very confusing. It
take me long time to figure out what the issue is.

Could you please refactor the change log and clearly say what the issue is
first, then what causes the issue and how to fix the issue at last?

If possible, give an example to show how the issue is triggered, e.g.,  a
event group with {instructions, instructions} is created, generally the
leader instructions event is programed on fixed counter 0 and the sibling
instructions event is programmed to GP counter 0. If they are overflowed at
the same time, the sibling event is handled first and then hwc->interrupts
of the 2 events is set to MAX_INTERRUPTS if the sibling event triggered
throttle. Then the leader event is handled and hwc->interrupts++ wraps to 0
from MAX_INTERRUPTS for the leader.

It blocks the subsequent unthrottle since the hwc->interrupts of the leader
event is not MAX_INTERRUPTS any more.

Thanks.


>
> A PMU interrupt handler can report such an overflow: one interrupt can
> carry the overflows of several events of a group, and the first of
> them may throttle the group. The following patches make the x86
> handlers report the others too. Without this change a group with its
> leader on a fixed counter of an Intel CPU then got 32 THROTTLE records
> and no UNTHROTTLE record in 4 seconds.
>
> Return early for an event which is already throttled. Its sample is
> still delivered.
>
> 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@mailbox.org>
> Cc: stable@vger.kernel.org
> ---
> The numbers are from a test kernel with patches 2 to 4 but without
> this one, on a Core i7-14700T: two instructions events with period
> 20000 in one group, pinned task. It delivered 1600 to 4046 samples per
> second instead of 100000.
>
> I looked for the same on mainline as it is, through the PEBS drain,
> which also delivers for an event stopped earlier in the same PMI. Two
> PEBS events in a group with one PMI per record did not show it.
>
> perf_event_account_interrupt() has other callers (Intel PEBS, AMD IBS,
> powerpc). For them the early return means that an event which is
> already throttled is not throttled a second time.
>
>  kernel/events/core.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 4ab3919ac78e..cfe9ec01fdff 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -10773,6 +10773,15 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle,
>  	int ret = 0;
>  	u64 seq;
>  
> +	/*
> +	 * A PMU handler can report an overflow which was pending when a
> +	 * throttle stopped the event together with its group. Accounting it
> +	 * would overwrite MAX_INTERRUPTS, and the tick would no longer
> +	 * unthrottle the group if the event is its leader.
> +	 */
> +	if (unlikely(hwc->interrupts == MAX_INTERRUPTS))
> +		return 0;
> +
>  	seq = __this_cpu_read(perf_throttled_seq);
>  	if (seq != hwc->interrupts_seq) {
>  		hwc->interrupts_seq = seq;

  reply	other threads:[~2026-12-03  8:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=2c1bb759-0808-4bee-a60a-022141097aca@linux.intel.com \
    --to=dapeng1.mi@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=john3@mailbox.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®