[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/22] aio-posix: Adjust polling time also for new handlers
From: |
Kevin Wolf |
Subject: |
[PULL 08/22] aio-posix: Adjust polling time also for new handlers |
Date: |
Tue, 11 Mar 2025 17:00:07 +0100 |
aio_dispatch_handler() adds handlers to ctx->poll_aio_handlers if
polling should be enabled. If we call adjust_polling_time() for all
polling handlers before this, new polling handlers are still left at
poll->ns = 0 and polling is only actually enabled after the next event.
Move the adjust_polling_time() call after aio_dispatch_handler().
This fixes test-nested-aio-poll, which expects that polling becomes
effective the first time around.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250311141912.135657-1-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
util/aio-posix.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/util/aio-posix.c b/util/aio-posix.c
index 80785c29d2..2e0a5dadc4 100644
--- a/util/aio-posix.c
+++ b/util/aio-posix.c
@@ -28,6 +28,9 @@
/* Stop userspace polling on a handler if it isn't active for some time */
#define POLL_IDLE_INTERVAL_NS (7 * NANOSECONDS_PER_SECOND)
+static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll,
+ int64_t block_ns);
+
bool aio_poll_disabled(AioContext *ctx)
{
return qatomic_read(&ctx->poll_disable_cnt);
@@ -392,7 +395,8 @@ static bool aio_dispatch_handler(AioContext *ctx,
AioHandler *node)
* scanning all handlers with aio_dispatch_handlers().
*/
static bool aio_dispatch_ready_handlers(AioContext *ctx,
- AioHandlerList *ready_list)
+ AioHandlerList *ready_list,
+ int64_t block_ns)
{
bool progress = false;
AioHandler *node;
@@ -400,6 +404,14 @@ static bool aio_dispatch_ready_handlers(AioContext *ctx,
while ((node = QLIST_FIRST(ready_list))) {
QLIST_REMOVE(node, node_ready);
progress = aio_dispatch_handler(ctx, node) || progress;
+
+ /*
+ * Adjust polling time only after aio_dispatch_handler(), which can
+ * add the handler to ctx->poll_aio_handlers.
+ */
+ if (ctx->poll_max_ns && QLIST_IS_INSERTED(node, node_poll)) {
+ adjust_polling_time(ctx, &node->poll, block_ns);
+ }
}
return progress;
@@ -653,6 +665,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
bool use_notify_me;
int64_t timeout;
int64_t start = 0;
+ int64_t block_ns = 0;
/*
* There cannot be two concurrent aio_poll calls for the same AioContext
(or
@@ -725,20 +738,13 @@ bool aio_poll(AioContext *ctx, bool blocking)
aio_notify_accept(ctx);
- /* Adjust polling time */
+ /* Calculate blocked time for adaptive polling */
if (ctx->poll_max_ns) {
- AioHandler *node;
- int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start;
-
- QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) {
- if (QLIST_IS_INSERTED(node, node_ready)) {
- adjust_polling_time(ctx, &node->poll, block_ns);
- }
- }
+ block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start;
}
progress |= aio_bh_poll(ctx);
- progress |= aio_dispatch_ready_handlers(ctx, &ready_list);
+ progress |= aio_dispatch_ready_handlers(ctx, &ready_list, block_ns);
aio_free_deleted_handlers(ctx);
--
2.48.1
- [PULL 09/22] iotests: Limit qsd-migrate to working formats, (continued)
- [PULL 09/22] iotests: Limit qsd-migrate to working formats, Kevin Wolf, 2025/03/11
- [PULL 17/22] virtio-blk: extract cleanup_iothread_vq_mapping() function, Kevin Wolf, 2025/03/11
- [PULL 15/22] virtio-scsi: protect events_dropped field, Kevin Wolf, 2025/03/11
- [PULL 12/22] scsi: track per-SCSIRequest AioContext, Kevin Wolf, 2025/03/11
- [PULL 19/22] virtio: extract iothread-vq-mapping.h API, Kevin Wolf, 2025/03/11
- [PULL 07/22] aio-posix: Separate AioPolledEvent per AioHandler, Kevin Wolf, 2025/03/11
- [PULL 05/22] aio: Create AioPolledEvent, Kevin Wolf, 2025/03/11
- [PULL 18/22] virtio-blk: tidy up iothread_vq_mapping functions, Kevin Wolf, 2025/03/11
- [PULL 10/22] scsi-disk: drop unused SCSIDiskState->bh field, Kevin Wolf, 2025/03/11
- [PULL 16/22] virtio-scsi: perform TMFs in appropriate AioContexts, Kevin Wolf, 2025/03/11
- [PULL 08/22] aio-posix: Adjust polling time also for new handlers,
Kevin Wolf <=
- [PULL 13/22] scsi: introduce requests_lock, Kevin Wolf, 2025/03/11
- [PULL 20/22] virtio-scsi: add iothread-vq-mapping parameter, Kevin Wolf, 2025/03/11
- [PULL 21/22] virtio-scsi: handle ctrl virtqueue in main loop, Kevin Wolf, 2025/03/11
- [PULL 14/22] virtio-scsi: introduce event and ctrl virtqueue locks, Kevin Wolf, 2025/03/11
- [PULL 22/22] virtio-scsi: only expose cmd vqs via iothread-vq-mapping, Kevin Wolf, 2025/03/11
- [PULL 06/22] aio-posix: Factor out adjust_polling_time(), Kevin Wolf, 2025/03/11
- [PULL 11/22] dma: use current AioContext for dma_blk_io(), Kevin Wolf, 2025/03/11
- Re: [PULL 00/22] Block layer patches, Stefan Hajnoczi, 2025/03/12