From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Zijlstra Subject: Re: [PATCH v10 10/19] qspinlock, x86: Allow unfair spinlock in a virtual guest Date: Thu, 8 May 2014 21:12:28 +0200 Message-ID: <20140508191228.GS2844@laptop.programming.kicks-ass.net> References: <1399474907-22206-1-git-send-email-Waiman.Long@hp.com> <1399474907-22206-11-git-send-email-Waiman.Long@hp.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1399474907-22206-11-git-send-email-Waiman.Long@hp.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Waiman Long Cc: linux-arch@vger.kernel.org, Rik van Riel , Raghavendra K T , Oleg Nesterov , Gleb Natapov , kvm@vger.kernel.org, Konrad Rzeszutek Wilk , Scott J Norton , x86@kernel.org, Paolo Bonzini , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Ingo Molnar , Chegu Vinod , David Vrabel , "H. Peter Anvin" , xen-devel@lists.xenproject.org, Thomas Gleixner , "Paul E. McKenney" , Linus Torvalds , Boris Ostrovsky List-Id: linux-arch.vger.kernel.org On Wed, May 07, 2014 at 11:01:38AM -0400, Waiman Long wrote: No, we want the unfair thing for VIRT, not PARAVIRT. > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index 9e7659e..10e87e1 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -227,6 +227,14 @@ static __always_inline int get_qlock(struct qspinlock *lock) > { > struct __qspinlock *l = (void *)lock; > > +#ifdef CONFIG_PARAVIRT_UNFAIR_LOCKS > + if (static_key_false(¶virt_unfairlocks_enabled)) > + /* > + * Need to use atomic operation to get the lock when > + * lock stealing can happen. > + */ > + return cmpxchg(&l->locked, 0, _Q_LOCKED_VAL) == 0; That's missing {}. > +#endif > barrier(); > ACCESS_ONCE(l->locked) = _Q_LOCKED_VAL; > barrier(); But no, what you want is: static __always_inline bool virt_lock(struct qspinlock *lock) { #ifdef CONFIG_VIRT_MUCK if (static_key_false(&virt_unfairlocks_enabled)) { while (!queue_spin_trylock(lock)) cpu_relax(); return true; } #else return false; } void queue_spin_lock_slowpath(struct qspinlock *lock, u32 val) { if (virt_lock(lock)) return; ... } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from casper.infradead.org ([85.118.1.10]:45447 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755435AbaEHTMb (ORCPT ); Thu, 8 May 2014 15:12:31 -0400 Date: Thu, 8 May 2014 21:12:28 +0200 From: Peter Zijlstra Subject: Re: [PATCH v10 10/19] qspinlock, x86: Allow unfair spinlock in a virtual guest Message-ID: <20140508191228.GS2844@laptop.programming.kicks-ass.net> References: <1399474907-22206-1-git-send-email-Waiman.Long@hp.com> <1399474907-22206-11-git-send-email-Waiman.Long@hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1399474907-22206-11-git-send-email-Waiman.Long@hp.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: Waiman Long Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , linux-arch@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, Paolo Bonzini , Konrad Rzeszutek Wilk , Boris Ostrovsky , "Paul E. McKenney" , Rik van Riel , Linus Torvalds , Raghavendra K T , David Vrabel , Oleg Nesterov , Gleb Natapov , Scott J Norton , Chegu Vinod Message-ID: <20140508191228.V46xBsZIxoxg7GuYkUUA6R3dKYh9Z3N9lJLFN4TP0wE@z> On Wed, May 07, 2014 at 11:01:38AM -0400, Waiman Long wrote: No, we want the unfair thing for VIRT, not PARAVIRT. > diff --git a/kernel/locking/qspinlock.c b/kernel/locking/qspinlock.c > index 9e7659e..10e87e1 100644 > --- a/kernel/locking/qspinlock.c > +++ b/kernel/locking/qspinlock.c > @@ -227,6 +227,14 @@ static __always_inline int get_qlock(struct qspinlock *lock) > { > struct __qspinlock *l = (void *)lock; > > +#ifdef CONFIG_PARAVIRT_UNFAIR_LOCKS > + if (static_key_false(¶virt_unfairlocks_enabled)) > + /* > + * Need to use atomic operation to get the lock when > + * lock stealing can happen. > + */ > + return cmpxchg(&l->locked, 0, _Q_LOCKED_VAL) == 0; That's missing {}. > +#endif > barrier(); > ACCESS_ONCE(l->locked) = _Q_LOCKED_VAL; > barrier(); But no, what you want is: static __always_inline bool virt_lock(struct qspinlock *lock) { #ifdef CONFIG_VIRT_MUCK if (static_key_false(&virt_unfairlocks_enabled)) { while (!queue_spin_trylock(lock)) cpu_relax(); return true; } #else return false; } void queue_spin_lock_slowpath(struct qspinlock *lock, u32 val) { if (virt_lock(lock)) return; ... }