Re: [RFC][PATCH 4/7] smp: Optimize send_call_function_single_ipi()
From: Peter Zijlstra
Date: Wed May 27 2020 - 12:36:10 EST
On Wed, May 27, 2020 at 08:56:56AM -0700, Paul E. McKenney wrote:
> On Wed, May 27, 2020 at 12:15:13PM +0200, Peter Zijlstra wrote:
> > At first glance, something like the below could work. But obviously I
> > might have overlooked something more subtle than a brick :-)
>
> This can work, but only if the call from the idle loop is a place where
> either RCU isn't watching on the one hand or that cannot be in an RCU
> read-side critical section on the other.
Guaranteed no RCU read side, although the call is in a place where RCU
is active again, is that a problem? I think with a bit of work I can
move it to where RCU is still idle.
> Because rcu_exp_handler() assumes that if this function returns true,
> we are not in an RCU read-side critical section. (I would expect this
> to be the case, but I figured that I should make it explicit.)
Indeed, I shall put a comment in the idle look to make sure it stays that way.
> > ---
> >
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index 90c8be22d57a..0792c032a972 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -426,8 +426,11 @@ EXPORT_SYMBOL_GPL(rcu_momentary_dyntick_idle);
> > */
>
> Could we please have a comment noting the change in semantics and
> the reason?
A Changelog you mean? Sure, I can do, but I wasn't nowhere confident
enough in the change to even bother trying to write one.
> > static int rcu_is_cpu_rrupt_from_idle(void)
> > {
> > - /* Called only from within the scheduling-clock interrupt */
> > - lockdep_assert_in_irq();
> > + /*
> > + * Usually called from the tick; but also used from smp_call_function()
> > + * for expedited grace periods.
> > + */
> > + lockdep_assert_irqs_disabled();
> >
> > /* Check for counter underflows */
> > RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nesting) < 0,
> > @@ -435,8 +438,11 @@ static int rcu_is_cpu_rrupt_from_idle(void)
> > RCU_LOCKDEP_WARN(__this_cpu_read(rcu_data.dynticks_nmi_nesting) <= 0,
> > "RCU dynticks_nmi_nesting counter underflow/zero!");
> >
> > - /* Are we at first interrupt nesting level? */
> > - if (__this_cpu_read(rcu_data.dynticks_nmi_nesting) != 1)
> > + /*
> > + * Are we at first interrupt nesting level? -- or below, when running
> > + * directly from the idle loop itself.
> > + */
> > + if (__this_cpu_read(rcu_data.dynticks_nmi_nesting) > 1)
>
> Wouldn't it also be a good idea to check that we are in the context of
> an idle thread? Just in case some idiot like me drops a call to this
> function in the wrong place, for example, if I were to mistakenly remember
> the old semantics where it would return false from process context?
>
> Maybe something like this?
>
> nesting = __this_cpu_read(rcu_data.dynticks_nmi_nesting;
> if (nesting > 1)
> return false;
> WARN_ON_ONCE(!nesting && !is_idle_task(current));
Yep, that should do.
> > return false;
> >
> > /* Does CPU appear to be idle from an RCU standpoint? */
>
> And let's check the other callers:
>
> rcu_sched_clock_irq(): This will always be called from IRQ (right?), so
> no problem.
>
> rcu_pending(): Only called from rcu_sched_clock_irq(), so still no problem.
>
> rcu_flavor_sched_clock_irq(): Ditto for both definitions.
Right, I went though them, didn't find anything obvious amiss. OK, let
me do a nicer patch.