From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761472AbcINKe0 (ORCPT ); Wed, 14 Sep 2016 06:34:26 -0400 Received: from merlin.infradead.org ([205.233.59.134]:48212 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756012AbcINKeO (ORCPT ); Wed, 14 Sep 2016 06:34:14 -0400 Date: Wed, 14 Sep 2016 12:33:48 +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: [PATCH -v3 07/10] mutex: Restructure wait loop Message-ID: <20160914103348.GB5016@twins.programming.kicks-ass.net> References: <20160905123636.450529224@infradead.org> <20160905124027.619747346@infradead.org> <57D31A3B.7000105@hpe.com> <57D31C67.8010809@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57D31C67.8010809@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 Fri, Sep 09, 2016 at 04:32:39PM -0400, Waiman Long wrote: > >I think you need to remove the HANDOFF flag here in the error path too. > >Maybe you should fix that in patch 6. > > > >It is also possible that __mutex_handoff() has been called at this point. > >So this task may now be the owner of the lock. Maybe you should do a final > >trylock here. > > Alternatively, we can move the trylock in the main loop after the > spin_lock_mutex(). In this case, we don't need an extra trylock in the error > path. I did something like so.. --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -629,12 +629,12 @@ __mutex_lock_common(struct mutex *lock, if (__mutex_waiter_is_first(lock, &waiter)) __mutex_set_flag(lock, MUTEX_FLAG_WAITERS); - if (__mutex_trylock(lock, false)) - goto remove_waiter; - lock_contended(&lock->dep_map, ip); for (;;) { + if (__mutex_trylock(lock, first)) + break; + /* * got a signal? (This code gets eliminated in the * TASK_UNINTERRUPTIBLE case.) @@ -659,13 +659,9 @@ __mutex_lock_common(struct mutex *lock, first = true; __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); } - - if (__mutex_trylock(lock, first)) - break; } __set_task_state(task, TASK_RUNNING); -remove_waiter: mutex_remove_waiter(lock, &waiter, task); if (likely(list_empty(&lock->wait_list))) __mutex_clear_flag(lock, MUTEX_FLAGS);