From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752857AbbFKPJw (ORCPT ); Thu, 11 Jun 2015 11:09:52 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:55519 "EHLO e35.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751056AbbFKPJt (ORCPT ); Thu, 11 Jun 2015 11:09:49 -0400 Date: Thu, 11 Jun 2015 08:07:16 -0700 From: "Paul E. McKenney" To: Kishan Kumar Cc: josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, laijs@cn.fujitsu.com, linux-kernel@vger.kernel.org, kaushalk@codeaurora.org, Mohammed Khajapasha , Vignesh Radhakrishnan Subject: Re: [PATCH] rcu: Start grace period even for single callback Message-ID: <20150611150715.GI3913@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <1434030498-25507-1-git-send-email-kishank@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1434030498-25507-1-git-send-email-kishank@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15061115-0013-0000-0000-00000E3846FB Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 11, 2015 at 07:18:18PM +0530, Kishan Kumar wrote: > When we queue a callback for RCU, it goes and sits > on the nxttail of the per-cpu RCU data structure. > Callback is represented via struct callback_head > structure. > > struct callback_head { > struct callback_head *next; > void (*func)(struct callback_head *head); > }; > > In case of a single callback queued in the nxttail, > the next field will be NULL. "next" happens to be > the zeroeth element of struct callback_head. > > The condition "if(*rdp->nxttail[RCU_NEXT_READY_TAIL])" > in the function cpu_needs_another_gp(), essentially > checks if any callback is queued. > > Since *rdp->nxttail[RCU_NEXT_READY_TAIL] dereferences > to the first element, the if condition will just turn > out to be if(NULL) in case there is a single callback > queued. This in turn causes cpu_needs_another_gp() to > return false even though we need a grace period to > process the single callback. This leads to writers > waiting until a second call_back gets queued, which can > cause undesirable effects like boot up delay upto 300 > seconds, etc. > > Fix this by performing this check on the "func" field > rather than the "next" field of the callback_head. > > Signed-off-by: Kishan Kumar > Signed-off-by: Mohammed Khajapasha > Signed-off-by: Vignesh Radhakrishnan Hmmm... Exactly what did you do to test the problem and verify your fix? >>From what I can see, if there is exactly one newly queued callback, we will have the following: o rdp->nxttail[RCU_DONE_TAIL] == &rdp->nxtlist o rdp->nxttail[RCU_WAIT_TAIL] == &rdp->nxtlist o rdp->nxttail[RCU_NEXT_READY_TAIL] == &rdp->nxtlist o rdp->nxttail[RCU_NEXT_TAIL] == &rdp->nxtlist->next And in this case, rdp->nxtlist will reference the first callback. So *rdp->nxttail[RCU_NEXT_READY_TAIL] will be non-NULL in this case, as required. So what am I missing here? Also, what version of the kernel are you using? Are you posting callbacks during early boot? (Such callbacks won't be invoked until after the scheduler starts running.) What kernel configuration are you using? Thanx, Paul > --- > kernel/rcu/tree.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > index fc3abf1..394a4fa 100644 > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -324,7 +324,7 @@ cpu_needs_another_gp(struct rcu_state *rsp, struct rcu_data *rdp) > return 1; /* Yes, a no-CBs CPU needs one. */ > if (!rdp->nxttail[RCU_NEXT_TAIL]) > return 0; /* No, this is a no-CBs (or offline) CPU. */ > - if (*rdp->nxttail[RCU_NEXT_READY_TAIL]) > + if (((struct callback_head *)rdp->nxttail[RCU_NEXT_READY_TAIL])->func) > return 1; /* Yes, this CPU has newly registered callbacks. */ > for (i = RCU_WAIT_TAIL; i < RCU_NEXT_TAIL; i++) > if (rdp->nxttail[i - 1] != rdp->nxttail[i] && > -- > QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation. >