From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnIc8-00039x-CD for qemu-devel@nongnu.org; Tue, 28 Apr 2015 23:24:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnIc6-0001LO-QJ for qemu-devel@nongnu.org; Tue, 28 Apr 2015 23:24:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnIc6-0001L9-JH for qemu-devel@nongnu.org; Tue, 28 Apr 2015 23:24:42 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 476C3A0E4A for ; Wed, 29 Apr 2015 03:24:42 +0000 (UTC) From: Fam Zheng Date: Wed, 29 Apr 2015 11:24:26 +0800 Message-Id: <1430277871-26761-3-git-send-email-famz@redhat.com> In-Reply-To: <1430277871-26761-1-git-send-email-famz@redhat.com> References: <1430277871-26761-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v4 2/7] posix-aio: Use QEMU poll interface List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi The AIO handler list is only modified by aio_set_fd_handler, so we can easily add del poll fd there. Initialize a QEMUPoll and keep track of all the fds, so we don't need to rebuild a GPollFD array for g_poll in aio_poll. Signed-off-by: Fam Zheng --- aio-posix.c | 26 ++++++++++++++++++++------ async.c | 3 +++ include/block/aio.h | 6 ++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/aio-posix.c b/aio-posix.c index 4abec38..312b552 100644 --- a/aio-posix.c +++ b/aio-posix.c @@ -17,6 +17,7 @@ #include "block/block.h" #include "qemu/queue.h" #include "qemu/sockets.h" +#include "qemu/poll.h" struct AioHandler { @@ -54,6 +55,7 @@ void aio_set_fd_handler(AioContext *ctx, /* Are we deleting the fd handler? */ if (!io_read && !io_write) { if (node) { + qemu_poll_del(ctx->qpoll, fd); g_source_remove_poll(&ctx->source, &node->pfd); /* If the lock is held, just mark the node as deleted */ @@ -70,13 +72,15 @@ void aio_set_fd_handler(AioContext *ctx, } } } else { - if (node == NULL) { + if (node) { + /* Remove the old */ + qemu_poll_del(ctx->qpoll, fd); + g_source_remove_poll(&ctx->source, &node->pfd); + } else { /* Alloc and insert if it's not already there */ node = g_new0(AioHandler, 1); node->pfd.fd = fd; QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node); - - g_source_add_poll(&ctx->source, &node->pfd); } /* Update handler with latest information */ node->io_read = io_read; @@ -85,6 +89,8 @@ void aio_set_fd_handler(AioContext *ctx, node->pfd.events = (io_read ? G_IO_IN | G_IO_HUP | G_IO_ERR : 0); node->pfd.events |= (io_write ? G_IO_OUT | G_IO_ERR : 0); + qemu_poll_add(ctx->qpoll, fd, node->pfd.events, node); + g_source_add_poll(&ctx->source, &node->pfd); } aio_notify(ctx); @@ -271,15 +277,23 @@ bool aio_poll(AioContext *ctx, bool blocking) if (timeout) { aio_context_release(ctx); } - ret = qemu_poll_ns((GPollFD *)pollfds, npfd, timeout); + ret = qemu_poll(ctx->qpoll, timeout); if (timeout) { aio_context_acquire(ctx); } /* if we have any readable fds, dispatch event */ if (ret > 0) { - for (i = 0; i < npfd; i++) { - nodes[i]->pfd.revents = pollfds[i].revents; + int r; + g_array_set_size(ctx->events, ret); + r = qemu_poll_get_events(ctx->qpoll, + (QEMUPollEvent *)ctx->events->data, + ret); + assert(r == ret); + for (i = 0; i < r; i++) { + QEMUPollEvent *e = &g_array_index(ctx->events, QEMUPollEvent, i); + node = e->opaque; + node->pfd.revents = e->revents; } } diff --git a/async.c b/async.c index 46d9e63..6464c6c 100644 --- a/async.c +++ b/async.c @@ -27,6 +27,7 @@ #include "block/thread-pool.h" #include "qemu/main-loop.h" #include "qemu/atomic.h" +#include "qemu/poll.h" /***********************************************************/ /* bottom halves (can be seen as timers which expire ASAP) */ @@ -292,6 +293,8 @@ AioContext *aio_context_new(Error **errp) return NULL; } g_source_set_can_recurse(&ctx->source, true); + ctx->qpoll = qemu_poll_new(); + ctx->events = g_array_new(FALSE, FALSE, sizeof(QEMUPollEvent)); aio_set_event_notifier(ctx, &ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear); diff --git a/include/block/aio.h b/include/block/aio.h index d2bb423..0ac7983 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -82,6 +82,12 @@ struct AioContext { /* Used for aio_notify. */ EventNotifier notifier; + /* qemu_poll context */ + QEMUPoll *qpoll; + + /* QEMUPollEvents for qemu_poll_get_events() */ + GArray *events; + /* Thread pool for performing work and receiving completion callbacks */ struct ThreadPool *thread_pool; -- 1.9.3