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=1796279231; b=4oOEDm24JEJ2rOt+ij743C21VAd2JjrKNzeYy8joSHx3uCa3C9D1R7J5cTIcJdKoHMV1 /0jH5AKiwZPCs2mMn0ssJD77f3ME1gkXGJ6QJPYhWLyumC+gh+sKA6FjtQm0SQU4U8jln i1BibDY1KmGLB3KgkjAgUPds9LXUT/IEtxzDk5LNizTcCwb/MUFkid8v9djEpelzhiefS kiH8a0zUWQB0sV5wkBFaWsJ6aErKB8H6dlG07zYl4QL2NBKZWPsVgbj2fSRjTRAORs2x2 jEwWZBnId5MtpLb0uM589BMymP3FEDVb1JspjO8vrtPWPPUbhL2Q55hdEN/bGrACigw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796279231; h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-MBO-RS-META:X-MBO-RS-ID; bh=SYVxOYZdaH+OBu2Us5pLIxWKfEd+U2ls/T3JPyPr0Yw=; b=OLB+89ljUkqBZ+5qIJDe6F+Z6opEpAaU/vgf94g94cj294QchwTjmDAAJItKoPtxds4p AJN7Vho3DbGa6WfrLfO+al2QmYo16Msbt22Z0TBlfo1y1coOmSdB/V4GisBm3/TfmcPyA YSPUrTdzYNo7n38Ol56jZ1IBIpRfFW7YJ93Kb1CglALSt0nzhRXIqY/5byLy1VijmFkPs 8Ly4hRxMujl5mRKRplXV466mFLYdUQG0YHSYfVxLa+QbkfUkDdt3us0ZDWI7CZY7BD+lX Q7QstnkoCgNrJmnFNA+Km38sB2rZ4T8B/z3S8cBxUA+yVzUGd4AKeKJciAwXsnTLpxA== 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=abajdwNv; 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 4A880606A322; Thu, 3 Dec 2026 06:27:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4A880606A322 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, unprotected) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=abajdwNv 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 4jg4RF6ZTCzKnDJ; Thu, 03 Dec 2026 07:27:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796279225; 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; bh=SYVxOYZdaH+OBu2Us5pLIxWKfEd+U2ls/T3JPyPr0Yw=; b=abajdwNviCPnTmH2+P4jYJyt3hbxt1pVqlyFH++bSPXFzXtRSNXqQ0orrDOSwF9bLRoqfx CiTt9CK07ASTFmgfBb60hTngNCxNc0eVL2n58rONmMbFbZlxgeY2YMxOfMpS4KDFxocL++ TbhOy8Hs24KE9KLNRNDKaqzZEr4eb8sUgIlW8PxPRPqH4vc3OLioOARGetQoCkd82p1RZ0 pI6UTvrHDochUpVc5jhZdk170oyB1Lc860B2oiLolJbghMUUoxv9eEI/VDXoofXKtd+V18 phukgR8D6lu/JshGkfU+Ld8SL3psxkir3qrlLfk0frXpz3kVg6G4iV0frPyi+g== 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 0/4] perf/x86: Handle overflows of counters stopped by a throttle Date: Thu, 3 Dec 2026 08:26:59 +0200 Message-ID: <20261203062703.15346-1-john3@mailbox.org> X-Mailer: git-send-email 2.56.1 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: xwryrgzrpsmrfu8a3ozfdohtokbbwea1 X-MBO-RS-ID: ba2bcd3d6a6603805ef Since 9734e25fbf5a ("perf: Fix the throttle logic for a group") a throttle stops the whole group, from inside the PMU interrupt handler. The x86 handlers test cpuc->active_mask while they walk the counters, so they skip a group member which was just stopped, also when its overflow is pending in the same interrupt: - amd_pmu_v2_handle_irq() warns "New overflows for inactive PMCs"; - x86_pmu_handle_irq() notices the overflow in a later NMI, or never; - handle_pmi_common() does not set the period up again, and the event stops sampling until it is scheduled in again. Patches 2 to 4 make the three handlers walk the counters which were active on entry, so that such an overflow is handled like any other. Patch 1 is needed for that: the overflow of an event which is already throttled must not go through the throttle accounting again. v3: - The stopped counter gets its sample now. Dapeng Mi asked why it did not: the sample made the group leader lose its throttled mark. Patch 1 (new) takes care of that. - Patches 3 and 4 are new. Dapeng asked for the Intel handler to be fixed in the same way, and the generic handler has the same loop. - Patch 2 is the v2 patch without the second active_mask test, with a shorter changelog. - Tested again, on 3f963696da44. v2: https://lore.kernel.org/all/20261201163432.44692-1-john3@mailbox.org/ v1: https://lore.kernel.org/all/20261124211146.61378-1-john3@mailbox.org/ Tested on 3f963696da44 with perf_event_paranoid at 2: - AMD Ryzen 9 7945HX, bare metal, as uid 65534: without the series the PerfMonV2 handler warns 3 and 14 seconds into the reproducer (two boots); with it there is no warning in two boots. perf record of two grouped cycles events gives 355996/355991 samples without and 393090/393090 with the series. - The same CPU as a KVM host, guest with KASAN and lockdep, as root and as uid 65534. PerfMonV2 handler: the warning shows in 3 of 3 boots without the series and in 0 of 6 with it. An MSR trace shows the stopped counter being handled in the same NMI in all 29122 cases, and in all 25120 with the generic handler (booted with clearcpuid=perfmon_v2); without the series in none of 3887. - Intel, on a Core i7-14700T, as an unprivileged user. Samples of two grouped events with period 20000 in 4 seconds, without and with the series: cycles, P-core 349634 / 60173 337035 / 337035 cycles, E-core 387674 / 112846 388066 / 388066 instructions (leader on a fixed counter), P-core 133650 / 383265 389577 / 389577 Also tested: PEBS events in the group and frequency mode. "perf test" gives the same failures with and without the series. knc_pmu_handle_irq(), p4_pmu_handle_irq() and zhaoxin_pmu_handle_irq() have the same loop. I have no such hardware and did not change them. Oancea Catalin (4): perf/core: Do not account overflows of a throttled event perf/x86/amd/core: Handle overflows of counters stopped by a throttle perf/x86: Handle overflows of counters stopped by a throttle perf/x86/intel: Handle overflows of counters stopped by a throttle arch/x86/events/amd/core.c | 10 +++++++++- arch/x86/events/core.c | 10 +++++++++- arch/x86/events/intel/core.c | 11 ++++++++++- kernel/events/core.c | 9 +++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) base-commit: 3f963696da4447986959d4a25c2ed69433ca3665 -- 2.56.1