From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.15 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288900; b=RmnpN2CTTT0fVX3/CayHZvuZ1cnzo491QcV5TtBt3yJjtQXmXOMj6dHSTlQcbNgW63Pc IXBj168Zao5LY4Im8Xh8mpnHL5pcfRG7kYMpyr1n7njEc7K0Bga0LaFbN3IKWFNfyly3f plqts9/I6YfFwrLYX51aVHsbcugPRjO62Me1uzJWDAlz+2xUs3JnHJwZNLqSw2Wxsp4Wu qb+COI4pcmLAvd458hxwKrcFzuFCo1aKFYWpzOjU/nDhQIbT3xiZnbShNgXg3r4iTomut d9tj8DiDztd+YNu6EfzDxkwhxPfWx59PDfCiNsQqPjVfx9Cm3Syyd9qIf8AKFfieM1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288900; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:Content-Language: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=C9nZ+frO3WnGNYg8csgESuqiRYAS7EtFlaafYahIOFc=; b=yK0ogoWrvGkDtGjTXrMkjmCBH6ybhxEZThaxDitGoE/ltTpsWkwRcBX0/0ex2HCeVXwj XItGIKZutb7tQB5NqYLR1wSNMg/VzQ3yFobajxkW961HZTr9SwcLh7rjbxN8vp2jIqSCV /iez7ZC6sY5O+q8oqV/gfMqytkSvW8bx1kdU+gGtgUcmDXkxB/jdGwWi3/8bholW5Zi1R raWFX5JCgogl20woLmw1t7S8dGfVwU3csvd3/BFY2h9Wyi16RWz1m5MYO8YrjMffXqBBP B7Xv/JGKdGbCY3w1G2OnYeqTUhad3rsM/eRxMu7l2TVzshR5BvO+LGxJlCzqED9tbtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Y0ah8t4s; arc=none smtp.remote-ip=198.175.65.15 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCD81606A322; Thu, 3 Dec 2026 09:08:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCD81606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Y0ah8t4s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796288900; x=1827824900; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=C9nZ+frO3WnGNYg8csgESuqiRYAS7EtFlaafYahIOFc=; b=Y0ah8t4svTcvlTdTE8W0EPj22OSCqqqyOGn/Lun0FzGAtVxtbtE7P5n7 pNDG5AxQC1sjqlC4XTLhkJNG1+t+cJD2VIybHxBY5Bxq+IB6DHT6/wXGI E5A0trVHdjKPV4Z1tNr7Nmivlyfc3cZ3NM9imPolWddMpkiAN6zYrhVBO Q3wy1LgORnF8wic9kgs5tkBvhMGvmBc5ndz5MFbEDrPnQMbIDDz9z4azF yobabVPT2Tvv5+Hq/1m6wQJbKsXwOK78mRLhAleBRdAhm7qg/UPFWuwc/ rjX8Ogs2hTwE3ci5HaocSK3r8A1WRg2lz2UAqyxVV2KTVx2eXT61suRs7 g==; X-CSE-ConnectionGUID: sCJHG1M1RUKT7K9GPsIuXg== X-CSE-MsgGUID: gWc3ElVYQcaj3OEBBGvBuA== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5236506" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5236506" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:08:19 -0800 X-CSE-ConnectionGUID: K8+vsKQWSFGwAODCgkw42Q== X-CSE-MsgGUID: S+o4tSOOTcGafjf/5rGL4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="13793720" Received: from dapengmi-mobl1.ccr.corp.intel.com (HELO [10.124.241.239]) ([10.124.241.239]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:08:13 -0800 Message-ID: Date: Thu, 3 Dec 2026 17:08:10 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/4] perf/x86/intel: Handle overflows of counters stopped by a throttle To: Oancea Catalin , 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 References: <20261203062703.15346-1-john3@mailbox.org> <20261203062703.15346-5-john3@mailbox.org> Content-Language: en-US From: "Mi, Dapeng" In-Reply-To: <20261203062703.15346-5-john3@mailbox.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Reviewed-by: Dapeng Mi Thanks. On 12/3/2026 2:27 PM, Oancea Catalin wrote: > 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)