diff options
| author | Jaehoon Kim <jhkim@linux.ibm.com> | 2026-04-23 14:59:18 -0500 |
|---|---|---|
| committer | Stefan Hajnoczi <stefanha@redhat.com> | 2026-04-29 11:31:44 -0400 |
| commit | 9fea80ddf0f58fed94f7e6d7d5c9e0ccf5cff44a (patch) | |
| tree | 77279b8832d5d7e1d1b3143eb45b949ccdbd459d /util | |
| parent | 9563d0b5e2d2056373e8af9eeb674fe64c19b2b2 (diff) | |
| download | qemu-9fea80ddf0f58fed94f7e6d7d5c9e0ccf5cff44a.tar.gz qemu-9fea80ddf0f58fed94f7e6d7d5c9e0ccf5cff44a.zip | |
qapi/iothread: introduce poll-weight parameter for aio-poll
Introduce a configurable poll-weight parameter for adaptive polling
in IOThread. This parameter replaces the hardcoded POLL_WEIGHT_SHIFT
constant, allowing runtime control over how much the most recent
event interval affects the next polling duration calculation.
The poll-weight parameter uses a shift value where larger values
decrease the weight of the current interval, enabling more gradual
adjustments. When set to 0, a default value of 3 is used (meaning
the current interval contributes approximately 1/8 to the weighted
average).
This patch also removes the hardcoded default value checks from
adjust_polling_time(). Instead, poll-grow, poll-shrink, and
poll-weight now use default values initialized in iothread.c
during IOThread creation.
Signed-off-by: Jaehoon Kim <jhkim@linux.ibm.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20260423195918.661299-4-jhkim@linux.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util')
| -rw-r--r-- | util/aio-posix.c | 37 | ||||
| -rw-r--r-- | util/aio-win32.c | 3 | ||||
| -rw-r--r-- | util/async.c | 1 |
3 files changed, 16 insertions, 25 deletions
diff --git a/util/aio-posix.c b/util/aio-posix.c index 8e9e9e5d8f..df1c213ce5 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -29,7 +29,6 @@ /* Stop userspace polling on a handler if it isn't active for some time */ #define POLL_IDLE_INTERVAL_NS (7 * NANOSECONDS_PER_SECOND) -#define POLL_WEIGHT_SHIFT (3) static void update_handler_poll_times(AioContext *ctx, int64_t block_ns, int64_t dispatch_time); @@ -582,28 +581,11 @@ static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list, static void adjust_polling_time(AioContext *ctx, int64_t block_ns) { - if (block_ns < ctx->poll_ns) { - int64_t old = ctx->poll_ns; - int64_t shrink = ctx->poll_shrink; - - if (shrink == 0) { - shrink = 2; - } - - if (block_ns < (ctx->poll_ns / shrink)) { - ctx->poll_ns /= shrink; - } - - trace_poll_shrink(ctx, old, ctx->poll_ns); - } else if (block_ns > ctx->poll_ns) { + if (block_ns > ctx->poll_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 (block_ns > ctx->poll_ns * grow) { ctx->poll_ns = block_ns; } else { @@ -615,6 +597,11 @@ static void adjust_polling_time(AioContext *ctx, int64_t block_ns) } trace_poll_grow(ctx, old, ctx->poll_ns); + } else if (block_ns < (ctx->poll_ns / ctx->poll_shrink)) { + int64_t old = ctx->poll_ns; + ctx->poll_ns /= ctx->poll_shrink; + + trace_poll_shrink(ctx, old, ctx->poll_ns); } } @@ -632,8 +619,8 @@ static void update_handler_poll_times(AioContext *ctx, int64_t block_ns, * block_ns and previous poll.ns to smooth adjustments. */ node->poll.ns = node->poll.ns - ? (node->poll.ns - (node->poll.ns >> POLL_WEIGHT_SHIFT)) - + (block_ns >> POLL_WEIGHT_SHIFT) : block_ns; + ? (node->poll.ns - (node->poll.ns >> ctx->poll_weight)) + + (block_ns >> ctx->poll_weight) : block_ns; if (node->poll.ns > ctx->poll_max_ns) { node->poll.ns = 0; @@ -819,7 +806,8 @@ void aio_context_destroy(AioContext *ctx) } void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, - int64_t grow, int64_t shrink, Error **errp) + int64_t grow, int64_t shrink, + int64_t weight, Error **errp) { AioHandler *node; @@ -833,8 +821,9 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, * is used once. */ ctx->poll_max_ns = max_ns; - ctx->poll_grow = grow; - ctx->poll_shrink = shrink; + ctx->poll_grow = (grow ? grow : IOTHREAD_POLL_GROW_DEFAULT); + ctx->poll_shrink = (shrink ? shrink : IOTHREAD_POLL_SHRINK_DEFAULT); + ctx->poll_weight = (weight ? weight : IOTHREAD_POLL_WEIGHT_DEFAULT); ctx->poll_ns = 0; aio_notify(ctx); diff --git a/util/aio-win32.c b/util/aio-win32.c index 6e6f699e4b..1985843233 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -429,7 +429,8 @@ void aio_context_destroy(AioContext *ctx) } void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, - int64_t grow, int64_t shrink, Error **errp) + int64_t grow, int64_t shrink, + int64_t weight, Error **errp) { if (max_ns) { error_setg(errp, "AioContext polling is not implemented on Windows"); diff --git a/util/async.c b/util/async.c index 9d3627566f..741fcfd6a7 100644 --- a/util/async.c +++ b/util/async.c @@ -609,6 +609,7 @@ AioContext *aio_context_new(Error **errp) ctx->poll_ns = 0; ctx->poll_grow = 0; ctx->poll_shrink = 0; + ctx->poll_weight = 0; ctx->aio_max_batch = 0; |
