From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751455AbcFFMRh (ORCPT ); Mon, 6 Jun 2016 08:17:37 -0400 Received: from ozlabs.org ([103.22.144.67]:47418 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750933AbcFFMRg (ORCPT ); Mon, 6 Jun 2016 08:17:36 -0400 Message-ID: <1465215445.2658.4.camel@ellerman.id.au> Subject: Re: [PATCH v3] powerpc: spinlock: Fix spin_unlock_wait() From: Michael Ellerman To: Peter Zijlstra Cc: linuxppc-dev@lists.ozlabs.org, Linux Kernel Mailing List , Benjamin Herrenschmidt , Paul Mackerras , "Paul E. McKenney" , Will Deacon , Boqun Feng Date: Mon, 06 Jun 2016 22:17:25 +1000 In-Reply-To: <20160606115655.GD30909@twins.programming.kicks-ass.net> References: <1465213340.2658.1.camel@ellerman.id.au> <20160606115655.GD30909@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.16.5-1ubuntu3.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2016-06-06 at 13:56 +0200, Peter Zijlstra wrote: > On Mon, Jun 06, 2016 at 09:42:20PM +1000, Michael Ellerman wrote: > > +static inline void arch_spin_unlock_wait(arch_spinlock_t *lock) > > +{ > > + arch_spinlock_t lock_val; > > + > > + smp_mb(); > > + > > + /* > > + * Atomically load and store back the lock value (unchanged). This > > + * ensures that our observation of the lock value is ordered with > > + * respect to other lock operations. > > + */ > > + __asm__ __volatile__( > > +"1: " PPC_LWARX(%0, 0, %2, 0) "\n" > > +" stwcx. %0, 0, %2\n" > > +" bne- 1b\n" > > + : "=&r" (lock_val), "+m" (*lock) > > + : "r" (lock) > > + : "cr0", "xer"); > > + > > + if (arch_spin_value_unlocked(lock_val)) > > + goto out; > > + > > + while (!arch_spin_value_unlocked(*lock)) { > > + HMT_low(); > > + if (SHARED_PROCESSOR) > > + __spin_yield(lock); > > + } > > + HMT_medium(); > > + > > +out: > > + smp_mb(); > > +} > > Why the move to in-line this implementation? It looks like a fairly big > function. I agree it's not pretty. I just didn't think having it out-of-line made it easier to understand. The previous version had: static inline void arch_spin_unlock_wait(arch_spinlock_t *lock) { ... if (!arch_spin_is_locked_sync(lock)) goto out; Then elsewhere: static inline bool arch_spin_is_locked_sync(arch_spinlock_t *lock) { ... return !arch_spin_value_unlocked(tmp); } So two negations and one routine called "locked" and one "unlocked", which just didn't read well IMHO. Another minor concern was that someone might be "clever" and call the _sync() version manually (though hopefully we'd catch that in review). I'm not beholden to v3 though if you hate it. cheers