From nobody Mon Feb 9 09:24:44 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1768326745; cv=none; d=zohomail.com; s=zohoarc; b=QtXU2nqcnJgBSFBUCcT9nYIbUwa2SVp2MNuqVT1IHfrV96yq10LO7clnDdOTbn4L8YYaOxtac25h9G3UExESXFwjJ20mIHX2adcUT9npcUgUoWZN93LStNFqiHS+YhtUCBfrOZcw2IL7pX/zKmfadggqyqq6YDw5cCrRxndq2MA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768326745; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1i5iH5p1Qm6eNxAOTFrUzoB4dCfBLLbv/tlSNeLToiA=; b=OpPXXVc0JxbA/R/fCqngvzdZmFP4W8kraNHFrNUwm0+7HJGBvR9SzScmj0bu4HoeQ+W7hagzr7bEx9cBVsOq9Cmb/ls3d5uZA030WKxWp8DOfuh64bbVELvZsvtrISt1MbYVt0fPZaWoG+LFOEou+vugD+UxsH5oQ00r9YhBJrc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768326745444610.3963434114406; Tue, 13 Jan 2026 09:52:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vfiWj-0005xJ-PT; Tue, 13 Jan 2026 12:49:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfiVT-0005UN-Lw; Tue, 13 Jan 2026 12:48:45 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vfiVQ-0004Ts-6l; Tue, 13 Jan 2026 12:48:38 -0500 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 60DF4MkM023973; Tue, 13 Jan 2026 17:48:32 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4bkd6e5j3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jan 2026 17:48:32 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 60DHO9YO031294; Tue, 13 Jan 2026 17:48:31 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([172.16.1.6]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4bm3t1nch0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Jan 2026 17:48:31 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 60DHmVeu61407518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Jan 2026 17:48:31 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF10058059; Tue, 13 Jan 2026 17:48:30 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 467D258053; Tue, 13 Jan 2026 17:48:30 +0000 (GMT) Received: from IBM-GLTZVH3.ibm.com (unknown [9.61.252.253]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 13 Jan 2026 17:48:30 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=1i5iH5p1Qm6eNxAOT FrUzoB4dCfBLLbv/tlSNeLToiA=; b=OH6mj87eqlmsmxozTflk/gRE5y2WXALXR X9Gg/3NQ8sXnpOBdQpHtsEQ4rMBUqhStUxTYgLSeZSkyoOEbP4HBURT6RZH7L0+X pGpjlORQMdhL5xcJ8/F1YMCR3dNpHGuXb7IGgxFb5gOUSJqzcVGSBv4a6kbLVgZW xbWQ783m4sX1GEWPwH/mRwMdDX2gGekVwUVAb5iiG5oXr2N3LWmHVaNysVgqYGYH aJSgbMFHJ/vrAjkP5YpbB2MtPbkm+ddhOKsbLH6YsPMJdtWucK8ayeZQ15bu010G sHfebdJ0xok4jExi1+WjUxds8DEd6pbOIk/mxBMCoAYA4/AaLrbUA== From: Jaehoon Kim To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: pbonzini@redhat.com, stefanha@redhat.com, fam@euphon.net, armbru@redhat.com, eblake@redhat.com, berrange@redhat.com, eduardo@habkost.net, dave@treblig.org, sw@weilnetz.de, Jaehoon Kim Subject: [PATCH RFC v1 3/3] qapi/iothread: introduce poll-weight parameter for aio-poll Date: Tue, 13 Jan 2026 11:48:24 -0600 Message-ID: <20260113174824.464720-4-jhkim@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260113174824.464720-1-jhkim@linux.ibm.com> References: <20260113174824.464720-1-jhkim@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vF3hIEfoDGD0QmnXrI2e7GNDooibAjAE X-Authority-Analysis: v=2.4 cv=LLxrgZW9 c=1 sm=1 tr=0 ts=69668570 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VnNF1IyMAAAA:8 a=A1X0JdhQAAAA:8 a=8dkL5VNdttJqmu350ZsA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTEzMDE0OCBTYWx0ZWRfXxiH60Cs+0+na o19YT/Bj031Cx1W27pi4h4tose4O30p2W7mzw0Y3zf1cePCMkbNJWBehMZAPBARrD6I+TCsH9y3 tFTJgq1BaSWP7pOKEnUrUgxOP7O8Fh/bQxnnwbVlrE7GkXXTkZ8+I7gEUvk421iYgiM3ppVNqoY fPYsYrdTqMNRDpcmo8Qr8eOKnEUWEcJ3RtXRItc6+i57lNLYUg5fEAmhWKtGf20jK9SF97Y2RsH QYVRVPemWJOcrYrI7GSf1ImeeKdaPjq0pzfllQ+hS9nPimubWikCjdbMwRsSABpx8jOJ1kbylTA dMeARsesbUO/OYkKOqhm9h/Es7ofaj+9Mz9qU/XQ8mCJgmcFLDVG/mAHbNNjeCl6sGY3zuzieOr Rn4Hdw+wZFWOzCfxR87NmRU4nFBlXNq567by7yESlXuSCFe4y7G9LPJ8km7yzNXmNmtomNrfy+e +OfUrySxWl5oogPfyhw== X-Proofpoint-ORIG-GUID: vF3hIEfoDGD0QmnXrI2e7GNDooibAjAE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-13_04,2026-01-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 impostorscore=0 malwarescore=0 phishscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2512120000 definitions=main-2601130148 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=jhkim@linux.ibm.com; helo=mx0b-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, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1768326746461158500 Content-Type: text/plain; charset="utf-8" Introduce a new poll-weight parameter for aio-poll. This parameter controls how much the most recent event interval affects the next polling duration. When set to 0, a default value of 2 is used, meaning the current interval contributes roughly 25% to the calculation. Larger values decrease the weight of the current interval, enabling more gradual adjustments to polling duration. Signed-off-by: Jaehoon Kim --- include/qemu/aio.h | 4 +++- include/system/iothread.h | 1 + iothread.c | 10 ++++++++++ monitor/hmp-cmds.c | 1 + qapi/misc.json | 6 ++++++ qapi/qom.json | 8 +++++++- qemu-options.hx | 7 ++++++- tests/unit/test-nested-aio-poll.c | 2 +- util/aio-posix.c | 9 ++++++--- util/aio-win32.c | 3 ++- util/async.c | 1 + 11 files changed, 44 insertions(+), 8 deletions(-) diff --git a/include/qemu/aio.h b/include/qemu/aio.h index 6c77a190e9..50b8db2712 100644 --- a/include/qemu/aio.h +++ b/include/qemu/aio.h @@ -311,6 +311,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 */ =20 /* AIO engine parameters */ int64_t aio_max_batch; /* maximum number of requests in a batch */ @@ -792,12 +793,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); =20 /** * aio_context_set_aio_params: diff --git a/include/system/iothread.h b/include/system/iothread.h index e26d13c6c7..6ea57ed126 100644 --- a/include/system/iothread.h +++ b/include/system/iothread.h @@ -38,6 +38,7 @@ struct IOThread { int64_t poll_max_ns; int64_t poll_grow; int64_t poll_shrink; + int64_t poll_weight; }; typedef struct IOThread IOThread; =20 diff --git a/iothread.c b/iothread.c index caf68e0764..68a944e57c 100644 --- a/iothread.c +++ b/iothread.c @@ -164,6 +164,7 @@ static void iothread_set_aio_context_params(EventLoopBa= se *base, Error **errp) iothread->poll_max_ns, iothread->poll_grow, iothread->poll_shrink, + iothread->poll_weight, errp); if (*errp) { return; @@ -233,6 +234,9 @@ static IOThreadParamInfo poll_grow_info =3D { static IOThreadParamInfo poll_shrink_info =3D { "poll-shrink", offsetof(IOThread, poll_shrink), }; +static IOThreadParamInfo poll_weight_info =3D { + "poll-weight", offsetof(IOThread, poll_weight), +}; =20 static void iothread_get_param(Object *obj, Visitor *v, const char *name, IOThreadParamInfo *info, Error **errp) @@ -288,6 +292,7 @@ static void iothread_set_poll_param(Object *obj, Visito= r *v, iothread->poll_max_ns, iothread->poll_grow, iothread->poll_shrink, + iothread->poll_weight, errp); } } @@ -311,6 +316,10 @@ static void iothread_class_init(ObjectClass *klass, co= nst void *class_data) iothread_get_poll_param, iothread_set_poll_param, NULL, &poll_shrink_info); + object_class_property_add(klass, "poll-weight", "int", + iothread_get_poll_param, + iothread_set_poll_param, + NULL, &poll_weight_info); } =20 static const TypeInfo iothread_info =3D { @@ -356,6 +365,7 @@ static int query_one_iothread(Object *object, void *opa= que) info->poll_max_ns =3D iothread->poll_max_ns; info->poll_grow =3D iothread->poll_grow; info->poll_shrink =3D iothread->poll_shrink; + info->poll_weight =3D iothread->poll_weight; info->aio_max_batch =3D iothread->parent_obj.aio_max_batch; =20 QAPI_LIST_APPEND(*tail, info); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 5a673cddb2..40e3b1da50 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -205,6 +205,7 @@ void hmp_info_iothreads(Monitor *mon, const QDict *qdic= t) monitor_printf(mon, " poll-max-ns=3D%" PRId64 "\n", value->poll_m= ax_ns); monitor_printf(mon, " poll-grow=3D%" PRId64 "\n", value->poll_gro= w); monitor_printf(mon, " poll-shrink=3D%" PRId64 "\n", value->poll_s= hrink); + monitor_printf(mon, " poll-weight=3D%" PRId64 "\n", value->poll_w= eight); monitor_printf(mon, " aio-max-batch=3D%" PRId64 "\n", value->aio_max_batch); } diff --git a/qapi/misc.json b/qapi/misc.json index 28c641fe2f..b21cc48a03 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -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. 0 means that the default +# value is used. (since 10.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' } } =20 ## diff --git a/qapi/qom.json b/qapi/qom.json index 6f5c9de0f0..d90823478d 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -606,6 +606,11 @@ # 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 current event interval contributes to +# the next polling time calculation. 0 selects a default +# behaviour (default: 0) since 10.1. +# # The @aio-max-batch option is available since 6.1. # # Since: 2.0 @@ -614,7 +619,8 @@ 'base': 'EventLoopBaseProperties', 'data': { '*poll-max-ns': 'int', '*poll-grow': 'int', - '*poll-shrink': 'int' } } + '*poll-shrink': 'int', + '*poll-weight': 'int' } } =20 ## # @MainLoopProperties: diff --git a/qemu-options.hx b/qemu-options.hx index ec92723f10..74adaf55fc 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -6352,7 +6352,7 @@ SRST =20 CN=3Dlaptop.example.com,O=3DExample Home,L=3DLondon,ST=3DLondo= n,C=3DGB =20 - ``-object iothread,id=3Did,poll-max-ns=3Dpoll-max-ns,poll-grow=3Dpoll-= grow,poll-shrink=3Dpoll-shrink,aio-max-batch=3Daio-max-batch`` + ``-object iothread,id=3Did,poll-max-ns=3Dpoll-max-ns,poll-grow=3Dpoll-= grow,poll-shrink=3Dpoll-shrink,poll-weight=3Dpoll-weight,aio-max-batch=3Dai= o-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. @@ -6388,6 +6388,11 @@ SRST the polling time when the algorithm detects it is spending too long polling without encountering events. =20 + The ``poll-weight`` parameter is the weight factor used in the + adaptive polling algorithm. It determines how much the most + recent event interval affects the calculation of the next + polling duration. + 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. diff --git a/tests/unit/test-nested-aio-poll.c b/tests/unit/test-nested-aio= -poll.c index 9ab1ad08a7..ed791fa23b 100644 --- a/tests/unit/test-nested-aio-poll.c +++ b/tests/unit/test-nested-aio-poll.c @@ -81,7 +81,7 @@ static void test(void) qemu_set_current_aio_context(td.ctx); =20 /* Enable polling */ - aio_context_set_poll_params(td.ctx, 1000000, 2, 2, &error_abort); + aio_context_set_poll_params(td.ctx, 1000000, 2, 2, 0, &error_abort); =20 /* Make the event notifier active (set) right away */ event_notifier_init(&td.poll_notifier, 1); diff --git a/util/aio-posix.c b/util/aio-posix.c index dd6008898b..d4f3d8ca8f 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -630,6 +630,7 @@ static void adjust_block_ns(AioContext *ctx, int64_t bl= ock_ns) { AioHandler *node; int64_t adj_block_ns =3D -1; + int64_t poll_weight =3D ctx->poll_weight ? : POLL_WEIGHT_SHIFT; =20 QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) { if (node->poll.has_event) { @@ -639,8 +640,8 @@ static void adjust_block_ns(AioContext *ctx, int64_t bl= ock_ns) * poll.ns to smooth out polling time adjustments. */ node->poll.ns =3D 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 >> poll_weight)) + + (block_ns >> poll_weight) : block_ns; =20 if (node->poll.ns >=3D ctx->poll_max_ns) { node->poll.ns =3D 0; @@ -830,7 +831,8 @@ void aio_context_destroy(AioContext *ctx) } =20 void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, - int64_t grow, int64_t shrink, Error **err= p) + int64_t grow, int64_t shrink, + int64_t weight, Error **errp) { AioHandler *node; =20 @@ -847,6 +849,7 @@ void aio_context_set_poll_params(AioContext *ctx, int64= _t max_ns, ctx->poll_max_ns =3D max_ns; ctx->poll_grow =3D grow; ctx->poll_shrink =3D shrink; + ctx->poll_weight =3D weight; ctx->poll_ns =3D 0; =20 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) } =20 void aio_context_set_poll_params(AioContext *ctx, int64_t max_ns, - int64_t grow, int64_t shrink, Error **err= p) + 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 =3D 0; ctx->poll_grow =3D 0; ctx->poll_shrink =3D 0; + ctx->poll_weight =3D 0; =20 ctx->aio_max_batch =3D 0; =20 --=20 2.50.1