mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Waiman Long <Waiman.Long@hpe.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ding Tianhong <dingtianhong@huawei.com>,
	Jason Low <jason.low2@hpe.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	"Paul E. McKenney" <paulmck@us.ibm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <Will.Deacon@arm.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Waiman Long <Waiman.Long@hp.com>
Subject: Re: [PATCH v3 3/3] locking/mutex: Avoid missed wakeup of mutex waiter
Date: Tue, 29 Mar 2016 18:36:54 +0200	[thread overview]
Message-ID: <20160329163654.GM3408@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1458668804-10138-4-git-send-email-Waiman.Long@hpe.com>

On Tue, Mar 22, 2016 at 01:46:44PM -0400, Waiman Long wrote:
> The current mutex code sets count to -1 and then sets the task
> state. This is the same sequence that the mutex unlock path is checking
> count and task state. That could lead to a missed wakeup even though
> the problem will be cleared when a new waiter enters the waiting queue.
> 
> This patch reverses the order in the locking slowpath so that the task
> state is set first before setting the count. This should eliminate
> the potential missed wakeup and improve latency.

Is it really a problem though?

So the 'race' is __mutex_lock_common() against
__mutex_fastpath_unlock(), and that is fully serialized as per the
atomic instructions. Either the fast unlock path does 1->0 and the lock
acquires, or the lock sets -1, at which the unlock fails and enters
__mutex_unlock_common_slowpath, which is fully serialised against
__mutex_lock_common by the lock->wait_lock.

I agree that the code is nicer after your patch, but I don't actually
see a problem.

  reply	other threads:[~2016-03-29 16:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22 17:46 [PATCH v3 0/3] locking/mutex: Enable optimistic spinning of lock waiter Waiman Long
2016-03-22 17:46 ` [PATCH v3 1/3] locking/mutex: Add waiter parameter to mutex_optimistic_spin() Waiman Long
2016-03-22 17:46 ` [PATCH v3 2/3] locking/mutex: Enable optimistic spinning of woken task in wait queue Waiman Long
2016-03-29 15:39   ` Peter Zijlstra
2016-03-29 16:42     ` Peter Zijlstra
2016-03-31 20:40       ` Waiman Long
2016-03-31 20:37     ` Waiman Long
2016-03-22 17:46 ` [PATCH v3 3/3] locking/mutex: Avoid missed wakeup of mutex waiter Waiman Long
2016-03-29 16:36   ` Peter Zijlstra [this message]
2016-03-31 20:39     ` Waiman Long
2016-07-18 17:59 ` [PATCH v3 0/3] locking/mutex: Enable optimistic spinning of lock waiter Jason Low
2016-07-18 20:50   ` Waiman Long

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=20160329163654.GM3408@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Waiman.Long@hp.com \
    --cc=Waiman.Long@hpe.com \
    --cc=Will.Deacon@arm.com \
    --cc=dave@stgolabs.net \
    --cc=dingtianhong@huawei.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@us.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    /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

Powered by JetHome