Re: [PATCH v3 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time
From: Ian Rogers
Date: Tue Dec 01 2026 - 11:48:12 EST
On Tue, Dec 1, 2026 at 1:19 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Mon, Nov 30, 2026 at 10:42:55AM -0800, Ian Rogers wrote:
> > On Wed, Nov 25, 2026 at 5:02 AM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > >
> > > On Wed, Nov 25, 2026 at 01:37:12PM +0100, Peter Zijlstra wrote:
> > > > On Tue, Nov 24, 2026 at 10:52:28PM -0800, Ian Rogers wrote:
> > > > > @@ -4134,6 +4154,21 @@ struct merge_sched_data {
> > > > > enum event_type_t event_type;
> > > > > };
> > > > >
> > > > > +static void group_set_inactive(struct perf_event *group_event)
> > > > > +{
> > > > > + struct perf_event *sibling;
> > > > > +
> > > > > + perf_event_set_state(group_event, PERF_EVENT_STATE_INACTIVE);
> > > > > +
> > > > > + for_each_sibling_event(sibling, group_event) {
> > > > > + if (sibling->state == PERF_EVENT_STATE_ON)
> > > > > + perf_event_set_state(sibling, PERF_EVENT_STATE_INACTIVE);
> > > > > + }
> > > > > +
> > > > > + list_add_tail(&group_event->active_list,
> > > > > + &group_event->pmu_ctx->flexible_inactive);
> > > > > +}
> > >
> > > This whole thing looks dodgy as well. This feels like
> > > __perf_effective_state() needs an update or something.
> >
> >
> > Thanks for the review, Peter! I've sent v4 addressing all of these:
> > https://lore.kernel.org/linux-perf-users/8b61be11e09ae7f663253cde769eff5456ebc263.1796063587.git.irogers@xxxxxxxxxx/
> >
> > - Took your state diagram and comment cleanup in perf_event.h.
> > - Updated __perf_effective_state() and perf_event_set_state() so enabled
> > (ON) siblings inherit INACTIVE from their group leader, removing
> > group_set_inactive() (while promoting ON siblings to INACTIVE on
> > flexible_inactive if an INACTIVE leader is detached).
> > - De-duplicated the pending_disable path in event_sched_out().
> > - Updated merge_sched_in() to branch directly on group_can_go_on() and
> > group_sched_in() rather than testing event->state == ON. In
> > event_sched_in(), reverting the speculative ACTIVE back to ON keeps
> > siblings in ON and matches group_error: rollback so merge_sched_in()
> > remains the single place transitioning ON -> {ERROR, INACTIVE}.
> >
>
> I've got to ask; are you vibing this? There seem to be random changes in
> the patch not listed above that make review harder than it wants to be.
>
> Eg. there is now a shortcut in group_sched_out() that avoids iterating
> the siblings when !active. This then leads to other weirdness.
Fair criticism - I used an AI assistant to help iterate and test
between v3 and v4, and I didn't keep the v3->v4 diff tight enough or
list all of the resulting churn in my reply. Sorry for wasting your
review time.
Specifically, the unlisted changes in v4 were:
1. group_sched_out() / group_update_userpage() move:
Once siblings stayed in ON (inheriting INACTIVE via
__perf_effective_state()), group_sched_out() iterating siblings would
hit `event->state < INACTIVE` and skip updating sibling userpages.
That led to moving event_update_userpage()/group_update_userpage() up
in core.c, calling group_update_userpage() from event_sched_out(),
and adding the `if (!active) return;` shortcut in group_sched_out().
Looking at it again, calling group_update_userpage() inside
event_sched_out() and moving those helpers 1,600 lines up is ugly and
unnecessary — if group_sched_out() itself handles the !active case
(or updates userpages there instead of in event_sched_out()), none of
that weirdness is needed.
2. READ_ONCE() in __perf_effective_state():
Was added so `leader->state` isn't loaded twice in the two checks
from lockless calc_timer_values() callers.
3. `if (event->state <= PERF_EVENT_STATE_OFF)` in merge_sched_in():
Previously implicit in `if (event->state == PERF_EVENT_STATE_ON)` to
avoid overwriting OFF if group_sched_in()'s rollback consumed
pending_disable.
4. `bool inactive` passed to perf_group_detach() /
perf_promote_sibling_to_leader():
Because siblings now stay ON, __event_disable() clears the leader's
INACTIVE state before perf_group_detach() runs, so without recording
that the detached leader was INACTIVE, promoted siblings would stay
ON and stop accruing enabled time.
Before I send a cleaner v5, I'd appreciate a quick sanity check on two
things:
- Is the `__perf_effective_state()` + `perf_event_set_state()` direction
for INACTIVE siblings what you had in mind (with the group_sched_out /
userpage weirdness cleaned up)?
- For event_sched_in() / merge_sched_in(), do you prefer keeping
event_sched_in() reverting its speculative ACTIVE back to ON (with
merge_sched_in() doing ON -> {ERROR,INACTIVE}), or would you rather
see the state transition structured differently?
Thanks,
Ian