From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758935AbcHYILy (ORCPT ); Thu, 25 Aug 2016 04:11:54 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:47070 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751731AbcHYILx (ORCPT ); Thu, 25 Aug 2016 04:11:53 -0400 Date: Thu, 25 Aug 2016 10:11:41 +0200 From: Peter Zijlstra To: Waiman Long Cc: Linus Torvalds , Jason Low , Ding Tianhong , Thomas Gleixner , Will Deacon , Ingo Molnar , Imre Deak , Linux Kernel Mailing List , Davidlohr Bueso , Tim Chen , Terry Rudd , "Paul E. McKenney" , Jason Low Subject: Re: [RFC][PATCH 3/3] locking/mutex: Add lock handoff to avoid starvation Message-ID: <20160825081141.GE10153@twins.programming.kicks-ass.net> References: <20160823124617.015645861@infradead.org> <20160823124856.898171453@infradead.org> <57BCA869.1050501@hpe.com> <20160823203204.GU10153@twins.programming.kicks-ass.net> <57BDFA72.4050700@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57BDFA72.4050700@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 On Wed, Aug 24, 2016 at 03:50:10PM -0400, Waiman Long wrote: > --- a/kernel/locking/mutex.c > +++ b/kernel/locking/mutex.c > @@ -97,6 +97,8 @@ static void __mutex_handoff(struct mutex *lock, struct > task_st > for (;;) { > unsigned long old, new; > > + if ((owner & ~MUTEX_FLAG_ALL) != current) > + break; > new = (owner & MUTEX_FLAG_WAITERS); > new |= (unsigned long)task; > > I also think that the MUTEX_FLAG_HANDOFF bit needs to be cleared if the list > is empty. > > @@ -614,7 +633,7 @@ __mutex_lock_common(struct mutex *lock, long state, > unsigned > mutex_remove_waiter(lock, &waiter, task); > /* set it to 0 if there are no waiters left: */ > if (likely(list_empty(&lock->wait_list))) > - __mutex_clear_flag(lock, MUTEX_FLAG_WAITERS); > + __mutex_clear_flag(lock, > MUTEX_FLAG_WAITERS|MUTEX_FLAG_HANDOFF); > > Or we should try to reset the handoff bit after the while loop exit if the > bit is still set. Yes, I think you're right. I've also found another issue wrt WAITERS in patch 1. I'm not trying to get aim7 running to see if I can reproduce Jason's results and verify things.