Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1207782pxb; Fri, 20 Nov 2020 04:05:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHkl9dej4DoUpY20sPIcWbX6Et0yTGHohoAyqFFi0702ScnuaHE36SNEMdJcGBkBYjRGiZ X-Received: by 2002:aa7:c34c:: with SMTP id j12mr36041771edr.17.1605873943681; Fri, 20 Nov 2020 04:05:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605873943; cv=none; d=google.com; s=arc-20160816; b=V82IG1KwrXC0l5JlbAvYmhen7C7PPMXeHEX16ZmTLAN/HALGj5V+TNQM63oZPSGsUx sWTV0eeS3VI4U/fXW+m89K+eedYI+nxKqtSAMtx5eSa24D89Sx1rbHYYTXuOVQPbyQKB wwq19nFX1Y1OJQ2chYajb2LIvFTKB/AYS4EbeN/h8yBaJ8/bcsNOxxBun8w5oZHXqUf+ 2EEkgu5ZGwim8uLfkWfrFS+XlNqufPki5FhQDYcMqYRCePZ6gKVvZe6/IcheAxeG6g30 GfIC3KEULZwgRDVStsWLluekRnLiIU4sFDfSbOaQvSoBxBTXCGkbIf9wL8ulyTM8vyAv G3qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dmarc-filter:sender:dkim-signature; bh=ts54798rTxZTjmbOx4G3RHPyu+HPUuWjafwL48ciZWc=; b=hjV6AVUbJ25rPGgHje/b/eNr0SVY9VsMzwTxKI4+5wQasqifSqgdhXCOWQb8yNoJ37 HkIZ/GQq29Cd/dAtjYw57O4O65DYAOWGOOugGZm7Svn8DsvtnzAOYgLlBsE8jrPMFVMF 15uvOIqVxrpZqXHx5a8CyOpdZhU6/y8pZ/Cb6OUWzfArDuy+A7z21jI1F9XjGIBD1w3n N5PglE8g6qDkS5IfCUw7uqT1tt5+cbT7qq7R9o4Upf6+I2t65iVxLNOV1dENndofhaL8 2/Qc7pVKJ4kLP4yisd/ikmvB+1mgV4KejL3f+mJp2Yqhsl2aNSkdCwV8bziR9xOilhM1 ef5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=xZnP7D23; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si1686383edn.109.2020.11.20.04.05.13; Fri, 20 Nov 2020 04:05:43 -0800 (PST) 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=@mg.codeaurora.org header.s=smtp header.b=xZnP7D23; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727994AbgKTMCX (ORCPT + 99 others); Fri, 20 Nov 2020 07:02:23 -0500 Received: from m42-4.mailgun.net ([69.72.42.4]:36265 "EHLO m42-4.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727905AbgKTMCX (ORCPT ); Fri, 20 Nov 2020 07:02:23 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1605873742; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=ts54798rTxZTjmbOx4G3RHPyu+HPUuWjafwL48ciZWc=; b=xZnP7D23t4sqlLNpsSVdfxANsiE3YRUuJuBRA09ONQztGyUz2FEUmvjqf8oukst1uK90NzEg Q4FfnIx2wUOZSBtURtDp5udxixxqR59JZjOFBNkzoB5PoCObbFjzjS3UozsAnOqrjiJJba2w tJeaB0KS+eHCo2dBAAZPNLd9UNM= X-Mailgun-Sending-Ip: 69.72.42.4 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n02.prod.us-west-2.postgun.com with SMTP id 5fb7b0301dba509aaeba91b8 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 20 Nov 2020 12:01:52 GMT Sender: neeraju=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 8F420C43468; Fri, 20 Nov 2020 12:01:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from [192.168.0.101] (unknown [124.123.182.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: neeraju) by smtp.codeaurora.org (Postfix) with ESMTPSA id DAE53C43460; Fri, 20 Nov 2020 12:01:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DAE53C43460 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=neeraju@codeaurora.org Subject: Re: [PATCH RFC tip/core/rcu 5/5] srcu: Provide polling interfaces for Tree SRCU grace periods To: paulmck@kernel.org, rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.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@joelfernandes.org References: <20201117004017.GA7444@paulmck-ThinkPad-P72> <20201117004052.14758-5-paulmck@kernel.org> From: Neeraj Upadhyay Message-ID: Date: Fri, 20 Nov 2020 17:31:43 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <20201117004052.14758-5-paulmck@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/17/2020 6:10 AM, paulmck@kernel.org wrote: > From: "Paul E. McKenney" > > There is a need for a polling interface for SRCU grace > periods, so this commit supplies get_state_synchronize_srcu(), > start_poll_synchronize_srcu(), and poll_state_synchronize_srcu() for this > purpose. The first can be used if future grace periods are inevitable > (perhaps due to a later call_srcu() invocation), the second if future > grace periods might not otherwise happen, and the third to check if a > grace period has elapsed since the corresponding call to either of the > first two. > > As with get_state_synchronize_rcu() and cond_synchronize_rcu(), > the return value from either get_state_synchronize_srcu() or > start_poll_synchronize_srcu() must be passed in to a later call to > poll_state_synchronize_srcu(). > > Link: https://lore.kernel.org/rcu/20201112201547.GF3365678@moria.home.lan/ > Reported-by: Kent Overstreet > [ paulmck: Add EXPORT_SYMBOL_GPL() per kernel test robot feedback. ] > Signed-off-by: Paul E. McKenney > --- > kernel/rcu/srcutree.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 60 insertions(+), 3 deletions(-) > > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c > index d930ece..015d80e 100644 > --- a/kernel/rcu/srcutree.c > +++ b/kernel/rcu/srcutree.c > @@ -810,7 +810,8 @@ static void srcu_leak_callback(struct rcu_head *rhp) > /* > * Start an SRCU grace period, and also queue the callback if non-NULL. > */ > -static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rhp, bool do_norm) > +static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp, > + struct rcu_head *rhp, bool do_norm) > { > unsigned long flags; > int idx; > @@ -822,7 +823,8 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rh > idx = srcu_read_lock(ssp); > sdp = raw_cpu_ptr(ssp->sda); > spin_lock_irqsave_rcu_node(sdp, flags); > - rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp); > + if (rhp) > + rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp); > rcu_segcblist_advance(&sdp->srcu_cblist, > rcu_seq_current(&ssp->srcu_gp_seq)); > s = rcu_seq_snap(&ssp->srcu_gp_seq); > @@ -841,6 +843,7 @@ static void srcu_gp_start_if_needed(struct srcu_struct *ssp, struct rcu_head *rh > else if (needexp) > srcu_funnel_exp_start(ssp, sdp->mynode, s); > srcu_read_unlock(ssp, idx); > + return s; > } > > /* > @@ -882,7 +885,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp, > return; > } > rhp->func = func; > - srcu_gp_start_if_needed(ssp, rhp, do_norm); > + (void)srcu_gp_start_if_needed(ssp, rhp, do_norm); > } > > /** > @@ -1011,6 +1014,60 @@ void synchronize_srcu(struct srcu_struct *ssp) > } > EXPORT_SYMBOL_GPL(synchronize_srcu); > > +/** > + * get_state_synchronize_srcu - Provide an end-of-grace-period cookie > + * @ssp: srcu_struct to provide cookie for. > + * > + * This function returns a cookie that can be passed to > + * poll_state_synchronize_srcu(), which will return true if a full grace > + * period has elapsed in the meantime. It is the caller's responsibility > + * to make sure that grace period happens, for example, by invoking > + * call_srcu() after return from get_state_synchronize_srcu(). > + */ > +unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp) > +{ > + // Any prior manipulation of SRCU-protected data must happen > + // before the load from ->srcu_gp_seq. > + smp_mb(); > + return rcu_seq_snap(&ssp->srcu_gp_seq); > +} > +EXPORT_SYMBOL_GPL(get_state_synchronize_srcu); > + > +/** > + * start_poll_synchronize_srcu - Provide cookie and start grace period > + * @ssp: srcu_struct to provide cookie for. > + * > + * This function returns a cookie that can be passed to > + * poll_state_synchronize_srcu(), which will return true if a full grace > + * period has elapsed in the meantime. Unlike get_state_synchronize_srcu(), > + * this function also ensures that any needed SRCU grace period will be > + * started. This convenience does come at a cost in terms of CPU overhead. > + */ > +unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp) > +{ > + return srcu_gp_start_if_needed(ssp, NULL, true); > +} > +EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu); > + > +/** > + * poll_state_synchronize_srcu - Has cookie's grace period ended? > + * @ssp: srcu_struct to provide cookie for. > + * @cookie: Return value from get_state_synchronize_srcu() or start_poll_synchronize_srcu(). > + * > + * This function takes the cookie that was returned from either > + * get_state_synchronize_srcu() or start_poll_synchronize_srcu(), and > + * returns @true if an SRCU grace period elapsed since the time that the > + * cookie was created. > + */ > +bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie) > +{ > + if (!rcu_seq_done(&ssp->srcu_gp_seq, cookie)) > + return false; > + smp_mb(); // ^^^ Minor: Should this comment be more descriptive? Thanks Neeraj > + return true; > +} > +EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu); > + > /* > * Callback function for srcu_barrier() use. > */ > -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation