From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367650; b=YPZ02CosknuehrN/z4TVnUl5aAv8CN51aqM3CSBmM0/wu05NYis1CPQ0APuCMlmgLFLk xU2PGjwPZNKZQy/bi1ebJRBM9v89a7jf09EFwN3z/8k2RS9Ql/ZKrrgkjP0S3p7EgzDw2 bPWsFrPw/j8tZaC68HYt/Y1R+Hitu+3s6MmZVg2oxcfGDmaV+k9yqy63BKSy+FQvxmxq7 D9YZMgENLxSrD5kFeQrPbTDbwHXbucxbpT+Oxy1Zk2Sq4kZR54eeiZtzeW59NcTjtcxF2 3C8CTTs29P8xq1yM10aEmJCE3+aejiPLq66CDBanp+BUs+Fh0nlGraIObx8wRBSIJgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367650; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=MZn9BojA7KwDNQGiVIe7HHuA7pJEEI6Ya5SS77TDL3c=; b=0jHcdVqcjPIiPjlv7mU2HANtIKxTZoLuLWYOa18DJS7yniGLohfXyaKvhCT1hJeudud5 qsO6gm99IqQehv2k89bdoqWV30WG3PBUED1PgMHqx9FfQueJnPaJ8OGXASlhS61UzD/Zc CZ4HwgXFNIhc4yNkgcXSJFzdeocvX3Nq7bZrwd4rA1JX+oMpbng5M9mmcKrAsuQ9V2ooz Rl+3VDaNnf8/HzhTgA26vQ4HxLLrz2CE4Sdgi6HNTyQoSKFHPX2oQ05JbreBG0iQQpxrt puw3YQt5i76JDQNT/I3fKFddL3ZcAATsYSgYYbmYnu0s5egAwBzhEf23/AXXN7gEX9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G8zqv5yH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F25B3606A683; Fri, 4 Dec 2026 07:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=G8zqv5yH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 697FD1F00897; Fri, 4 Dec 2026 07:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796367649; bh=MZn9BojA7KwDNQGiVIe7HHuA7pJEEI6Ya5SS77TDL3c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=G8zqv5yHTFKEll9k/QFv6f1SY6id3ZOTnOUTJcb13vOrFijCPWsopazpbzC84D9Kg OAx0lRbEaN+vfqCWjHwB2uvEDxeMVA6mtAvu7VTPSkZQ5fHSj1V2LhsrHbvcAf/1cI 6CKuQkoW9CoeafuEKucuqtE0hArIlHL1pyimjuiQMa176IiV1Jk0GHEbA98JhRPALH QrMKRrl75w5bqJtp56+ERsiPQvXga851Ro4NKZjlwHBQtGNSYpE9mMJoIYB3ODHMGu YuGemd8vzb5wX/yIxNA2Z2mHHT8t5hcEAysKd1zU1KKxrS3Mo81VbtHZBn4quBeTMH IuK9S5s0/Lm6Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time Reply-To: sashiko-reviews@lists.linux.dev To: "Ian Rogers" Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 07:00:49 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] perf/core: O(N) INACTIVE scan per tick in perf_adjust_freq_unthr_context() - [Medium] perf/core: O(N*S) sched mutations and double userpage updates on rotation -- commit 7f7c05c1a50554767d36de028fe90262549caf18 Author: Ian Rogers perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time This commit introduces PERF_EVENT_STATE_ON for enabled events that are filtered out during sched_in and reserves PERF_EVENT_STATE_INACTIVE for flexible groups that cannot be scheduled due to counter or exclusivity constraints, linking them onto epc->flexible_active after the active groups. > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 614f9f0e65005..fc312d3e309fd 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c [ ... ] > @@ -2505,16 +2509,23 @@ event_sched_out(struct perf_event *event, struct = perf_event_context *ctx) > =20 > perf_event_set_state(event, state); > =20 > - if (!is_software_event(event)) > - cpc->active_oncpu--; > - if (is_event_in_freq_mode(event)) { > - ctx->nr_freq--; > - epc->nr_freq--; > - } > - if (event->attr.exclusive || !cpc->active_oncpu) > - cpc->exclusive =3D 0; > + if (active) { > + if (!is_software_event(event)) > + cpc->active_oncpu--; > + if (is_event_in_freq_mode(event)) { > + ctx->nr_freq--; > + epc->nr_freq--; > + } > + if (event->attr.exclusive || !cpc->active_oncpu) > + cpc->exclusive =3D 0; > =20 > - perf_pmu_enable(event->pmu); > + perf_pmu_enable(event->pmu); > + } else if (refcount_read(&event->mmap_count)) { > + /* > + * active events get this through ->del(). > + */ > + perf_event_update_userpage(event); > + } > } [Severity: Medium] Does transitioning every inactive flexible group and its siblings through event_sched_out() and group_set_inactive() regress multiplexing rotation latency and double userpage updates? In perf_rotate_context() (every 4ms in hardirq context), __pmu_ctx_sched_ou= t() now walks all groups on flexible_active, including unscheduled inactive gro= ups and all enabled siblings, moving them to PERF_EVENT_STATE_ON and updating mmapped userpages here. __pmu_ctx_sched_in() -> merge_sched_in() then calls group_set_inactive() on those same unscheduled groups and siblings, mutating them back to PERF_EVENT_STATE_INACTIVE and updating mmapped userpages a second time under ctx->lock with IRQs and the PMU disabled, even though neither the CPU, task, cgroup, nor EVENT_TIME changed between the two calls. [ ... ] > @@ -4156,29 +4178,38 @@ static int merge_sched_in(struct perf_event *even= t, void *data) [ ... ] > + } else { > + struct perf_cpu_pmu_context *cpc =3D this_cpc(event->pmu_ctx->pmu); > + > + event->pmu_ctx->rotate_necessary =3D 1; > + perf_mux_hrtimer_restart(cpc); > + > + group_set_inactive(event); > + list_add_tail(&event->active_list, > + &event->pmu_ctx->flexible_active); > } [Severity: Medium] Does appending unscheduled inactive groups to pmu_ctx->flexible_active degrade perf_adjust_freq_unthr_context() from scanning only active counters to scanning all multiplexed flexible groups on every scheduler tick? On every tick with a frequency-mode event or unthrottle pending, perf_adjust_freq_unthr_context() holds ctx->lock with IRQs and the PMU disabled and walks flexible_active in perf_adjust_freq_unthr_events(), which continues past non-active entries rather than stopping at the first inactive group. In addition, perf_pmu_ctx_is_active() checks !list_empty() on flexible_active, so a pmu_ctx with only inactive groups triggers unnecessary perf_pmu_disable()/perf_pmu_enable() cycles and a full list scan on unthrottle ticks. Since active groups precede inactive ones on flexible_active, breaking on t= he first non-active entry in perf_adjust_freq_unthr_events() and checking the head entry state in perf_pmu_ctx_is_active() would avoid this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/ed76be2c2d97d398770= d742df8028634925da3e4.1796365469.git.irogers@google.com?part=3D1