Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled
From: Jason Low
Date: Tue Aug 16 2016 - 15:45:48 EST
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