Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1038502ybz; Fri, 17 Apr 2020 14:43:31 -0700 (PDT) X-Google-Smtp-Source: APiQypIkhUU37K6+a2If9Rd/2SUWry3qJpLx4n3DhYtQw6/jE6CoqLzEAhGsKG4fAGrVL7kA+GHv X-Received: by 2002:a17:906:168f:: with SMTP id s15mr5285982ejd.17.1587159811304; Fri, 17 Apr 2020 14:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587159811; cv=none; d=google.com; s=arc-20160816; b=uThJPCOI5yCRDlnA330gOOuFNZpfsISwT4hmEGqJEB8ZuFX2vBgQmR6ppmL0d0qSoX zSrFjTB1gM3OPm4HCi0YhycXajyWN4HJwAplhLGjhpCCfxITZHqsMbbjdsWDF/vM3Rjw +ha/9GV2ErV9nqDA4r7SlDNnNpBscV8Mw695KWk6JH0ll3ORlOjH8976ZAsoiMFRBXO1 rTkO7It/voOnwSTF/nP4WSzhhQaT5H+IJkk2yEawqXCIcUqjJVGEvLNyLYmtKncu6N0b z/JPK/dqQvvZD8+uBCvaV+9jAeNbqxTT2EH+KtwSbnFH4K/zuFRY3v4EHb2RrpmDXgWv YQlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=BX33Nlq2rNRQa3TPS+MKAJHFMMQ9tszkDs8MRHulQEo=; b=SS8KX63PRtV9+3SLy/CmemUSc6cCKCwAGcW909qf3QTIoSidx3O3KJSMPXLCGKXML0 S2Nn2rY2Ukichrb3gD+tl/4MF/6egUgVQP7hJ+8sJGJkAaE/XFaxso01Wv/1SzsnzpuD PFaTXpMG0A8MsfDi8dZ8vphL/UqavdOhiz4wA6/FHcvnmhRg0BZj8yvWsrA9YPQJFv6B Ov2hzddruvflF3tQZbSim41f7dSLl2sO44qBxS5Da8EX8JV9aeSmFitzQtlYBnNKeOE6 GNh1nduOujnpAZiAGMEdMLXFzGi1iwq6PzjSrCyf9hjuE+++ErHpBhVOlOHdUgS1g99Y F6UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mIHO9lYz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f26si7591826edm.141.2020.04.17.14.43.07; Fri, 17 Apr 2020 14:43:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mIHO9lYz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbgDQVkC (ORCPT + 99 others); Fri, 17 Apr 2020 17:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728087AbgDQVkB (ORCPT ); Fri, 17 Apr 2020 17:40:01 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A8BC061A0C; Fri, 17 Apr 2020 14:40:01 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id k11so4680411wrp.5; Fri, 17 Apr 2020 14:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BX33Nlq2rNRQa3TPS+MKAJHFMMQ9tszkDs8MRHulQEo=; b=mIHO9lYzoEk0nC+E43MFKDhIVzbEx/1UEXaDSzp1LhuwJzXr+DTJtyxGXdVUaBVgoK y4mauhwmxJW0XVQMBmW0iZwPVb0wQuxD/zlGkqckFVt8rXcZiJufzFlRHNzDoTErptGj R/y4gUO+Wfb77d3/W0ALeMx+7/Nz3mH9JOuQAkBCrA1L2tJd3J6W4qvC4OIlS3Z9QXaU gsB1UwkhyCKnFHIt2NgwyMHPMlXP6pQzRBKsmpVMwaY8YhBotD8+dQBOFOIhWdOkE93m 78QmaNqLg/EdkZcF2gZwBs+7oNDoRtX/uer5H4PaqkOmOQb0V/r9bESDv6oBW2IjdUGE eR4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BX33Nlq2rNRQa3TPS+MKAJHFMMQ9tszkDs8MRHulQEo=; b=e5jyhHRPcXrR++841p6VOCD8PYdLapnPPcbmF29l6+1dXkdlDY4e6NeYdIGTSgF06r laRd5Ru4DJz3DtzAM0gZnz53DVGTdObIJ5L7L2dPc8F/fz8m+CM55T1MHsjrOfpgqwig IE/v3re60S0cWJ4nAdXiylyhpFWucpXFe87w/eRnK47dsq8cXqUEs+ROUpUun2mk3ytw 5lnGqBQbdnndVrpaUn1UxZC2LQ8XdiHCx9JNTxlJGZeJChEZd3NLnujEeOoFELKu8d5r XHIYYZcmBf0GdIv4qOFRJByacZHOSoDZ2eF6huJ88/nkQ9sg489UWWcovqorESdU66rn UKMA== X-Gm-Message-State: AGi0Pua1Kz2igEahNeEYj/YSJtXwS71L7Y7Sm9ZwU5JurLgTwBwU9o1q /lW7q+uNspgguZyq53A65m0= X-Received: by 2002:a05:6000:f:: with SMTP id h15mr5877118wrx.408.1587159599795; Fri, 17 Apr 2020 14:39:59 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id v16sm9079325wml.30.2020.04.17.14.39.59 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Apr 2020 14:39:59 -0700 (PDT) From: Wei Yang To: paulmck@kernel.org, josh@joshtriplett.org Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] rcu: simplify the calculation of rcu_state.ncpus Date: Fri, 17 Apr 2020 21:39:51 +0000 Message-Id: <20200417213951.29837-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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