[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 4/4] coroutine/rwlock: Wake writers in preference to read
From: |
David Edmondson |
Subject: |
Re: [RFC PATCH 4/4] coroutine/rwlock: Wake writers in preference to readers |
Date: |
Tue, 09 Mar 2021 11:57:02 +0000 |
On Tuesday, 2021-03-09 at 12:06:22 +01, Paolo Bonzini wrote:
> On 09/03/21 11:21, David Edmondson wrote:
>> - /* The critical section started in qemu_co_rwlock_wrlock. */
>> - qemu_co_queue_restart_all(&lock->queue);
>> + /* The critical section started in qemu_co_rwlock_wrlock or
>> + * qemu_co_rwlock_upgrade.
>> + */
>> + qemu_co_queue_restart_all(&lock->wqueue);
>> + qemu_co_queue_restart_all(&lock->rqueue);
>
> Hmm, the devil is in the details---this is a thundering herd waiting to
> happen. But fortunately this can be fixed while making the unlock
> primitive even simpler:
>
> if (lock->reader) {
> self->locks_held--;
>
> /* Read-side critical sections do not keep lock->mutex. */
> qemu_co_mutex_lock(&lock->mutex);
> lock->reader--;
> assert(lock->reader >= 0);
> }
>
> /* If there are no remaining readers wake one waiting writer
> * or all waiting readers.
> */
> if (!lock->reader && !qemu_co_queue_next(&lock->wqueue)) {
> assert(!lock->pending_writer);
> qemu_co_queue_restart_all(&lock->rqueue);
> }
That's a nice improvement, I agree. I'll roll it into another revision
and work on a test.
dme.
--
But uh oh, I love her because, she moves in her own way.
[RFC PATCH 3/4] coroutine/mutex: Store the coroutine in the CoWaitRecord only once, David Edmondson, 2021/03/09