lkml.org 
[lkml]   [2016]   [Aug]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled
From
Date
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

\
 
 \ /
  Last update: 2016-09-17 09:57    [W:0.370 / U:1.884 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site