Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3902627pxb; Mon, 30 Aug 2021 13:31:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH+5hYVjWSdcLc2DuJdRargaBH5K/rsZKSasMxxpHikrX3Pd3Uk0V7IPDAXm6spoBt9da7 X-Received: by 2002:a05:6e02:d0f:: with SMTP id g15mr17082968ilj.71.1630355514953; Mon, 30 Aug 2021 13:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630355514; cv=none; d=google.com; s=arc-20160816; b=F61RS0eY1kWL+Rwba+8Os9F9uYp7n5GX+LqBOhJTA1oyOKrmP8EGWGwZKj+7gL7QNC oHZBYM6F28jYVHFav2GueRIQkpfX+iucUMnbi5T1aHv4S1DY4kA9ru09BdFdQyek0WBw tU5G1pf6tPme3xFzzavLlnEeGlwwKZlYU2L9C0FgDZ4uspP2LHYMSOKW57QvYbeskhYL Hstb3leHubzgKExzjaOKqu1DTCPD4kkDLhijZJrFH2tF1k8vxmMtxFniIAzSH0hld4Up taBlXeQxlbGTeaQJGuCnESGfRgBcppTMB8URob2+0ivezsFEPRRecXBIp4mDVs285Yzi +sFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JkROzlhA4MhTOxIqVTvP49R0HK+gruGKFndCLexz3Pk=; b=W3YzvSJN20AvUp97YIYZLh7aH1uw0miRYhn2esHwpfPsFREggq5SXiTOyAlTOZZ04j /ENhc5AfDH6+rhx2gxJikXLC/yB67GOVtAsr/OeRED5oqky429mcSb1ks0krTib4UOpq MW/g0teymqOyFPu+rJF4H0PZ0XG0VccjW4DyqbfdpMXswB58qu3xrOoH3bNR0GuJv1Lr 8CPDQ88ldytrKaZ/FXfUGbkyuqeDwqEF+moTIMdFX0WfO4yvrvVWCefejymOj5kzhL7h leb50ckGHTRxQZSDUqnLXWJFOMXH10VzqlEwCY38YCCJP44ZtNteyKSGrTxK4LOn8W8Z R3lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c80kt7cl; 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 y12si19080163ilu.84.2021.08.30.13.31.38; Mon, 30 Aug 2021 13:31:54 -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=k20201202 header.b=c80kt7cl; 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 S235338AbhH3Ubw (ORCPT + 99 others); Mon, 30 Aug 2021 16:31:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:58488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232906AbhH3Ubv (ORCPT ); Mon, 30 Aug 2021 16:31:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 631BF601FF; Mon, 30 Aug 2021 20:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630355457; bh=PQ/UUD8FB2gcWzuczuUee+HXWZBb4JP7G6smzvxluYs=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=c80kt7clZNEi6jQbl9Fd5B4FM/Ou77qrdxurAC3S5qEdRVA3JQDOBsZUhvWjB/e+u Acv1LftdExbsFFesVSV1O5w/fvRVRp4yDNH/IiL9qIuCx6mYNDmm6vXeu0V+w4Vlya kBgO3nSoj97DHwz0OOPduUWC/m83oHJtgw9NbLLub4sEghrd3qEP5L+leLdXwH4Q9d P7IYNecBFmHTOPds96FX4MewYBfvaWjAiCaka2A2OXTLdN22ATaiqBCx8q2ec/0JPA TiIvro0INuWu2WPJsMMXeK83SRBFV+fDUJs+Ul+TTOQB03OApvyZZNW3p7HpzifyAM sSMFtiTGFnB2g== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 35E825C0566; Mon, 30 Aug 2021 13:30:57 -0700 (PDT) Date: Mon, 30 Aug 2021 13:30:57 -0700 From: "Paul E. McKenney" To: Andrii Nakryiko Cc: Waiman Long , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu@vger.kernel.org, open list , Alexei Starovoitov , Andrii Nakryiko Subject: Re: [PATCH] rcu: Avoid unneeded function call in rcu_read_unlock() Message-ID: <20210830203057.GZ4156@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210827022122.15816-1-longman@redhat.com> <20210827183455.GP4156@paulmck-ThinkPad-P17-Gen-1> <20210830184610.GX4156@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 30, 2021 at 12:34:04PM -0700, Andrii Nakryiko wrote: > On Mon, Aug 30, 2021 at 11:46 AM Paul E. McKenney wrote: > > > > On Mon, Aug 30, 2021 at 11:36:51AM -0700, Andrii Nakryiko wrote: > > > On Fri, Aug 27, 2021 at 11:34 AM Paul E. McKenney wrote: > > > > > > > > On Thu, Aug 26, 2021 at 10:21:22PM -0400, Waiman Long wrote: > > > > > Since commit aa40c138cc8f3 ("rcu: Report QS for outermost > > > > > PREEMPT=n rcu_read_unlock() for strict GPs"). A real function call > > > > > rcu_read_unlock_strict() is added to the inlined rcu_read_unlock(). > > > > > The rcu_read_unlock_strict() call is only needed if the performance > > > > > sagging CONFIG_RCU_STRICT_GRACE_PERIOD option is set. This config > > > > > option isn't set for most production kernels while the function call > > > > > overhead remains. > > > > > > > > > > To provide a slight performance improvement, the > > > > > CONFIG_RCU_STRICT_GRACE_PERIOD config check is moved from > > > > > rcu_read_unlock_strict() to __rcu_read_unlock() so that the function > > > > > call can be compiled out in most cases. > > > > > > > > > > Besides, the GPL exported rcu_read_unlock_strict() also impact the > > > > > the compilation of non-GPL kernel modules as rcu_read_unlock() is a > > > > > frequently used kernel API. > > > > > > > > > > Signed-off-by: Waiman Long > > > > > > > > Nice, and good eyes!!! > > > > > > > > I have queued this for v5.16, that is, not the upcoming merge window > > > > but the one after that. > > > > > > > > I did my usual wordsmithing, so please check the following in case I > > > > messed something up. I intentionally omitted the EXPORT_SYMBOL_GPL() > > > > discussion because: > > > > > > > > 1. Kernels built with CONFIG_PREEMPT=y have the same issue > > > > with the __rcu_read_lock() and __rcu_read_unlock() functions. > > > > > > > > 2. Many other RCU functions are EXPORT_SYMBOL_GPL() and have > > > > been for almost two decades. > > > > > > > > But if someone does use RCU readers within CONFIG_PREEMPT=n kernels from > > > > a binary module, I will happily refer them to you for any RCU issues > > > > that they encounter. ;-) > > > > > > > > I am also CCing the BPF guys in case my interpretation of the code in > > > > the BPF verifier is incorrect. > > > > > > > > > > LGTM from the BPF side, nothing really changed about when > > > rcu_read_unlock_strict is an actual function vs no-op macro. It's also > > > important to minimize the number of function calls in the context of > > > recent LBR on-demand work done by Song, so this is a great > > > improvement! > > > > Thank you for looking this over! May I add your Acked-by or similar? > > > > Sure. > > Acked-by: Andrii Nakryiko Thank you! I will add this on the next rebase. Thanx, Paul > > > > ------------------------------------------------------------------------ > > > > > > > > commit 4a9f53b997b809c0256838e31c604aeeded2345a > > > > Author: Waiman Long > > > > Date: Thu Aug 26 22:21:22 2021 -0400 > > > > > > > > rcu: Avoid unneeded function call in rcu_read_unlock() > > > > > > > > Since commit aa40c138cc8f3 ("rcu: Report QS for outermost PREEMPT=n > > > > rcu_read_unlock() for strict GPs") the function rcu_read_unlock_strict() > > > > is invoked by the inlined rcu_read_unlock() function. However, > > > > rcu_read_unlock_strict() is an empty function in production kernels, > > > > which are built with CONFIG_RCU_STRICT_GRACE_PERIOD=n. > > > > > > > > There is a mention of rcu_read_unlock_strict() in the BPF verifier, > > > > but this is in a deny-list, meaning that BPF does not care whether > > > > rcu_read_unlock_strict() is ever called. > > > > > > > > This commit therefore provides a slight performance improvement > > > > by hoisting the check of CONFIG_RCU_STRICT_GRACE_PERIOD from > > > > rcu_read_unlock_strict() into rcu_read_unlock(), thus avoiding the > > > > pointless call to an empty function. > > > > > > > > Cc: Alexei Starovoitov > > > > Cc: Andrii Nakryiko > > > > Signed-off-by: Waiman Long > > > > Signed-off-by: Paul E. McKenney > > > > > > > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > > > > index 434d12fe2d4f..5e0beb5c5659 100644 > > > > --- a/include/linux/rcupdate.h > > > > +++ b/include/linux/rcupdate.h > > > > @@ -71,7 +71,8 @@ static inline void __rcu_read_lock(void) > > > > static inline void __rcu_read_unlock(void) > > > > { > > > > preempt_enable(); > > > > - rcu_read_unlock_strict(); > > > > + if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD)) > > > > + rcu_read_unlock_strict(); > > > > } > > > > > > > > static inline int rcu_preempt_depth(void) > > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h > > > > index 7a4876a3a882..0b55c647ab80 100644 > > > > --- a/kernel/rcu/tree_plugin.h > > > > +++ b/kernel/rcu/tree_plugin.h > > > > @@ -814,8 +814,7 @@ void rcu_read_unlock_strict(void) > > > > { > > > > struct rcu_data *rdp; > > > > > > > > - if (!IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD) || > > > > - irqs_disabled() || preempt_count() || !rcu_state.gp_kthread) > > > > + if (irqs_disabled() || preempt_count() || !rcu_state.gp_kthread) > > > > return; > > > > rdp = this_cpu_ptr(&rcu_data); > > > > rcu_report_qs_rdp(rdp);