{"id":2220015,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2220015/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260405200735.3075407-4-jhkim@linux.ibm.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","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":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260405200735.3075407-4-jhkim@linux.ibm.com>","list_archive_url":null,"date":"2026-04-05T20:07:34","name":"[v3,3/3] qapi/iothread: introduce poll-weight parameter for aio-poll","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e0543498f317026149d83e9f9bd0def2bbb214ee","submitter":{"id":91012,"url":"http://patchwork.ozlabs.org/api/1.2/people/91012/?format=json","name":"Jaehoon Kim","email":"jhkim@linux.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260405200735.3075407-4-jhkim@linux.ibm.com/mbox/","series":[{"id":498805,"url":"http://patchwork.ozlabs.org/api/1.2/series/498805/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=498805","date":"2026-04-05T20:07:32","name":"improve aio-polling efficiency","version":3,"mbox":"http://patchwork.ozlabs.org/series/498805/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2220015/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220015/checks/","tags":{},"related":[],"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 (2048-bit key;\n unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256\n header.s=pp1 header.b=Gwer1odk;\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=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.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 4fpk7C21xMz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 06 Apr 2026 06:08:53 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w9TlB-0005gZ-UZ; Sun, 05 Apr 2026 16:07:53 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <jhkim@linux.ibm.com>)\n id 1w9Tl9-0005fN-NB; Sun, 05 Apr 2026 16:07:51 -0400","from mx0a-001b2d01.pphosted.com ([148.163.156.1])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <jhkim@linux.ibm.com>)\n id 1w9Tl7-000370-8Z; Sun, 05 Apr 2026 16:07:51 -0400","from pps.filterd (m0353729.ppops.net [127.0.0.1])\n by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n 635DcAkL2751733; Sun, 5 Apr 2026 20:07:45 GMT","from ppma23.wdc07v.mail.ibm.com\n (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93])\n by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4datap46yd-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n Sun, 05 Apr 2026 20:07:44 +0000 (GMT)","from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1])\n by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id\n 635Ge66E022883;\n Sun, 5 Apr 2026 20:07:43 GMT","from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8])\n by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dbefka768-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);\n Sun, 05 Apr 2026 20:07:43 +0000","from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com\n [10.241.53.101])\n by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id\n 635K7gYr31064684\n (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK);\n Sun, 5 Apr 2026 20:07:42 GMT","from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id 66DB858051;\n Sun,  5 Apr 2026 20:07:42 +0000 (GMT)","from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1])\n by IMSVA (Postfix) with ESMTP id 13D105805C;\n Sun,  5 Apr 2026 20:07:42 +0000 (GMT)","from IBM-GLTZVH3.ibm.com (unknown [9.61.243.136])\n by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP;\n Sun,  5 Apr 2026 20:07:42 +0000 (GMT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc\n :content-transfer-encoding:date:from:in-reply-to:message-id\n :mime-version:references:subject:to; s=pp1; bh=x+ig7IiReeCq9m5VX\n rH4NZ6kCaebUCZTUKKG8vtQka0=; b=Gwer1odkIABBi2iVetSADnxqBRtPbBHPj\n +RnUc4EFkoCnUKP7TbcKdzgZMdLV2BBPUL2EW35WTEn7p9PAyeyb5WMJWo+e/1rG\n 5S6a9c5Fjv0GuMgS1xKKJT7nMY1nlUmVQKiKFgBMEa0kOzjae3Z3LNADZNprdbd6\n lv4wbkHkAvpH2GMml+aEmAjbZYLO5vcnRJH/q+I5ZbToNAaXmT4yLcMg5i6O77UY\n UEQCgIHHL/ya+q7erwGNbA2HaJOcU2y/XQptVPEmJbW8imOC+cNSne1Iwlx4dwf5\n gyiRjYn+5MRz3igf1QjL9Tyh2kkxGpZojpLkQaAtAXjBoZ3dJSnXw==","From":"Jaehoon Kim <jhkim@linux.ibm.com>","To":"qemu-devel@nongnu.org, qemu-block@nongnu.org","Cc":"pbonzini@redhat.com, stefanha@redhat.com, fam@euphon.net,\n armbru@redhat.com, eblake@redhat.com, berrange@redhat.com,\n eduardo@habkost.net, dave@treblig.org, sw@weilnetz.de,\n mjrosato@linux.ibm.com, farman@linux.ibm.com,\n Jaehoon Kim <jhkim@linux.ibm.com>","Subject":"[PATCH v3 3/3] qapi/iothread: introduce poll-weight parameter for\n aio-poll","Date":"Sun,  5 Apr 2026 15:07:34 -0500","Message-ID":"<20260405200735.3075407-4-jhkim@linux.ibm.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260405200735.3075407-1-jhkim@linux.ibm.com>","References":"<20260405200735.3075407-1-jhkim@linux.ibm.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-TM-AS-GCONF":"00","X-Authority-Analysis":"v=2.4 cv=Bp+QAIX5 c=1 sm=1 tr=0 ts=69d2c111 cx=c_pps\n a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17\n a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22\n a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=20KFwNOVAAAA:8 a=A1X0JdhQAAAA:8\n a=lBH6PFgD_fRyFddJ3aEA:9","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDA1MDIwNiBTYWx0ZWRfXwmY8OISVFm1A\n VD0dKffjguw2Ea9xDi79Ypel3tgev9urfPtfYGhRQq6pEWDyA8diC6rza3JshMg2NiZbAu4KOCn\n sASvHlfJquc7DTdfO54F0P+TRiIqdAaiJLRyqnsf6CmPE1K9HjPl9lexkAdLhY9r/ngDNm3hP4G\n SYc2RiGbGHdf/hhnEZ6t32W/MH1J76AyiA4yUP3yBmGeJ5BidqvJNmYP5rsZYJ7vrtpmuci6LT/\n zmRY7VlFGcVGyROCtwenQKOLhZLDBFjf5YK8J4k8aSzsN0Ybj7z24tuxDGOJm8aaZs7EZXTcVp9\n VmVdsyJf3iVCGkW4vYr+1QkMSpBPPNF588mGgGZ5IEgN/jNSqqKEfUFd4d/ymzQY4lX35KUI1E6\n iVgCYWPah4pKELaGH05NPlme/PdbHwE/kYgOr5H7eqxL6Y+RyINf+1+R7cCmAk3sviaEdF6k77r\n zs37lHfa6zrpblHFF5g==","X-Proofpoint-GUID":"lQ0MFx7p4-_iFxc_MV2G0RpBim_BNyB8","X-Proofpoint-ORIG-GUID":"lQ0MFx7p4-_iFxc_MV2G0RpBim_BNyB8","X-Proofpoint-Virus-Version":"vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-04-05_06,2026-04-03_01,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n phishscore=0 malwarescore=0 suspectscore=0 adultscore=0 impostorscore=0\n spamscore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 clxscore=1015\n classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0\n reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2604050206","Received-SPF":"pass client-ip=148.163.156.1; envelope-from=jhkim@linux.ibm.com;\n helo=mx0a-001b2d01.pphosted.com","X-Spam_score_int":"-26","X-Spam_score":"-2.7","X-Spam_bar":"--","X-Spam_report":"(-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\n RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_NONE=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":"Introduce a configurable poll-weight parameter for adaptive polling\nin IOThread. This parameter replaces the hardcoded POLL_WEIGHT_SHIFT\nconstant, allowing runtime control over how much the most recent\nevent interval affects the next polling duration calculation.\n\nThe poll-weight parameter uses a shift value where larger values\ndecrease the weight of the current interval, enabling more gradual\nadjustments. When set to 0, a default value of 3 is used (meaning\nthe current interval contributes approximately 1/8 to the weighted\naverage).\n\nThis patch also removes the hardcoded default values for poll-grow\nand poll-shrink parameters from the grow_polling_time() and\nshrink_polling_time() functions, as these defaults are now properly\ninitialized in iothread.c during IOThread creation.\n\nSigned-off-by: Jaehoon Kim <jhkim@linux.ibm.com>\nReviewed-by: Stefan Hajnoczi <stefanha@redhat.com>\n---\n include/qemu/aio.h                |  4 ++-\n include/system/iothread.h         | 18 ++++++++++++\n iothread.c                        | 47 ++++++++++++++++++++++---------\n monitor/hmp-cmds.c                |  1 +\n qapi/misc.json                    |  7 +++++\n qapi/qom.json                     | 10 ++++++-\n qemu-options.hx                   |  7 ++++-\n tests/unit/test-nested-aio-poll.c |  2 +-\n util/aio-posix.c                  | 37 +++++++++---------------\n util/aio-win32.c                  |  3 +-\n util/async.c                      |  1 +\n 11 files changed, 95 insertions(+), 42 deletions(-)","diff":"diff --git a/include/qemu/aio.h b/include/qemu/aio.h\nindex 6c22064a28..e65e90093a 100644\n--- a/include/qemu/aio.h\n+++ b/include/qemu/aio.h\n@@ -310,6 +310,7 @@ struct AioContext {\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 */\n+    int64_t poll_weight;    /* weight of current interval in calculation */\n \n     /* AIO engine parameters */\n     int64_t aio_max_batch;  /* maximum number of requests in a batch */\n@@ -791,12 +792,13 @@ void aio_context_destroy(AioContext *ctx);\n  * @max_ns: how long to busy poll for, in nanoseconds\n  * @grow: polling time growth factor\n  * @shrink: polling time shrink factor\n+ * @weight: weight factor applied to the current polling interval\n  *\n  * Poll mode can be disabled by setting poll_max_ns to 0.\n  */\n void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,\n                                  int64_t grow, int64_t shrink,\n-                                 Error **errp);\n+                                 int64_t weight, Error **errp);\n \n /**\n  * aio_context_set_aio_params:\ndiff --git a/include/system/iothread.h b/include/system/iothread.h\nindex e26d13c6c7..a1ef7696cb 100644\n--- a/include/system/iothread.h\n+++ b/include/system/iothread.h\n@@ -21,6 +21,23 @@\n \n #define TYPE_IOTHREAD \"iothread\"\n \n+#ifdef CONFIG_POSIX\n+/*\n+ * Benchmark results from 2016 on NVMe SSD drives show max polling times around\n+ * 16-32 microseconds yield IOPS improvements for both iodepth=1 and iodepth=32\n+ * workloads.\n+ */\n+#define IOTHREAD_POLL_MAX_NS_DEFAULT 32768ULL\n+#define IOTHREAD_POLL_GROW_DEFAULT 2ULL\n+#define IOTHREAD_POLL_SHRINK_DEFAULT 2ULL\n+#define IOTHREAD_POLL_WEIGHT_DEFAULT 3ULL\n+#else\n+#define IOTHREAD_POLL_MAX_NS_DEFAULT 0ULL\n+#define IOTHREAD_POLL_GROW_DEFAULT 0ULL\n+#define IOTHREAD_POLL_SHRINK_DEFAULT 0ULL\n+#define IOTHREAD_POLL_WEIGHT_DEFAULT 0ULL\n+#endif\n+\n struct IOThread {\n     EventLoopBase parent_obj;\n \n@@ -38,6 +55,7 @@ struct IOThread {\n     int64_t poll_max_ns;\n     int64_t poll_grow;\n     int64_t poll_shrink;\n+    int64_t poll_weight;\n };\n typedef struct IOThread IOThread;\n \ndiff --git a/iothread.c b/iothread.c\nindex caf68e0764..3558535b40 100644\n--- a/iothread.c\n+++ b/iothread.c\n@@ -25,17 +25,6 @@\n #include \"qemu/rcu.h\"\n #include \"qemu/main-loop.h\"\n \n-\n-#ifdef CONFIG_POSIX\n-/* Benchmark results from 2016 on NVMe SSD drives show max polling times around\n- * 16-32 microseconds yield IOPS improvements for both iodepth=1 and iodepth=32\n- * workloads.\n- */\n-#define IOTHREAD_POLL_MAX_NS_DEFAULT 32768ULL\n-#else\n-#define IOTHREAD_POLL_MAX_NS_DEFAULT 0ULL\n-#endif\n-\n static void *iothread_run(void *opaque)\n {\n     IOThread *iothread = opaque;\n@@ -103,6 +92,10 @@ static void iothread_instance_init(Object *obj)\n     IOThread *iothread = IOTHREAD(obj);\n \n     iothread->poll_max_ns = IOTHREAD_POLL_MAX_NS_DEFAULT;\n+    iothread->poll_grow = IOTHREAD_POLL_GROW_DEFAULT;\n+    iothread->poll_shrink = IOTHREAD_POLL_SHRINK_DEFAULT;\n+    iothread->poll_weight = IOTHREAD_POLL_WEIGHT_DEFAULT;\n+\n     iothread->thread_id = -1;\n     qemu_sem_init(&iothread->init_done_sem, 0);\n     /* By default, we don't run gcontext */\n@@ -164,6 +157,7 @@ static void iothread_set_aio_context_params(EventLoopBase *base, Error **errp)\n                                 iothread->poll_max_ns,\n                                 iothread->poll_grow,\n                                 iothread->poll_shrink,\n+                                iothread->poll_weight,\n                                 errp);\n     if (*errp) {\n         return;\n@@ -233,6 +227,9 @@ static IOThreadParamInfo poll_grow_info = {\n static IOThreadParamInfo poll_shrink_info = {\n     \"poll-shrink\", offsetof(IOThread, poll_shrink),\n };\n+static IOThreadParamInfo poll_weight_info = {\n+    \"poll-weight\", offsetof(IOThread, poll_weight),\n+};\n \n static void iothread_get_param(Object *obj, Visitor *v,\n         const char *name, IOThreadParamInfo *info, Error **errp)\n@@ -254,13 +251,31 @@ static bool iothread_set_param(Object *obj, Visitor *v,\n         return false;\n     }\n \n-    if (value < 0) {\n+    if (info->offset == offsetof(IOThread, poll_weight)) {\n+        if (value < 0 || value > 63) {\n+            error_setg(errp, \"%s value must be in range [0, 63]\",\n+                       info->name);\n+            return false;\n+        }\n+    } else if (value < 0) {\n         error_setg(errp, \"%s value must be in range [0, %\" PRId64 \"]\",\n                    info->name, INT64_MAX);\n         return false;\n     }\n \n-    *field = value;\n+    if (value == 0) {\n+        if (info->offset == offsetof(IOThread, poll_grow)) {\n+            *field = IOTHREAD_POLL_GROW_DEFAULT;\n+        } else if (info->offset == offsetof(IOThread, poll_shrink)) {\n+            *field = IOTHREAD_POLL_SHRINK_DEFAULT;\n+        } else if (info->offset == offsetof(IOThread, poll_weight)) {\n+            *field = IOTHREAD_POLL_WEIGHT_DEFAULT;\n+        } else {\n+            *field = value;\n+        }\n+    } else {\n+        *field = value;\n+    }\n \n     return true;\n }\n@@ -288,6 +303,7 @@ static void iothread_set_poll_param(Object *obj, Visitor *v,\n                                     iothread->poll_max_ns,\n                                     iothread->poll_grow,\n                                     iothread->poll_shrink,\n+                                    iothread->poll_weight,\n                                     errp);\n     }\n }\n@@ -311,6 +327,10 @@ static void iothread_class_init(ObjectClass *klass, const void *class_data)\n                               iothread_get_poll_param,\n                               iothread_set_poll_param,\n                               NULL, &poll_shrink_info);\n+    object_class_property_add(klass, \"poll-weight\", \"int\",\n+                              iothread_get_poll_param,\n+                              iothread_set_poll_param,\n+                              NULL, &poll_weight_info);\n }\n \n static const TypeInfo iothread_info = {\n@@ -356,6 +376,7 @@ static int query_one_iothread(Object *object, void *opaque)\n     info->poll_max_ns = iothread->poll_max_ns;\n     info->poll_grow = iothread->poll_grow;\n     info->poll_shrink = iothread->poll_shrink;\n+    info->poll_weight = iothread->poll_weight;\n     info->aio_max_batch = iothread->parent_obj.aio_max_batch;\n \n     QAPI_LIST_APPEND(*tail, info);\ndiff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c\nindex bad034937a..75b6e7fa65 100644\n--- a/monitor/hmp-cmds.c\n+++ b/monitor/hmp-cmds.c\n@@ -206,6 +206,7 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdict)\n         monitor_printf(mon, \"  poll-max-ns=%\" PRId64 \"\\n\", value->poll_max_ns);\n         monitor_printf(mon, \"  poll-grow=%\" PRId64 \"\\n\", value->poll_grow);\n         monitor_printf(mon, \"  poll-shrink=%\" PRId64 \"\\n\", value->poll_shrink);\n+        monitor_printf(mon, \"  poll-weight=%\" PRId64 \"\\n\", value->poll_weight);\n         monitor_printf(mon, \"  aio-max-batch=%\" PRId64 \"\\n\",\n                        value->aio_max_batch);\n     }\ndiff --git a/qapi/misc.json b/qapi/misc.json\nindex 28c641fe2f..554b0c5717 100644\n--- a/qapi/misc.json\n+++ b/qapi/misc.json\n@@ -85,6 +85,12 @@\n # @poll-shrink: how many ns will be removed from polling time, 0 means\n #     that it's not configured (since 2.9)\n #\n+# @poll-weight: the weight factor for adaptive polling.\n+#     Determines how much the current event interval contributes to\n+#     the next polling time calculation.  Valid values are 1 or\n+#     greater.  0 selects the system default value which is currently\n+#     3 (since 11.1)\n+#\n # @aio-max-batch: maximum number of requests in a batch for the AIO\n #     engine, 0 means that the engine will use its default (since 6.1)\n #\n@@ -96,6 +102,7 @@\n            'poll-max-ns': 'int',\n            'poll-grow': 'int',\n            'poll-shrink': 'int',\n+           'poll-weight': 'int',\n            'aio-max-batch': 'int' } }\n \n ##\ndiff --git a/qapi/qom.json b/qapi/qom.json\nindex c653248f85..dd45ac1087 100644\n--- a/qapi/qom.json\n+++ b/qapi/qom.json\n@@ -606,6 +606,13 @@\n #     algorithm detects it is spending too long polling without\n #     encountering events.  0 selects a default behaviour (default: 0)\n #\n+# @poll-weight: the weight factor for adaptive polling.  Determines\n+#     how much the most recent event interval affects the next\n+#     polling duration calculation.  If set to 0, the system default\n+#     value of 3 is used.  Typical values: 1 (high weight on recent\n+#     interval), 2-4 (moderate weight on recent interval).\n+#     (default: 0) (since 11.1)\n+#\n # The @aio-max-batch option is available since 6.1.\n #\n # Since: 2.0\n@@ -614,7 +621,8 @@\n   'base': 'EventLoopBaseProperties',\n   'data': { '*poll-max-ns': 'int',\n             '*poll-grow': 'int',\n-            '*poll-shrink': 'int' } }\n+            '*poll-shrink': 'int',\n+            '*poll-weight': 'int' } }\n \n ##\n # @MainLoopProperties:\ndiff --git a/qemu-options.hx b/qemu-options.hx\nindex 69e5a874c1..8ddf6c8d36 100644\n--- a/qemu-options.hx\n+++ b/qemu-options.hx\n@@ -6413,7 +6413,7 @@ SRST\n \n             CN=laptop.example.com,O=Example Home,L=London,ST=London,C=GB\n \n-    ``-object iothread,id=id,poll-max-ns=poll-max-ns,poll-grow=poll-grow,poll-shrink=poll-shrink,aio-max-batch=aio-max-batch``\n+    ``-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``\n         Creates a dedicated event loop thread that devices can be\n         assigned to. This is known as an IOThread. By default device\n         emulation happens in vCPU threads or the main event loop thread.\n@@ -6449,6 +6449,11 @@ SRST\n         the polling time when the algorithm detects it is spending too\n         long polling without encountering events.\n \n+        The ``poll-weight`` parameter is the weight factor used in the\n+        adaptive polling algorithm. It determines how much the most\n+        recent event interval affects the calculation of the next\n+        polling duration.\n+\n         The ``aio-max-batch`` parameter is the maximum number of requests\n         in a batch for the AIO engine, 0 means that the engine will use\n         its default.\ndiff --git a/tests/unit/test-nested-aio-poll.c b/tests/unit/test-nested-aio-poll.c\nindex 9ab1ad08a7..4c38f36fd4 100644\n--- a/tests/unit/test-nested-aio-poll.c\n+++ b/tests/unit/test-nested-aio-poll.c\n@@ -81,7 +81,7 @@ static void test(void)\n     qemu_set_current_aio_context(td.ctx);\n \n     /* Enable polling */\n-    aio_context_set_poll_params(td.ctx, 1000000, 2, 2, &error_abort);\n+    aio_context_set_poll_params(td.ctx, 1000000, 2, 2, 3, &error_abort);\n \n     /* Make the event notifier active (set) right away */\n     event_notifier_init(&td.poll_notifier, 1);\ndiff --git a/util/aio-posix.c b/util/aio-posix.c\nindex 8e9e9e5d8f..df1c213ce5 100644\n--- a/util/aio-posix.c\n+++ b/util/aio-posix.c\n@@ -29,7 +29,6 @@\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 update_handler_poll_times(AioContext *ctx, int64_t block_ns,\n                                       int64_t dispatch_time);\n@@ -582,28 +581,11 @@ static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list,\n \n static void adjust_polling_time(AioContext *ctx, int64_t block_ns)\n {\n-    if (block_ns < ctx->poll_ns) {\n-        int64_t old = ctx->poll_ns;\n-        int64_t shrink = ctx->poll_shrink;\n-\n-        if (shrink == 0) {\n-            shrink = 2;\n-        }\n-\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+    if (block_ns > ctx->poll_ns) {\n         /* There is room to grow, poll longer */\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 (block_ns > ctx->poll_ns * grow) {\n             ctx->poll_ns = block_ns;\n         } else {\n@@ -615,6 +597,11 @@ static void adjust_polling_time(AioContext *ctx, int64_t block_ns)\n         }\n \n         trace_poll_grow(ctx, old, ctx->poll_ns);\n+    } else if (block_ns < (ctx->poll_ns / ctx->poll_shrink)) {\n+        int64_t old = ctx->poll_ns;\n+        ctx->poll_ns /= ctx->poll_shrink;\n+\n+        trace_poll_shrink(ctx, old, ctx->poll_ns);\n     }\n }\n \n@@ -632,8 +619,8 @@ static void update_handler_poll_times(AioContext *ctx, int64_t block_ns,\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+                ? (node->poll.ns - (node->poll.ns >> ctx->poll_weight))\n+                + (block_ns >> ctx->poll_weight) : block_ns;\n \n             if (node->poll.ns > ctx->poll_max_ns) {\n                 node->poll.ns = 0;\n@@ -819,7 +806,8 @@ void aio_context_destroy(AioContext *ctx)\n }\n \n void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,\n-                                 int64_t grow, int64_t shrink, Error **errp)\n+                                 int64_t grow, int64_t shrink,\n+                                 int64_t weight, Error **errp)\n {\n     AioHandler *node;\n \n@@ -833,8 +821,9 @@ void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,\n      * is used once.\n      */\n     ctx->poll_max_ns = max_ns;\n-    ctx->poll_grow = grow;\n-    ctx->poll_shrink = shrink;\n+    ctx->poll_grow = (grow ? grow : IOTHREAD_POLL_GROW_DEFAULT);\n+    ctx->poll_shrink = (shrink ? shrink : IOTHREAD_POLL_SHRINK_DEFAULT);\n+    ctx->poll_weight = (weight ? weight : IOTHREAD_POLL_WEIGHT_DEFAULT);\n     ctx->poll_ns = 0;\n \n     aio_notify(ctx);\ndiff --git a/util/aio-win32.c b/util/aio-win32.c\nindex 6e6f699e4b..1985843233 100644\n--- a/util/aio-win32.c\n+++ b/util/aio-win32.c\n@@ -429,7 +429,8 @@ void aio_context_destroy(AioContext *ctx)\n }\n \n void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns,\n-                                 int64_t grow, int64_t shrink, Error **errp)\n+                                 int64_t grow, int64_t shrink,\n+                                 int64_t weight, Error **errp)\n {\n     if (max_ns) {\n         error_setg(errp, \"AioContext polling is not implemented on Windows\");\ndiff --git a/util/async.c b/util/async.c\nindex 9d3627566f..741fcfd6a7 100644\n--- a/util/async.c\n+++ b/util/async.c\n@@ -609,6 +609,7 @@ AioContext *aio_context_new(Error **errp)\n     ctx->poll_ns = 0;\n     ctx->poll_grow = 0;\n     ctx->poll_shrink = 0;\n+    ctx->poll_weight = 0;\n \n     ctx->aio_max_batch = 0;\n \n","prefixes":["v3","3/3"]}