[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 17/24] async: remove unnecessary inc/dec pairs
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL v2 17/24] async: remove unnecessary inc/dec pairs |
Date: |
Tue, 21 Feb 2017 11:56:37 +0000 |
From: Paolo Bonzini <address@hidden>
Pull the increment/decrement pair out of aio_bh_poll and into the
callers.
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: Daniel P. Berrange <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
util/aio-posix.c | 8 +++-----
util/aio-win32.c | 8 ++++----
util/async.c | 12 ++++++------
3 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/util/aio-posix.c b/util/aio-posix.c
index 2173378..2d51239 100644
--- a/util/aio-posix.c
+++ b/util/aio-posix.c
@@ -425,9 +425,8 @@ static bool aio_dispatch_handlers(AioContext *ctx)
void aio_dispatch(AioContext *ctx)
{
+ qemu_lockcnt_inc(&ctx->list_lock);
aio_bh_poll(ctx);
-
- qemu_lockcnt_inc(&ctx->list_lock);
aio_dispatch_handlers(ctx);
qemu_lockcnt_dec(&ctx->list_lock);
@@ -679,16 +678,15 @@ bool aio_poll(AioContext *ctx, bool blocking)
}
npfd = 0;
- qemu_lockcnt_dec(&ctx->list_lock);
progress |= aio_bh_poll(ctx);
if (ret > 0) {
- qemu_lockcnt_inc(&ctx->list_lock);
progress |= aio_dispatch_handlers(ctx);
- qemu_lockcnt_dec(&ctx->list_lock);
}
+ qemu_lockcnt_dec(&ctx->list_lock);
+
progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress;
diff --git a/util/aio-win32.c b/util/aio-win32.c
index 442a179..bca496a 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -253,8 +253,6 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE
event)
bool progress = false;
AioHandler *tmp;
- qemu_lockcnt_inc(&ctx->list_lock);
-
/*
* We have to walk very carefully in case aio_set_fd_handler is
* called while we're walking.
@@ -305,14 +303,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);
}
@@ -349,7 +348,6 @@ bool aio_poll(AioContext *ctx, bool blocking)
}
}
- qemu_lockcnt_dec(&ctx->list_lock);
first = true;
/* ctx->notifier is always registered. */
@@ -392,6 +390,8 @@ bool aio_poll(AioContext *ctx, bool blocking)
progress |= aio_dispatch_handlers(ctx, event);
} while (count > 0);
+ qemu_lockcnt_dec(&ctx->list_lock);
+
progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress;
}
diff --git a/util/async.c b/util/async.c
index 187bc5b..7d469eb 100644
--- a/util/async.c
+++ b/util/async.c
@@ -90,15 +90,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);
@@ -123,11 +124,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;
@@ -138,7 +138,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;
}
--
2.9.3
- [Qemu-devel] [PULL v2 06/24] io: make qio_channel_yield aware of AioContexts, (continued)
- [Qemu-devel] [PULL v2 06/24] io: make qio_channel_yield aware of AioContexts, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 09/24] blkdebug: reschedule coroutine on the AioContext it is running on, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 08/24] coroutine-lock: reschedule coroutine on the AioContext it was running on, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 10/24] qed: introduce qed_aio_start_io and qed_aio_next_io_cb, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 11/24] aio: push aio_context_acquire/release down to dispatching, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 07/24] nbd: convert to use qio_channel_yield, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 12/24] block: explicitly acquire aiocontext in timers that need it, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 13/24] block: explicitly acquire aiocontext in callbacks that need it, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 14/24] block: explicitly acquire aiocontext in bottom halves that need it, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 15/24] block: explicitly acquire aiocontext in aio callbacks that need it, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 17/24] async: remove unnecessary inc/dec pairs,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL v2 18/24] block: document fields protected by AioContext lock, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 16/24] aio-posix: partially inline aio_dispatch into aio_poll, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 19/24] coroutine-lock: make CoMutex thread-safe, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 20/24] coroutine-lock: add limited spinning to CoMutex, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 21/24] test-aio-multithread: add performance comparison with thread-based mutexes, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 22/24] coroutine-lock: place CoMutex before CoQueue in header, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 23/24] coroutine-lock: add mutex argument to CoQueue APIs, Stefan Hajnoczi, 2017/02/21
- [Qemu-devel] [PULL v2 24/24] coroutine-lock: make CoRwlock thread-safe and fair, Stefan Hajnoczi, 2017/02/21
- Re: [Qemu-devel] [PULL v2 00/24] Block patches, Peter Maydell, 2017/02/21