[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 02/14] aio: add flag to skip fds to aio_dispatch()
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 02/14] aio: add flag to skip fds to aio_dispatch() |
Date: |
Wed, 4 Jan 2017 13:34:02 +0000 |
Polling mode will not call ppoll(2)/epoll_wait(2). Therefore we know
there are no fds ready and should avoid looping over fd handlers in
aio_dispatch().
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
include/block/aio.h | 6 +++++-
aio-posix.c | 14 ++++++++++----
aio-win32.c | 6 ++++--
async.c | 2 +-
4 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/include/block/aio.h b/include/block/aio.h
index ca551e3..c1519ec 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -295,8 +295,12 @@ bool aio_pending(AioContext *ctx);
/* Dispatch any pending callbacks from the GSource attached to the AioContext.
*
* This is used internally in the implementation of the GSource.
+ *
+ * @dispatch_fds: true to process fds, false to skip them
+ * (can be used as an optimization by callers that know there
+ * are no fds ready)
*/
-bool aio_dispatch(AioContext *ctx);
+bool aio_dispatch(AioContext *ctx, bool dispatch_fds);
/* Progress in completing AIO work to occur. This can issue new pending
* aio as a result of executing I/O completion or bh callbacks.
diff --git a/aio-posix.c b/aio-posix.c
index e13b9ab..4ac2346 100644
--- a/aio-posix.c
+++ b/aio-posix.c
@@ -290,9 +290,13 @@ bool aio_pending(AioContext *ctx)
return false;
}
-bool aio_dispatch(AioContext *ctx)
+/*
+ * Note that dispatch_fds == false has the side-effect of post-poning the
+ * freeing of deleted handlers.
+ */
+bool aio_dispatch(AioContext *ctx, bool dispatch_fds)
{
- AioHandler *node;
+ AioHandler *node = NULL;
bool progress = false;
/*
@@ -308,7 +312,9 @@ bool aio_dispatch(AioContext *ctx)
* We have to walk very carefully in case aio_set_fd_handler is
* called while we're walking.
*/
- node = QLIST_FIRST(&ctx->aio_handlers);
+ if (dispatch_fds) {
+ node = QLIST_FIRST(&ctx->aio_handlers);
+ }
while (node) {
AioHandler *tmp;
int revents;
@@ -473,7 +479,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
ctx->walking_handlers--;
/* Run dispatch even if there were no readable fds to run timers */
- if (aio_dispatch(ctx)) {
+ if (aio_dispatch(ctx, ret > 0)) {
progress = true;
}
diff --git a/aio-win32.c b/aio-win32.c
index c8c249e..3ef8ea4 100644
--- a/aio-win32.c
+++ b/aio-win32.c
@@ -271,12 +271,14 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE
event)
return progress;
}
-bool aio_dispatch(AioContext *ctx)
+bool aio_dispatch(AioContext *ctx, bool dispatch_fds)
{
bool progress;
progress = aio_bh_poll(ctx);
- progress |= aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
+ if (dispatch_fds) {
+ progress |= aio_dispatch_handlers(ctx, INVALID_HANDLE_VALUE);
+ }
progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress;
}
diff --git a/async.c b/async.c
index b2de360..52bdb8f 100644
--- a/async.c
+++ b/async.c
@@ -251,7 +251,7 @@ aio_ctx_dispatch(GSource *source,
AioContext *ctx = (AioContext *) source;
assert(callback == NULL);
- aio_dispatch(ctx);
+ aio_dispatch(ctx, true);
return true;
}
--
2.9.3
- [Qemu-devel] [PULL 00/14] Block patches, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 02/14] aio: add flag to skip fds to aio_dispatch(),
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 01/14] HACKING: document #include order, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 04/14] aio: add polling mode to AioContext, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 06/14] linux-aio: poll ring for completions, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 07/14] iothread: add polling parameters, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 05/14] virtio: poll virtqueues for new buffers, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 03/14] aio: add AioPollFn and io_poll() interface, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 08/14] virtio-blk: suppress virtqueue kick during processing, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 09/14] virtio-scsi: suppress virtqueue kick during processing, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 10/14] virtio: turn vq->notification into a nested counter, Stefan Hajnoczi, 2017/01/04
- [Qemu-devel] [PULL 12/14] virtio: disable virtqueue notifications during polling, Stefan Hajnoczi, 2017/01/04