From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753334AbcHPTpq (ORCPT ); Tue, 16 Aug 2016 15:45:46 -0400 Received: from g2t4619.austin.hp.com ([15.73.212.82]:50112 "EHLO g2t4619.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752053AbcHPTpo (ORCPT ); Tue, 16 Aug 2016 15:45:44 -0400 Message-ID: <1471376683.17361.23.camel@j-VirtualBox> Subject: Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled From: Jason Low To: Waiman Long Cc: jason.low2@hpe.com, Peter Zijlstra , 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 Date: Tue, 16 Aug 2016 12:44:43 -0700 In-Reply-To: <57AC9C64.7080500@hpe.com> References: <1470854648.17361.9.camel@j-VirtualBox> <57AC9C64.7080500@hpe.com> 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 Thu, 2016-08-11 at 11:40 -0400, Waiman Long wrote: > On 08/10/2016 02:44 PM, Jason Low wrote: > > +static inline void do_yield_to_waiter(struct mutex *lock, int *wakeups) > > +{ > > + return; > > +} > > + > > +static inline void clear_yield_to_waiter(struct mutex *lock) > > +{ > > + return; > > +} > > + > > +static inline bool need_yield_to_waiter(struct mutex *lock) > > +{ > > + return false; > > +} > > + > > #else > > static bool mutex_optimistic_spin(struct mutex *lock, > > struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx) > > { > > return false; > > } > > + > > +#define MUTEX_WAKEUP_THRESHOLD 16 > > + > > +static inline void do_yield_to_waiter(struct mutex *lock, int *wakeups) > > +{ > > + *wakeups += 1; > > + > > + if (*wakeups< MUTEX_WAKEUP_THRESHOLD) > > + return; > > + > > + if (lock->yield_to_waiter != true) > > + lock->yield_to_waiter = true; > > +} > > + > > +static inline void clear_yield_to_waiter(struct mutex *lock) > > +{ > > + lock->yield_to_waiter = false; > > +} > > + > > +static inline bool need_yield_to_waiter(struct mutex *lock) > > +{ > > + return lock->yield_to_waiter; > > +} > > #endif > > > > _ > > The *yield* helper functions should be in a separate conditional > compilation block as the declaration of yield_to_waiter may not match > the helper functions with certain combination of config variables. > > Something like > > #if !defined(CONFIG_MUTEX_SPIN_ON_OWNER) && defined(CONFIG_SMP) > ... > #else > ... > #endif Right, we will need to incorporate the CONFIG_SMP logic when defining these functions here, otherwise they would be undefined in the !SMP case. Thanks, Jason