From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757535AbcHXQzD (ORCPT ); Wed, 24 Aug 2016 12:55:03 -0400 Received: from merlin.infradead.org ([205.233.59.134]:34218 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757247AbcHXQzB (ORCPT ); Wed, 24 Aug 2016 12:55:01 -0400 Date: Wed, 24 Aug 2016 18:52:44 +0200 From: Peter Zijlstra To: Will Deacon 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: <20160824165244.GE10168@twins.programming.kicks-ass.net> References: <20160823124617.015645861@infradead.org> <20160823124856.763266868@infradead.org> <20160824095659.GC16944@arm.com> <20160824153412.GA10153@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160824153412.GA10153@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23.1 (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 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 ...