From: Peter Zijlstra <peterz@infradead.org>
To: Ian Rogers <irogers@google.com>
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
Date: Fri, 4 Dec 2026 18:14:35 +0100 [thread overview]
Message-ID: <20261204171435.GX2668804@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAP-5=fWU=Mhm6ntqGCW=qKa0N2gCpv4Qa1qmY94EvmSguFDJ_A@mail.gmail.com>
On Fri, Dec 04, 2026 at 08:39:14AM -0800, Ian Rogers wrote:
> On Fri, Dec 4, 2026 at 8:38 AM Ian Rogers <irogers@google.com> wrote:
> >
> > On Thu, Dec 3, 2026 at 11:00 PM <sashiko-bot@kernel.org> 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 <irogers@google.com>
> > >
> > > 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?
next prev parent reply other threads:[~2026-12-04 17:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:27 [PATCH v6 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time Ian Rogers
2026-12-04 6:27 ` [PATCH v6 2/2] perf test: Add filtered event enabled time tests to event-times Ian Rogers
2026-12-04 7:00 ` [PATCH v6 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time sashiko-bot
2026-12-04 16:38 ` Ian Rogers
2026-12-04 16:39 ` Ian Rogers
2026-12-04 17:14 ` Peter Zijlstra [this message]
2026-12-04 17:38 ` Ian Rogers
2026-12-04 7:00 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204171435.GX2668804@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.