Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754603AbbKWQ2j (ORCPT ); Mon, 23 Nov 2015 11:28:39 -0500 Received: from terminus.zytor.com ([198.137.202.10]:44702 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751417AbbKWQ2f (ORCPT ); Mon, 23 Nov 2015 11:28:35 -0500 Date: Mon, 23 Nov 2015 08:27:33 -0800 From: tip-bot for Waiman Long Message-ID: Cc: hpa@zytor.com, akpm@linux-foundation.org, doug.hatch@hpe.com, tglx@linutronix.de, peterz@infradead.org, scott.norton@hpe.com, Waiman.Long@hpe.com, torvalds@linux-foundation.org, dave@stgolabs.net, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, mingo@kernel.org Reply-To: mingo@kernel.org, paulmck@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, dave@stgolabs.net, Waiman.Long@hpe.com, scott.norton@hpe.com, peterz@infradead.org, doug.hatch@hpe.com, tglx@linutronix.de, hpa@zytor.com, akpm@linux-foundation.org In-Reply-To: <1447114167-47185-4-git-send-email-Waiman.Long@hpe.com> References: <1447114167-47185-4-git-send-email-Waiman.Long@hpe.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/qspinlock: Avoid redundant read of next pointer Git-Commit-ID: aa68744f80bfb6f26fbe7f10e42876066f7dac1b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2315 Lines: 64 Commit-ID: aa68744f80bfb6f26fbe7f10e42876066f7dac1b Gitweb: http://git.kernel.org/tip/aa68744f80bfb6f26fbe7f10e42876066f7dac1b Author: Waiman Long AuthorDate: Mon, 9 Nov 2015 19:09:23 -0500 Committer: Ingo Molnar CommitDate: Mon, 23 Nov 2015 10:02:00 +0100 locking/qspinlock: Avoid redundant read of next pointer With optimistic prefetch of the next node cacheline, the next pointer may have been properly inititalized. As a result, the reading of node->next in the contended path may be redundant. This patch eliminates the redundant read if the next pointer value is not NULL. Signed-off-by: Waiman Long Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Davidlohr Bueso Cc: Douglas Hatch Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Scott J Norton Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/1447114167-47185-4-git-send-email-Waiman.Long@hpe.com Signed-off-by: Ingo Molnar --- kernel/locking/qspinlock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c index 365b203..9862078 100644 --- a/kernel/locking/qspinlock.c +++ b/kernel/locking/qspinlock.c @@ -396,6 +396,7 @@ queue: * p,*,* -> n,*,* */ old = xchg_tail(lock, tail); + next = NULL; /* * if there was a previous node; link it and wait until reaching the @@ -463,10 +464,12 @@ queue: } /* - * contended path; wait for next, release. + * contended path; wait for next if not observed yet, release. */ - while (!(next = READ_ONCE(node->next))) - cpu_relax(); + if (!next) { + while (!(next = READ_ONCE(node->next))) + cpu_relax(); + } arch_mcs_spin_unlock_contended(&next->locked); pv_kick_node(lock, next); -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/