public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jason Low <jason.low2@hpe.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	imre.deak@intel.com, linux-kernel@vger.kernel.org,
	Jason Low <jason.low2@hp.com>, Waiman Long <Waiman.Long@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	terry.rudd@hpe.com, "Paul E. McKenney" <paulmck@us.ibm.com>
Subject: Re: [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled
Date: Thu, 18 Aug 2016 17:18:43 +0200	[thread overview]
Message-ID: <20160818151843.GA10168@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20160818142735.GB10121@twins.programming.kicks-ass.net>

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.

  reply	other threads:[~2016-08-19  0:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 18:44 [PATCH v2] locking/mutex: Prevent lock starvation when spinning is enabled Jason Low
2016-08-10 20:00 ` kbuild test robot
2016-08-10 20:01 ` kbuild test robot
2016-08-16 20:19   ` Jason Low
2016-08-10 22:07 ` Jason Low
2016-08-11  2:30 ` Jason Low
2016-08-11 15:40 ` Waiman Long
2016-08-16 19:44   ` Jason Low
2016-08-17  1:41 ` Wanpeng Li
2016-08-17 18:30   ` Jason Low
2016-08-18  0:38     ` Wanpeng Li
2016-08-18 14:14 ` Peter Zijlstra
2016-08-18 15:22   ` Waiman Long
2016-08-18 14:27 ` Peter Zijlstra
2016-08-18 15:18   ` Peter Zijlstra [this message]
2016-08-18 15:30     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160818151843.GA10168@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Waiman.Long@hpe.com \
    --cc=dave@stgolabs.net \
    --cc=imre.deak@intel.com \
    --cc=jason.low2@hp.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=terry.rudd@hpe.com \
    --cc=tim.c.chen@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox