Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp406462pxk; Wed, 9 Sep 2020 08:23:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxS/R+Ajzwf7o4SKVrUg9b2MWLcCciJPwBtEfp97hWuDNy8mtj8Wse7yXWtQyHBjFleWWwe X-Received: by 2002:a17:906:1f42:: with SMTP id d2mr4049831ejk.407.1599664981040; Wed, 09 Sep 2020 08:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599664981; cv=none; d=google.com; s=arc-20160816; b=Gue2XCtJxy6VwIPLBYZqSMgLAmwuVRQ0jCCj1wCgmbJ0zrfiz4ML3Lxpu+PS/AvW9M ZYRka+8zb8HjVluyNWbfhpWEZVENV/YqJF7/Yw9HHtJ9V+LKGHAyIJFCn2ANQMHZ+ji6 5qEktEAGV5VrQHSoNxU7dxCPoQcy7oMqmeYudueydm9BG09FzX2zUHnWgWnBpfk9HR3W Bd75ItiruRVtQVoSNyTp3ant6yOVc20oYFg4+6iJpkkXDfmhQ58N5AjVbw94fbujjTCO 6t4JTHjfATPji9/NATeLenU4kN+7mDlOAmcEcOL3IhYDjl14mJhv7ceg4O8aHXNhqVX5 JvRA== 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=FDpT//FhQEh30gLOaH7MAsfu63i18Ae3ZcoppldcLSQ=; b=v/4n8SalZLDWA5x/pMaUuA1myVGmQqqo/v38H5UINTV8mGxiICYdyQPhFluDshIuta il/bLCABQckqGr/A59iJKGSH6rMgj6DEVqqylHjvqimh5t5clBX9862/h6NqLdkiHk6/ uWDDS419NTtRHRjTLysIcB+sbtvNge9ccD/czIasjMYO5ACHSKM6Xd4/Ha/ZxG+grZNY bAuVwVfAzcfcIUFxpoHk5lmrsNHqI59B7Zb1PzxWRaRRRt7y9r+3b0vlpDZAeC0UE7/P W7FlkElMrv1AtDsR++wL/YiGhaKuaxyLxx6RpL0dCGQfpVxbp8cC32zfsSppW+IkzY4a Y0/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VGlHUA84; 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 m18si1567413eja.292.2020.09.09.08.22.37; Wed, 09 Sep 2020 08:23:01 -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=VGlHUA84; 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 S1729692AbgIIPQd (ORCPT + 99 others); Wed, 9 Sep 2020 11:16:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:36526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729135AbgIILao (ORCPT ); Wed, 9 Sep 2020 07:30:44 -0400 Received: from paulmck-ThinkPad-P72.home (unknown [50.45.173.55]) (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 E1F5820897; Wed, 9 Sep 2020 11:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599650561; bh=oAgyl5YCzOi2Oys2dADhKhmSZ1VDNwqV2xCYDMZdcWw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=VGlHUA84CYJaxv0ABm+a7LxuNh29gVlf7PMfczNBCR98EuKwBIr0Bd91ClwrEdbao ZJmTM2fuC1vKlva5mCMB7bzzkTO9BoXDAgwzncyqAvGsXx1PyTsiLJdMRE2XiO4/rq m3UHhFdkjCrWGoIUrbT2sCHDNVlTZYQL/eUnmEZA= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id AB27F3523091; Wed, 9 Sep 2020 04:22:41 -0700 (PDT) Date: Wed, 9 Sep 2020 04:22:41 -0700 From: "Paul E. McKenney" To: "Zhang, Qiang" Cc: Joel Fernandes , Uladzislau Rezki , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , rcu , LKML Subject: Re: RCU: Question rcu_preempt_blocked_readers_cgp in rcu_gp_fqs_loop func Message-ID: <20200909112241.GE29330@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200818220245.GO27891@paulmck-ThinkPad-P72> <20200819135654.GB3875610@google.com> <20200819152159.GX27891@paulmck-ThinkPad-P72> <20200819155808.GA8817@pc636> <20200820223957.GB120898@google.com> <20200821153328.GH2855@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Sep 09, 2020 at 07:03:39AM +0000, Zhang, Qiang wrote: > > When config preempt RCU, and then there are multiple levels node, the current task is preempted in rcu read critical region. > the current task be add to "rnp->blkd_tasks" link list, and the "rnp->gp_tasks" may be assigned a value . these rnp is leaf node in RCU tree. > > But in "rcu_gp_fqs_loop" func, we check blocked readers in root node. > > static void rcu_gp_fqs_loop(void) > { > ..... > struct rcu_node *rnp = rcu_get_root(); > ..... > if (!READ_ONCE(rnp->qsmask) && > !rcu_preempt_blocked_readers_cgp(rnp)) ------> rnp is root node > break; > .... > } > > the root node's blkd_tasks never add task, the "rnp->gp_tasks" is never be assigned value, this check is invailed. > Should we check leaf nodes like this There are two cases: 1. There is only a single rcu_node structure, which is both root and leaf. In this case, the current check is required: Both ->qsmask and the ->blkd_tasks list must be checked. Your rcu_preempt_blocked_readers() would work in this case, but the current code is a bit faster because it does not need to acquire the ->lock nor does it need the loop overhead. 2. There are multiple levels. In this case, as you say, the root rcu_node structure's ->blkd_tasks list will always be empty. But also in this case, the root rcu_node structure's ->qsmask cannot be zero until all the leaf rcu_node structures' ->qsmask fields are zero and their ->blkd_tasks lists no longer have tasks blocking the current grace period. This means that your rcu_preempt_blocked_readers() function would never return true in this case. So the current code is fine. Are you seeing failures on mainline kernels? If so, what is the failure mode? Thanx, Paul > --- a/kernel/rcu/tree.c > +++ b/kernel/rcu/tree.c > @@ -1846,6 +1846,25 @@ static bool rcu_gp_init(void) > return true; > } > > +static bool rcu_preempt_blocked_readers(void) > +{ > + struct rcu_node *rnp; > + unsigned long flags; > + bool ret = false; > + > + rcu_for_each_leaf_node(rnp) { > + raw_spin_lock_irqsave_rcu_node(rnp, flags); > + if (rcu_preempt_blocked_readers_cgp(rnp)) { > + ret = true; > + raw_spin_unlock_irqrestore_rcu_node(rnp, flags); > + break; > + } > + raw_spin_unlock_irqrestore_rcu_node(rnp, flags); > + } > + > + return ret; > +} > + > /* > * Helper function for swait_event_idle_exclusive() wakeup at force-quiescent-state > * time. > @@ -1864,7 +1883,7 @@ static bool rcu_gp_fqs_check_wake(int *gfp) > return true; > > // The current grace period has completed. > - if (!READ_ONCE(rnp->qsmask) && !rcu_preempt_blocked_readers_cgp(rnp)) > + if (!READ_ONCE(rnp->qsmask) && !rcu_preempt_blocked_readers()) > return true; > > return false; > @@ -1927,7 +1946,7 @@ static void rcu_gp_fqs_loop(void) > /* Locking provides needed memory barriers. */ > /* If grace period done, leave loop. */ > if (!READ_ONCE(rnp->qsmask) && > - !rcu_preempt_blocked_readers_cgp(rnp)) > + !rcu_preempt_blocked_readers()) > break; > /* If time for quiescent-state forcing, do it. */ > if (!time_after(rcu_state.jiffies_force_qs, jiffies) || > -- > > > thanks > Qiang