From: Stefan Hajnoczi Date: Tue, 4 Nov 2025 02:29:22 +0000 (-0500) Subject: aio-posix: keep polling enabled with fdmon-io_uring.c X-Git-Tag: v10.2.0-rc1~10^2~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=511c62a2c6f8c6c9b0ddb235b1bddd6884a78c38;p=thirdparty%2Fqemu.git aio-posix: keep polling enabled with fdmon-io_uring.c Commit 816a430c517e ("util/aio: Defer disabling poll mode as long as possible") kept polling enabled when the event loop timeout is 0. Since there is no timeout the event loop will continue immediately and the overhead of disabling and re-enabling polling can be avoided. fdmon-io_uring.c is unable to take advantage of this optimization because its ->need_wait() function returns true whenever there are new io_uring SQEs to submit: if (timeout || ctx->fdmon_ops->need_wait(ctx)) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Polling will be disabled even when timeout == 0. Extend the optimization to handle the case when need_wait() returns true and timeout == 0. Cc: Chao Gao Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Message-ID: <20251104022933.618123-5-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- diff --git a/util/aio-posix.c b/util/aio-posix.c index 2e0a5dadc4..824fdc34cc 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -559,7 +559,14 @@ static bool run_poll_handlers(AioContext *ctx, AioHandlerList *ready_list, elapsed_time = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start_time; max_ns = qemu_soonest_timeout(*timeout, max_ns); assert(!(max_ns && progress)); - } while (elapsed_time < max_ns && !ctx->fdmon_ops->need_wait(ctx)); + + if (ctx->fdmon_ops->need_wait(ctx)) { + if (fdmon_supports_polling(ctx)) { + *timeout = 0; /* stay in polling mode */ + } + break; + } + } while (elapsed_time < max_ns); if (remove_idle_poll_handlers(ctx, ready_list, start_time + elapsed_time)) { @@ -722,7 +729,7 @@ bool aio_poll(AioContext *ctx, bool blocking) * up IO threads when some work becomes pending. It is essential to * avoid hangs or unnecessary latency. */ - if (poll_set_started(ctx, &ready_list, false)) { + if (timeout && poll_set_started(ctx, &ready_list, false)) { timeout = 0; progress = true; }