Re: [PATCH 03/11] rcu: clean up rcu_preempt_deferred_qs_irqrestore()
From: Paul E. McKenney
Date: Thu Oct 31 2019 - 15:02:32 EST
On Thu, Oct 31, 2019 at 11:57:18AM -0700, Paul E. McKenney wrote:
> On Thu, Oct 31, 2019 at 11:25:11PM +0800, Lai Jiangshan wrote:
> >
> >
> > On 2019/10/31 9:52 äå, Paul E. McKenney wrote:
> > > On Thu, Oct 31, 2019 at 10:07:58AM +0000, Lai Jiangshan wrote:
> > > > Remove several unneeded return.
> > > >
> > > > It doesn't need to return earlier after every code block.
> > > > The code protects itself and be safe to fall through because
> > > > every code block has its own condition tests.
> > > >
> > > > Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>
> > > > ---
> > > > kernel/rcu/tree_plugin.h | 14 +-------------
> > > > 1 file changed, 1 insertion(+), 13 deletions(-)
> > > >
> > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
> > > > index 59ef10da1e39..82595db04eec 100644
> > > > --- a/kernel/rcu/tree_plugin.h
> > > > +++ b/kernel/rcu/tree_plugin.h
> > > > @@ -439,19 +439,10 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags)
> > > > * t->rcu_read_unlock_special cannot change.
> > > > */
> > > > special = t->rcu_read_unlock_special;
> > > > - rdp = this_cpu_ptr(&rcu_data);
> > > > - if (!special.s && !rdp->exp_deferred_qs) {
> > > > - local_irq_restore(flags);
> > > > - return;
> > > > - }
> > >
> > > The point of this check is the common case of this function being invoked
> > > when both fields are zero, avoiding the below redundant store and all the
> > > extra checks of subfields of special.
> > >
> > > Or are you saying that current compilers figure all this out?
> >
> > No.
> >
> > So, I have to keep the first/above return branch.
> >
> > Any reasons to keep the following 2 return branches?
> > There is no redundant store and the load for the checks
> > are hot in the cache if the condition for return is met.
>
> And the code further down is not in a fastpath. So, good point, it
> should be find to remove the two early exits below.
That is, assuming that interrupts cannot occur within interrupts-disabled
regions of code. ;-)
Thanx, Paul
> > Thanks.
> > Lai
> >
> > >
> > > Thanx, Paul
> > >
> > > > t->rcu_read_unlock_special.b.deferred_qs = false;
> > > > if (special.b.need_qs) {
> > > > rcu_qs();
> > > > t->rcu_read_unlock_special.b.need_qs = false;
> > > > - if (!t->rcu_read_unlock_special.s && !rdp->exp_deferred_qs) {
> > > > - local_irq_restore(flags);
> > > > - return;
> > > > - }
> > > > }
> > > > /*
> > > > @@ -460,12 +451,9 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags)
> > > > * tasks are handled when removing the task from the
> > > > * blocked-tasks list below.
> > > > */
> > > > + rdp = this_cpu_ptr(&rcu_data);
> > > > if (rdp->exp_deferred_qs) {
> > > > rcu_report_exp_rdp(rdp);
> > > > - if (!t->rcu_read_unlock_special.s) {
> > > > - local_irq_restore(flags);
> > > > - return;
> > > > - }
> > > > }
> > > > /* Clean up if blocked during RCU read-side critical section. */
> > > > --
> > > > 2.20.1
> > > >