[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 02/10] async: add aio_bh_schedule_oneshot
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 02/10] async: add aio_bh_schedule_oneshot |
Date: |
Fri, 7 Oct 2016 15:42:51 +0200 |
From: Paolo Bonzini <address@hidden>
qemu_bh_delete is already clearing bh->scheduled at the same time
as it's setting bh->deleted. Since it's not using any memory
barriers, there is no synchronization going on for bh->deleted,
and this makes the bh->deleted checks superfluous in aio_compute_timeout,
aio_bh_poll and aio_ctx_check.
Just remove them, and put the (bh->scheduled && bh->deleted) combo
to work in a new function aio_bh_schedule_oneshot. The new function
removes the need to save the QEMUBH pointer between the creation
and the execution of the bottom half.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
async.c | 27 +++++++++++++++++++++++----
include/block/aio.h | 6 ++++++
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/async.c b/async.c
index 3bca9b0..f30d011 100644
--- a/async.c
+++ b/async.c
@@ -44,6 +44,25 @@ struct QEMUBH {
bool deleted;
};
+void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
+{
+ QEMUBH *bh;
+ bh = g_new(QEMUBH, 1);
+ *bh = (QEMUBH){
+ .ctx = ctx,
+ .cb = cb,
+ .opaque = opaque,
+ };
+ qemu_mutex_lock(&ctx->bh_lock);
+ bh->next = ctx->first_bh;
+ bh->scheduled = 1;
+ bh->deleted = 1;
+ /* Make sure that the members are ready before putting bh into list */
+ smp_wmb();
+ ctx->first_bh = bh;
+ qemu_mutex_unlock(&ctx->bh_lock);
+}
+
QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque)
{
QEMUBH *bh;
@@ -86,7 +105,7 @@ int aio_bh_poll(AioContext *ctx)
* thread sees the zero before bh->cb has run, and thus will call
* aio_notify again if necessary.
*/
- if (!bh->deleted && atomic_xchg(&bh->scheduled, 0)) {
+ if (atomic_xchg(&bh->scheduled, 0)) {
/* Idle BHs and the notify BH don't count as progress */
if (!bh->idle && bh != ctx->notify_dummy_bh) {
ret = 1;
@@ -104,7 +123,7 @@ int aio_bh_poll(AioContext *ctx)
bhp = &ctx->first_bh;
while (*bhp) {
bh = *bhp;
- if (bh->deleted) {
+ if (bh->deleted && !bh->scheduled) {
*bhp = bh->next;
g_free(bh);
} else {
@@ -168,7 +187,7 @@ aio_compute_timeout(AioContext *ctx)
QEMUBH *bh;
for (bh = ctx->first_bh; bh; bh = bh->next) {
- if (!bh->deleted && bh->scheduled) {
+ if (bh->scheduled) {
if (bh->idle) {
/* idle bottom halves will be polled at least
* every 10ms */
@@ -216,7 +235,7 @@ aio_ctx_check(GSource *source)
aio_notify_accept(ctx);
for (bh = ctx->first_bh; bh; bh = bh->next) {
- if (!bh->deleted && bh->scheduled) {
+ if (bh->scheduled) {
return true;
}
}
diff --git a/include/block/aio.h b/include/block/aio.h
index 173c1ed..b9fe2cb 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -181,6 +181,12 @@ void aio_context_acquire(AioContext *ctx);
void aio_context_release(AioContext *ctx);
/**
+ * aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run
+ * only once and as soon as possible.
+ */
+void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
+
+/**
* aio_bh_new: Allocate a new bottom half structure.
*
* Bottom halves are lightweight callbacks whose invocation is guaranteed
--
1.8.3.1
- [Qemu-devel] [PULL 00/10] Block layer patches, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 01/10] block: use bdrv_add_before_write_notifier, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 04/10] block: Add bdrv_runtime_opts to query-command-line-options, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 05/10] block: Add node name to BLOCK_IO_ERROR event, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 03/10] block: use aio_bh_schedule_oneshot, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 02/10] async: add aio_bh_schedule_oneshot,
Kevin Wolf <=
- [Qemu-devel] [PULL 07/10] block: Add qdev ID to DEVICE_TRAY_MOVED, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 08/10] scripts: Allow block module to not define BlockDriver, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 06/10] block-backend: Remember if attached device is non-qdev, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 09/10] module: Don't load the same module if requested multiple times, Kevin Wolf, 2016/10/07
- [Qemu-devel] [PULL 10/10] dmg: Move libbz2 code to dmg-bz2.so, Kevin Wolf, 2016/10/07
- Re: [Qemu-devel] [PULL 00/10] Block layer patches, Peter Maydell, 2016/10/10