Re: [PATCH tip/core/rcu 22/30] rcu: Don't flag non-starting GPs before GP kthread is running

From: Paul E. McKenney
Date: Mon Feb 17 2020 - 18:04:13 EST


On Mon, Feb 17, 2020 at 05:21:31PM -0500, Steven Rostedt wrote:
> On Mon, 17 Feb 2020 14:03:56 -0800
> "Paul E. McKenney" <paulmck@xxxxxxxxxx> wrote:
>
> > And what is a day without micro-optimization of a slowpath? :-)
>
> A day you have off, but still find yourself working ;-)
>
> >
> > OK, let's see...
> >
> > Grace-period kthread wakeups are normally mediated by rcu_start_this_gp(),
> > which uses a funnel lock to consolidate concurrent requests to start
> > a grace period. If a grace period is already in progress, it refrains
> > from doing a wakeup because that means that the grace-period kthread
> > will check for another grace period being needed at the end of the
> > current grace period.
> >
> > Exceptions include:
> >
> > o The wakeup reporting the last quiescent state of the current
> > grace period.
> >
> > o Emergency situations such as callback overloads and RCU CPU stalls.
> >
> > So on a busy system that is not overloaded, the common case is that
> > rcu_gp_kthread_wake() is invoked only once per grace period because there
> > is no emergency and there is a grace period in progress. If this system
> > has short idle periods and a fair number of quiescent states, a reasonable
> > amount of idle time, then the last quiescent state will not normally be
> > detected by the grace-period kthread. But workloads can of course vary.
> >
> > The "!t" holds only during early boot. So we could put a likely() around
> > the "t". But more to the point, at runtime, "!t" would always be false,
> > so it really should be last in the list of "||" clauses. This isn't
> > enough of a fastpath for a static branch to make sense.
>
> Hey! Does that mean we can add a static branch for that check?
>
>
> struct static_key rcu_booting = STATIC_KEY_INIT_TRUE;
>
> [...]
>
> if (READ_ONCE(rcu_state.gp_flags) ||
> (current == t && !in_irq() && !in_serving_softirq())
> return;
>
> if (static_branch_unlikely(&rcu_booting) && !t)
> return;
>
> At end of boot:
>
> static_key_disable(&rcu_booting);
>
> That way we can really micro-optimize the slow path, and it basically
> becomes a nop!

;-) ;-) ;-)

There might be some place where static branches would be of use in RCU,
but unfortunately none that I can think of on the read side. Though I
am once again making progress on Lai Jiangshan's patchset, which might
one day result in inlining of __rcu_read_lock() and __rcu_read_unlock()
in PREEMPT=y kernels.

Thanx, Paul

> -- Steve
>
> >
> > The "!READ_ONCE(rcu_state.gp_flags)" will normally hold, though it is
> > false often enough to pay for itself. Or has been in the past, anyway.
> > I suspect that access to the global variable rcu_state.gp_flags is not
> > always fast either.
> >
> > So I am having difficulty talking myself into modifying this one given
> > the frequency of operations.
> >
> > Thanx, Paul
>