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=1796297970; b=3HNVdrrIKShqAtnGAeqaMAVnaUujQqOMtrPnB8hYoFqVi1gWDU6uqGB3FBm1duGYFnyr drTag1Pc6jaex5xA/TQuUHmhw7tktdk70m5A3w+92WK25vpgxzWS6hxaCi5kHGuxMo3p7 Xx5wnTP9gJQCDodyMhK1QCbid12W7UtaoSqrJFvYZTipEyBXrAx+DHSJxCSZdxQHuP7I/ MpVUp9LA1M5N9xcRg2C6SjgE2nI7tJuO0Yg5D0MoVhHr9B806euaXy4SmchMwEAnUSzLG TL3kIPCmaMPBLiroNT92sPS8ybUPTDOLVQBD1cbfrXyYCPOlY1L6gPl98BjT9VeU2HA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297970; 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=GCoIqmxIXQe698Fv1wPLVN+7YMNWm7OaGxf5FztA6fo=; b=tDnO9uWbeixn5V/ZbMuk3BIHQdOY/FAHPpVSJopj745GlCxH5H18vHucKejy8O1jP3h+ bS7pnLc+cQcMM1qNfpL+BS7fkZJCtAHeTTPRniVH1lOok6q/6h3Yl0gUtbJ/0GAYSVTL3 Xq1al1qoiy1Jn8A4Kf2LtHWHHFbUlfml7bAGX13NhvvH4hc1pdE4PY1gI4zGX+vUB8twA ujZMTz4Zgl6dVrhFS3/LLahgTHtyaSUyNkopzRse8sUwLyZeJI/Gg5myWlpU4qAIbtjpi pdj/6GZVo0Hb7/0B6Lwh9+W682NrSBxNQ4JnpUdHqPCa5XkRbczQL2IzgqyXAVkjjxw== 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=V45ge3oN; 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 BFD13606A32D; Thu, 3 Dec 2026 11:39:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BFD13606A32D 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=V45ge3oN Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4jgCMd72dhzKm6G; Thu, 03 Dec 2026 12:39:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796297966; 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=GCoIqmxIXQe698Fv1wPLVN+7YMNWm7OaGxf5FztA6fo=; b=V45ge3oNJbOHzBCH3LPgxPMw2+EeibsEiV32/6XsoRVgg/BVkGdbQiyCwn9QKyKblHcW1m h07z0bsOkG3Q9Zh6MucKPNgssKS4rzwRGUJ6XmPYXT02HmbNturj2TRgeIs1b26p3OytZz L84tThgv3Ax7EXAGyiqK8vNwemLo+BzU002NPz4W56tmx7VMGo0Hjr/9yLclmOBSu1VfEW 3RdJgybw5tAGMZkvhi4yu6sVV/MD1ptooH9x2/9RKgftdDlURKlt242A2EtopMLbz7ub7H 9YewqJRBTxRswNPX+Shi5q5pAMYAhnQikLzu8mcJXF2AwjOWQfG4KVjUxd5gzg== 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 v4 0/4] perf/x86: Handle overflows of counters stopped by a throttle Date: Thu, 3 Dec 2026 13:39:18 +0200 Message-ID: <20261203113922.77972-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: z7s95rk1yy8pxxbegww4hm9q3z9saagm X-MBO-RS-ID: e6951c4aea3a8ba1a1a 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. It also fixes a case in which a group is not unthrottled today. v4: - Patch 1 returns 1 instead of 0 for an event which is already throttled. With 0, perf_swevent_overflow() did not leave its loop when an NMI throttled the group under it, as the Sashiko review of v3 pointed out. It reproduces with v3: a tracepoint event delivered over 100 million samples in one go, with interrupts off for more than 3 seconds (KVM guest). - Patch 1 has a new changelog, as Dapeng asked. The test for the point above showed that mainline already loses unthrottles when a software event is in the group, so the changelog starts from that. The comment in the code says both cases now. - Patches 3 and 4 have Dapeng's Reviewed-by. Patches 2 to 4 are unchanged. - Tested again, on d06ce6f1eb5e. v3: https://lore.kernel.org/all/20261203062703.15346-1-john3@mailbox.org/ 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 d06ce6f1eb5e with perf_event_paranoid at 2: - AMD Ryzen 9 7945HX, bare metal, as uid 65534: without the series the PerfMonV2 handler warns in 2 of 2 boots; with it there is no warning, on either handler. An MSR trace of two grouped cycles events shows the stopped counter being handled in the same NMI in all 822 cases with each handler, and never without the series. perf record of that group gives 332080/332077 samples without and 385857/385857 with the series. The group of patch 1 (as root, leader period 8000) gets 289 THROTTLE and 264 UNTHROTTLE records in 5 seconds without the series, 1273 of each with it. - 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 28706 cases, and in all 20671 with the generic handler (booted with clearcpuid=perfmon_v2); without the series in none of 6040. - 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 389471 / 333850 317204 / 317204 cycles, E-core 386871 / 6211 387302 / 387302 instructions (leader on a fixed counter), P-core 166259 / 382270 386034 / 386034 Also tested: PEBS events in the group and frequency mode. "perf test" gives the same failures with and without the series. - The group of patch 1 (cycles leader, tracepoint sibling, as root), 5 seconds on the Intel machine: 150 THROTTLE and 76 UNTHROTTLE records without the series, 1317 of each with it. The series is against mainline and applies to tip perf/urgent. On tip perf/core patches 2 to 4 need their context adjusted (the declarations of the sample data, and the PEBS drain lines in handle_pmi_common()). 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: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106 -- 2.56.1