X-Received: by 10.112.171.41 with SMTP id ar9mr4932650lbc.24.1429902621077;
        Fri, 24 Apr 2015 12:10:21 -0700 (PDT)
X-BeenThere: linux.kernel@googlegroups.com
Received: by 10.152.22.134 with SMTP id d6ls501488laf.95.gmail; Fri, 24 Apr
 2015 12:10:02 -0700 (PDT)
X-Received: by 10.152.184.73 with SMTP id es9mr4934034lac.4.1429902602403;
        Fri, 24 Apr 2015 12:10:02 -0700 (PDT)
MIME-Version: 1.0
Path: rq4ni23131lbb.1!nntp.google.com!goblin1!goblin.stu.neva.ru!news.panservice.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod
From: Waiman Long <Waima...@hp.com>
Newsgroups: linux.kernel
Subject: [PATCH v16 07/14] qspinlock: Revert to test-and-set on hypervisors
Date: Fri, 24 Apr 2015 21:10:02 +0200
Message-ID: <piR98-86R-5@gated-at.bofh.it>
References: <piQZr-7FS-3@gated-at.bofh.it>
X-Original-To: Thomas Gleixner <tg...@linutronix.de>,
	Ingo Molnar <mi...@redhat.com>,
	"H. Peter Anvin" <h...@zytor.com>,
	Peter Zijlstra <pet...@infradead.org>
X-Mailer: git-send-email 1.7.1
Sender: rob...@news.nic.it
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-...@vger.kernel.org
Approved: rob...@news.nic.it
Lines: 86
Organization: linux.* mail to news gateway
X-Original-Cc: linux...@vger.kernel.org, x...@kernel.org,
	linux-...@vger.kernel.org,
	virtual...@lists.linux-foundation.org,
	xen-...@lists.xenproject.org, k...@vger.kernel.org,
	Paolo Bonzini <paolo....@gmail.com>,
	Konrad Rzeszutek Wilk <konra...@oracle.com>,
	Boris Ostrovsky <boris.o...@oracle.com>,
	"Paul E. McKenney" <pau...@linux.vnet.ibm.com>,
	Rik van Riel <ri...@redhat.com>,
	Linus Torvalds <torv...@linux-foundation.org>,
	Raghavendra K T <raghave...@linux.vnet.ibm.com>,
	David Vrabel <david....@citrix.com>,
	Oleg Nesterov <ol...@redhat.com>,
	Daniel J Blueman <dan...@numascale.com>,
	Scott J Norton <scott....@hp.com>,
	Douglas Hatch <doug....@hp.com>,
	"Peter Zijlstra (Intel)" <pet...@infradead.org>,
	Waiman Long <Waima...@hp.com>
X-Original-Date: Fri, 24 Apr 2015 14:56:36 -0400
X-Original-Message-ID: <1429901803-29771-8-git...@hp.com>
X-Original-References: <1429901803-29771-1-git...@hp.com>
X-Original-Sender: linux-ker...@vger.kernel.org

From: Peter Zijlstra (Intel) <pet...@infradead.org>

When we detect a hypervisor (!paravirt, see qspinlock paravirt support
patches), revert to a simple test-and-set lock to avoid the horrors
of queue preemption.

Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org>
Signed-off-by: Waiman Long <Waima...@hp.com>
---
 arch/x86/include/asm/qspinlock.h |   14 ++++++++++++++
 include/asm-generic/qspinlock.h  |    7 +++++++
 kernel/locking/qspinlock.c       |    3 +++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/qspinlock.h b/arch/x86/include/asm/qspinlock.h
index 222995b..64c925e 100644
--- a/arch/x86/include/asm/qspinlock.h
+++ b/arch/x86/include/asm/qspinlock.h
@@ -1,6 +1,7 @@
 #ifndef _ASM_X86_QSPINLOCK_H
 #define _ASM_X86_QSPINLOCK_H
 
+#include <asm/cpufeature.h>
 #include <asm-generic/qspinlock_types.h>
 
 #define	queue_spin_unlock queue_spin_unlock
@@ -15,6 +16,19 @@ static inline void queue_spin_unlock(struct qspinlock *lock)
 	smp_store_release((u8 *)lock, 0);
 }
 
+#define virt_queue_spin_lock virt_queue_spin_lock
+
+static inline bool virt_queue_spin_lock(struct qspinlock *lock)
+{
+	if (!static_cpu_has(X86_FEATURE_HYPERVISOR))
+		return false;
+
+	while (atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL) != 0)
+		cpu_relax();
+
+	return true;
+}
+
 #include <asm-generic/qspinlock.h>
 
 #endif /* _ASM_X86_QSPINLOCK_H */
diff --git a/include/asm-generic/qspinlock.h b/include/asm-generic/qspinlock.h
index 315d6dc..bcbbc5e 100644
--- a/include/asm-generic/qspinlock.h
+++ b/include/asm-generic/qspinlock.h
@@ -111,6 +111,13 @@ static inline void queue_spin_unlock_wait(struct qspinlock *lock)
 		cpu_relax();
 }
 
+#ifndef virt_queue_spin_lock
+static __always_inline bool virt_queue_spin_lock(struct qspinlock *lock)
+{
+	return false;
+}
+#endif
+
 /*
  * Initializier
  */
diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c
index 99503ef..fc2e5ab 100644
--- a/kernel/locking/qspinlock.c
+++ b/kernel/locking/qspinlock.c
@@ -249,6 +249,9 @@ void queue_spin_lock_slowpath(struct qspinlock *lock, u32 val)
 
 	BUILD_BUG_ON(CONFIG_NR_CPUS >= (1U << _Q_TAIL_CPU_BITS));
 
+	if (virt_queue_spin_lock(lock))
+		return;
+
 	/*
 	 * wait for in-progress pending->locked hand-overs
 	 *
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

