lkml.org 
[lkml]   [2016]   [Mar]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 3/3] locking/mutex: Avoid missed wakeup of mutex waiter
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.

\
 
 \ /
  Last update: 2016-03-29 19:01    [W:0.301 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site