Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1465513 > unrolled thread

Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled

Started byPeter Zijlstra <peterz@infradead.org>
First post2016-08-18 16:30 +0200
Last post2016-08-19 02:50 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning  is enabled Peter Zijlstra <peterz@infradead.org> - 2016-08-18 16:30 +0200
    Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning  is enabled Peter Zijlstra <peterz@infradead.org> - 2016-08-19 02:50 +0200
      Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning  is enabled Peter Zijlstra <peterz@infradead.org> - 2016-08-19 02:50 +0200

#1465513 — Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled

FromPeter Zijlstra <peterz@infradead.org>
Date2016-08-18 16:30 +0200
SubjectRe: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled
Message-ID<s7wut-WK-21@gated-at.bofh.it>
On Wed, Aug 10, 2016 at 11:44:08AM -0700, Jason Low wrote:
> @@ -556,8 +604,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
>  		 * other waiters. We only attempt the xchg if the count is
>  		 * non-negative in order to avoid unnecessary xchg operations:
>  		 */
> -		if (atomic_read(&lock->count) >= 0 &&
> +		if ((!need_yield_to_waiter(lock) || wakeups > 1) &&
> +		    atomic_read(&lock->count) >= 0 &&
>  		    (atomic_xchg_acquire(&lock->count, -1) == 1))
> +			if (wakeups > 1)
> +				clear_yield_to_waiter(lock);
> +
>  			break;
>  
>  		/*

There's some { } gone missing there...

Also, I think I'll change it to avoid that extra wakeups > 1 condition..

[toc] | [next] | [standalone]


#1465662

FromPeter Zijlstra <peterz@infradead.org>
Date2016-08-19 02:50 +0200
Message-ID<s7Gat-6Ui-11@gated-at.bofh.it>
In reply to#1465513
On Thu, Aug 18, 2016 at 04:27:35PM +0200, Peter Zijlstra wrote:
> On Wed, Aug 10, 2016 at 11:44:08AM -0700, Jason Low wrote:
> > @@ -556,8 +604,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
> >  		 * other waiters. We only attempt the xchg if the count is
> >  		 * non-negative in order to avoid unnecessary xchg operations:
> >  		 */
> > -		if (atomic_read(&lock->count) >= 0 &&
> > +		if ((!need_yield_to_waiter(lock) || wakeups > 1) &&
> > +		    atomic_read(&lock->count) >= 0 &&
> >  		    (atomic_xchg_acquire(&lock->count, -1) == 1))
> > +			if (wakeups > 1)
> > +				clear_yield_to_waiter(lock);
> > +
> >  			break;
> >  
> >  		/*
> 
> There's some { } gone missing there...
> 
> Also, I think I'll change it to avoid that extra wakeups > 1 condition..

Also, its broken, even if we should not trylock, we should still very
much xchg(-1) to mark the lock as having waiters.

[toc] | [prev] | [next] | [standalone]


#1465667

FromPeter Zijlstra <peterz@infradead.org>
Date2016-08-19 02:50 +0200
Message-ID<s7Gat-6Ui-27@gated-at.bofh.it>
In reply to#1465662
On Thu, Aug 18, 2016 at 05:18:43PM +0200, Peter Zijlstra wrote:
> On Thu, Aug 18, 2016 at 04:27:35PM +0200, Peter Zijlstra wrote:
> > On Wed, Aug 10, 2016 at 11:44:08AM -0700, Jason Low wrote:
> > > @@ -556,8 +604,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
> > >  		 * other waiters. We only attempt the xchg if the count is
> > >  		 * non-negative in order to avoid unnecessary xchg operations:
> > >  		 */
> > > -		if (atomic_read(&lock->count) >= 0 &&
> > > +		if ((!need_yield_to_waiter(lock) || wakeups > 1) &&
> > > +		    atomic_read(&lock->count) >= 0 &&
> > >  		    (atomic_xchg_acquire(&lock->count, -1) == 1))
> > > +			if (wakeups > 1)
> > > +				clear_yield_to_waiter(lock);
> > > +
> > >  			break;
> > >  
> > >  		/*
> > 
> > There's some { } gone missing there...
> > 
> > Also, I think I'll change it to avoid that extra wakeups > 1 condition..
> 
> Also, its broken, even if we should not trylock, we should still very
> much xchg(-1) to mark the lock as having waiters.

Ah, no. Since need_yield_to_waiter() can only be true if there is an
actual waiter, at which point count must already be -1. /me adds a
comment.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web