diff mbox series

[2/9] rcu: Use rcu_segcblist_segempty() instead of open coding it

Message ID 20230531101736.12981-3-frederic@kernel.org (mailing list archive)
State New, archived
Headers show
Series rcu: Support for lazy callbacks on !CONFIG_RCU_NOCB_CPU | expand

Commit Message

Frederic Weisbecker May 31, 2023, 10:17 a.m. UTC
This makes the code more readable.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 kernel/rcu/rcu_segcblist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Joel Fernandes June 2, 2023, 11 p.m. UTC | #1
On Wed, May 31, 2023 at 6:17 AM Frederic Weisbecker <frederic@kernel.org> wrote:
>
> This makes the code more readable.
>
> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> ---
>  kernel/rcu/rcu_segcblist.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c
> index f71fac422c8f..1693ea22ef1b 100644
> --- a/kernel/rcu/rcu_segcblist.c
> +++ b/kernel/rcu/rcu_segcblist.c
> @@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
>         smp_mb(); /* Ensure counts are updated before callback is entrained. */
>         rhp->next = NULL;
>         for (i = RCU_NEXT_TAIL; i > RCU_DONE_TAIL; i--)
> -               if (rsclp->tails[i] != rsclp->tails[i - 1])
> +               if (!rcu_segcblist_segempty(rsclp, i))

Hopefully the compiler optimizer will be smart enough to remove this
from the inlined code ;-):
if (seg == RCU_DONE_TAIL)
   return &rsclp->head == rsclp->tails[RCU_DONE_TAIL];

Otherwise it appears to be no functional change for this and the below
change, and straightforward so for this patch:
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

thanks,

 - Joel


>                         break;
>         rcu_segcblist_inc_seglen(rsclp, i);
>         WRITE_ONCE(*rsclp->tails[i], rhp);
> @@ -551,7 +551,7 @@ bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq)
>          * as their ->gp_seq[] grace-period completion sequence number.
>          */
>         for (i = RCU_NEXT_READY_TAIL; i > RCU_DONE_TAIL; i--)
> -               if (rsclp->tails[i] != rsclp->tails[i - 1] &&
> +               if (!rcu_segcblist_segempty(rsclp, i) &&
>                     ULONG_CMP_LT(rsclp->gp_seq[i], seq))
>                         break;
>
> --
> 2.40.1
>
Zhuo, Qiuxu June 13, 2023, 8:44 a.m. UTC | #2
This patch LGTM. Thanks!

Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>

> From: Frederic Weisbecker <frederic@kernel.org>
> Sent: Wednesday, May 31, 2023 6:17 PM
> To: Paul E . McKenney <paulmck@kernel.org>
> Cc: LKML <linux-kernel@vger.kernel.org>; Frederic Weisbecker
> <frederic@kernel.org>; rcu <rcu@vger.kernel.org>; Uladzislau Rezki
> <urezki@gmail.com>; Neeraj Upadhyay <quic_neeraju@quicinc.com>; Joel
> Fernandes <joel@joelfernandes.org>; Giovanni Gherdovich
> <ggherdovich@suse.cz>
> Subject: [PATCH 2/9] rcu: Use rcu_segcblist_segempty() instead of open
> coding it
> 
> This makes the code more readable.
> 
> Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> ---
>  kernel/rcu/rcu_segcblist.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c index
> f71fac422c8f..1693ea22ef1b 100644
> --- a/kernel/rcu/rcu_segcblist.c
> +++ b/kernel/rcu/rcu_segcblist.c
> @@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
>  	smp_mb(); /* Ensure counts are updated before callback is entrained.
> */
>  	rhp->next = NULL;
>  	for (i = RCU_NEXT_TAIL; i > RCU_DONE_TAIL; i--)
> -		if (rsclp->tails[i] != rsclp->tails[i - 1])
> +		if (!rcu_segcblist_segempty(rsclp, i))
>  			break;
>  	rcu_segcblist_inc_seglen(rsclp, i);
>  	WRITE_ONCE(*rsclp->tails[i], rhp);
> @@ -551,7 +551,7 @@ bool rcu_segcblist_accelerate(struct rcu_segcblist
> *rsclp, unsigned long seq)
>  	 * as their ->gp_seq[] grace-period completion sequence number.
>  	 */
>  	for (i = RCU_NEXT_READY_TAIL; i > RCU_DONE_TAIL; i--)
> -		if (rsclp->tails[i] != rsclp->tails[i - 1] &&
> +		if (!rcu_segcblist_segempty(rsclp, i) &&
>  		    ULONG_CMP_LT(rsclp->gp_seq[i], seq))
>  			break;
> 
> --
> 2.40.1
Frederic Weisbecker July 5, 2023, 12:21 p.m. UTC | #3
Le Fri, Jun 02, 2023 at 07:00:00PM -0400, Joel Fernandes a écrit :
> On Wed, May 31, 2023 at 6:17 AM Frederic Weisbecker <frederic@kernel.org> wrote:
> >
> > This makes the code more readable.
> >
> > Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> > ---
> >  kernel/rcu/rcu_segcblist.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c
> > index f71fac422c8f..1693ea22ef1b 100644
> > --- a/kernel/rcu/rcu_segcblist.c
> > +++ b/kernel/rcu/rcu_segcblist.c
> > @@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
> >         smp_mb(); /* Ensure counts are updated before callback is entrained. */
> >         rhp->next = NULL;
> >         for (i = RCU_NEXT_TAIL; i > RCU_DONE_TAIL; i--)
> > -               if (rsclp->tails[i] != rsclp->tails[i - 1])
> > +               if (!rcu_segcblist_segempty(rsclp, i))
> 
> Hopefully the compiler optimizer will be smart enough to remove this
> from the inlined code ;-):
> if (seg == RCU_DONE_TAIL)
>    return &rsclp->head == rsclp->tails[RCU_DONE_TAIL];

I'm counting on that indeed :-)

> 
> Otherwise it appears to be no functional change for this and the below
> change, and straightforward so for this patch:
> Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

Thanks.
diff mbox series

Patch

diff --git a/kernel/rcu/rcu_segcblist.c b/kernel/rcu/rcu_segcblist.c
index f71fac422c8f..1693ea22ef1b 100644
--- a/kernel/rcu/rcu_segcblist.c
+++ b/kernel/rcu/rcu_segcblist.c
@@ -368,7 +368,7 @@  bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
 	smp_mb(); /* Ensure counts are updated before callback is entrained. */
 	rhp->next = NULL;
 	for (i = RCU_NEXT_TAIL; i > RCU_DONE_TAIL; i--)
-		if (rsclp->tails[i] != rsclp->tails[i - 1])
+		if (!rcu_segcblist_segempty(rsclp, i))
 			break;
 	rcu_segcblist_inc_seglen(rsclp, i);
 	WRITE_ONCE(*rsclp->tails[i], rhp);
@@ -551,7 +551,7 @@  bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long seq)
 	 * as their ->gp_seq[] grace-period completion sequence number.
 	 */
 	for (i = RCU_NEXT_READY_TAIL; i > RCU_DONE_TAIL; i--)
-		if (rsclp->tails[i] != rsclp->tails[i - 1] &&
+		if (!rcu_segcblist_segempty(rsclp, i) &&
 		    ULONG_CMP_LT(rsclp->gp_seq[i], seq))
 			break;