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

From: Peter Zijlstra

Date: Wed Dec 02 2026 - 05:17:55 EST


On Tue, Dec 01, 2026 at 08:47:55AM -0800, Ian Rogers wrote:

> 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?

Hold off on the v5. I can't seem to make up my mind on what I want here.
I'll poke at the thing a little.