[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 02/10] qemu-thread: introduce QemuLockCnt
From: |
Fam Zheng |
Subject: |
Re: [Qemu-devel] [PATCH 02/10] qemu-thread: introduce QemuLockCnt |
Date: |
Wed, 11 Jan 2017 23:48:00 +0800 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
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.
> 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/
> + * @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?
> + *
> + * 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