Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2230452/?format=api
{ "id": 2230452, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2230452/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260429182127.219776-3-stefanha@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.1/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260429182127.219776-3-stefanha@redhat.com>", "date": "2026-04-29T18:21:26", "name": "[PULL,2/3] aio-poll: refine iothread polling using weighted handler intervals", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "c4615fbbd9a9fff9d4d86b8d441f890c2e5d9be2", "submitter": { "id": 17227, "url": "http://patchwork.ozlabs.org/api/1.1/people/17227/?format=api", "name": "Stefan Hajnoczi", "email": "stefanha@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260429182127.219776-3-stefanha@redhat.com/mbox/", "series": [ { "id": 502128, "url": "http://patchwork.ozlabs.org/api/1.1/series/502128/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=502128", "date": "2026-04-29T18:21:24", "name": "[PULL,1/3] aio-poll: avoid unnecessary polling time computation", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/502128/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2230452/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2230452/checks/", "tags": {}, "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Az7pa3V7;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g5Qcy2DL2z1yKJ\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 30 Apr 2026 04:22:10 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wI9Xs-0002fp-Od; Wed, 29 Apr 2026 14:22:01 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <stefanha@redhat.com>)\n id 1wI9Xk-0002dY-Iq\n for qemu-devel@nongnu.org; Wed, 29 Apr 2026 14:21:53 -0400", "from us-smtp-delivery-124.mimecast.com ([170.10.133.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <stefanha@redhat.com>)\n id 1wI9Xd-0003hz-Pm\n for qemu-devel@nongnu.org; Wed, 29 Apr 2026 14:21:48 -0400", "from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-484-vmZs4b_SM_mkATI4zAmauQ-1; Wed,\n 29 Apr 2026 14:21:42 -0400", "from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id D0E3F18002CA; Wed, 29 Apr 2026 18:21:40 +0000 (UTC)", "from localhost (unknown [10.44.33.46])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 90CA41800480; Wed, 29 Apr 2026 18:21:38 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1777486904;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=iXB5hgY0R41Sv4TSwA9HHxO+9wz/jng/A3ubUblAZ5o=;\n b=Az7pa3V7NsE4s8JdgvN0SqeC4OdjVJB/du07HEtRGqBLp3o8qe4WorAQ6zM+Z0VTsSK02l\n 3hp9foDTKjpDKXqoY2170cjCDak0nTX8QmwooHFyq4ue3rjnjsxbw8qQ4JE3fKPwiZXr8m\n vYI4A6XSmqq4msspv7ADv+JJEqJl1SE=", "X-MC-Unique": "vmZs4b_SM_mkATI4zAmauQ-1", "X-Mimecast-MFC-AGG-ID": "vmZs4b_SM_mkATI4zAmauQ_1777486900", "From": "Stefan Hajnoczi <stefanha@redhat.com>", "To": "qemu-devel@nongnu.org", "Cc": "Stefan Weil <sw@weilnetz.de>, Hanna Reitz <hreitz@redhat.com>,\n Peter Maydell <peter.maydell@linaro.org>, Kevin Wolf <kwolf@redhat.com>,\n Markus Armbruster <armbru@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>,\n qemu-block@nongnu.org, \"Dr. David Alan Gilbert\" <dave@treblig.org>,\n Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>,\n \"Michael S. Tsirkin\" <mst@redhat.com>,\n =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= <berrange@redhat.com>,\n Eric Blake <eblake@redhat.com>, Jaehoon Kim <jhkim@linux.ibm.com>", "Subject": "[PULL 2/3] aio-poll: refine iothread polling using weighted handler\n intervals", "Date": "Wed, 29 Apr 2026 14:21:26 -0400", "Message-ID": "<20260429182127.219776-3-stefanha@redhat.com>", "In-Reply-To": "<20260429182127.219776-1-stefanha@redhat.com>", "References": "<20260429182127.219776-1-stefanha@redhat.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.93", "Received-SPF": "pass client-ip=170.10.133.124;\n envelope-from=stefanha@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com", "X-Spam_score_int": "-20", "X-Spam_score": "-2.1", "X-Spam_bar": "--", "X-Spam_report": "(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no", "X-Spam_action": "no action", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "qemu development <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "From: Jaehoon Kim <jhkim@linux.ibm.com>\n\nImprove adaptive polling by updating each AioHandler's poll.ns\nevery loop iteration using weighted averages. This reduces CPU\nconsumption while minimizing performance impact.\n\nBackground:\nStarting from QEMU 10.0, poll.ns was introduced per event handler\nto mitigate excessive fluctuations in IOThread polling times\nobserved in earlier versions (QEMU 9.x). However, the current\ndesign has limitations:\n\n1. poll.ns is updated only when an event occurs, making it\n difficult to treat block_ns as a reliable event interval.\n2. The IOThread's next polling time is determined by the maximum\n poll.ns among all AioHandlers, meaning idle AioHandlers with\n high poll.ns can have an outsized impact on polling duration.\n3. For io_uring, idle AioHandlers are cleared after\n POLL_IDLE_INTERVAL_NS (7s), but for ppoll/epoll there is no\n such mechanism, leading to increased CPU consumption from idle\n nodes.\n\nImplementation:\nThis patch treats block_ns as an event interval and updates each\nAioHandler's poll.ns in every loop iteration:\n\n- Active handlers (with events): poll.ns is updated using a\n weighted average of the current block_ns and previous poll.ns,\n smoothing out adjustments and preventing excessive fluctuations.\n- Inactive handlers (no events): poll.ns accumulates block_ns\n without weighting, allowing rapid isolation of idle nodes. When\n poll.ns exceeds poll_max_ns, it resets to 0, preventing\n sporadically active handlers from unnecessarily prolonging\n iothread polling.\n- The iothread polling duration is set based on the largest poll.ns\n among active handlers. The shrink divider defaults to 2, matching\n the grow rate, to reduce frequent poll_ns resets for slow devices.\n\nThe implementation renames poll_idle_timeout to last_dispatch_timestamp\nfor use as an active handler identifier.\n\nTesting:\nPOLL_WEIGHT_SHIFT=3 (12.5% weight) was selected based on testing\ncomparing baseline vs weight=2/3 across various workloads:\nPerformance results (RHEL 10.1 + QEMU 10.0.0, FCP/FICON, 1-8 iothreads,\nnumjobs 1/4/8 averaged):\n | poll-weight=2 | poll-weight=3\n--------------------|--------------------|-----------------\nThroughput avg | -2.4% (all tests) | -2.2% (all tests)\nCPU consumption avg | -10.9% (all tests) | -9.4% (all tests)\n\nBoth configurations achieve ~10% CPU reduction with minimal throughput\nimpact (~2%). Weight=3 is chosen as default for slightly better\nthroughput while maintaining substantial CPU savings.\n\nAdditional validation testing on s390x SSD with fio (bs=8k, iodepth=8,\nnumjobs=1) shows how poll_weight affects polling time (poll.ns)\nbehavior:\n\nRandRead workload:\n+-------------+-----------+-----------+-------------+-------------+\n| poll_weight | #samples | Mean (ns) | 50th % (ns) | 90th % (ns) |\n+-------------+-----------+-----------+-------------+-------------+\n| 1 | 4.79M | 8,034 | 5,116 | 20,509 |\n| 2 | 5.01M | 12,584 | 11,078 | 24,693 |\n| 3 | 5.01M | 15,647 | 14,863 | 28,695 |\n| 4 | 5.12M | 16,430 | 15,556 | 30,848 |\n| 5 | 5.14M | 16,461 | 15,306 | 32,123 |\n+-------------+-----------+-----------+-------------+-------------+\nRandWrite workload:\n+-------------+-----------+-----------+-------------+-------------+\n| poll_weight | #samples | Mean (ns) | 50th % (ns) | 90th % (ns) |\n+-------------+-----------+-----------+-------------+-------------+\n| 1 | 6.37M | 2,049 | 1,262 | 4,301 |\n| 2 | 7.46M | 4,118 | 3,226 | 7,476 |\n| 3 | 7.97M | 7,034 | 5,984 | 11,645 |\n| 4 | 7.96M | 12,789 | 11,362 | 20,040 |\n| 5 | 7.82M | 22,992 | 20,644 | 32,768 |\n+-------------+-----------+-----------+-------------+-------------+\n\nSigned-off-by: Jaehoon Kim <jhkim@linux.ibm.com>\nMessage-ID: <20260423195918.661299-3-jhkim@linux.ibm.com>\nSigned-off-by: Stefan Hajnoczi <stefanha@redhat.com>\n---\n include/qemu/aio.h | 3 +-\n util/aio-posix.h | 2 +-\n util/aio-posix.c | 128 ++++++++++++++++++++++++++++++---------------\n util/async.c | 1 +\n 4 files changed, 89 insertions(+), 45 deletions(-)", "diff": "diff --git a/include/qemu/aio.h b/include/qemu/aio.h\nindex 8cca2360d1..6c22064a28 100644\n--- a/include/qemu/aio.h\n+++ b/include/qemu/aio.h\n@@ -195,7 +195,7 @@ struct BHListSlice {\n typedef QSLIST_HEAD(, AioHandler) AioHandlerSList;\n \n typedef struct AioPolledEvent {\n- int64_t ns; /* current polling time in nanoseconds */\n+ int64_t ns; /* estimated block time in nanoseconds */\n } AioPolledEvent;\n \n struct AioContext {\n@@ -306,6 +306,7 @@ struct AioContext {\n int poll_disable_cnt;\n \n /* Polling mode parameters */\n+ int64_t poll_ns; /* current polling time in nanoseconds */\n int64_t poll_max_ns; /* maximum polling time in nanoseconds */\n int64_t poll_grow; /* polling time growth factor */\n int64_t poll_shrink; /* polling time shrink factor */\ndiff --git a/util/aio-posix.h b/util/aio-posix.h\nindex ab894a3c0f..cd459bbbae 100644\n--- a/util/aio-posix.h\n+++ b/util/aio-posix.h\n@@ -38,7 +38,7 @@ struct AioHandler {\n unsigned flags; /* see fdmon-io_uring.c */\n CqeHandler internal_cqe_handler; /* used for POLL_ADD/POLL_REMOVE */\n #endif\n- int64_t poll_idle_timeout; /* when to stop userspace polling */\n+ int64_t last_dispatch_timestamp; /* when last handler was dispatched */\n bool poll_ready; /* has polling detected an event? */\n AioPolledEvent poll;\n };\ndiff --git a/util/aio-posix.c b/util/aio-posix.c\nindex 351847c6fb..8e9e9e5d8f 100644\n--- a/util/aio-posix.c\n+++ b/util/aio-posix.c\n@@ -29,9 +29,11 @@\n \n /* Stop userspace polling on a handler if it isn't active for some time */\n #define POLL_IDLE_INTERVAL_NS (7 * NANOSECONDS_PER_SECOND)\n+#define POLL_WEIGHT_SHIFT (3)\n \n-static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll,\n- int64_t block_ns);\n+static void update_handler_poll_times(AioContext *ctx, int64_t block_ns,\n+ int64_t dispatch_time);\n+static void adjust_polling_time(AioContext *ctx, int64_t block_ns);\n \n bool aio_poll_disabled(AioContext *ctx)\n {\n@@ -359,7 +361,7 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHandler *node)\n \n static bool aio_dispatch_ready_handlers(AioContext *ctx,\n AioHandlerList *ready_list,\n- int64_t block_ns)\n+ int64_t dispatch_time)\n {\n bool progress = false;\n AioHandler *node;\n@@ -369,11 +371,11 @@ static bool aio_dispatch_ready_handlers(AioContext *ctx,\n progress = aio_dispatch_handler(ctx, node) || progress;\n \n /*\n- * Adjust polling time only after aio_dispatch_handler(), which can\n- * add the handler to ctx->poll_aio_handlers.\n+ * Update last_dispatch_timestamp to mark this as an active\n+ * handler for polling time adjustment and prevent idle removal.\n */\n if (ctx->poll_max_ns && QLIST_IS_INSERTED(node, node_poll)) {\n- adjust_polling_time(ctx, &node->poll, block_ns);\n+ node->last_dispatch_timestamp = dispatch_time;\n }\n }\n \n@@ -394,7 +396,7 @@ void aio_dispatch(AioContext *ctx)\n ctx->fdmon_ops->dispatch(ctx);\n }\n \n- /* block_ns is 0 because polling is disabled in the glib event loop */\n+ /* Set now to 0 as polling is disabled in the glib event loop */\n aio_dispatch_ready_handlers(ctx, &ready_list, 0);\n \n aio_free_deleted_handlers(ctx);\n@@ -415,9 +417,6 @@ static bool run_poll_handlers_once(AioContext *ctx,\n QLIST_FOREACH_SAFE(node, &ctx->poll_aio_handlers, node_poll, tmp) {\n if (node->io_poll(node->opaque)) {\n aio_add_poll_ready_handler(ready_list, node);\n-\n- node->poll_idle_timeout = now + POLL_IDLE_INTERVAL_NS;\n-\n /*\n * Polling was successful, exit try_poll_mode immediately\n * to adjust the next polling time.\n@@ -458,11 +457,10 @@ static bool remove_idle_poll_handlers(AioContext *ctx,\n }\n \n QLIST_FOREACH_SAFE(node, &ctx->poll_aio_handlers, node_poll, tmp) {\n- if (node->poll_idle_timeout == 0LL) {\n- node->poll_idle_timeout = now + POLL_IDLE_INTERVAL_NS;\n- } else if (now >= node->poll_idle_timeout) {\n+ if (node->poll_ready == false &&\n+ now >= node->last_dispatch_timestamp + POLL_IDLE_INTERVAL_NS) {\n trace_poll_remove(ctx, node, node->pfd.fd);\n- node->poll_idle_timeout = 0LL;\n+ node->last_dispatch_timestamp = 0LL;\n QLIST_SAFE_REMOVE(node, node_poll);\n if (ctx->poll_started && node->io_poll_end) {\n node->io_poll_end(node->opaque);\n@@ -560,18 +558,13 @@ static bool run_poll_handlers(AioContext *ctx, AioHandlerList *ready_list,\n static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list,\n int64_t *timeout)\n {\n- AioHandler *node;\n int64_t max_ns;\n \n if (QLIST_EMPTY_RCU(&ctx->poll_aio_handlers)) {\n return false;\n }\n \n- max_ns = 0;\n- QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) {\n- max_ns = MAX(max_ns, node->poll.ns);\n- }\n- max_ns = qemu_soonest_timeout(*timeout, max_ns);\n+ max_ns = qemu_soonest_timeout(*timeout, ctx->poll_ns);\n \n if (max_ns && !ctx->fdmon_ops->need_wait(ctx)) {\n /*\n@@ -587,43 +580,85 @@ static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list,\n return false;\n }\n \n-static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll,\n- int64_t block_ns)\n+static void adjust_polling_time(AioContext *ctx, int64_t block_ns)\n {\n- if (block_ns <= poll->ns) {\n- /* This is the sweet spot, no adjustment needed */\n- } else if (block_ns > ctx->poll_max_ns) {\n- /* We'd have to poll for too long, poll less */\n- int64_t old = poll->ns;\n+ if (block_ns < ctx->poll_ns) {\n+ int64_t old = ctx->poll_ns;\n+ int64_t shrink = ctx->poll_shrink;\n \n- if (ctx->poll_shrink) {\n- poll->ns /= ctx->poll_shrink;\n- } else {\n- poll->ns = 0;\n+ if (shrink == 0) {\n+ shrink = 2;\n }\n \n- trace_poll_shrink(ctx, old, poll->ns);\n- } else if (poll->ns < ctx->poll_max_ns &&\n- block_ns < ctx->poll_max_ns) {\n+ if (block_ns < (ctx->poll_ns / shrink)) {\n+ ctx->poll_ns /= shrink;\n+ }\n+\n+ trace_poll_shrink(ctx, old, ctx->poll_ns);\n+ } else if (block_ns > ctx->poll_ns) {\n /* There is room to grow, poll longer */\n- int64_t old = poll->ns;\n+ int64_t old = ctx->poll_ns;\n int64_t grow = ctx->poll_grow;\n \n if (grow == 0) {\n grow = 2;\n }\n \n- if (poll->ns) {\n- poll->ns *= grow;\n+ if (block_ns > ctx->poll_ns * grow) {\n+ ctx->poll_ns = block_ns;\n } else {\n- poll->ns = 4000; /* start polling at 4 microseconds */\n+ ctx->poll_ns *= grow;\n }\n \n- if (poll->ns > ctx->poll_max_ns) {\n- poll->ns = ctx->poll_max_ns;\n+ if (ctx->poll_ns > ctx->poll_max_ns) {\n+ ctx->poll_ns = ctx->poll_max_ns;\n }\n \n- trace_poll_grow(ctx, old, poll->ns);\n+ trace_poll_grow(ctx, old, ctx->poll_ns);\n+ }\n+}\n+\n+static void update_handler_poll_times(AioContext *ctx, int64_t block_ns,\n+ int64_t dispatch_time)\n+{\n+ AioHandler *node;\n+ int64_t max_poll_ns = -1;\n+\n+ QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) {\n+ if (node->last_dispatch_timestamp == dispatch_time) {\n+ /*\n+ * Active handler: had an event in this aio_poll() call.\n+ * Update poll.ns using a weighted average of the current\n+ * block_ns and previous poll.ns to smooth adjustments.\n+ */\n+ node->poll.ns = node->poll.ns\n+ ? (node->poll.ns - (node->poll.ns >> POLL_WEIGHT_SHIFT))\n+ + (block_ns >> POLL_WEIGHT_SHIFT) : block_ns;\n+\n+ if (node->poll.ns > ctx->poll_max_ns) {\n+ node->poll.ns = 0;\n+ }\n+ /*\n+ * Track the maximum poll.ns among active handlers to\n+ * calculate the next polling time.\n+ */\n+ max_poll_ns = MAX(max_poll_ns, node->poll.ns);\n+ } else {\n+ /*\n+ * Inactive handler: no event in this aio_poll() call but\n+ * was active before. Increase poll.ns by block_ns. If it\n+ * exceeds poll_max_ns, reset to 0 until next event.\n+ */\n+ if (node->poll.ns != 0) {\n+ node->poll.ns += block_ns;\n+ if (node->poll.ns > ctx->poll_max_ns) {\n+ node->poll.ns = 0;\n+ }\n+ }\n+ }\n+ }\n+ if (max_poll_ns >= 0) {\n+ adjust_polling_time(ctx, max_poll_ns);\n }\n }\n \n@@ -635,6 +670,7 @@ bool aio_poll(AioContext *ctx, bool blocking)\n int64_t timeout;\n int64_t start = 0;\n int64_t block_ns = 0;\n+ int64_t dispatch_ns = 0;\n \n /*\n * There cannot be two concurrent aio_poll calls for the same AioContext (or\n@@ -711,7 +747,8 @@ bool aio_poll(AioContext *ctx, bool blocking)\n \n /* Calculate blocked time for adaptive polling */\n if (ctx->poll_max_ns) {\n- block_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - start;\n+ dispatch_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);\n+ block_ns = dispatch_ns - start;\n }\n \n if (ctx->fdmon_ops->dispatch) {\n@@ -719,10 +756,14 @@ bool aio_poll(AioContext *ctx, bool blocking)\n }\n \n progress |= aio_bh_poll(ctx);\n- progress |= aio_dispatch_ready_handlers(ctx, &ready_list, block_ns);\n+ progress |= aio_dispatch_ready_handlers(ctx, &ready_list, dispatch_ns);\n \n aio_free_deleted_handlers(ctx);\n \n+ if (ctx->poll_max_ns) {\n+ update_handler_poll_times(ctx, block_ns, dispatch_ns);\n+ }\n+\n qemu_lockcnt_dec(&ctx->list_lock);\n \n progress |= timerlistgroup_run_timers(&ctx->tlg);\n@@ -794,6 +835,7 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,\n ctx->poll_max_ns = max_ns;\n ctx->poll_grow = grow;\n ctx->poll_shrink = shrink;\n+ ctx->poll_ns = 0;\n \n aio_notify(ctx);\n }\ndiff --git a/util/async.c b/util/async.c\nindex 80d6b01a8a..9d3627566f 100644\n--- a/util/async.c\n+++ b/util/async.c\n@@ -606,6 +606,7 @@ AioContext *aio_context_new(Error **errp)\n timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx);\n \n ctx->poll_max_ns = 0;\n+ ctx->poll_ns = 0;\n ctx->poll_grow = 0;\n ctx->poll_shrink = 0;\n \n", "prefixes": [ "PULL", "2/3" ] }