From patchwork Thu May 12 10:15:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milton Miller X-Patchwork-Id: 95279 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id A9166100A69 for ; Thu, 12 May 2011 20:16:49 +1000 (EST) Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 173F7B6FD7 for ; Thu, 12 May 2011 20:16:40 +1000 (EST) Received: from hera.kernel.org (localhost [127.0.0.1]) by hera.kernel.org (8.14.4/8.14.3) with ESMTP id p4CAFq3u014416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 12 May 2011 10:15:52 GMT X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.97 at hera.kernel.org Received: (from hpa@localhost) by hera.kernel.org (8.14.4/8.14.4/Submit) id p4CAFnYU014411; Thu, 12 May 2011 10:15:49 GMT Date: Thu, 12 May 2011 10:15:49 GMT X-Authentication-Warning: hera.kernel.org: hpa set sender to bounces.tip@hpa.at.zytor.com using -f From: tip-bot for Milton Miller Message-ID: To: linux-tip-commits@vger.kernel.org Subject: [tip:core/locking] seqlock: Don't smp_rmb in seqlock reader spin loop Git-Commit-ID: 5db1256a5131d3b133946fa02ac9770a784e6eb2 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk X-Spam-Status: No, score=-1.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=no version=3.3.2-r929478 X-Spam-Checker-Version: SpamAssassin 3.3.2-r929478 (2010-03-31) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.3 (hera.kernel.org [127.0.0.1]); Thu, 12 May 2011 10:15:57 +0000 (UTC) Cc: andi@firstfloor.org, npiggin@kernel.dk, eric.dumazet@gmail.com, linuxppc-dev@lists.ozlabs.org, miltonm@bga.com, mingo@redhat.com, anton@samba.org, hpa@zytor.com, stable@vger.kernel.org, tglx@linutronix.de, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Reply-To: linux-kernel@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, anton@samba.org, andi@firstfloor.org, eric.dumazet@gmail.com, torvalds@linux-foundation.org, miltonm@bga.com, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org, paulmck@linux.vnet.ibm.com, npiggin@kernel.dk, benh@kernel.crashing.org, tglx@linutronix.de List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Commit-ID: 5db1256a5131d3b133946fa02ac9770a784e6eb2 Gitweb: http://git.kernel.org/tip/5db1256a5131d3b133946fa02ac9770a784e6eb2 Author: Milton Miller AuthorDate: Thu, 12 May 2011 04:13:54 -0500 Committer: Thomas Gleixner CommitDate: Thu, 12 May 2011 12:13:43 +0200 seqlock: Don't smp_rmb in seqlock reader spin loop Move the smp_rmb after cpu_relax loop in read_seqlock and add ACCESS_ONCE to make sure the test and return are consistent. A multi-threaded core in the lab didn't like the update from 2.6.35 to 2.6.36, to the point it would hang during boot when multiple threads were active. Bisection showed af5ab277ded04bd9bc6b048c5a2f0e7d70ef0867 (clockevents: Remove the per cpu tick skew) as the culprit and it is supported with stack traces showing xtime_lock waits including tick_do_update_jiffies64 and/or update_vsyscall. Experimentation showed the combination of cpu_relax and smp_rmb was significantly slowing the progress of other threads sharing the core, and this patch is effective in avoiding the hang. A theory is the rmb is affecting the whole core while the cpu_relax is causing a resource rebalance flush, together they cause an interfernce cadance that is unbroken when the seqlock reader has interrupts disabled. At first I was confused why the refactor in 3c22cd5709e8143444a6d08682a87f4c57902df3 (kernel: optimise seqlock) didn't affect this patch application, but after some study that affected seqcount not seqlock. The new seqcount was not factored back into the seqlock. I defer that the future. While the removal of the timer interrupt offset created contention for the xtime lock while a cpu does the additonal work to update the system clock, the seqlock implementation with the tight rmb spin loop goes back much further, and is just waiting for the right trigger. Cc: Signed-off-by: Milton Miller Cc: Cc: Linus Torvalds Cc: Andi Kleen Cc: Nick Piggin Cc: Benjamin Herrenschmidt Cc: Anton Blanchard Cc: Paul McKenney Acked-by: Eric Dumazet Link: http://lkml.kernel.org/r/%3Cseqlock-rmb%40mdm.bga.com%3E Signed-off-by: Thomas Gleixner --- include/linux/seqlock.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index e98cd2e..06d6964 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -88,12 +88,12 @@ static __always_inline unsigned read_seqbegin(const seqlock_t *sl) unsigned ret; repeat: - ret = sl->sequence; - smp_rmb(); + ret = ACCESS_ONCE(sl->sequence); if (unlikely(ret & 1)) { cpu_relax(); goto repeat; } + smp_rmb(); return ret; }