Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3138434ybz; Sun, 19 Apr 2020 18:44:56 -0700 (PDT) X-Google-Smtp-Source: APiQypK2uo0O6WIC8HR6vST/HX3qCxy/GM0maJlpc/3vv4KAIoV61f9mvOmJCi9fL3+MKZl/W32z X-Received: by 2002:a50:c112:: with SMTP id l18mr12841605edf.37.1587347096249; Sun, 19 Apr 2020 18:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587347096; cv=none; d=google.com; s=arc-20160816; b=yXVfyMCV9TVvqwXf173vrQEOf00LHQd9ITUyxktb5sSW7OaMgfoQdexODaOzPKueIU +q6ygxX1ExIalLSFk4lCuDm0ILdxMJaobbSpxwmmJv1opF9s6ANJLY5cVXmY2LzUWC95 e9QqYT9qMgLUlEcJxPQIDeWYQBGyJzr8Bl+MHKbHRlA4UiOFdhpvoeVVp43DtqpZt7sd r+oZHZmZXdEVK2UKYv1yOn5zHltpEvnny68v5+DyGBeuxEyTRMh6xgvtdLzQBQObsCRT LyGJ1gZo9OAYkWkbCFa8gGvLZWPgNUtG+qiYer89pCtCAZsn5QohbezhmfchJjnpN+4z KY9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=hkT8O04bYSd7Dcv0UKKy4+3TquF5z7knQNjmD0ZBtHI=; b=nmCCKF8nDVBiVe4wTSoD5IZJg6I5On1YdxLtte3HE9nTWqjsnncbIoAMQQBg4gzTmu EXirEjBjTSCrwZVu07ju2alv5s8vO/snKI1SNtzNC4vZq3TsaYm75KDgQDG4MJMh6rSs SyjIJkOjgk2z913jsYtoG8zRfEIOfg7DxJNYTCvYhLASFhuqbiZO/j1qMOkPbleLqWn7 4NwZB5WXKAIOQnmJuviN66kvMDe9Fg1VYPJGdz8OeOVd3tkOPcVaO2ykaq0KLUajXMM3 neLrgGSenAAwHkSvy8sEeamBOwUkhAWAwXIb8iTkouKVNsJLmkotg/KfV7PWOgNelo7A myxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VSYqKY2O; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc28si23935925edb.531.2020.04.19.18.44.33; Sun, 19 Apr 2020 18:44:56 -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=@kernel.org header.s=default header.b=VSYqKY2O; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725991AbgDTBli (ORCPT + 99 others); Sun, 19 Apr 2020 21:41:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:40514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbgDTBli (ORCPT ); Sun, 19 Apr 2020 21:41:38 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B0592087E; Mon, 20 Apr 2020 01:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587346898; bh=az85tus44NMG4SMjB0IngO85+hPz52zrrMtkhEa/4RA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=VSYqKY2OT5HtsftDAocIYLAXRfFoDwWR0WgW6DWWmZmmaVMZ3rQ8BXHrNdRYDsyLw y+bGFOKGZH5e0QJavheQ2doNarmdccz7piZwe74/4gaMCfEE7ti1KShLFmpAxyfZZh 2PHj9fnl+Ot8EG/SDE+BRagfBO7o+OTAvLypE1IY= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id CE5713522C68; Sun, 19 Apr 2020 18:41:37 -0700 (PDT) Date: Sun, 19 Apr 2020 18:41:37 -0700 From: "Paul E. McKenney" To: Wei Yang Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [Patch v2] rcu: simplify the calculation of rcu_state.ncpus Message-ID: <20200420014137.GW17661@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200419215715.21071-1-richard.weiyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200419215715.21071-1-richard.weiyang@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 19, 2020 at 09:57:15PM +0000, Wei Yang wrote: > 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 rnp->expmaskinitnext. > > Signed-off-by: Wei Yang Queued, thank you! I updated the commit log as shown below, so please let me know if I messed something up. Thanx, Paul ------------------------------------------------------------------------ commit 2ff1b8268456b1a476f8b79672c87d32d4f59024 Author: Wei Yang Date: Sun Apr 19 21:57:15 2020 +0000 rcu: Simplify the calculation of rcu_state.ncpus There is only 1 bit set in mask, which means that the only difference between oldmask and the new one will be at the position where the bit is set in mask. This commit therefore updates rcu_state.ncpus by checking whether the bit in mask is already set in rnp->expmaskinitnext. Signed-off-by: Wei Yang Signed-off-by: Paul E. McKenney diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index f288477..6d39485 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3732,10 +3732,9 @@ 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; + bool newcpu; if (per_cpu(rcu_cpu_started, cpu)) return; @@ -3747,12 +3746,10 @@ void rcu_cpu_starting(unsigned int cpu) mask = rdp->grpmask; raw_spin_lock_irqsave_rcu_node(rnp, flags); WRITE_ONCE(rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); - oldmask = rnp->expmaskinitnext; + newcpu = !(rnp->expmaskinitnext & mask); 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); /* ^^^ */ + smp_store_release(&rcu_state.ncpus, rcu_state.ncpus + newcpu); /* ^^^ */ ASSERT_EXCLUSIVE_WRITER(rcu_state.ncpus); rcu_gpnum_ovf(rnp, rdp); /* Offline-induced counter wrap? */ rdp->rcu_onl_gp_seq = READ_ONCE(rcu_state.gp_seq);