From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754861AbcHSTeO (ORCPT ); Fri, 19 Aug 2016 15:34:14 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:48607 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753576AbcHSTeN (ORCPT ); Fri, 19 Aug 2016 15:34:13 -0400 Date: Fri, 19 Aug 2016 21:33:15 +0200 From: Peter Zijlstra To: Waiman Long Cc: Jason Low , Linus Torvalds , Ding Tianhong , Thomas Gleixner , Will Deacon , Ingo Molnar , imre.deak@intel.com, linux-kernel@vger.kernel.org, Davidlohr Bueso , Tim Chen , terry.rudd@hpe.com, "Paul E. McKenney" , jason.low2@hp.com Subject: Re: [PATCH v4] locking/mutex: Prevent lock starvation when spinning is disabled Message-ID: <20160819193315.GG10153@twins.programming.kicks-ass.net> References: <1471567197.4991.41.camel@j-VirtualBox> <57B73A62.9020901@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57B73A62.9020901@hpe.com> 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 Please trim your emails.. On Fri, Aug 19, 2016 at 12:57:06PM -0400, Waiman Long wrote: > >+static inline bool __mutex_trylock_pending(struct mutex *lock) > >+{ > >+ return atomic_read(&lock->count)>= 0&& > >+ atomic_xchg_acquire(&lock->count, -1) == 1; > >+} > >+ > > Maybe you can make a more general __mutex_trylock function that is used in > all three trylock attempts in the slowpath. For example, > > static inline bool __mutex_trylock(struct mutex *lock, bool waiter) > { > if (waiter) { > return atomic_read(&lock->count) >= 0 && > atomic_xchg_acquire(&lock->count, -1) == 1; > } else { > return !need_yield_to_waiter(lock) && > !mutex_is_locked(lock) && > ((atomic_xchg_acquire(&lock->count, 0) == 1); > } > } That seems more messy to me..