improve aio-polling efficiency
v5 cover improve aio-polling efficiency
Dear all,
This is v5 of the patch series to refine aio_poll adaptive polling logic for better CPU efficiency.
v1: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v3: https://lore.kernel.org/qemu-devel/[email protected]/
v4: https://lore.kernel.org/qemu-devel/[email protected]/
Changes in v5:
- Patch 3/3: Fixed QAPI documentation based on review feedback:
* qapi/misc.json: Removed the sentence about returning poll-weight=0 since query-iothreads never returns 0 for this field.
* qemu-options.hx: Enhanced poll-weight parameter documentation to match the detail level in qom.json, including information about default value and typical value examples.
Changes in v4:
- Patch 2/3: Added detailed validation tables showing poll.ns statistics across different poll_weight values (1-5) for SSD randread/randwrite workloads to demonstrate algorithm behavior and justify poll_weight=3 as the optimal default.
- Patch 3/3: Fixed commit message to correctly reference adjust_polling_time() instead of the removed grow_polling_time() and shrink_polling_time() functions from v2.
Changes in v3:
- Patch 1/3: Removed timeout check in aio_poll() as suggested by Stefan Hajnoczi.
- Patch 2/3: Major refactoring based on review feedback:
* Removed has_event and renamed poll_idle_timeout to last_dispatch_timestamp from AioHandler structure to identify active handlers.
* Merged grow_polling_time() and shrink_polling_time() into single adjust_polling_time() function to simplify code review, with no functional changes.
* Renamed adjust_block_ns() to update_handler_poll_times()
* Modified remove_idle_poll_handlers() to use last_dispatch_timestamp directly instead of checking poll_idle_timeout
* Updated commit message
- Patch 3/3: Enhanced parameter handling:
* Moved IOTHREAD_POLL_*_DEFAULT constants to iothread.h header
* Added validation for poll-weight range [0, 63] in iothread.c
* Added the divide-by-0 protection in aio_context_set_poll_params()
* Updated QAPI version from 10.2 to 11.1
* Enhanced qom.json documentation for poll-weight values
This series reduces CPU usage in aio_poll adaptive polling by ~10% with minimal throughput impact (~2%). Tested on s390x with various workloads.
Testing details:
Initial testing (Fedora 42, 16 virtio-blk devices, FCP multipath):
- Throughput: -3% to -8% (1 iothread), -2% to -5% (2 iothreads)
- CPU usage: -10% to -25% (1 iothread), -7% to -12% (2 iothreads)
Additional validation (RHEL 10.1 + QEMU 10.0.0, FCP/FICON, 1-8 iothreads):
- Throughput: -2.2% (weight=3), -2.4% (weight=2)
- CPU usage: -9.4% (weight=3), -10.9% (weight=2)
Weight=3 selected for slightly better throughput while maintaining substantial CPU savings.
Best regards,
Jaehoon Kim
Jaehoon Kim (3):
aio-poll: avoid unnecessary polling time computation
aio-poll: refine iothread polling using weighted handler intervals qapi/iothread: introduce poll-weight parameter for aio-poll
include/qemu/aio.h | 7 +- include/system/iothread.h | 18 ++++ iothread.c | 47 +++++++--- monitor/hmp-cmds.c | 1 + qapi/misc.json | 6 ++ qapi/qom.json | 10 +- qemu-options.hx | 8 +- tests/unit/test-nested-aio-poll.c | 2 +- util/aio-posix.c | 148 ++++++++++++++++++------------ util/aio-posix.h | 2 +- util/aio-win32.c | 3 +- util/async.c | 2 + 12 files changed, 176 insertions(+), 78 deletions(-)
Signature · 1 line
2.50.1
PATCH v5 1/3 aio-poll: avoid unnecessary polling time computation
Nodes are no longer added to poll_aio_handlers when adaptive polling is disabled, preventing unnecessary try_poll_mode() calls. This avoids iterating over all nodes to compute max_ns unnecessarily when polling is disabled.
--- util/aio-posix.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
util/aio-posix.c +6 -5
@@ -307,9 +307,8 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHandler *node)* fdmon_supports_polling(), but only until the fd fires for the first * time. */ -if (!QLIST_IS_INSERTED (node, node_deleted) && - !QLIST_IS_INSERTED (node, node_poll) && - node->io_poll) { +if (ctx->poll_max_ns && !QLIST_IS_INSERTED (node, node_deleted) && + !QLIST_IS_INSERTED (node, node_poll) && node->io_poll) {trace_poll_add (ctx, node, node->pfd.fd, revents);if (ctx->poll_started && node->io_poll_begin) { node->io_poll_begin (node->opaque);
@@ -631,7 +630,7 @@ static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll,bool aio_poll (AioContext *ctx,bool blocking) {AioHandlerList ready_list =QLIST_HEAD_INITIALIZER (ready_list); -bool progress; +bool progress = false;bool use_notify_me;int64_t timeout;int64_t start =0 ;
@@ -656,7 +655,9 @@ bool aio_poll(AioContext *ctx, bool blocking) } timeout = blocking ?aio_compute_timeout (ctx) :0 ; - progress =try_poll_mode (ctx, &ready_list, &timeout); +if (ctx->poll_max_ns !=0 ) { + progress =try_poll_mode (ctx, &ready_list, &timeout); + }assert (!(timeout && progress));/*
Signature · 1 line
2.50.1
PATCH v5 2/3 aio-poll: refine iothread polling using weighted handler intervals
In reply to Jaehoon KimImprove adaptive polling by updating each AioHandler's poll.ns every loop iteration using weighted averages. This reduces CPU consumption while minimizing performance impact.
Background:
Starting from QEMU 10.0, poll.ns was introduced per event handler to mitigate excessive fluctuations in IOThread polling times observed in earlier versions (QEMU 9.x). However, the current design has limitations:
1. poll.ns is updated only when an event occurs, making it difficult to treat block_ns as a reliable event interval.
2. The IOThread's next polling time is determined by the maximum poll.ns among all AioHandlers, meaning idle AioHandlers with high poll.ns can have an outsized impact on polling duration.
3. For io_uring, idle AioHandlers are cleared after POLL_IDLE_INTERVAL_NS (7s), but for ppoll/epoll there is no such mechanism, leading to increased CPU consumption from idle nodes.
Implementation:
This patch treats block_ns as an event interval and updates each AioHandler's poll.ns in every loop iteration:
- Active handlers (with events): poll.ns is updated using a weighted average of the current block_ns and previous poll.ns, smoothing out adjustments and preventing excessive fluctuations.
- Inactive handlers (no events): poll.ns accumulates block_ns without weighting, allowing rapid isolation of idle nodes. When poll.ns exceeds poll_max_ns, it resets to 0, preventing sporadically active handlers from unnecessarily prolonging iothread polling.
- The iothread polling duration is set based on the largest poll.ns among active handlers. The shrink divider defaults to 2, matching the grow rate, to reduce frequent poll_ns resets for slow devices.
The implementation renames poll_idle_timeout to last_dispatch_timestamp for use as an active handler identifier.
Testing:
POLL_WEIGHT_SHIFT=3 (12.5% weight) was selected based on testing comparing baseline vs weight=2/3 across various workloads:
Performance results (RHEL 10.1 + QEMU 10.0.0, FCP/FICON, 1-8 iothreads, numjobs 1/4/8 averaged):
| poll-weight=2 | poll-weight=3 --------------------|--------------------|----------------- Throughput avg | -2.4% (all tests) | -2.2% (all tests) CPU consumption avg | -10.9% (all tests) | -9.4% (all tests)
Both configurations achieve ~10% CPU reduction with minimal throughput impact (~2%). Weight=3 is chosen as default for slightly better throughput while maintaining substantial CPU savings.
Additional validation testing on s390x SSD with fio (bs=8k, iodepth=8, numjobs=1) shows how poll_weight affects polling time (poll.ns) behavior:
RandRead workload:
+-------------+-----------+-----------+-------------+-------------+ | poll_weight | #samples | Mean (ns) | 50th % (ns) | 90th % (ns) | +-------------+-----------+-----------+-------------+-------------+ | 1 | 4.79M | 8,034 | 5,116 | 20,509 | | 2 | 5.01M | 12,584 | 11,078 | 24,693 | | 3 | 5.01M | 15,647 | 14,863 | 28,695 | | 4 | 5.12M | 16,430 | 15,556 | 30,848 | | 5 | 5.14M | 16,461 | 15,306 | 32,123 | +-------------+-----------+-----------+-------------+-------------+ RandWrite workload: +-------------+-----------+-----------+-------------+-------------+ | poll_weight | #samples | Mean (ns) | 50th % (ns) | 90th % (ns) | +-------------+-----------+-----------+-------------+-------------+ | 1 | 6.37M | 2,049 | 1,262 | 4,301 | | 2 | 7.46M | 4,118 | 3,226 | 7,476 | | 3 | 7.97M | 7,034 | 5,984 | 11,645 | | 4 | 7.96M | 12,789 | 11,362 | 20,040 | | 5 | 7.82M | 22,992 | 20,644 | 32,768 | +-------------+-----------+-----------+-------------+-------------+
--- include/qemu/aio.h | 3 +- util/aio-posix.c | 130 ++++++++++++++++++++++++++++++--------------- util/aio-posix.h | 2 +- util/async.c | 1 + 4 files changed, 90 insertions(+), 46 deletions(-)
include/qemu/aio.h +2 -1
@@ -195,7 +195,7 @@ struct BHListSlice { typedef QSLIST_HEAD(, AioHandler) AioHandlerSList;typedef struct AioPolledEvent { -int64_t ns;/* current polling time in nanoseconds */ +int64_t ns;/* estimated block time in nanoseconds */ }AioPolledEvent ;struct AioContext {
@@ -306,6 +306,7 @@ struct AioContext {int poll_disable_cnt;/* Polling mode parameters */ +int64_t poll_ns;/* current polling time in nanoseconds */ int64_t poll_max_ns;/* maximum polling time in nanoseconds */ int64_t poll_grow;/* polling time growth factor */ int64_t poll_shrink;/* polling time shrink factor */
util/aio-posix.c +86 -44
230 lines not on this page · raw message
util/aio-posix.h +1 -1
@@ -38,7 +38,7 @@ struct AioHandler {unsigned flags;/* see fdmon-io_uring.c */ CqeHandler internal_cqe_handler;/* used for POLL_ADD/POLL_REMOVE */ #endif -int64_t poll_idle_timeout;/* when to stop userspace polling */ +int64_t last_dispatch_timestamp;/* when last handler was dispatched */ bool poll_ready;/* has polling detected an event? */ AioPolledEvent poll; };
util/async.c +1 -0
@@ -606,6 +606,7 @@ AioContext *aio_context_new(Error **errp)timerlistgroup_init (&ctx->tlg, aio_timerlist_notify, ctx); ctx->poll_max_ns =0 ; + ctx->poll_ns =0 ; ctx->poll_grow =0 ; ctx->poll_shrink =0 ;
Signature · 1 line
2.50.1
PATCH v5 3/3 qapi/iothread: introduce poll-weight parameter for aio-poll
In reply to Jaehoon KimIntroduce 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.
--- include/qemu/aio.h | 4 ++- include/system/iothread.h | 18 ++++++++++++ iothread.c | 47 ++++++++++++++++++++++--------- monitor/hmp-cmds.c | 1 + qapi/misc.json | 6 ++++ qapi/qom.json | 10 ++++++- qemu-options.hx | 8 +++++- tests/unit/test-nested-aio-poll.c | 2 +- util/aio-posix.c | 37 +++++++++--------------- util/aio-win32.c | 3 +- util/async.c | 1 + 11 files changed, 95 insertions(+), 42 deletions(-)
include/qemu/aio.h +3 -1
@@ -310,6 +310,7 @@ struct AioContext {int64_t poll_max_ns;/* maximum polling time in nanoseconds */ int64_t poll_grow;/* polling time growth factor */ int64_t poll_shrink;/* polling time shrink factor */ +int64_t poll_weight;/* weight of current interval in calculation */ /* AIO engine parameters */ int64_t aio_max_batch;/* maximum number of requests in a batch */
@@ -791,12 +792,13 @@ void aio_context_destroy(AioContext *ctx);* @max_ns: how long to busy poll for, in nanoseconds * @grow: polling time growth factor * @shrink: polling time shrink factor +* @weight: weight factor applied to the current polling interval * * Poll mode can be disabled by setting poll_max_ns to 0. */ void aio_context_set_poll_params (AioContext *ctx,int64_t max_ns,int64_t grow,int64_t shrink, -Error **errp); +int64_t weight,Error **errp);/** * aio_context_set_aio_params:
include/system/iothread.h +18 -0
@@ -21,6 +21,23 @@#define TYPE_IOTHREAD "iothread" +#ifdef CONFIG_POSIX +/* +* Benchmark results from 2016 on NVMe SSD drives show max polling times around +* 16-32 microseconds yield IOPS improvements for both iodepth=1 and iodepth=32 +* workloads. +*/ +#define IOTHREAD_POLL_MAX_NS_DEFAULT 32768ULL +#define IOTHREAD_POLL_GROW_DEFAULT 2ULL +#define IOTHREAD_POLL_SHRINK_DEFAULT 2ULL +#define IOTHREAD_POLL_WEIGHT_DEFAULT 3ULL +#else +#define IOTHREAD_POLL_MAX_NS_DEFAULT 0ULL +#define IOTHREAD_POLL_GROW_DEFAULT 0ULL +#define IOTHREAD_POLL_SHRINK_DEFAULT 0ULL +#define IOTHREAD_POLL_WEIGHT_DEFAULT 0ULL +#endif +struct IOThread {EventLoopBase parent_obj;
@@ -38,6 +55,7 @@ struct IOThread {int64_t poll_max_ns;int64_t poll_grow;int64_t poll_shrink; +int64_t poll_weight; };typedef struct IOThread IOThread ;
iothread.c +34 -13
100 lines not on this page · raw message
monitor/hmp-cmds.c +1 -0
@@ -206,6 +206,7 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)monitor_printf (mon," poll-max-ns=%" PRId64"\n" , value->poll_max_ns);monitor_printf (mon," poll-grow=%" PRId64"\n" , value->poll_grow);monitor_printf (mon," poll-shrink=%" PRId64"\n" , value->poll_shrink); +monitor_printf (mon," poll-weight=%" PRId64"\n" , value->poll_weight);monitor_printf (mon," aio-max-batch=%" PRId64"\n" , value->aio_max_batch); }
qapi/misc.json +6 -0
@@ -85,6 +85,11 @@ # @poll-shrink: how many ns will be removed from polling time, 0 means # that it's not configured (since 2.9) # +# @poll-weight: the weight factor for adaptive polling. +# Determines how much the current event interval contributes to +# the next polling time calculation. Valid values are 1 or +# greater (since 11.1) +# # @aio-max-batch: maximum number of requests in a batch for the AIO # engine, 0 means that the engine will use its default (since 6.1) #
@@ -96,6 +101,7 @@ 'poll-max-ns': 'int', 'poll-grow': 'int', 'poll-shrink': 'int', + 'poll-weight': 'int', 'aio-max-batch': 'int' } } ##
qapi/qom.json +9 -1
@@ -606,6 +606,13 @@ # algorithm detects it is spending too long polling without # encountering events. 0 selects a default behaviour (default: 0) # +# @poll-weight: the weight factor for adaptive polling. Determines +# how much the most recent event interval affects the next +# polling duration calculation. If set to 0, the system default +# value of 3 is used. Typical values: 1 (high weight on recent +# interval), 2-4 (moderate weight on recent interval). +# (default: 0) (since 11.1) +# # The @aio-max-batch option is available since 6.1. # # Since: 2.0
@@ -614,7 +621,8 @@ 'base': 'EventLoopBaseProperties', 'data': { '*poll-max-ns': 'int', '*poll-grow': 'int', - '*poll-shrink': 'int' } } + '*poll-shrink': 'int', + '*poll-weight': 'int' } } ## # @MainLoopProperties:
qemu-options.hx +7 -1
@@ -6443,7 +6443,7 @@ SRST CN=laptop.example.com,O=Example Home,L=London,ST=London,C=GB - ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch`` + ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,poll-weight=poll-weight,aio-max-batch=aio-max-batch`` Creates a dedicated event loop thread that devices can be assigned to. This is known as an IOThread. By default device emulation happens in vCPU threads or the main event loop thread.
@@ -6479,6 +6479,12 @@ SRST the polling time when the algorithm detects it is spending too long polling without encountering events. + The ``poll-weight`` parameter is the weight factor for adaptive + polling. It determines how much the most recent event interval + affects the next polling duration calculation. If set to 0, the + system default value of 3 is used. Typical values: 1 (high weight + on recent interval), 2-4 (moderate weight on recent interval). + The ``aio-max-batch`` parameter is the maximum number of requests in a batch for the AIO engine, 0 means that the engine will use its default.
tests/unit/test-nested-aio-poll.c +1 -1
@@ -81,7 +81,7 @@ static void test(void)qemu_set_current_aio_context (td.ctx);/* Enable polling */ -aio_context_set_poll_params (td.ctx,1000000 ,2 ,2 , &error_abort); +aio_context_set_poll_params (td.ctx,1000000 ,2 ,2 ,3 , &error_abort);/* Make the event notifier active (set) right away */ event_notifier_init (&td.poll_notifier,1 );
util/aio-posix.c +13 -24
@@ -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);
util/aio-win32.c +2 -1
@@ -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" );
util/async.c +1 -0
@@ -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 ;
Signature · 1 line
2.50.1
Re: [PATCH v5 3/3] qapi/iothread: introduce poll-weight parameter for aio-poll
Quoted 11 lines · Jaehoon Kim
Introduce a configurable poll-weight parameter for adaptive polling in IOThread. This parameter replaces the hardcoded
POLL_WEIGHT_SHIFTconstant, 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).
Quoted 7 lines
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 iniothread.cduring IOThread creation.Signed-off-by Jaehoon Kim <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>
QAPI schema
Stefan Hajnoczi
AppliedQuoted 76 lines · Jaehoon Kim
Dear all,
This is v5 of the patch series to refine
aio_polladaptive polling logic for better CPU efficiency.v1: https://lore.kernel.org/qemu-devel/[email protected]/
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v3: https://lore.kernel.org/qemu-devel/[email protected]/
v4: https://lore.kernel.org/qemu-devel/[email protected]/Changes in v5:
- Patch 3/3: Fixed QAPI documentation based on review feedback:
*qapi/misc.json: Removed the sentence about returning poll-weight=0 since query-iothreads never returns 0 for this field.
* qemu-options.hx: Enhanced poll-weight parameter documentation to match the detail level in qom.json, including information about default value and typical value examples.Changes in v4:
- Patch 2/3: Added detailed validation tables showing poll.ns statistics across differentpoll_weightvalues (1-5) for SSD randread/randwrite workloads to demonstrate algorithm behavior and justify poll_weight=3 as the optimal default.- Patch 3/3: Fixed commit message to correctly reference
adjust_polling_time()instead of the removedgrow_polling_time()andshrink_polling_time()functions from v2.Changes in v3:
- Patch 1/3: Removed timeout check inaio_poll()as suggested by Stefan Hajnoczi.- Patch 2/3: Major refactoring based on review feedback:
* Removedhas_eventand renamedpoll_idle_timeouttolast_dispatch_timestampfrom AioHandler structure to identify active handlers.
* Mergedgrow_polling_time()andshrink_polling_time()into singleadjust_polling_time()function to simplify code review, with no functional changes.
* Renamedadjust_block_ns()toupdate_handler_poll_times()
* Modifiedremove_idle_poll_handlers()to uselast_dispatch_timestampdirectly instead of checkingpoll_idle_timeout
* Updated commit message- Patch 3/3: Enhanced parameter handling:
* Moved IOTHREAD_POLL_*_DEFAULT constants toiothread.hheader
* Added validation for poll-weight range [0, 63] iniothread.c
* Added the divide-by-0 protection inaio_context_set_poll_params()
* Updated QAPI version from 10.2 to 11.1
* Enhanced qom.json documentation for poll-weight valuesThis series reduces CPU usage in
aio_polladaptive polling by ~10% with minimal throughput impact (~2%). Tested on s390x with various workloads.Testing details:
Initial testing (Fedora 42, 16 virtio-blk devices, FCP multipath):
- Throughput: -3% to -8% (1 iothread), -2% to -5% (2 iothreads)
- CPU usage: -10% to -25% (1 iothread), -7% to -12% (2 iothreads)Additional validation (RHEL 10.1 + QEMU 10.0.0, FCP/FICON, 1-8 iothreads):
- Throughput: -2.2% (weight=3), -2.4% (weight=2)
- CPU usage: -9.4% (weight=3), -10.9% (weight=2)Weight=3 selected for slightly better throughput while maintaining substantial CPU savings.
Best regards,
Jaehoon KimJaehoon Kim (3):
aio-poll: avoid unnecessary polling time computation
aio-poll: refine iothread polling using weighted handler intervals qapi/iothread: introduce poll-weight parameter for aio-poll
Quoted 17 lines
include/qemu/aio.h | 7 +- include/system/iothread.h | 18 ++++ iothread.c | 47 +++++++--- monitor/hmp-cmds.c | 1 + qapi/misc.json | 6 ++ qapi/qom.json | 10 +- qemu-options.hx | 8 +- tests/unit/test-nested-aio-poll.c | 2 +- util/aio-posix.c | 148 ++++++++++++++++++------------ util/aio-posix.h | 2 +- util/aio-win32.c | 3 +- util/async.c | 2 + 12 files changed, 176 insertions(+), 78 deletions(-)Signature · 1 line
2.50.1
Thanks, applied to my block tree:
https://gitlab.com/stefanha/qemu/commits/block
Stefan