From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=90.155.50.34 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796404480; b=E92xZ0LT9VQLLYBp92gue4oIn4CY3RipPKbylesfW05UyItA4hS0qAUMtiRvk99z41uW shDm66c1ukNtAPkqGHLHIbjr4TYsvOWgiDd/Z6akJ1ew9bGIpToghvodukqF5h3cOc+8V zD0AcwKJn+MI5exp+0N0GKtxgdTF6Gmt8WaZ66LmGnB2sS+lZFoySa1xByHD51bmmNotQ esiiWL1A0WrymSR2Xmd0Lodrv7dShvTE+VxAwKTYvqrWKcN8OllbjFLGQb1+WX+a3tbUi VGzZ13uMz0nRJKFsAJp+KAJnGU+NCNZ9rcj8+O0Yp4Twzwrev/CmUMZ2d+GVvkQrW6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796404480; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; bh=QvRYsWibacLLFQiE4Xz/XFEFMHDXKVPaJ4cxZ+qhCKI=; b=cYYWru2InzDWBGUExqhSKFgXwRTAsmAuLVEd+YFHNc3vS9vakDo1pAioOORkBLF+NiJJ 4F402oJytIeVl5XCUX3MtuKCXqfOEw1vj6QrA/nPPF739eM2rgt+/Y6D71hZPOc5h+Jn1 VEs7nCrCQqsN5DW6hDmd8LnIoTasDOMm58Lpllls4D7ayh58PJa7E/ynPl88IKeXNUdAi 6YQU3YxZfLpf1JiacTf1fQaUu0kRRBZm7TZJmpKdG3GaEdIeHXukK+NFbhRn4OQEBN1wN ubkwFS1DgCKILdzEVnH7ou0+BYhEWgxOdOf4ia3ZyVjMcFUHgQ2SEYxsmUYZBLnL45w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=GKw7Bn4X; arc=none smtp.remote-ip=90.155.50.34 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 E4D74606A32D; Fri, 4 Dec 2026 17:14:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E4D74606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=GKw7Bn4X DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=QvRYsWibacLLFQiE4Xz/XFEFMHDXKVPaJ4cxZ+qhCKI=; b=GKw7Bn4XJcqmDOvnycxgRyuMl8 hu4CrOxNRGS1bNTWSQgAkgU/1NFO07S1rIGzEhEHNWXpXBhc8IC+qXLYXfUAQXVMv+4/+qNgZZUOV xHUaOCpGTHmepwXtiLaKRhD1tLh507udkGveA1vx+ksftBdvg0HV03dDCvMZS4psjRSL1ivKnkMwx mlypwpx3yhphN6TXrRUvrP1UuS056TtLMhrfyLtQ9rmq2BA41XQQYTQ6QgGjv7Cs4N6D3kP7R+J22 ht7BVW1Xsd9USIMKdXpRq7o7LYoHXKGafBgOYh20agF6h524hsKHyWlYo/h+LlQGI5Xik69FRcJLa 7r/hbwgw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZWrk-0000000CMmf-1Ive; Fri, 04 Dec 2026 17:14:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6FE8A300673; Fri, 04 Dec 2026 18:14:35 +0100 (CET) Date: Fri, 4 Dec 2026 18:14:35 +0100 From: Peter Zijlstra To: Ian Rogers Cc: sashiko-reviews@lists.linux.dev, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH v6 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time Message-ID: <20261204171435.GX2668804@noisy.programming.kicks-ass.net> References: 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 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Dec 04, 2026 at 08:39:14AM -0800, Ian Rogers wrote: > On Fri, Dec 4, 2026 at 8:38 AM Ian Rogers wrote: > > > > On Thu, Dec 3, 2026 at 11:00 PM wrote: > > > > > > 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) > > > > > > > > perf_event_set_state(event, state); > > > > > > > > - 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 = 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 = 0; > > > > > > > > - 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_out() > > > now walks all groups on flexible_active, including unscheduled inactive groups > > > 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. > > +Peter Zijlstra Just ignore the thing if its wrong?