lkml.org 
[lkml]   [2019]   [Apr]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v4 11/16] locking/rwsem: Enable readers spinning on writer
From
Date
On 04/17/2019 10:05 AM, Peter Zijlstra wrote:
> On Sat, Apr 13, 2019 at 01:22:54PM -0400, Waiman Long wrote:
>> @@ -650,6 +686,33 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state)
>> struct rwsem_waiter waiter;
>> DEFINE_WAKE_Q(wake_q);
>>
>> + if (!rwsem_can_spin_on_owner(sem))
>> + goto queue;
>> +
>> + /*
>> + * Undo read bias from down_read() and do optimistic spinning.
>> + */
>> + atomic_long_add(-RWSEM_READER_BIAS, &sem->count);
>> + adjustment = 0;
>> + if (rwsem_optimistic_spin(sem, false)) {
>> + unsigned long flags;
>> +
>> + /*
>> + * Opportunistically wake up other readers in the wait queue.
>> + * It has another chance of wakeup at unlock time.
>> + */
>> + if ((atomic_long_read(&sem->count) & RWSEM_FLAG_WAITERS) &&
>> + raw_spin_trylock_irqsave(&sem->wait_lock, flags)) {
> why trylock? Also the rest of this function uses _irq(). Having had to
> define @flags should've been a clue.
>
> You simply cnanot do down_*() with IRQs disabled.

I used trylock to avoid getting stuck in the spinlock while holding a
read lock on the rwsem.

You are right. I don't to use _irqsave version. Just the _irq version is
enough.

Thanks,
Longman


\
 
 \ /
  Last update: 2019-04-17 19:51    [W:1.386 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site