[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 2/7] posix-aio: Use QEMU poll interface
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH v4 2/7] posix-aio: Use QEMU poll interface |
Date: |
Wed, 29 Apr 2015 11:24:26 +0800 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH v4 0/7] aio: Support epoll by introducing qemu_poll abstraction, Fam Zheng, 2015/04/28
- [Qemu-devel] [PATCH v4 1/7] poll: Introduce QEMU Poll API, Fam Zheng, 2015/04/28
- [Qemu-devel] [PATCH v4 2/7] posix-aio: Use QEMU poll interface,
Fam Zheng <=
- [Qemu-devel] [PATCH v4 3/7] poll: Add epoll implementation for qemu_poll, Fam Zheng, 2015/04/28
- [Qemu-devel] [PATCH v4 4/7] main-loop: Replace qemu_poll_ns with qemu_poll, Fam Zheng, 2015/04/28
- [Qemu-devel] [PATCH v4 7/7] poll-linux: Add timerfd support, Fam Zheng, 2015/04/28
- [Qemu-devel] [PATCH v4 5/7] tests: Add test case for qemu_poll, Fam Zheng, 2015/04/28
- [Qemu-devel] [PATCH v4 6/7] poll-glib: Support ppoll, Fam Zheng, 2015/04/28
- Re: [Qemu-devel] [PATCH v4 0/7] aio: Support epoll by introducing qemu_poll abstraction, Stefan Hajnoczi, 2015/04/29
- Re: [Qemu-devel] [PATCH v4 0/7] aio: Support epoll by introducing qemu_poll abstraction, Kevin Wolf, 2015/04/30