[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/22] aio-posix: Factor out adjust_polling_time()
From: |
Kevin Wolf |
Subject: |
[PULL 06/22] aio-posix: Factor out adjust_polling_time() |
Date: |
Tue, 11 Mar 2025 17:00:05 +0100 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250307221634.71951-5-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
util/aio-posix.c | 77 ++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 36 deletions(-)
diff --git a/util/aio-posix.c b/util/aio-posix.c
index 95bddb9e4b..259827c7ad 100644
--- a/util/aio-posix.c
+++ b/util/aio-posix.c
@@ -600,6 +600,46 @@ static bool try_poll_mode(AioContext *ctx, AioHandlerList
*ready_list,
return false;
}
+static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll,
+ int64_t block_ns)
+{
+ if (block_ns <= poll->ns) {
+ /* This is the sweet spot, no adjustment needed */
+ } else if (block_ns > ctx->poll_max_ns) {
+ /* We'd have to poll for too long, poll less */
+ int64_t old = poll->ns;
+
+ if (ctx->poll_shrink) {
+ poll->ns /= ctx->poll_shrink;
+ } else {
+ poll->ns = 0;
+ }
+
+ trace_poll_shrink(ctx, old, poll->ns);
+ } else if (poll->ns < ctx->poll_max_ns &&
+ block_ns < ctx->poll_max_ns) {
+ /* There is room to grow, poll longer */
+ int64_t old = poll->ns;
+ int64_t grow = ctx->poll_grow;
+
+ if (grow == 0) {
+ grow = 2;
+ }
+
+ if (poll->ns) {
+ poll->ns *= grow;
+ } else {
+ poll->ns = 4000; /* start polling at 4 microseconds */
+ }
+
+ if (poll->ns > ctx->poll_max_ns) {
+ poll->ns = ctx->poll_max_ns;
+ }
+
+ trace_poll_grow(ctx, old, poll->ns);
+ }
+}
+
bool aio_poll(AioContext *ctx, bool blocking)
{
AioHandlerList ready_list = QLIST_HEAD_INITIALIZER(ready_list);
@@ -682,42 +722,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
/* Adjust polling time */
if (ctx->poll_max_ns) {
int64_t block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start;
-
- if (block_ns <= ctx->poll.ns) {
- /* This is the sweet spot, no adjustment needed */
- } else if (block_ns > ctx->poll_max_ns) {
- /* We'd have to poll for too long, poll less */
- int64_t old = ctx->poll.ns;
-
- if (ctx->poll_shrink) {
- ctx->poll.ns /= ctx->poll_shrink;
- } else {
- ctx->poll.ns = 0;
- }
-
- trace_poll_shrink(ctx, old, ctx->poll.ns);
- } else if (ctx->poll.ns < ctx->poll_max_ns &&
- block_ns < ctx->poll_max_ns) {
- /* There is room to grow, poll longer */
- int64_t old = ctx->poll.ns;
- int64_t grow = ctx->poll_grow;
-
- if (grow == 0) {
- grow = 2;
- }
-
- if (ctx->poll.ns) {
- ctx->poll.ns *= grow;
- } else {
- ctx->poll.ns = 4000; /* start polling at 4 microseconds */
- }
-
- if (ctx->poll.ns > ctx->poll_max_ns) {
- ctx->poll.ns = ctx->poll_max_ns;
- }
-
- trace_poll_grow(ctx, old, ctx->poll.ns);
- }
+ adjust_polling_time(ctx, &ctx->poll, block_ns);
}
progress |= aio_bh_poll(ctx);
--
2.48.1
- [PULL 18/22] virtio-blk: tidy up iothread_vq_mapping functions, (continued)
- [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, 2025/03/11
- [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 <=
- [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