Re: [PATCH v3 1/4] perf/core: Do not account overflows of a throttled event
From: Mi, Dapeng
Date: Thu Dec 03 2026 - 03:59:44 EST
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@xxxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> ---
> 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;