From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757381AbcHXQzs (ORCPT ); Wed, 24 Aug 2016 12:55:48 -0400 Received: from foss.arm.com ([217.140.101.70]:50514 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756040AbcHXQzp (ORCPT ); Wed, 24 Aug 2016 12:55:45 -0400 Date: Wed, 24 Aug 2016 17:54:32 +0100 From: Will Deacon To: Peter Zijlstra Cc: Linus Torvalds , Waiman Long , Jason Low , Ding Tianhong , Thomas Gleixner , Ingo Molnar , Imre Deak , Linux Kernel Mailing List , Davidlohr Bueso , Tim Chen , Terry Rudd , "Paul E. McKenney" , Jason Low Subject: Re: [RFC][PATCH 1/3] locking/mutex: Rework mutex::owner Message-ID: <20160824165431.GH16944@arm.com> References: <20160823124617.015645861@infradead.org> <20160823124856.763266868@infradead.org> <20160824095659.GC16944@arm.com> <20160824153412.GA10153@twins.programming.kicks-ass.net> <20160824165244.GE10168@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160824165244.GE10168@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 24, 2016 at 06:52:44PM +0200, Peter Zijlstra wrote: > On Wed, Aug 24, 2016 at 05:34:12PM +0200, Peter Zijlstra wrote: > > On Wed, Aug 24, 2016 at 10:56:59AM +0100, Will Deacon wrote: > > > > + owner = atomic_long_read(&lock->owner); > > > > + for (;;) { > > > > + unsigned long old; > > > > + > > > > + old = atomic_long_cmpxchg_release(&lock->owner, owner, owner & 0x03); > > > > + if (old == owner) > > > > + break; > > > > + > > > > + owner = old; > > > > + } > > > > > > Can you rewrite this using atomic_long_fetch_and_release? > > > > Yes, until patch 3/3.. but now that you mention it I think we can do: > > > > owner = atomic_long_read(&lock->owner); > > if (!(owner & MUTEX_FLAG_HANDOFF)) > > (void)atomic_long_fetch_and_release(MUTEX_FLAGS, &lock->owner); > > > > And of course, x86 would very much like atomic_long_and_release() here, > such that it can do LOCK ADD instead of a LOCK CMPXCHG loop. But of > course, we don't have that ... ... yeah, I noticed that. There is a curious use of atomic_and in linux/atomic.h, but it's packed full of false promises. Will