Re: [PATCH v5 16/18] timer: Implement the hierarchical pull model

From: Peter Zijlstra
Date: Tue Mar 21 2023 - 11:29:42 EST


On Wed, Mar 01, 2023 at 03:17:42PM +0100, Anna-Maria Behnsen wrote:
> +static bool tmigr_active_up(struct tmigr_group *group,
> + struct tmigr_group *child,
> + void *ptr)
> +{
> + union tmigr_state curstate, newstate;
> + struct tmigr_walk *data = ptr;
> + bool walk_done;
> + u32 childmask;
> +
> + childmask = data->childmask;
> + newstate = curstate = data->groupstate;
> +
> +retry:
> + walk_done = true;
> +
> + if (newstate.migrator == TMIGR_NONE) {
> + newstate.migrator = (u8)childmask;
> +
> + /* Changes need to be propagated */
> + walk_done = false;
> + }
> +
> + newstate.active |= (u8)childmask;
> +
> + newstate.seq++;
> +
> + if (atomic_cmpxchg(group->migr_state, curstate.state, newstate.state) != curstate.state) {
> + newstate.state = curstate.state = atomic_read(group->migr_state);
> + goto retry;
> + }

if (!atomic_try_cmpxchg(group->migr_state, &curstate.state, newstate.state)) {
newstate.state = curstate.state;
goto retry;
}

> +
> + if (group->parent && (walk_done == false)) {
> + data->groupstate.state = atomic_read(group->parent->migr_state);
> + data->childmask = group->childmask;
> + }
> +
> + /*
> + * Group is active, event will be ignored - bit is updated without
> + * holding the lock. In case bit is set while another CPU already
> + * handles remote events, nothing happens, because it is clear that
> + * CPU became active just in this moment, or in worst case event is
> + * handled remote. Nothing to worry about.
> + */
> + group->groupevt.ignore = 1;
> +
> + return walk_done;
> +}