From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288589; b=fdk3Z24czPXBAMgxmH5+pgCdMJsVYh+pguHx7M7H4v/0kDzAjVuoSL3WmijleCvBmDOe vs8CR3TnfX7D7iLZNo5NkrXcX51MJZL7k2Os096a7gUEXZ4+tqMmx6MSl57+MDezWKBXy WFnabg1Vh+oLJfJk65SwdErehjR0Yj9sl4xxFZzgoDj4hyYcSZWwVY6l0ypGoyYJ7O/qa 51iFtRgnyA/7023oDcy1OyQ43yuFYO530dYBmfpUM/rHZYVLTtrCOHXXYHqSljXT2oaV2 cQ/k9j005XEhyK8UZoQ23DE8Xknf2pJfHBEEQ2P5AAiEMj4kBSo1Djl34mnUPbDQ16w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288589; 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=hBUyTEEqt/CICmEjUx6x3XQ0TVCB+iGUPTVAJmsUv8Y=; b=0I3hmXKx4Rk+xhWQpRQOYbRh1nUUkVYcTCvG0rfsy/GSzdOnfh/2YG3I2ZEWabFAO9ym L3vH1LThhVEjvn0HAIAe7flmXQvPITLbddaB/W8gQ0gMHOiKJEIi55XWYvu/4rh0JW7Yy posKhvpuEeLB297gFoHqbMrqaYuwYaJWLKl5db8mH/zxPUD5mvH5v5S/PpsFWLhqtqbdU WIY8MPvxo5xXbvJ4W4AD/UYogOC1OFWA7SntdtKRwOQEtYFDzo/0OLPOiXyyj/vYC5LGI UMI7pGD2yO/LsEg+2elzoIw4acKYQKXPQU5sL3TX4RhOR6/wZtzsZwzFpcei+A0hkGg== 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=aB69IvEv; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 3BD64606A33B; Thu, 3 Dec 2026 09:03:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3BD64606A33B 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=aB69IvEv DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796288588; x=1827824588; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=hBUyTEEqt/CICmEjUx6x3XQ0TVCB+iGUPTVAJmsUv8Y=; b=aB69IvEvpXWMQ47vZMJqj53l6nCmXeP7O4jmWl6Pi+lSpSogehyv4zlA f8/07G8bi+J4/ZOQJ8wPsE/PLGPQtA4LhfhUva+m4yCY0EVW0Ee+osE/f 9q5IBeRLfeQha1e8vPOSqevRuqMUtiTJDCxxEjQ4nt2X9o9wL8geoFAdC tDNVfw7yRwbcpL26NlpFT1erRi3m5bES7XRRXqkCXJKWCdoXX1AcC9TZy 9U7KoyxrjPu3bbvHBOcCSejQccD53lqXvBSgrjFkKp2MBai+iA4UnoW2n nRRv9kP7WwyA7uGBOHg1HUa/Ob3+hK9Q3L8KuV4QJ8BF+fVmNmdEGSkeN Q==; X-CSE-ConnectionGUID: MkFU4/fpS3uXtppETw2XtA== X-CSE-MsgGUID: x/C59lrvTfWTLqWN2XBpcw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5247695" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5247695" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:03:07 -0800 X-CSE-ConnectionGUID: 8sbWuIINQESjxd0cR2uFuQ== X-CSE-MsgGUID: jd+vJroIRhuPbc5swjnriw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="13739603" 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:03:03 -0800 Message-ID: Date: Thu, 3 Dec 2026 17:03:00 +0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/4] perf/x86: 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-4-john3@mailbox.org> Content-Language: en-US From: "Mi, Dapeng" In-Reply-To: <20261203062703.15346-4-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: > x86_pmu_handle_irq() tests cpuc->active_mask while it walks the > counters. When perf_event_overflow() throttles a group, the other > events of the group are stopped and the loop skips them, also when > they have overflowed in the same NMI. > > The period of such a counter is not set up again. The counter is > restarted as it is when the group is unthrottled, so the overflow is > noticed by a later NMI of another counter, or not at all when the > event is scheduled out first. > > Take a copy of active_mask before the loop and walk the counters which > were active on entry, as in amd_pmu_v2_handle_irq(). > > 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 > --- > Tested with the reproducer of patch 2 on the same AMD machine and in > the guest, booted with clearcpuid=perfmon_v2 so that > amd_pmu_handle_irq() is used. I have no other hardware which uses > this handler. > > arch/x86/events/core.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c > index 4e344fb1ae3e..b4f956c5ca1c 100644 > --- a/arch/x86/events/core.c > +++ b/arch/x86/events/core.c > @@ -2157,6 +2157,7 @@ void x86_pmu_update_perf_regs(struct perf_event *event, > > int x86_pmu_handle_irq(struct pt_regs *regs) > { > + DECLARE_BITMAP(active, X86_PMC_IDX_MAX); > struct perf_sample_data data; > struct cpu_hw_events *cpuc; > struct perf_event *event; > @@ -2176,8 +2177,15 @@ int x86_pmu_handle_irq(struct pt_regs *regs) > */ > apic_write(APIC_LVTPC, APIC_DM_NMI); > > + /* > + * perf_event_overflow() can throttle and thereby stop the whole group. > + * Walk the counters which 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); > + > for_each_set_bit(idx, x86_pmu.cntr_mask, X86_PMC_IDX_MAX) { > - if (!test_bit(idx, cpuc->active_mask)) > + if (!test_bit(idx, active)) > continue; > > event = cpuc->events[idx];