From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796279238; b=B2r5yq0Pw0xUBxJLJfOZ48dKa+yd9Au8b/NPbZEdqaGDeMiBMWvgYiFFfhCX/BT68Y5A +ZgCR66a10YuaUkfqCJxWVcRmb0cO2SdNt40ZFbkB40HtEPUu++6KxuVMFoADDqWfJY+q LFZ7RJukGvXDkvGgynbmzmXqi/+JQGwxN2opKwLmtuFC72G2cxVZHenDj28npVXthgUQa pw5/7x077JP4QPI53BPgFXMmimdtPEf4alXgTGtTH5qHz7X0Ltvl1hZajimHNyLcBx/YA FxkKxa5xLkL44q5bTwigspttIr5a05HwGL0AX1iLoLZW3mlNiNQFZhZhalKnwgaBh7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796279238; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-MBO-RS-META:X-MBO-RS-ID; bh=3ubKUkK7H2zGC4OhRMbvDtedVqCNfGS18ZcSghhLSyM=; b=zjmBYyeJd3K/xpJMA/3JWEh/+o80HLQB+MYXJUxTn+LYk5cgB26F9m4MmsXjFbTsjgi9 6Yl+pl9MWSpUKWXLaMsfr7jUSUTf7tX37i4Z5BFyyQ/K2os+SOu3oLXjRBjTNM9Ks2mjr Pc+hFTUM2FWyRcPjQvLuXQq2z42PTEtY58YoLZa1wDkx3xdbosW4ZC34gPb1lpfackTYN q+fqAda9AnM0PpoKZSDkzt9pRLdHEU1RfYBRCZNYlErw2616RPnZSQBwmr0pI8dGbQvvk z6wDwjhnKk1ZCWlc4xv7TBZa1UPp35roc56IRGwNlA9na76iBrMKVOfZBHkhLXXf0Aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=SUa6oCmW; arc=none smtp.remote-ip=80.241.56.171 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D5D6606A32D; Thu, 3 Dec 2026 06:27:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9D5D6606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=SUa6oCmW Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4jg4RH49P8zMld8; Thu, 03 Dec 2026 07:27:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796279227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ubKUkK7H2zGC4OhRMbvDtedVqCNfGS18ZcSghhLSyM=; b=SUa6oCmWIqspoVZKhDleEgFdzZdTpJdYYsfeZH+p/UfpCyCgzbuv/1BbyTv++4e3vXNLOk XTg4GmiWu6JWiyTWOlNt+2JpRlWoPkFK5tceYGFf6YrQCP7jgIlBMHLZldvlpta/QNykXV Ba54FGHuUQE+zbL9S9TCL/CoGfkATF7LlqR+ZMa4FEJoQkF23MfzQ1crFSF2NQv/wuPWH4 TLynFP8f7oeNEC2ua4AH45Cq3jqWf3uWfzezXnbDvytfMacLPfO65wuFnFhwjbdHe00UUM J6yHj5GkTjRMH7Lw58udFZF5asnDesV74eQDkhDb99lM1e/rhfFfRcrY/whWDw== From: Oancea Catalin 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@kernel.org, "H. Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Bangoria , Dapeng Mi Subject: [PATCH v3 1/4] perf/core: Do not account overflows of a throttled event Date: Thu, 3 Dec 2026 08:27:00 +0200 Message-ID: <20261203062703.15346-2-john3@mailbox.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203062703.15346-1-john3@mailbox.org> References: <20261203062703.15346-1-john3@mailbox.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MBO-RS-META: whkw3xy5347uu9qiwwh131kyysnwuyyb X-MBO-RS-ID: 741219e8d8a9b73de24 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. 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 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; -- 2.56.1