lkml.org 
[lkml]   [2018]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers
From
Date
On 04/24/2018 05:15 AM, Peter Zijlstra wrote:
> On Mon, Apr 23, 2018 at 10:55:14PM +0200, Andrea Parri wrote:
>>>> + /*
>>>> + * To avoid missed wakeup of reader, we need to make sure
>>>> + * that task state and waiter->task are properly synchronized.
>>>> + *
>>>> + * wakeup sleep
>>>> + * ------ -----
>>>> + * __rwsem_mark_wake: rwsem_down_read_failed*:
>>>> + * [S] waiter->task [S] set_current_state(state)
>>>> + * MB MB
>>>> + * try_to_wake_up:
>>>> + * [L] state [L] waiter->task
>>>> + *
>>>> + * For the wakeup path, the original lock release-acquire pair
>>>> + * does not provide enough guarantee of proper synchronization.
>>>> + */
>>>> + smp_mb();
>>>> +
>>>> adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment;
>>>> if (list_empty(&sem->wait_list)) {
>>>> /* hit end of list above */
>> try_to_wake_up() does:
>>
>> raw_spin_lock_irqsave(&p->pi_lock, flags);
>> smp_mb__after_spinlock();
>> if (!(p->state & state))
>>
>> My understanding is that this smp_mb__after_spinlock() provides us with
>> the guarantee you described above. The smp_mb__after_spinlock() should
>> represent a 'cheaper way' to provide such a guarantee.
> Right, I don't see what problem is being fixed here either. The scenario
> in the comment is already closed by the smp_mb__after_spinlock() you
> mention.
>
> And it is fine to rely on that, we do in other places.

Right, I missed the smp_mb__after_spinlock(). So the upstream code is
fine after all. Sorry for the noise.

Cheers,
Longman

\
 
 \ /
  Last update: 2018-04-24 16:49    [W:0.076 / U:0.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site