From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754009AbcHSAtT (ORCPT ); Thu, 18 Aug 2016 20:49:19 -0400 Received: from merlin.infradead.org ([205.233.59.134]:33072 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753973AbcHSAtR (ORCPT ); Thu, 18 Aug 2016 20:49:17 -0400 Date: Thu, 18 Aug 2016 17:18:43 +0200 From: Peter Zijlstra To: Jason Low Cc: Ingo Molnar , imre.deak@intel.com, linux-kernel@vger.kernel.org, Jason Low , Waiman Long , Davidlohr Bueso , Tim Chen , terry.rudd@hpe.com, "Paul E. McKenney" Subject: Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled Message-ID: <20160818151843.GA10168@twins.programming.kicks-ass.net> References: <1470854648.17361.9.camel@j-VirtualBox> <20160818142735.GB10121@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160818142735.GB10121@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 Thu, Aug 18, 2016 at 04:27:35PM +0200, Peter Zijlstra wrote: > On Wed, Aug 10, 2016 at 11:44:08AM -0700, Jason Low wrote: > > @@ -556,8 +604,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, > > * other waiters. We only attempt the xchg if the count is > > * non-negative in order to avoid unnecessary xchg operations: > > */ > > - if (atomic_read(&lock->count) >= 0 && > > + if ((!need_yield_to_waiter(lock) || wakeups > 1) && > > + atomic_read(&lock->count) >= 0 && > > (atomic_xchg_acquire(&lock->count, -1) == 1)) > > + if (wakeups > 1) > > + clear_yield_to_waiter(lock); > > + > > break; > > > > /* > > There's some { } gone missing there... > > Also, I think I'll change it to avoid that extra wakeups > 1 condition.. Also, its broken, even if we should not trylock, we should still very much xchg(-1) to mark the lock as having waiters.