Re: [PATCH v3 1/2] perf/core: Add PERF_EVENT_STATE_ON to fix filtered event enabled time

From: Peter Zijlstra

Date: Thu Dec 03 2026 - 07:16:53 EST


On Wed, Dec 02, 2026 at 10:24:26AM -0800, Ian Rogers wrote:

> > > - 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?
> >
> > I got rid of that speculative 'ON' thing, but I'm not convinced of the
> > result, see below.
>
> Replacing event_update_userpage()/group_update_userpage() in-place with
> event_set_inactive()/group_set_inactive() looks much cleaner than the v4
> detour. A few bugs I spotted in the draft patch above:
>
> 1. In group_sched_in()'s partial_tail loop:
> - `if (partial_tail) perf_event_set_state(event, PERF_EVENT_STATE_INACTIVE);`
> is missing `if (event->state <= PERF_EVENT_STATE_OFF) continue;`,
> so it will transition disabled (OFF) siblings in the tail to
> INACTIVE.
> - For a *pinned* group that fails on a sibling or commit_txn(),
> group_error: moves all siblings to PERF_EVENT_STATE_INACTIVE while
> merge_sched_in() only sets the leader to ERROR, leaving the
> siblings stuck in INACTIVE (so if the leader is later re-enabled on
> a filtered CPU or detached, those siblings remain INACTIVE).
> - Similarly, if __event_sched_out(group_event, ...) in group_error:
> consumes pending_disable and moves the leader to OFF, siblings
> already transitioned to INACTIVE earlier in the loop remain stuck
> in INACTIVE when merge_sched_in() exits at `state <= OFF`.
>
> Since merge_sched_in() already calls group_set_inactive(event) for
> flexible groups (and sets ERROR for pinned groups), having
> event_sched_in() and group_error: simply roll back to ON (no
> __event_sched_out() or partial_tail) avoids all three cases and keeps
> the single ON -> {ERROR, INACTIVE} transition in merge_sched_in().

Yeah, fair enough.

> 2. In __perf_event_enable(), without __perf_effective_state(), enabling
> a disabled sibling while its group leader is INACTIVE needs to match
> the leader's state:
>
> if (leader != event && leader->state != PERF_EVENT_STATE_ACTIVE) {
> if (leader->state == PERF_EVENT_STATE_INACTIVE)
> event_set_inactive(event); /* or set_state + userpage */
> return;
> }
>
> Otherwise the newly enabled sibling stays ON and accrues 0 enabled
> time while the leader is INACTIVE (until the next rotation, or
> indefinitely if counters are held by pinned events).
>
> Happy to fold those into your version and re-test (including hybrid +
> pinned-blocked/rollback tests) if this direction looks good to you.

Yeah, that seems sensible. Thanks!