From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932334AbcHXJ5g (ORCPT ); Wed, 24 Aug 2016 05:57:36 -0400 Received: from foss.arm.com ([217.140.101.70]:46137 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999AbcHXJ5e (ORCPT ); Wed, 24 Aug 2016 05:57:34 -0400 Date: Wed, 24 Aug 2016 10:56:59 +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: <20160824095659.GC16944@arm.com> References: <20160823124617.015645861@infradead.org> <20160823124856.763266868@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160823124856.763266868@infradead.org> 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 Tue, Aug 23, 2016 at 02:46:18PM +0200, Peter Zijlstra wrote: > There's a number of iffy in mutex because mutex::count and > mutex::owner are two different fields; this too is the reason > MUTEX_SPIN_ON_OWNER and DEBUG_MUTEX are mutually exclusive. > > Cure this by folding them into a single atomic_long_t field. > > This nessecairly kills all the architecture specific mutex code. > > Signed-off-by: Peter Zijlstra (Intel) [...] > void __sched mutex_unlock(struct mutex *lock) > { > - /* > - * The unlocking fastpath is the 0->1 transition from 'locked' > - * into 'unlocked' state: > - */ > -#ifndef CONFIG_DEBUG_MUTEXES > - /* > - * When debugging is enabled we must not clear the owner before time, > - * the slow path will always be taken, and that clears the owner field > - * after verifying that it was indeed current. > - */ > - mutex_clear_owner(lock); > + unsigned long owner; > + > +#ifdef CONFIG_DEBUG_MUTEXES > + DEBUG_LOCKS_WARN_ON(__mutex_owner(lock) != current); > #endif > - __mutex_fastpath_unlock(&lock->count, __mutex_unlock_slowpath); > -} > > + 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? Will