Received: by 10.192.165.148 with SMTP id m20csp2949521imm; Sun, 22 Apr 2018 20:07:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+2KOH4rGbMQAaEnrAzUtYAA6cGUNjYTX0sllfSuwOLS+GFSxpnGxqT6IdcJdtNfBl9aCHZ X-Received: by 10.98.253.9 with SMTP id p9mr18254783pfh.152.1524452863834; Sun, 22 Apr 2018 20:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524452863; cv=none; d=google.com; s=arc-20160816; b=LevgdKAaZSNtnYnxucGYCnWqUh7KvtCY44IO3okObDb9HfXdzeF9/pRanyxM3gPfkI bl3TD0X8o+r6yZdNFj/QGpEeOOKIu5e3/8eYJwrNrt3CMMer0ZwA0OuzB7v6cK5hFSFC CSlYwUu1PrMpeDuJPBPiSy3Ocf65iUxrMCNDMPvutlXO2LYO4Aplk4VSV29RxVQ71tEh lihj4jT/bEL/hKmjW4X3SD1+pUDGiIjqDao3YIfa7pI6ik6PdnPQjdRwTndQ+Vw52amI tuM9gs3dYD/6NBqTGBS5drH3zB3IABdkiW33I73KxEK9b0L4dmfESn+5zvk/Aw8EnykV 3j2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=/hBb1/s0FGrY7VLTO8HAtPIIvyIfwgW0/aKiuSFbhVo=; b=AtIa2p0hfTkkr6WRZOPYM4p6oJ9GuligFP0QJNwwGauP/EwIzgAo6a7Uw4/bdEecvb ZsEoTT21W6zEWXouOsaANBEvxRlq3I5x41NbCvxFwQ5jJ6w+3cKfpz5dAllr+TgS6vEq Z+1AqK6mLXgoutdXdabl3Ea3LmFjiWE8DRRUbsm9mzo4IiTlbI5vfT2mFNcdBklGyQxF q/rIKPhTzLj4o6vE2Wfnq9l5E2AYXDFFqZYoXyEq9udBl4BQs6zkI2vQZgLMg3XMOVrK 2KPZZFG69GfQT08WPg/qOXJPyjPnu/QXR2EfPs0nah1rqjcDS7AM6jKkcUR3jtVsTDrs 2bLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si10324602pfe.19.2018.04.22.20.07.29; Sun, 22 Apr 2018 20:07:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754208AbeDWDEn (ORCPT + 99 others); Sun, 22 Apr 2018 23:04:43 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39330 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753969AbeDWDCk (ORCPT ); Sun, 22 Apr 2018 23:02:40 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3N2wfjb118704 for ; Sun, 22 Apr 2018 23:02:39 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hh3w5dhjs-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Sun, 22 Apr 2018 23:02:39 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 22 Apr 2018 23:02:38 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 22 Apr 2018 23:02:31 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3N32VWM55378046; Mon, 23 Apr 2018 03:02:31 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 37085B2054; Mon, 23 Apr 2018 00:04:34 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.149.45]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id EF6FBB204E; Mon, 23 Apr 2018 00:04:33 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id F1D1916C83BE; Sun, 22 Apr 2018 20:03:44 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel.opensrc@gmail.com, torvalds@linux-foundation.org, npiggin@gmail.com, "Paul E. McKenney" Subject: [PATCH tip/core/rcu 01/21] rcu: Improve non-root rcu_cbs_completed() accuracy Date: Sun, 22 Apr 2018 20:03:24 -0700 X-Mailer: git-send-email 2.5.2 In-Reply-To: <20180423030258.GA23370@linux.vnet.ibm.com> References: <20180423030258.GA23370@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18042303-0040-0000-0000-000004207439 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008903; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000257; SDB=6.01021898; UDB=6.00521542; IPR=6.00801134; MB=3.00020719; MTD=3.00000008; XFM=3.00000015; UTC=2018-04-23 03:02:36 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18042303-0041-0000-0000-000008267DAC Message-Id: <1524452624-27589-1-git-send-email-paulmck@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-23_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804230032 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When rcu_cbs_completed() is invoked on a non-root rcu_node structure, it unconditionally assumes that two grace periods must complete before the callbacks at hand can be invoked. This is overly conservative because if that non-root rcu_node structure believes that no grace period is in progress, and if the corresponding rcu_state structure's ->gpnum field has not yet been incremented, then these callbacks may safely be invoked after only one grace period has completed. This change is required to permit grace-period start requests to use funnel locking, which is in turn permitted to reduce root rcu_node ->lock contention, which has been observed by Nick Piggin. Furthermore, such contention will likely be increased by the merging of RCU-bh, RCU-preempt, and RCU-sched, so it makes sense to take steps to decrease it. This commit therefore improves the accuracy of rcu_cbs_completed() when invoked on a non-root rcu_node structure as described above. Reported-by: Nicholas Piggin Signed-off-by: Paul E. McKenney --- kernel/rcu/tree.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 2a734692a581..f5ca72f2ed43 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -1642,6 +1642,21 @@ static unsigned long rcu_cbs_completed(struct rcu_state *rsp, return rnp->completed + 1; /* + * If the current rcu_node structure believes that RCU is + * idle, and if the rcu_state structure does not yet reflect + * the start of a new grace period, then the next grace period + * will suffice. The memory barrier is needed to accurately + * sample the rsp->gpnum, and pairs with the second lock + * acquisition in rcu_gp_init(), which is augmented with + * smp_mb__after_unlock_lock() for this purpose. + */ + if (rnp->gpnum == rnp->completed) { + smp_mb(); /* See above block comment. */ + if (READ_ONCE(rsp->gpnum) == rnp->completed) + return rnp->completed + 1; + } + + /* * Otherwise, wait for a possible partial grace period and * then the subsequent full grace period. */ -- 2.5.2