From patchwork Wed Jul 27 21:48:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 107152 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 B5D44B7402 for ; Thu, 28 Jul 2011 07:58:31 +1000 (EST) X-Greylist: delayed 601 seconds by postgrey-1.34 at bilbo; Thu, 28 Jul 2011 07:58:16 EST Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ozlabs.org (Postfix) with ESMTP id 6B965B6EE8 for ; Thu, 28 Jul 2011 07:58:16 +1000 (EST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 27 Jul 2011 14:48:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.67,279,1309762800"; d="scan'208";a="32826247" Received: from tassilo.jf.intel.com ([10.7.201.108]) by orsmga001.jf.intel.com with ESMTP; 27 Jul 2011 14:48:04 -0700 Received: by tassilo.jf.intel.com (Postfix, from userid 501) id 6E36E2403FF; Wed, 27 Jul 2011 14:48:04 -0700 (PDT) From: Andi Kleen References: <20110727247.325703029@firstfloor.org> In-Reply-To: <20110727247.325703029@firstfloor.org> To: miltonm@bga.com, linuxppc-dev@lists.ozlabs.org, torvalds@linux-foundation.org, andi@firstfloor.org, npiggin@kernel.dk, benh@kernel.crashing.org, anton@samba.org, paulmck@linux.vnet.ibm.com, eric.dumazet@gmail.com, ak@linux.intel.com, tglx@linutronix.de, gregkh@suse.de, linux-kernel@vger.kernel.org, stable@kernel.org, tim.bird@am.sony.com Subject: [PATCH] [6/99] seqlock: Don't smp_rmb in seqlock reader spin loop Message-Id: <20110727214804.6E36E2403FF@tassilo.jf.intel.com> Date: Wed, 27 Jul 2011 14:48:04 -0700 (PDT) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org 2.6.35-longterm review patch. If anyone has any objections, please let me know. ------------------ From: Milton Miller commit 5db1256a5131d3b133946fa02ac9770a784e6eb2 upstream. 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. 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 Signed-off-by: Andi Kleen Link: http://lkml.kernel.org/r/%3Cseqlock-rmb%40mdm.bga.com%3E Signed-off-by: Thomas Gleixner Signed-off-by: Greg Kroah-Hartman --- include/linux/seqlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Index: linux-2.6.35.y/include/linux/seqlock.h =================================================================== --- linux-2.6.35.y.orig/include/linux/seqlock.h +++ linux-2.6.35.y/include/linux/seqlock.h @@ -88,12 +88,12 @@ static __always_inline unsigned read_seq 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; }