From patchwork Tue Jun 1 09:35:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 103437 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o519a8jg024364 for ; Tue, 1 Jun 2010 09:36:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755807Ab0FAJfp (ORCPT ); Tue, 1 Jun 2010 05:35:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53535 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755765Ab0FAJfn (ORCPT ); Tue, 1 Jun 2010 05:35:43 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o519ZJLF012224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Jun 2010 05:35:19 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o519ZGMq020977; Tue, 1 Jun 2010 05:35:16 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 4118C133D53; Tue, 1 Jun 2010 12:35:15 +0300 (IDT) Date: Tue, 1 Jun 2010 12:35:15 +0300 From: Gleb Natapov To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, avi@redhat.com, hpa@zytor.com, mingo@elte.hu, npiggin@suse.de, tglx@linutronix.de, mtosatti@redhat.com Subject: [PATCH] use unfair spinlock when running on hypervisor. Message-ID: <20100601093515.GH24302@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 01 Jun 2010 09:36:09 +0000 (UTC) diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h index 3089f70..b919b54 100644 --- a/arch/x86/include/asm/spinlock.h +++ b/arch/x86/include/asm/spinlock.h @@ -60,19 +60,27 @@ static __always_inline void __ticket_spin_lock(arch_spinlock_t *lock) { - short inc = 0x0100; + short inc; asm volatile ( + "1:\t\n" + "mov $0x100, %0\n\t" LOCK_PREFIX "xaddw %w0, %1\n" - "1:\t" + "2:\t" "cmpb %h0, %b0\n\t" - "je 2f\n\t" + "je 4f\n\t" + "3:\t\n" "rep ; nop\n\t" - "movb %1, %b0\n\t" /* don't need lfence here, because loads are in-order */ - "jmp 1b\n" - "2:" - : "+Q" (inc), "+m" (lock->slock) + ALTERNATIVE( + "movb %1, %b0\n\t" + "jmp 2b\n", + "nop", X86_FEATURE_HYPERVISOR)"\n\t" + "cmpw $0, %1\n\t" + "jne 3b\n\t" + "jmp 1b\n\t" + "4:" + : "=Q" (inc), "+m" (lock->slock) : : "memory", "cc"); } @@ -98,10 +106,13 @@ static __always_inline int __ticket_spin_trylock(arch_spinlock_t *lock) static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock) { - asm volatile(UNLOCK_LOCK_PREFIX "incb %0" - : "+m" (lock->slock) - : - : "memory", "cc"); + asm volatile( + ALTERNATIVE(UNLOCK_LOCK_PREFIX "incb (%0);"ASM_NOP3, + UNLOCK_LOCK_PREFIX "movw $0, (%0)", + X86_FEATURE_HYPERVISOR) + : + : "Q" (&lock->slock) + : "memory", "cc"); } #else #define TICKET_SHIFT 16