Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755969AbbEUNpq (ORCPT ); Thu, 21 May 2015 09:45:46 -0400 Received: from smtprelay0041.hostedemail.com ([216.40.44.41]:46971 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754514AbbEUNpo (ORCPT ); Thu, 21 May 2015 09:45:44 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::::,RULES_HIT:2:41:69:355:379:541:599:800:960:966:967:973:988:989:1260:1263:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1593:1594:1605:1730:1747:1777:1792:2194:2196:2199:2200:2393:2525:2553:2560:2563:2682:2685:2740:2859:2895:2919:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3622:3742:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4049:4119:4250:4321:4385:4605:5007:6119:6261:7875:7903:8603:8957:9007:9025:9038:9388:10004:10848:10967:11026:11232:11473:11658:11914:12043:12114:12291:12296:12438:12517:12519:12555:12683:12740:13141:13230:14096:14097:21067:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: bell19_89290cb260437 X-Filterd-Recvd-Size: 8030 Date: Thu, 21 May 2015 09:45:41 -0400 From: Steven Rostedt To: Denys Vlasenko Cc: "Paul E. McKenney" , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , linux-kernel@vger.kernel.org, Tejun Heo , Oleg Nesterov Subject: Re: [PATCH] rcu: Deinline rcu_read_lock_sched_held() if DEBUG_LOCK_ALLOC Message-ID: <20150521094541.0eb0ce34@gandalf.local.home> In-Reply-To: <1432202647-20201-1-git-send-email-dvlasenk@redhat.com> References: <1432202647-20201-1-git-send-email-dvlasenk@redhat.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7038 Lines: 169 On Thu, 21 May 2015 12:04:07 +0200 Denys Vlasenko wrote: > DEBUG_LOCK_ALLOC=y is not a production setting, but it is > not very unusual either. Many developers routinely > use kernels built with it enabled. > > Apart from being selected by hand, it is also auto-selected by > PROVE_LOCKING "Lock debugging: prove locking correctness" and > LOCK_STAT "Lock usage statistics" config options. > LOCK STAT is necessary for "perf lock" to work. > > I wouldn't spend too much time optimizing it, but this particular > function has a very large cost in code size: when it is deinlined, > code size decreases by 830,000 bytes: > > text data bss dec hex filename > 85674192 22294776 20627456 128596424 7aa39c8 vmlinux.before > 84837612 22294424 20627456 127759492 79d7484 vmlinux > > (with this config: http://busybox.net/~vda/kernel_config) > > Signed-off-by: Denys Vlasenko > CC: "Paul E. McKenney" > CC: Josh Triplett > CC: Steven Rostedt > CC: Mathieu Desnoyers > CC: Lai Jiangshan > CC: linux-kernel@vger.kernel.org > CC: Tejun Heo > CC: Oleg Nesterov > --- > include/linux/rcupdate.h | 40 ++----------------------------------- > kernel/rcu/update.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 54 insertions(+), 38 deletions(-) > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > index 7809749..6024a65 100644 > --- a/include/linux/rcupdate.h > +++ b/include/linux/rcupdate.h > @@ -439,46 +439,10 @@ int rcu_read_lock_bh_held(void); > * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an > * RCU-sched read-side critical section. In absence of > * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side > - * critical section unless it can prove otherwise. Note that disabling > - * of preemption (including disabling irqs) counts as an RCU-sched > - * read-side critical section. This is useful for debug checks in functions > - * that required that they be called within an RCU-sched read-side > - * critical section. > - * > - * Check debug_lockdep_rcu_enabled() to prevent false positives during boot > - * and while lockdep is disabled. > - * > - * Note that if the CPU is in the idle loop from an RCU point of > - * view (ie: that we are in the section between rcu_idle_enter() and > - * rcu_idle_exit()) then rcu_read_lock_held() returns false even if the CPU > - * did an rcu_read_lock(). The reason for this is that RCU ignores CPUs > - * that are in such a section, considering these as in extended quiescent > - * state, so such a CPU is effectively never in an RCU read-side critical > - * section regardless of what RCU primitives it invokes. This state of > - * affairs is required --- we need to keep an RCU-free window in idle > - * where the CPU may possibly enter into low power mode. This way we can > - * notice an extended quiescent state to other CPUs that started a grace > - * period. Otherwise we would delay any grace period as long as we run in > - * the idle task. > - * > - * Similarly, we avoid claiming an SRCU read lock held if the current > - * CPU is offline. > + * critical section unless it can prove otherwise. > */ > #ifdef CONFIG_PREEMPT_COUNT > -static inline int rcu_read_lock_sched_held(void) > -{ > - int lockdep_opinion = 0; > - > - if (!debug_lockdep_rcu_enabled()) > - return 1; > - if (!rcu_is_watching()) > - return 0; > - if (!rcu_lockdep_current_cpu_online()) > - return 0; > - if (debug_locks) > - lockdep_opinion = lock_is_held(&rcu_sched_lock_map); > - return lockdep_opinion || preempt_count() != 0 || irqs_disabled(); > -} > +int rcu_read_lock_sched_held(void); > #else /* #ifdef CONFIG_PREEMPT_COUNT */ > static inline int rcu_read_lock_sched_held(void) > { > diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c > index e0d31a3..e02218f 100644 > --- a/kernel/rcu/update.c > +++ b/kernel/rcu/update.c > @@ -62,6 +62,58 @@ MODULE_ALIAS("rcupdate"); > > module_param(rcu_expedited, int, 0); > > +#ifdef CONFIG_DEBUG_LOCK_ALLOC > +/** > + * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section? > + * > + * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an > + * RCU-sched read-side critical section. In absence of > + * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side > + * critical section unless it can prove otherwise. Note that disabling > + * of preemption (including disabling irqs) counts as an RCU-sched > + * read-side critical section. This is useful for debug checks in functions > + * that required that they be called within an RCU-sched read-side > + * critical section. > + * > + * Check debug_lockdep_rcu_enabled() to prevent false positives during boot > + * and while lockdep is disabled. > + * > + * Note that if the CPU is in the idle loop from an RCU point of > + * view (ie: that we are in the section between rcu_idle_enter() and > + * rcu_idle_exit()) then rcu_read_lock_held() returns false even if the CPU > + * did an rcu_read_lock(). The reason for this is that RCU ignores CPUs > + * that are in such a section, considering these as in extended quiescent > + * state, so such a CPU is effectively never in an RCU read-side critical > + * section regardless of what RCU primitives it invokes. This state of > + * affairs is required --- we need to keep an RCU-free window in idle > + * where the CPU may possibly enter into low power mode. This way we can > + * notice an extended quiescent state to other CPUs that started a grace > + * period. Otherwise we would delay any grace period as long as we run in > + * the idle task. > + * > + * Similarly, we avoid claiming an SRCU read lock held if the current > + * CPU is offline. > + */ > +#ifdef CONFIG_PREEMPT_COUNT > +int rcu_read_lock_sched_held(void) > +{ > + int lockdep_opinion = 0; > + > + if (!debug_lockdep_rcu_enabled()) > + return 1; > + if (!rcu_is_watching()) > + return 0; > + if (!rcu_lockdep_current_cpu_online()) > + return 0; > + if (debug_locks) > + lockdep_opinion = lock_is_held(&rcu_sched_lock_map); > + return lockdep_opinion || preempt_count() != 0 || irqs_disabled(); > +} > +EXPORT_SYMBOL(rcu_read_lock_sched_held); > +#else > +/* !CONFIG_PREEMPT_COUNT - the function is inlined to always return 1 */ Nuke the #else. It's not needed and this is a common enough practice to have the static inline foo() { } when disabled that we do not need to comment about it here. > +#endif Hmm, you added two #ifdef, and one #endif. How does this even compile?? -- Steve > + > #ifdef CONFIG_PREEMPT_RCU > > /* -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/