From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932477AbcHKCja (ORCPT ); Wed, 10 Aug 2016 22:39:30 -0400 Received: from g2t4622.austin.hp.com ([15.73.212.79]:50556 "EHLO g2t4622.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752164AbcHKCj3 (ORCPT ); Wed, 10 Aug 2016 22:39:29 -0400 Message-ID: <1470882626.17361.18.camel@j-VirtualBox> Subject: Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled From: Jason Low To: Peter Zijlstra Cc: jason.low2@hpe.com, Ingo Molnar , imre.deak@intel.com, linux-kernel@vger.kernel.org, Waiman Long , Davidlohr Bueso , Tim Chen , terry.rudd@hpe.com, "Paul E. McKenney" Date: Wed, 10 Aug 2016 19:30:26 -0700 In-Reply-To: <1470854648.17361.9.camel@j-VirtualBox> References: <1470854648.17361.9.camel@j-VirtualBox> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-08-10 at 11:44 -0700, Jason Low wrote: > @@ -917,11 +976,12 @@ EXPORT_SYMBOL(mutex_trylock); > int __sched > __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) > { > - int ret; > + int ret = 1; > > might_sleep(); > > - ret = __mutex_fastpath_lock_retval(&lock->base.count); > + if (!need_yield_to_waiter(lock)) > + ret = __mutex_fastpath_lock_retval(&lock->base.count); > > if (likely(!ret)) { > ww_mutex_set_context_fastpath(lock, ctx); > @@ -935,11 +995,12 @@ EXPORT_SYMBOL(__ww_mutex_lock); > int __sched > __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) > { > - int ret; > + int ret = 1; > > might_sleep(); > > - ret = __mutex_fastpath_lock_retval(&lock->base.count); > + if (!need_yield_to_waiter(lock)) And we would need to pass &lock->base instead of lock since lock is struct ww_mutex * here.