[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 02/10] qemu-thread: introduce QemuLockCnt
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 02/10] qemu-thread: introduce QemuLockCnt |
Date: |
Wed, 11 Jan 2017 17:09:17 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 |
On 11/01/2017 16:48, Fam Zheng wrote:
> On Wed, 01/04 14:26, Paolo Bonzini wrote:
>> +For example, QEMU uses QemuLockCnt to manage an AioContext's list of
>> +bottom halves and file descriptor handlers. Modifications to the list
>> +of file descriptor handlers are rare. Creation of a new bottom half is
>> +frequent and can happen on a fast path; however: 1) it is almost never
>> +concurrent with a visit to the list of bottom halves;
>
> Isn't it common that thread A is busy notifying thread B with BH, and thread B
> is busy processing the notification? In that case creation and visiting the BH
> list are concurrent.
For multi-threaded cases you may can create the BH just once
(thread-pool does it, and aio_co_schedule will be there in the next part
of the work to simplify "remote" qemu_coroutine_enter).
The case where thread A creates the bottom half does occur with rbd.c,
but then, the next point applies:
>> 2) it only has
>> +three instructions in the critical path, two assignments and a smp_wmb().
>> +
>> +/**
>> + * qemu_lockcnt_dec: possibly decrement a QemuLockCnt's counter and lock it.
>
> s/qemu_lockcnt_dec/qemu_lockcnt_dec_if_lock/
Oops, I'll wait for full review and send v4.
>> + * @lockcnt: the lockcnt to operate on
>> + *
>> + * If the count is 1, decrement the count to zero, lock
>> + * the mutex and return true. Otherwise, return false.
>> + */
>> +bool qemu_lockcnt_dec_if_lock(QemuLockCnt *lockcnt);
>> +
>> +/**
>> + * qemu_lockcnt_lock: lock a QemuLockCnt's mutex.
>> + * @lockcnt: the lockcnt to operate on
>> + *
>> + * Remember that concurrent visits are not blocked unless the count is
>> + * also zero. You can use qemu_lockcnt_count to check for this inside a
>> + * critical section.
>> + */
>> +void qemu_lockcnt_lock(QemuLockCnt *lockcnt);
>> diff --git a/util/lockcnt.c b/util/lockcnt.c
>> new file mode 100644
>> index 0000000..78ed1e4
>> --- /dev/null
>> +++ b/util/lockcnt.c
>> @@ -0,0 +1,113 @@
>> +/*
>> + * QemuLockCnt implementation
>> + *
>> + * Copyright Red Hat, Inc. 2015
>
> 2015, 2016?
Or 2017 even. :)
Paolo
>> + *
>> + * Author:
>> + * Paolo Bonzini <address@hidden>
>> + */
>> +#include "qemu/osdep.h"
>> +#include "qemu/thread.h"
>> +#include "qemu/atomic.h"
- [Qemu-devel] [PATCH v3 00/10] aio_context_acquire/release pushdown, part 1, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 01/10] aio: rename bh_lock to list_lock, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 03/10] aio: make ctx->list_lock a QemuLockCnt, subsuming ctx->walking_bh, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 05/10] aio-posix: split aio_dispatch_handlers out of aio_dispatch, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 02/10] qemu-thread: introduce QemuLockCnt, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 04/10] qemu-thread: optimize QemuLockCnt with futexes on Linux, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 06/10] aio: tweak walking in dispatch phase, Paolo Bonzini, 2017/01/04
- [Qemu-devel] [PATCH 07/10] aio-posix: remove walking_handlers, protecting AioHandler list with list_lock, Paolo Bonzini, 2017/01/04