[PATCH] rcu: simplify the calculation of rcu_state.ncpus

From: Wei Yang
Date: Fri Apr 17 2020 - 17:40:03 EST


There is only 1 bit set in mask, which means the difference between
oldmask and the new one would be at the position where the bit is set in
mask.

Based on this knowledge, rcu_state.ncpus could be calculated by checking
whether mask is already set in oldmask.

BTW, the comment at the last of this line is mysterious. Not sure it
could be removed or not.

Signed-off-by: Wei Yang <richard.weiyang@xxxxxxxxx>
---
kernel/rcu/tree.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index d91c9156fab2..f0d9251fa663 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3364,7 +3364,6 @@ void rcu_cpu_starting(unsigned int cpu)
{
unsigned long flags;
unsigned long mask;
- int nbits;
unsigned long oldmask;
struct rcu_data *rdp;
struct rcu_node *rnp;
@@ -3381,10 +3380,9 @@ void rcu_cpu_starting(unsigned int cpu)
rnp->qsmaskinitnext |= mask;
oldmask = rnp->expmaskinitnext;
rnp->expmaskinitnext |= mask;
- oldmask ^= rnp->expmaskinitnext;
- nbits = bitmap_weight(&oldmask, BITS_PER_LONG);
/* Allow lockless access for expedited grace periods. */
- smp_store_release(&rcu_state.ncpus, rcu_state.ncpus + nbits); /* ^^^ */
+ if (!(oldmask & mask))
+ smp_store_release(&rcu_state.ncpus, rcu_state.ncpus + 1); /* ^^^ */
rcu_gpnum_ovf(rnp, rdp); /* Offline-induced counter wrap? */
rdp->rcu_onl_gp_seq = READ_ONCE(rcu_state.gp_seq);
rdp->rcu_onl_gp_flags = READ_ONCE(rcu_state.gp_flags);
--
2.23.0