aio: add flag to skip fds to aio_dispatch()

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 <stefanha@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 20161201192652.9509-2-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
master
Stefan Hajnoczi 2016-12-01 19:26:40 +00:00
parent 0891ee1112
commit 721671ade7
4 changed files with 20 additions and 8 deletions

View File

@ -290,9 +290,13 @@ bool aio_pending(AioContext *ctx)
return false; 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; 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 * We have to walk very carefully in case aio_set_fd_handler is
* called while we're walking. * called while we're walking.
*/ */
node = QLIST_FIRST(&ctx->aio_handlers); if (dispatch_fds) {
node = QLIST_FIRST(&ctx->aio_handlers);
}
while (node) { while (node) {
AioHandler *tmp; AioHandler *tmp;
int revents; int revents;
@ -473,7 +479,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
ctx->walking_handlers--; ctx->walking_handlers--;
/* Run dispatch even if there were no readable fds to run timers */ /* Run dispatch even if there were no readable fds to run timers */
if (aio_dispatch(ctx)) { if (aio_dispatch(ctx, ret > 0)) {
progress = true; progress = true;
} }

View File

@ -271,12 +271,14 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
return progress; return progress;
} }
bool aio_dispatch(AioContext *ctx) bool aio_dispatch(AioContext *ctx, bool dispatch_fds)
{ {
bool progress; bool progress;
progress = aio_bh_poll(ctx); 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); progress |= timerlistgroup_run_timers(&ctx->tlg);
return progress; return progress;
} }

View File

@ -251,7 +251,7 @@ aio_ctx_dispatch(GSource *source,
AioContext *ctx = (AioContext *) source; AioContext *ctx = (AioContext *) source;
assert(callback == NULL); assert(callback == NULL);
aio_dispatch(ctx); aio_dispatch(ctx, true);
return true; return true;
} }

View File

@ -295,8 +295,12 @@ bool aio_pending(AioContext *ctx);
/* Dispatch any pending callbacks from the GSource attached to the AioContext. /* Dispatch any pending callbacks from the GSource attached to the AioContext.
* *
* This is used internally in the implementation of the GSource. * 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 /* Progress in completing AIO work to occur. This can issue new pending
* aio as a result of executing I/O completion or bh callbacks. * aio as a result of executing I/O completion or bh callbacks.