From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.152 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796279236; b=sZ7dht80sHj33Qoh6LghYD+iCfX+z40zKz7y4kCwfnglMdeyz5j9N5jKgLhQnnETWBo8 2CtTb0XxnTMeid6HWk/2IvnM6975wQulpy1mDebbN262gUeUBTgIngN41KMpsitkT3ZwT 0IB5cSkxQJOqj9PDjjP2o34VPEb7NUKikB5O0RSGEX9J3LkSGrDTtMNx1nX0sJ2Z9MtZ+ q66DCZ7ooiWIi2UFB7rT/1h8EIr/p3FUsB0FVVK83mpy5g1pWthuDcT36XxPIe0LZkuav p/48QQbVO317YI5Y7NrxTLu93nQIbTnAYIxjBbXUUowr3/k1/x7nCZGoWMIRyf4W46g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796279236; 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-ID:X-MBO-RS-META; bh=4pVGX8Tn27CM1PDoU4055nfjgF0b504tjNkyGDKEgEM=; b=d2B7UPwztkPBpMweQ+MSgQ+Ajj/Y1qXWOjQoM1t4TQlOUTkeGZJfLiilYmqz0hQv8dXv OXGdbYYZt5P1JANyrttgKt7dE3F8LV95scHCNLO+jFEd19iHfxfTS+pZvSrz8nfsTybla 3iXAqmMWIajdUQZEGC5MYdIHYN/KmZSUi5iHrRDGw15XS3MBw0auylCnUSemHvzPC2XSj 6jcgvAHa42AgZDAtgoRlMMiGV5Uc1SKfPVsl2Ds4zj9LSWvoPjRTptFxW+F25VMRQjWpZ KB0Sp0MsMgCuFRA1V5jRhgLfD1XTgZ15UgxItQHp9k0uE5OHLCeVZmz2GjuA13GgNcQ== 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="rKhX//QF"; arc=none smtp.remote-ip=80.241.56.152 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) (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 C26CF606A336; Thu, 3 Dec 2026 06:27:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C26CF606A336 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=rKhX//QF 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-102.mailbox.org (Postfix) with ESMTPS id 4jg4RN5RtkzKsY7; Thu, 03 Dec 2026 07:27:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796279232; 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=4pVGX8Tn27CM1PDoU4055nfjgF0b504tjNkyGDKEgEM=; b=rKhX//QFJkekb+tyXQf5g3HsJGgCHpRHOXSx4RJT9Zjh3njqCwSXxn8t5GZT1Uz/ydNFiv swM360gtZLK4p+C4ESFhbkzeHpEXDIO1rhzTZ0GMzrrdgAKyI0pCw+jKYQBN/Eabb5wQfg Nln5B6asnmED2NJDlHCj8+uJ0Gvzf753klKBNQ8xNvZqGmHyd+bcD04kjbiPRA6wq97DwU ge/B0NJmg4Iqe0ORwNa6M/VkeD/gkjQMlVAvIApKI71xUx81EVfAP7Pt8fCR7aZ8LZHZsM g01jFcJ2FnTAFF3OnjkVRSsV3s2VDIUmKAj2/4l8F5PF/bxSc/xiyXqUA8YjOQ== 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 4/4] perf/x86/intel: Handle overflows of counters stopped by a throttle Date: Thu, 3 Dec 2026 08:27:03 +0200 Message-ID: <20261203062703.15346-5-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-perf-users@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-ID: c4e4426405b7442315c X-MBO-RS-META: gk63axi3txn8jhuqa3wdx7gckjumnjks handle_pmi_common() tests cpuc->active_mask while it walks the status bits. When perf_event_overflow() throttles a group, in the loop or in the PEBS drain before it, the other events of the group are stopped and the loop skips them, also when they have overflowed in the same PMI. The status bit of such a counter is acked, but its period is not set up again, and the counter is restarted as it is when the group is unthrottled. The event then delivers no samples until it is scheduled in again. Two identical events in one group, on a Core i7-14700T: $ perf record -c 20000 -e '{cpu_core/cycles/u,cpu_core/cycles/u}' \ -- taskset -c 4 ./spin cpu_core/cycles/u 349634 samples cpu_core/cycles/u 60173 samples Take a copy of active_mask on entry, before the PEBS drain, and walk the counters which were active then, as in the AMD and the generic handler. With the change both events deliver 337035 samples. 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 # needs adjustments for <= 7.1 --- ./spin is a loop in user space. Debug prints in the handler (not part of this patch) show what happens to a skipped counter without the change: it is started again without a reload at every unthrottle and only gets a new period when the event is scheduled in again, up to 0.9 seconds later. The PEBS case: group of cycles (period 20000) and a PEBS instructions event which interrupts for every record. The PEBS drain throttles the group and the cycles event's pending overflow is skipped. It delivered 6257 to 13360 samples per second without the change and 25836 to 26002 with it, which is what its counter says. The second hunk sits right above the drain_pebs call in the loop, which Dapeng's pending "perf/x86/intel: Fix draining of un-overflowed PEBS buffer in PMI handler" changes. I can rebase on whatever goes in first. On the Fixes: tag: the skip needs the group stop which 9734e25fbf5a added. The sample numbers were not better before it, though. On its parent the sibling delivers about 2000 samples per second in the same test, as far as I can read because a throttled sibling was only unthrottled when it was scheduled in. On stable: 7.2 and later take the series as it is. In 6.18.y the first hunk of this patch has a different context line. I ran the series with that one change on 6.18.66 on the same machine (same tests, same result) and will send the backport once this is in mainline. arch/x86/events/intel/core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 88a60d3e4eeb..ea109b262a21 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3821,11 +3821,20 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) { struct perf_sample_data data; struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); + DECLARE_BITMAP(active, X86_PMC_IDX_MAX); int bit; int handled = 0; inc_perf_irq_stat(); + /* + * perf_event_overflow() can throttle and thereby stop the whole group, + * from the PEBS drain as well as from the loop below. Remember which + * counters are active now, so that a pending overflow of a sibling + * stopped that way is still handled. + */ + bitmap_copy(active, cpuc->active_mask, X86_PMC_IDX_MAX); + /* * Ignore a range of extra bits in status that do not indicate * overflow by themselves. @@ -3936,7 +3945,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) handled++; - if (!test_bit(bit, cpuc->active_mask)) + if (!test_bit(bit, active)) continue; /* Event may have already been cleared: */ if (!event) -- 2.56.1