From patchwork Wed May 1 15:55:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 240781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 006912C00B0 for ; Thu, 2 May 2013 01:56:43 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756859Ab3EAP4k (ORCPT ); Wed, 1 May 2013 11:56:40 -0400 Received: from merlin.infradead.org ([205.233.59.134]:33980 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756383Ab3EAP4j (ORCPT ); Wed, 1 May 2013 11:56:39 -0400 Received: from dhcp-089-099-019-018.chello.nl ([89.99.19.18] helo=dyad.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1UXZOJ-0006Mz-N3; Wed, 01 May 2013 15:56:23 +0000 Received: by dyad.programming.kicks-ass.net (Postfix, from userid 1000) id 8E5C2F148; Wed, 1 May 2013 17:55:02 +0200 (CEST) Date: Wed, 1 May 2013 17:55:02 +0200 From: Peter Zijlstra To: Julian Anastasov Cc: Simon Horman , Eric Dumazet , Ingo Molnar , "Paul E. McKenney" , lvs-devel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Pablo Neira Ayuso , Dipankar Sarma Subject: Re: [PATCH v2 1/2] sched: Add cond_resched_rcu_lock() helper Message-ID: <20130501155501.GB7521@dyad.programming.kicks-ass.net> References: <1367290378-29224-1-git-send-email-horms@verge.net.au> <1367290378-29224-2-git-send-email-horms@verge.net.au> <20130430072944.GA13959@verge.net.au> <20130501091012.GB28253@dyad.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org On Wed, May 01, 2013 at 05:22:05PM +0300, Julian Anastasov wrote: > > static void inline cond_resched_rcu_lock(void) > > { > > #ifdef CONFIG_PREEMPT_RCU > > You mean '#ifndef' here, right? But in the non-preempt > case is using the need_resched() needed? rcu_read_unlock > and rcu_read_lock do not generate code. Uhm... yes! > > if (need_resched()) { > > rcu_read_unlock(); > > cond_resched(); > > rcu_read_lock(); > > } > > #endif /* CONFIG_PREEMPT_RCU */ > > } > > > > That would have an rcu_read_lock() break and voluntary preemption point for > > non-preemptible RCU and not bother with the stuff for preemptible RCU. > > I see. So, can we choose one of both variants: > > 1. Your variant but with ifndef: > > static void inline cond_resched_rcu_lock(void) > { > #ifndef CONFIG_PREEMPT_RCU > if (need_resched()) { > rcu_read_unlock(); > cond_resched(); > rcu_read_lock(); > } > #endif > } > > 2. Same without need_resched because cond_resched already > performs the same checks: > > static void inline cond_resched_rcu_lock(void) > { > #ifndef CONFIG_PREEMPT_RCU > rcu_read_unlock(); > cond_resched(); > rcu_read_lock(); > #endif > } Ah so the 'problem' with this last version is that it does an unconditional / unnessecary rcu_read_unlock(). The below would be in line with all the other cond_resched*() implementations. --- include/linux/sched.h | 7 +++++++ kernel/sched/core.c | 14 ++++++++++++++ 2 files changed, 21 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/sched.h b/include/linux/sched.h index 802a751..fd2c77f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2449,6 +2449,13 @@ extern int __cond_resched_softirq(void); __cond_resched_softirq(); \ }) +extern int __cond_resched_rcu(void); + +#define cond_resched_rcu() ({ \ + __might_sleep(__FILE__, __LINE__, 0); \ + __cond_resched_rcu(); \ +}) + /* * Does a critical section need to be broken due to another * task waiting?: (technically does not depend on CONFIG_PREEMPT, diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 7d7901a..2b3b4e6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4358,6 +4358,20 @@ int __sched __cond_resched_softirq(void) } EXPORT_SYMBOL(__cond_resched_softirq); +int __sched __cond_resched_rcu(void) +{ +#ifndef CONFIG_PREEMPT_RCU + if (should_resched()) { + rcu_read_unlock(); + __cond_resched(); + rcu_read_lock(); + return 1; + } +#endif + return 0; +} +EXPORT_SYMBOL(__cond_resched_rcu); + /** * yield - yield the current processor to other threads. *