[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 39/40] async: remove unnecessary inc/dec pairs
From: |
Paolo Bonzini |
Subject: |
[Qemu-block] [PATCH 39/40] async: remove unnecessary inc/dec pairs |
Date: |
Tue, 24 Nov 2015 19:01:30 +0100 |
Pull the increment/decrement pair out of aio_bh_poll and into the
callers.
Signed-off-by: Paolo Bonzini <address@hidden>
---
aio-posix.c | 7 ++-----
aio-win32.c | 9 ++++++---
async.c | 12 ++++++------
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/aio-posix.c b/aio-posix.c
index b372816..23dcbaa 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -346,9 +346,8 @@ static bool aio_dispatch_handlers(AioContext *ctx)
void aio_dispatch(AioContext *ctx)
{
- aio_bh_poll(ctx);
-
qemu_lockcnt_inc(&ctx->list_lock);
+ aio_bh_poll(ctx);
aio_dispatch_handlers(ctx);
qemu_lockcnt_dec(&ctx->list_lock);
@@ -461,12 +460,10 @@ bool aio_poll(AioContext *ctx, bool blocking)
}
npfd = 0;
- qemu_lockcnt_dec(&ctx->list_lock);
progress |= aio_bh_poll(ctx);
-
- qemu_lockcnt_inc(&ctx->list_lock);
progress |= aio_dispatch_handlers(ctx);
+
qemu_lockcnt_dec(&ctx->list_lock);
progress |= timerlistgroup_run_timers(&ctx->tlg);
diff --git a/aio-win32.c b/aio-win32.c
index feffdc4..36d39f7 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -231,8 +231,6 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE
event)
AioHandler *node;
bool progress = false;
- qemu_lockcnt_inc(&ctx->list_lock);
-
/*
* We have to walk very carefully in case aio_set_fd_handler is
* called while we're walking.
@@ -282,14 +280,15 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE
event)
}
}
- qemu_lockcnt_dec(&ctx->list_lock);
return progress;
}
void aio_dispatch(AioContext *ctx)
{
+ qemu_lockcnt_inc(&ctx->list_lock);
aio_bh_poll(ctx);
aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
+ qemu_lockcnt_dec(&ctx->list_lock);
timerlistgroup_run_timers(&ctx->tlg);
}
@@ -350,6 +349,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
if (first) {
aio_notify_accept(ctx);
+ qemu_lockcnt_inc(&ctx->list_lock);
progress |= aio_bh_poll(ctx);
first = false;
}
@@ -369,6 +369,9 @@ bool aio_poll(AioContext *ctx, bool blocking)
progress |= aio_dispatch_handlers(ctx, event);
} while (count > 0);
+ assert(!first); /* and lockcnt incremented */
+ qemu_lockcnt_dec(&ctx->list_lock);
+
progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress;
diff --git a/async.c b/async.c
index 529934c..db05243 100644
--- a/async.c
+++ b/async.c
@@ -64,15 +64,16 @@ void aio_bh_call(QEMUBH *bh)
bh->cb(bh->opaque);
}
-/* Multiple occurrences of aio_bh_poll cannot be called concurrently */
+/* Multiple occurrences of aio_bh_poll cannot be called concurrently.
+ * The count in ctx->list_lock is incremented before the call, and is
+ * not affected by the call.
+ */
int aio_bh_poll(AioContext *ctx)
{
QEMUBH *bh, **bhp, *next;
int ret;
bool deleted = false;
- qemu_lockcnt_inc(&ctx->list_lock);
-
ret = 0;
for (bh = atomic_rcu_read(&ctx->first_bh); bh; bh = next) {
next = atomic_rcu_read(&bh->next);
@@ -98,11 +99,10 @@ int aio_bh_poll(AioContext *ctx)
/* remove deleted bhs */
if (!deleted) {
- qemu_lockcnt_dec(&ctx->list_lock);
return ret;
}
- if (qemu_lockcnt_dec_and_lock(&ctx->list_lock)) {
+ if (qemu_lockcnt_dec_if_lock(&ctx->list_lock)) {
bhp = &ctx->first_bh;
while (*bhp) {
bh = *bhp;
@@ -113,7 +113,7 @@ int aio_bh_poll(AioContext *ctx)
bhp = &bh->next;
}
}
- qemu_lockcnt_unlock(&ctx->list_lock);
+ qemu_lockcnt_inc_and_unlock(&ctx->list_lock);
}
return ret;
}
--
1.8.3.1
- [Qemu-block] [PATCH 28/40] aio: push aio_context_acquire/release down to dispatching, (continued)
- [Qemu-block] [PATCH 28/40] aio: push aio_context_acquire/release down to dispatching, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 31/40] qed: introduce qed_aio_start_io and qed_aio_next_io_cb, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 34/40] block: explicitly acquire aiocontext in timers that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 33/40] block: explicitly acquire aiocontext in bottom halves that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 32/40] block: explicitly acquire aiocontext in callbacks that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 37/40] async: optimize aio_bh_poll, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 36/40] aio: update locking documentation, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 35/40] block: explicitly acquire aiocontext in aio callbacks that need it, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 38/40] aio-posix: partially inline aio_dispatch into aio_poll, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 40/40] dma-helpers: avoid lock inversion with AioContext, Paolo Bonzini, 2015/11/24
- [Qemu-block] [PATCH 39/40] async: remove unnecessary inc/dec pairs,
Paolo Bonzini <=
- Re: [Qemu-block] [Qemu-devel] [RFC PATCH 00/40] Sneak peek of virtio and dataplane changes for 2.6, Christian Borntraeger, 2015/11/26