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=1796288380; b=gRgnrVVQHJPqW9PrlY8aSARo/SHXNHyovxiqeyqysOJp4TNcTJpzT7ETySWIrJEr60zj 9QN3jikzZxIWw2mDD94SDk9CXX8ZWmM7Ft8uSPfmMg8H+Ag4BCxtQVP2wIXsS42U1Acf5 zKzVYlKv3rd2mMOO7iyFKeNpuZXHFbM+z0PT6jzPBl2bFLTX8hSeTfOWIHBNC5koog5nU A75JQs3sVHsxyHAnJtQm/n5QVxCqjxOJdxYt4SkeX06ISI81OECDjCcLCke9v7QBwBruM 85LEg7KbHsRB8udTPuX3GaeAUflhpY+FoP+yc7H7JagQABQpkQjWsdhRZRsb6CatQLA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288380; 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=WzsdxamSQlVS18fkQsOGAvPieqvBdsv9aY3Rl6gJeO0=; b=1C3lY1LMaAE22OvptRrv24z5/KPdDtaA5PiSK/HKztzr6aA/cohd4xz+9tvjK2QPuWm/ 3rzR/7ioJR2LL7CpoTmwDzzcXgUiqssVw9mpo+i3qy8Wj5MT0oXA9J6KLVc9CmqP81d1b tBiUM2mGFJHhAD4yfylZddEFiAc0TFbukxu5+3Cy9n6qXQb40cgtasuDG9iVFHB6qoONQ i5MrQBDd6qc/Uh42vGHiKWzADuEjwWX8GkBSYPpKKb6phFjG7f78arhvQS8pnqXPCjxN0 66keef56RCB44zUI3WfzWh6gpsn/zXrGYnlkj3LhDcZrDAjgMOsqdEvwTCJK3cQlniA== 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=QDBoZzQO; 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 280DC606A322; Thu, 3 Dec 2026 08:59:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 280DC606A322 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=QDBoZzQO DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796288380; x=1827824380; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=WzsdxamSQlVS18fkQsOGAvPieqvBdsv9aY3Rl6gJeO0=; b=QDBoZzQOkkZdyQDFF3Hen/AIrAE7JVYStD9QSJ6ibjS5f+w8QBOAUGLf 21UiJMrJyK9ANwzmfhC2iXN8/eAnAzJydsq7I7/X6bbTFTJyFjkTan/Wr gTOzKywmndFnSjhKnJ2X2iAaky2oRKmITPk50lm489bUUepRoKPWF/i/O +GAujrKT1qs9MIJf7eOd8H4vVNySupO8mr7J5B4LHsoh2RnlJwdpw09AG ep8m6W5l0not55ZIJxyA8/IpWlF8tn9yKOfu1S7TtmLLEzuCTWPPmal9M n3Ph+WWUOTfs/nyrgOlKLXcbtHUWf8AUowGETGpXC7uHeOMYofglqTYYw A==; X-CSE-ConnectionGUID: aorfG9G0SC6LkOUWF06Sww== X-CSE-MsgGUID: ixj+ThGVTF6ACKii185Wtw== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5247055" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5247055" 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 00:59:39 -0800 X-CSE-ConnectionGUID: G75Rn9NjR+22e6ziBuZ1VA== X-CSE-MsgGUID: AQ4yx1tFSCaNmT0y+po/GQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="13739057" 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 00:59:34 -0800 Message-ID: <2c1bb759-0808-4bee-a60a-022141097aca@linux.intel.com> Date: Thu, 3 Dec 2026 16:59:32 +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 1/4] perf/core: Do not account overflows of a throttled event 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-2-john3@mailbox.org> Content-Language: en-US From: "Mi, Dapeng" In-Reply-To: <20261203062703.15346-2-john3@mailbox.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 12/3/2026 2:27 PM, Oancea Catalin wrote: > A throttle marks every event of the group with hw.interrupts == > MAX_INTERRUPTS and stops it. The tick unthrottles the group when it > finds that mark on the group leader. > > __perf_event_account_interrupt() counts the overflow of an event which > is already throttled like any other. This overwrites the mark, and if > the event is the leader, the group stays stopped until it is scheduled > in again. I'm fine with the code change, but the change log is very confusing. It take me long time to figure out what the issue is. Could you please refactor the change log and clearly say what the issue is first, then what causes the issue and how to fix the issue at last? If possible, give an example to show how the issue is triggered, e.g.,  a event group with {instructions, instructions} is created, generally the leader instructions event is programed on fixed counter 0 and the sibling instructions event is programmed to GP counter 0. If they are overflowed at the same time, the sibling event is handled first and then hwc->interrupts of the 2 events is set to MAX_INTERRUPTS if the sibling event triggered throttle. Then the leader event is handled and hwc->interrupts++ wraps to 0 from MAX_INTERRUPTS for the leader. It blocks the subsequent unthrottle since the hwc->interrupts of the leader event is not MAX_INTERRUPTS any more. Thanks. > > A PMU interrupt handler can report such an overflow: one interrupt can > carry the overflows of several events of a group, and the first of > them may throttle the group. The following patches make the x86 > handlers report the others too. Without this change a group with its > leader on a fixed counter of an Intel CPU then got 32 THROTTLE records > and no UNTHROTTLE record in 4 seconds. > > Return early for an event which is already throttled. Its sample is > still delivered. > > 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 > --- > The numbers are from a test kernel with patches 2 to 4 but without > this one, on a Core i7-14700T: two instructions events with period > 20000 in one group, pinned task. It delivered 1600 to 4046 samples per > second instead of 100000. > > I looked for the same on mainline as it is, through the PEBS drain, > which also delivers for an event stopped earlier in the same PMI. Two > PEBS events in a group with one PMI per record did not show it. > > perf_event_account_interrupt() has other callers (Intel PEBS, AMD IBS, > powerpc). For them the early return means that an event which is > already throttled is not throttled a second time. > > kernel/events/core.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 4ab3919ac78e..cfe9ec01fdff 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -10773,6 +10773,15 @@ __perf_event_account_interrupt(struct perf_event *event, int throttle, > int ret = 0; > u64 seq; > > + /* > + * A PMU handler can report an overflow which was pending when a > + * throttle stopped the event together with its group. Accounting it > + * would overwrite MAX_INTERRUPTS, and the tick would no longer > + * unthrottle the group if the event is its leader. > + */ > + if (unlikely(hwc->interrupts == MAX_INTERRUPTS)) > + return 0; > + > seq = __this_cpu_read(perf_throttled_seq); > if (seq != hwc->interrupts_seq) { > hwc->interrupts_seq = seq;