From patchwork Wed Feb 22 09:29:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 6874 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id EB54C23EAE for ; Wed, 22 Feb 2012 09:25:07 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id B3D24A186B8 for ; Wed, 22 Feb 2012 09:25:07 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id z7so14128999iab.11 for ; Wed, 22 Feb 2012 01:25:07 -0800 (PST) Received: from mr.google.com ([10.50.156.225]) by 10.50.156.225 with SMTP id wh1mr25423919igb.0.1329902707574 (num_hops = 1); Wed, 22 Feb 2012 01:25:07 -0800 (PST) Received: by 10.50.156.225 with SMTP id wh1mr20583735igb.0.1329902707490; Wed, 22 Feb 2012 01:25:07 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.11.10 with SMTP id r10csp129382ibr; Wed, 22 Feb 2012 01:25:07 -0800 (PST) Received: by 10.42.161.73 with SMTP id s9mr25025904icx.16.1329902706862; Wed, 22 Feb 2012 01:25:06 -0800 (PST) Received: from song.cn.fujitsu.com ([222.73.24.84]) by mx.google.com with ESMTP id hx1si10078075igc.36.2012.02.22.01.25.05; Wed, 22 Feb 2012 01:25:06 -0800 (PST) Received-SPF: neutral (google.com: 222.73.24.84 is neither permitted nor denied by best guess record for domain of laijs@cn.fujitsu.com) client-ip=222.73.24.84; Authentication-Results: mx.google.com; spf=neutral (google.com: 222.73.24.84 is neither permitted nor denied by best guess record for domain of laijs@cn.fujitsu.com) smtp.mail=laijs@cn.fujitsu.com Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 2F7F3170156; Wed, 22 Feb 2012 17:25:04 +0800 (CST) Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q1M9P2EA030312; Wed, 22 Feb 2012 17:25:02 +0800 Received: from lai.fc14.fnst ([10.167.225.146]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2012022217232163-733193 ; Wed, 22 Feb 2012 17:23:21 +0800 Message-ID: <4F44B57C.3020104@cn.fujitsu.com> Date: Wed, 22 Feb 2012 17:29:32 +0800 From: Lai Jiangshan User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc14 Thunderbird/3.1.4 MIME-Version: 1.0 To: paulmck@linux.vnet.ibm.com CC: linux-kernel@vger.kernel.org, mingo@elte.hu, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca, josh@joshtriplett.org, niv@us.ibm.com, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, Valdis.Kletnieks@vt.edu, dhowells@redhat.com, eric.dumazet@gmail.com, darren@dvhart.com, fweisbec@gmail.com, patches@linaro.org Subject: [PATCH 2/3 RFC paul/rcu/srcu] srcu: only increase the upper bit for srcu_read_lock() References: <20120213020951.GA12138@linux.vnet.ibm.com> <4F41F315.1040900@cn.fujitsu.com> <20120220174418.GI2470@linux.vnet.ibm.com> <4F42EF53.6060400@cn.fujitsu.com> <20120221015037.GE2384@linux.vnet.ibm.com> <4F435966.9020106@cn.fujitsu.com> <20120221172442.GG2375@linux.vnet.ibm.com> In-Reply-To: <20120221172442.GG2375@linux.vnet.ibm.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-02-22 17:23:21, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2012-02-22 17:23:22, Serialize complete at 2012-02-22 17:23:22 X-Gm-Message-State: ALoCoQk1RpodZxrNjpHYyIpJHsKdHpJi/ENuoojcdy6uUvKyHA0qHpq8WmG0zXdgcm+RfFbjxuRf >From de49bb517e6367776e2226b931346ab6c798b122 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Wed, 22 Feb 2012 10:41:59 +0800 Subject: [PATCH 2/3 RFC paul/rcu/srcu] srcu: only increase the upper bit for srcu_read_lock() The algorithm/smp_mb()s ensure 'there is only one srcu_read_lock() between flip and recheck for a cpu'. Increment of the upper bit for srcu_read_lock() only can ensure a single pair of lock/unlock change the cpu counter. Signed-off-by: Lai Jiangshan --- include/linux/srcu.h | 2 +- kernel/srcu.c | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/linux/srcu.h b/include/linux/srcu.h index a478c8e..5b49d41 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h @@ -35,7 +35,7 @@ struct srcu_struct_array { }; /* Bit definitions for field ->c above and ->snap below. */ -#define SRCU_USAGE_BITS 2 +#define SRCU_USAGE_BITS 1 #define SRCU_REF_MASK (ULONG_MAX >> SRCU_USAGE_BITS) #define SRCU_USAGE_COUNT (SRCU_REF_MASK + 1) diff --git a/kernel/srcu.c b/kernel/srcu.c index 17e95bc..a51ac48 100644 --- a/kernel/srcu.c +++ b/kernel/srcu.c @@ -138,10 +138,10 @@ static bool srcu_readers_active_idx_check(struct srcu_struct *sp, int idx) /* * Now, we check the ->snap array that srcu_readers_active_idx() - * filled in from the per-CPU counter values. Since both - * __srcu_read_lock() and __srcu_read_unlock() increment the - * upper bits of the per-CPU counter, an increment/decrement - * pair will change the value of the counter. Since there is + * filled in from the per-CPU counter values. Since + * __srcu_read_lock() increments the upper bits of + * the per-CPU counter, an increment/decrement pair will + * change the value of the counter. Since there is * only one possible increment, the only way to wrap the counter * is to have a huge number of counter decrements, which requires * a huge number of tasks and huge SRCU read-side critical-section @@ -234,8 +234,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx) { preempt_disable(); smp_mb(); /* C */ /* Avoid leaking the critical section. */ - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += - SRCU_USAGE_COUNT - 1; + ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += -1; preempt_enable(); } EXPORT_SYMBOL_GPL(__srcu_read_unlock);