From patchwork Thu Jun 16 00:15:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gregkh@suse.de X-Patchwork-Id: 100602 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 42237B714D for ; Thu, 16 Jun 2011 17:05:54 +1000 (EST) Received: from out4.smtp.messagingengine.com (out4.smtp.messagingengine.com [66.111.4.28]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AB045B6FA3 for ; Thu, 16 Jun 2011 17:05:33 +1000 (EST) Received: from compute5.internal (compute5.nyi.mail.srv.osa [10.202.2.45]) by gateway1.messagingengine.com (Postfix) with ESMTP id 070DC21A80; Thu, 16 Jun 2011 03:05:31 -0400 (EDT) Received: from frontend2.messagingengine.com ([10.202.2.161]) by compute5.internal (MEProxy); Thu, 16 Jun 2011 03:05:31 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:to:cc:subject:in-reply-to; s=smtpout; bh=2t1BrDh+7yQBKFg9zIcbPnn1ipw=; b=Ra8/OUKcJe3+oZ5sZKxubLy/QkykxqP8CMz9Hlcb6LPV6ArnK0sTiGIhP0r28d9eRFmA501nDtmIlzskBQUXMJJ9LZKM5OSBwllBJ1wAMwgzcxTtSiPx5EeH4IZTO6h+ymQmCIc9XMzmeBqwFZZmUFIaDAIpOOjMH0Vy5uElQIk= X-Sasl-enc: +V0TAlAHOSZVoSRhh9G6rhzNfaUZDQerE5UmivnD3PFu 1308207930 Received: from localhost (c-76-121-69-168.hsd1.wa.comcast.net [76.121.69.168]) by mail.messagingengine.com (Postfix) with ESMTPSA id 5FA87444293; Thu, 16 Jun 2011 03:05:30 -0400 (EDT) X-Mailbox-Line: From gregkh@clark.kroah.org Wed Jun 15 17:16:11 2011 Message-Id: <20110616001611.375030180@clark.kroah.org> User-Agent: quilt/0.48-16.4 Date: Wed, 15 Jun 2011 17:15:18 -0700 From: Greg KH To: linux-kernel@vger.kernel.org, stable@kernel.org Subject: [21/91] seqlock: Dont smp_rmb in seqlock reader spin loop In-Reply-To: <20110616001900.GA25375@kroah.com> Cc: Nick Piggin , Eric Dumazet , torvalds@linux-foundation.org, Milton Miller , Andi Kleen , Thomas Gleixner , Anton Blanchard , akpm@linux-foundation.org, Paul McKenney , linuxppc-dev@lists.ozlabs.org, stable-review@kernel.org, alan@lxorguk.ukuu.org.uk 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.32-longterm review patch. If anyone has any objections, please let us 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 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(-) --- a/include/linux/seqlock.h +++ b/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; }