Re: [RFC][PATCH 6/7] context_tracking: Provide SMP ordering using RCU

From: Paul E. McKenney
Date: Wed Sep 22 2021 - 15:59:41 EST


On Wed, Sep 22, 2021 at 09:47:59PM +0200, Peter Zijlstra wrote:
> On Wed, Sep 22, 2021 at 09:33:43PM +0200, Peter Zijlstra wrote:
>
> > Anyway, lemme see if I get your proposal; lets say the counter starts at
> > 0 and is in kernel space.
> >
> > 0x00(0) - kernel
> > 0x02(2) - user
> > 0x04(0) - kernel
> >
> > So far so simple, then NMI on top of that goes:
> >
> > 0x00(0) - kernel
> > 0x03(3) - kernel + nmi
> > 0x04(0) - kernel
> > 0x06(2) - user
> > 0x09(1) - user + nmi
> > 0x0a(2) - user
> >
> > Which then gives us:
> >
> > (0) := kernel
> > (1) := nmi-from-user
> > (2) := user
> > (3) := nmi-from-kernel
> >
> > Which should work I suppose. But like I said above, I'd be happier if
> > this counter would live in context_tracking rather than RCU.
>
> Furthermore, if we have this counter, the we can also do things like:
>
> seq = context_tracking_seq_cpu(that_cpu);
> if ((seq & 3) != USER)
> // nohz_fail, do something
> set_tsk_thread_flag(curr_task(that_cpu), TIF_DO_SOME_WORK);
> if (seq == context_tracking_seq_cpu(that_cpu))
> // success!!
>
> To remotely set pending state. Allowing yet more NOHZ_FULL fixes, like,
> for example, eliding the text_poke IPIs.

Nice!

There have been several instances where I thought that the extra state
would help RCU, but each time there turned out to be a simpler way to
get things done. Or that it eventually turned out that RCU didn't need
to care about the difference between idle and nohz_full userspace.

Thanx, Paul