From nobody Fri Apr 3 20:53:40 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=1774274149; cv=none; d=zohomail.com; s=zohoarc; b=kIbPhF8f8Tk5cFxozt7woxSPVTVgIk29QnXvA84segNApA157HxlXlCO0HrvhG0r5Ri+Hc/Si5G6db02e/aXTdyj7lKUcr03MtQTPHzWA3qoeQbf7sPUc99Ggl7Z7Odp4+fxSlVpixnDLjS3Z11dCgTBy9ppxfpDjg2eIxmi2p8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774274149; 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=leRhdWaBWAl6vsaaMyYddgrMqxbeuMfq5lKtc1bFpqU=; b=FLuysDYCg4y8sqqPyV4EwnISo2fFt23oM6nZNP0FGcRn9OYims5vu2ZhDACXOOy4FfC1IlMxHvM3fCJNjQagyIMti+/4z1SUhPONcWczmFp/OdjS2dxG6y4BNALgv9BBRPm4cGjnTLgo179ZqOqR0CufxsmmsAWt1DICp9aiAzw= 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 1774274149801526.3653651676867; Mon, 23 Mar 2026 06:55:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4fkl-0004Pw-OP; Mon, 23 Mar 2026 09:55:35 -0400 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 1w4fkT-0004I4-Ik; Mon, 23 Mar 2026 09:55:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w4fkR-0006Qx-SO; Mon, 23 Mar 2026 09:55:17 -0400 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62MNPEcj666646; Mon, 23 Mar 2026 13:55:10 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4d1ktxq3qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2026 13:55:09 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62NBr9VS005972; Mon, 23 Mar 2026 13:55:08 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([172.16.1.9]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4d261ydped-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2026 13:55:08 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62NDt6F023724566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Mar 2026 13:55:07 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB5CE58063; Mon, 23 Mar 2026 13:55:06 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 23E5958055; Mon, 23 Mar 2026 13:55:06 +0000 (GMT) Received: from IBM-GLTZVH3.ibm.com (unknown [9.61.250.54]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Mar 2026 13:55:06 +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=leRhdWaBWAl6vsaaM yYddgrMqxbeuMfq5lKtc1bFpqU=; b=OoG6BtX/jMm8C+uGV+W45Osm2I5KIpaFp ytxqIlf2OV97dzc7Iwcma1DuSVt07VxqpPi5MLLbg07Z0SWqgTK7f0O48E761E9i 0mI0551Q3DyzbyZL2E0iB6n3tmEzHMG6xfElVnt+1SKDgk7RJFlpiSyzDuelRMq3 J4f84JK3wPAI7dugySvf1RQBWQqOvY/mlAjGPwiZLDHEd/HGaf5qqtzEjwotsje2 XIks5NgDXPJR5NoKjTLV9IjjmymQ7eVrxeu95TSeKD1lr7JhNP66vp0bpemZE1cQ Yvi+1wfUNEA0dXje8UCacIbp28tVlyCWtgNtDjo/V2WpELnvHLfvg== From: Jaehoon Kim To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: mjrosato@linux.ibm.com, farman@linux.ibm.com, 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 v2 1/3] aio-poll: avoid unnecessary polling time computation Date: Mon, 23 Mar 2026 08:54:49 -0500 Message-ID: <20260323135451.579655-2-jhkim@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260323135451.579655-1-jhkim@linux.ibm.com> References: <20260323135451.579655-1-jhkim@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=IqITsb/g c=1 sm=1 tr=0 ts=69c1463d cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=6MqEkq6nHlEWUoCmaegA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzIzMDEwNyBTYWx0ZWRfXziuOAgUl3hB7 OtLnhbouMa8jhDF5327cUIuDQDA1ijWncoewirWOFsUM8CxDLKiDr47ySiwgzODQuAd/GHPjCak IxD7oQr1w27eQhYN/GhfZvZfRYf1txFsnFJZzJmWQbCakhg7h4vqUqqWulfN/IsEf1bsjrIqDmO 63UOKjQYHgpIn/xxkhM0OAQt6jj/jeYE22rCi9R1Av3Y5A/59a6a+Dd5yb9zdO61ZhiWl7UG1jF N27L20GcWlmNVkxPQP6iwOiXt8sTQFlRB3dluJ3nDDemlDifObQqDY0hQwvtwH4oY4ULRpFiq7e 2qVZumbL0h+AN22hwctFCAjDwUp4CTUlhovsPn2VLnwXBuEzHGkVT6kChgn/ZpdSOeq9+nrdB7m vNuQck3B4mthbzXL2HcJ5IZe970gbdNpaRSzCBUxoBX8/8mZRH+h9oLyIH2wSFDidvzX6s0n4CA SRQQmKBs/iRVvPQV6Uw== X-Proofpoint-GUID: geWwTWbnqISl1V1gTeSR21NNT2Zi7G9N X-Proofpoint-ORIG-GUID: geWwTWbnqISl1V1gTeSR21NNT2Zi7G9N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-23_04,2026-03-20_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 spamscore=0 impostorscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603230107 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.156.1; envelope-from=jhkim@linux.ibm.com; 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, 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: 1774274151100154101 Content-Type: text/plain; charset="utf-8" Nodes are no longer added to poll_aio_handlers when adaptive polling is disabled, preventing unnecessary try_poll_mode() calls. Additionally, aio_poll() skips try_poll_mode() when timeout is 0. This avoids iterating over all nodes to compute max_ns unnecessarily when polling is disabled or timeout is 0. Signed-off-by: Jaehoon Kim Reviewed-by: Stefan Hajnoczi --- util/aio-posix.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 488d964611..b02beb0505 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -307,9 +307,8 @@ static bool aio_dispatch_handler(AioContext *ctx, AioHa= ndler *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, AioPol= ledEvent *poll, bool aio_poll(AioContext *ctx, bool blocking) { AioHandlerList ready_list =3D QLIST_HEAD_INITIALIZER(ready_list); - bool progress; + bool progress =3D false; bool use_notify_me; int64_t timeout; int64_t start =3D 0; @@ -656,7 +655,9 @@ bool aio_poll(AioContext *ctx, bool blocking) } =20 timeout =3D blocking ? aio_compute_timeout(ctx) : 0; - progress =3D try_poll_mode(ctx, &ready_list, &timeout); + if ((ctx->poll_max_ns !=3D 0) && (timeout !=3D 0)) { + progress =3D try_poll_mode(ctx, &ready_list, &timeout); + } assert(!(timeout && progress)); =20 /* --=20 2.50.1 From nobody Fri Apr 3 20:53:40 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=1774274172; cv=none; d=zohomail.com; s=zohoarc; b=Kctt8cse+JmsGBeFnTk1670EOS3kidgud9Pcr1nSATscuQw27l39U8dAB2SXKxK2WSQ+gJtaDVduOPspK6jHigzd5FoVzcsJNUnSPCTIeXmEXzS02O+S28hCnhSB2P3K+WQOWwZJzx/D4Rx9VJXOwDXQOAjVNXjgg0ruOb0E2O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774274172; 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=cAk4sgZufdpjvnpR48ebECgNeceQtYvYmskYqF/jHKc=; b=EQcwD6hGf4ieqWFKart3Z8olI7UkPyzrk3QWk4gXf4xMphvJtw1FhKa2hrN6N795XjXLvDoWPQNC3WZ6LZCkvzKbpe6bmRx3lY1jtrQrr9Mj3n4Z/zWHEf5mRJLJIa5bkh34QzvYqKz8NR7Exqegu2oTIzPjfPWzlqYPLlqmA4w= 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 1774274172201908.7670532952026; Mon, 23 Mar 2026 06:56:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4fkm-0004T1-J2; Mon, 23 Mar 2026 09:55:36 -0400 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 1w4fkW-0004JB-PK; Mon, 23 Mar 2026 09:55:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w4fkU-0006RD-D7; Mon, 23 Mar 2026 09:55:20 -0400 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62NAVvvJ3744362; Mon, 23 Mar 2026 13:55:11 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 4d1kw9q3ty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2026 13:55:11 +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 62NDbPVm004369; Mon, 23 Mar 2026 13:55:10 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4d28c1wak2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2026 13:55:10 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62NDt8Ow13632216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Mar 2026 13:55:08 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A561D58063; Mon, 23 Mar 2026 13:55:08 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EC64F58055; Mon, 23 Mar 2026 13:55:07 +0000 (GMT) Received: from IBM-GLTZVH3.ibm.com (unknown [9.61.250.54]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Mar 2026 13:55:07 +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=cAk4sgZufdpjvnpR4 8ebECgNeceQtYvYmskYqF/jHKc=; b=ntJd6VgWw9p4yKBn4MeLOZwf2stQLj68E r9cDRGSn+FtLaUfecfbxi+eaZJG1aYE72WS0uGaMLIeVoWUo4Y2FA6jHx0lG53is Vb3QKn3lpJhQU3Eln1CRP+aFbw2PCEUvvfcrhbv5/UQPWnB6bkS2uErDtOnF8Rfn cCCiiqS+nO2/U+ZQrct/qIDjF0Tk1ERnvOQxXQaI1dYgLZoI1QJYcU59zpfW57tx MPIPVP8tU7lz/5qxS9tXex1hWz8kpzvbLObj1rpAAMfGQRFtv1apyZKt5A2v6VDf q2xZGCwBXK1bdBkXVnGwIz6YeQtFfd03BPrjcHqgDybMVJOZGFHEA== From: Jaehoon Kim To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: mjrosato@linux.ibm.com, farman@linux.ibm.com, 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 v2 2/3] aio-poll: refine iothread polling using weighted handler intervals Date: Mon, 23 Mar 2026 08:54:50 -0500 Message-ID: <20260323135451.579655-3-jhkim@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260323135451.579655-1-jhkim@linux.ibm.com> References: <20260323135451.579655-1-jhkim@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: LphzQBpHZyqgBXF8ZGoo2cRI5I3Ux8Ik X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzIzMDEwNyBTYWx0ZWRfXzPRs6KtRkQmj PWYHiKfBXWBLKjdRZiMl33Qlfahe5eW5NsJ7R9by2KlZpmTrqqxA7c9ukSbZw0EeaBJOoOoQXUm RYDloIotDajsnoJ7t5fkDAEpVfvehXnHtk5C6ysU3TjcH3RNrEtUuZ9p8j3EZA5jC20EMgeJqaA 9vrjy2K1XKNjt3w4MxKA96znp6P+HpQ+mQWVRfMXs0uf3MBDxfj0m3Sh2HmfvkfoJ2IxS+qZwYY MmjehE6q2YOWDOwROLjRPCuBov+h//fG+xsCyCXlx6h7aaMIt2oRovwBYlIa5VFaX+f7IIi7VNI 2CwrN+kDS/nusiU+v8g9c0BumNE65oAKlqn8LTyMhU6OX5y/fIXZlux85G8+N9MLaY7sF31ID9D Rm8PL+Ajv2b7rQQ0ipEziGp0OzcfdLIonuYD4pNgyx8ehqcEwhyUuL1PKjUWfQUTKB+ftR89TT+ zt4hvXsM5P/BORbcuIw== X-Proofpoint-GUID: LphzQBpHZyqgBXF8ZGoo2cRI5I3Ux8Ik X-Authority-Analysis: v=2.4 cv=OsZCCi/t c=1 sm=1 tr=0 ts=69c1463f cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=0fTNcCBiaAR8iZ-VC-YA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-23_04,2026-03-20_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 clxscore=1015 phishscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 spamscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603230107 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.156.1; envelope-from=jhkim@linux.ibm.com; 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, 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: 1774274173787158500 Content-Type: text/plain; charset="utf-8" Refine adaptive polling in aio_poll by updating iothread polling duration based on weighted AioHandler event intervals. Each AioHandler's poll.ns is updated using a weighted factor when an event occurs. Idle handlers accumulate block_ns until poll_max_ns and then reset 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 default weight factor (POLL_WEIGHT_SHIFT=3D3, meaning the current interval contributes 12.5% to the weighted average) was selected based on extensive testing comparing QEMU 10.0.0 baseline vs poll-weight=3D2 and poll-weight=3D3 across various workloads. The table below shows a comparison between: -Host: RHEL 10.1 GA + qemu-10.0.0-14.el10_1, Guest: RHEL 9.6GA vs. -Host: RHEL 10.1 GA + qemu-10.0.0-14.el10_1 (w=3D2/w=3D3), Guest: RHEL 9.6GA for FIO FCP and FICON with 1 iothread and 8 iothreads. The values shown are the averages for numjobs 1, 4, and 8. Summary of results (% change vs baseline): | poll-weight=3D2 | poll-weight=3D3 --------------------|--------------------|----------------- Throughput avg | -2.4% (all tests) | -2.2% (all tests) CPU consumption avg | -10.9% (all tests) | -9.4% (all tests) Both weight=3D2 and weight=3D3 show significant CPU consumption reduction (~10%) compared to baseline, which addresses the CPU utilization regression observed in QEMU 10.0.0. The throughput impact is minimal for both (~2%). Weight=3D3 is selected as the default because it provides slightly better throughput (-2.2% vs -2.4%) while still achieving substantial CPU savings (-9.4%). The difference between weight=3D2 and weight=3D3 is small, but weight=3D3 offers a better balance for general-purpose workloads. Signed-off-by: Jaehoon Kim --- include/qemu/aio.h | 4 +- util/aio-posix.c | 135 +++++++++++++++++++++++++++++++-------------- util/async.c | 1 + 3 files changed, 99 insertions(+), 41 deletions(-) diff --git a/include/qemu/aio.h b/include/qemu/aio.h index 8cca2360d1..6c77a190e9 100644 --- a/include/qemu/aio.h +++ b/include/qemu/aio.h @@ -195,7 +195,8 @@ struct BHListSlice { typedef QSLIST_HEAD(, AioHandler) AioHandlerSList; =20 typedef struct AioPolledEvent { - int64_t ns; /* current polling time in nanoseconds */ + bool has_event; /* Flag to indicate if an event has occurred */ + int64_t ns; /* estimated block time in nanoseconds */ } AioPolledEvent; =20 struct AioContext { @@ -306,6 +307,7 @@ struct AioContext { int poll_disable_cnt; =20 /* 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 */ diff --git a/util/aio-posix.c b/util/aio-posix.c index b02beb0505..2b3522f2f9 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -29,9 +29,11 @@ =20 /* 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) =20 -static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll, - int64_t block_ns); +static void adjust_block_ns(AioContext *ctx, int64_t block_ns); +static void grow_polling_time(AioContext *ctx, int64_t block_ns); +static void shrink_polling_time(AioContext *ctx, int64_t block_ns); =20 bool aio_poll_disabled(AioContext *ctx) { @@ -373,7 +375,7 @@ static bool aio_dispatch_ready_handlers(AioContext *ctx, * add the handler to ctx->poll_aio_handlers. */ if (ctx->poll_max_ns && QLIST_IS_INSERTED(node, node_poll)) { - adjust_polling_time(ctx, &node->poll, block_ns); + node->poll.has_event =3D true; } } =20 @@ -560,18 +562,13 @@ static bool run_poll_handlers(AioContext *ctx, AioHan= dlerList *ready_list, static bool try_poll_mode(AioContext *ctx, AioHandlerList *ready_list, int64_t *timeout) { - AioHandler *node; int64_t max_ns; =20 if (QLIST_EMPTY_RCU(&ctx->poll_aio_handlers)) { return false; } =20 - max_ns =3D 0; - QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) { - max_ns =3D MAX(max_ns, node->poll.ns); - } - max_ns =3D qemu_soonest_timeout(*timeout, max_ns); + max_ns =3D qemu_soonest_timeout(*timeout, ctx->poll_ns); =20 if (max_ns && !ctx->fdmon_ops->need_wait(ctx)) { /* @@ -587,46 +584,98 @@ static bool try_poll_mode(AioContext *ctx, AioHandler= List *ready_list, return false; } =20 -static void adjust_polling_time(AioContext *ctx, AioPolledEvent *poll, - int64_t block_ns) +static void shrink_polling_time(AioContext *ctx, int64_t block_ns) { - if (block_ns <=3D poll->ns) { - /* This is the sweet spot, no adjustment needed */ - } else if (block_ns > ctx->poll_max_ns) { - /* We'd have to poll for too long, poll less */ - int64_t old =3D poll->ns; - - if (ctx->poll_shrink) { - poll->ns /=3D ctx->poll_shrink; - } else { - poll->ns =3D 0; - } + /* + * Reduce polling time if the block_ns is zero or + * less than the current poll_ns. + */ + int64_t old =3D ctx->poll_ns; + int64_t shrink =3D ctx->poll_shrink; =20 - trace_poll_shrink(ctx, old, poll->ns); - } else if (poll->ns < ctx->poll_max_ns && - block_ns < ctx->poll_max_ns) { - /* There is room to grow, poll longer */ - int64_t old =3D poll->ns; - int64_t grow =3D ctx->poll_grow; + if (shrink =3D=3D 0) { + shrink =3D 2; + } =20 - if (grow =3D=3D 0) { - grow =3D 2; - } + if (block_ns < (ctx->poll_ns / shrink)) { + ctx->poll_ns /=3D shrink; + } =20 - if (poll->ns) { - poll->ns *=3D grow; - } else { - poll->ns =3D 4000; /* start polling at 4 microseconds */ - } + trace_poll_shrink(ctx, old, ctx->poll_ns); +} =20 - if (poll->ns > ctx->poll_max_ns) { - poll->ns =3D ctx->poll_max_ns; - } +static void grow_polling_time(AioContext *ctx, int64_t block_ns) +{ + /* There is room to grow, poll longer */ + int64_t old =3D ctx->poll_ns; + int64_t grow =3D ctx->poll_grow; =20 - trace_poll_grow(ctx, old, poll->ns); + if (grow =3D=3D 0) { + grow =3D 2; } + + if (block_ns > ctx->poll_ns * grow) { + ctx->poll_ns =3D block_ns; + } else { + ctx->poll_ns *=3D grow; + } + + if (ctx->poll_ns > ctx->poll_max_ns) { + ctx->poll_ns =3D ctx->poll_max_ns; + } + + trace_poll_grow(ctx, old, ctx->poll_ns); } =20 +static void adjust_block_ns(AioContext *ctx, int64_t block_ns) +{ + AioHandler *node; + int64_t adj_block_ns =3D -1; + + QLIST_FOREACH(node, &ctx->poll_aio_handlers, node_poll) { + if (node->poll.has_event) { + /* + * Update poll.ns for the node with an event. + * Uses a weighted average of the current block_ns and the pre= vious + * 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; + + if (node->poll.ns > ctx->poll_max_ns) { + node->poll.ns =3D 0; + } + /* + * To avoid excessive polling time increase, update adj_block_= ns + * for nodes with the event flag set to true + */ + adj_block_ns =3D MAX(adj_block_ns, node->poll.ns); + node->poll.has_event =3D false; + } else { + /* + * No event now, but was active before. + * If it waits longer than poll_max_ns, poll.ns will stay 0 + * until the next event arrives. + */ + if (node->poll.ns !=3D 0) { + node->poll.ns +=3D block_ns; + if (node->poll.ns > ctx->poll_max_ns) { + node->poll.ns =3D 0; + } + } + } + } + + if (adj_block_ns >=3D 0) { + if (adj_block_ns > ctx->poll_ns) { + grow_polling_time(ctx, adj_block_ns); + } else { + shrink_polling_time(ctx, adj_block_ns); + } + } + } + bool aio_poll(AioContext *ctx, bool blocking) { AioHandlerList ready_list =3D QLIST_HEAD_INITIALIZER(ready_list); @@ -723,6 +772,10 @@ bool aio_poll(AioContext *ctx, bool blocking) =20 aio_free_deleted_handlers(ctx); =20 + if (ctx->poll_max_ns) { + adjust_block_ns(ctx, block_ns); + } + qemu_lockcnt_dec(&ctx->list_lock); =20 progress |=3D timerlistgroup_run_timers(&ctx->tlg); @@ -784,6 +837,7 @@ void aio_context_set_poll_params(AioContext *ctx, int64= _t max_ns, =20 qemu_lockcnt_inc(&ctx->list_lock); QLIST_FOREACH(node, &ctx->aio_handlers, node) { + node->poll.has_event =3D false; node->poll.ns =3D 0; } qemu_lockcnt_dec(&ctx->list_lock); @@ -794,6 +848,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_ns =3D 0; =20 aio_notify(ctx); } diff --git a/util/async.c b/util/async.c index 80d6b01a8a..9d3627566f 100644 --- a/util/async.c +++ b/util/async.c @@ -606,6 +606,7 @@ AioContext *aio_context_new(Error **errp) timerlistgroup_init(&ctx->tlg, aio_timerlist_notify, ctx); =20 ctx->poll_max_ns =3D 0; + ctx->poll_ns =3D 0; ctx->poll_grow =3D 0; ctx->poll_shrink =3D 0; =20 --=20 2.50.1 From nobody Fri Apr 3 20:53:40 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=1774274158; cv=none; d=zohomail.com; s=zohoarc; b=f8NFt4RCV1VYKGy0mhrpjXQ0jYakPBRb1JobegzJUYtRAdC5k0W1EwAGQ6GU6DCZiIc/cfWusiAkaCKPImLkeGBPvt8fuHaCqzcUOUMjYEEM8MzJ45KEyfbhsz8D1PQRKz5i+UC6KHH4mA4g3aCGFfAgkXKWpBDU+GUrUc/SRg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774274158; 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=lcbnpfBJVTyJcVunsTyLxArvfPrWZVsAm5mqRKTbaow=; b=exq+pPCjtLNtbrIIee+8AkVfRGTmjktQfH9mCeOF2lv6sW5Nxm0abSq5z67WeOJpO1+G091LxWGa9q38IRwYH42Imf6ucegdepjgIgHx7ChALCapvy4iyNbgkikuAGEpSjbiH7c5rCNu/dqHTRXMtJqXngz4xvWvk7pZjz0XzNo= 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 1774274158397917.1268519078775; Mon, 23 Mar 2026 06:55:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4fkn-0004Ur-6z; Mon, 23 Mar 2026 09:55:37 -0400 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 1w4fkY-0004K1-0u; Mon, 23 Mar 2026 09:55:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w4fkV-0006RM-At; Mon, 23 Mar 2026 09:55:21 -0400 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62MMLd62832984; Mon, 23 Mar 2026 13:55:13 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 4d1kxq73wf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2026 13:55:13 +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 62NDXAMf004375; Mon, 23 Mar 2026 13:55:12 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4d28c1wak3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2026 13:55:12 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62NDtASB61931892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Mar 2026 13:55:10 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6D7CC58063; Mon, 23 Mar 2026 13:55:10 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B934A58059; Mon, 23 Mar 2026 13:55:09 +0000 (GMT) Received: from IBM-GLTZVH3.ibm.com (unknown [9.61.250.54]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 23 Mar 2026 13:55:09 +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=lcbnpfBJVTyJcVuns TyLxArvfPrWZVsAm5mqRKTbaow=; b=d+RCfqOoiQrS4N7/P+DTA3R8tkw5X6M9q jbr3Lxp4nY4OWVOvNYFhFI4E+7lln2hloBvmkd/YGSyRSu9Xb+IJxIW/FUwazpy6 6BPxCIAFqak1HC8u1a9pKj0LVBUGAm9mUXUSF1PRxCEMYw4Jf3J8zuGg2imqtu7K MrhlQzwxJmIXVmW8tK8uK2oeNvYlHkxShRHa1qWfloj8smJUKt2jnl1iveYgv5F+ vhx3VgQlxHQeNPplSdCtz/boQL2ejwuNWaTnNP+syR/ZJ9mBpFHUW80w38iT+4fv 9B/TEfR92BOgURMoBqBcWtpyPMQPwEQ4ALg6MGVUH3B6Tu4qQZGNQ== From: Jaehoon Kim To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: mjrosato@linux.ibm.com, farman@linux.ibm.com, 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 v2 3/3] qapi/iothread: introduce poll-weight parameter for aio-poll Date: Mon, 23 Mar 2026 08:54:51 -0500 Message-ID: <20260323135451.579655-4-jhkim@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260323135451.579655-1-jhkim@linux.ibm.com> References: <20260323135451.579655-1-jhkim@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: TIIRIPUfpMeU2mxIgVBh32h9tJMZCKj_ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzIzMDEwNyBTYWx0ZWRfX18qkWnb1byd+ mgySBvFMbh2i+godQSArL9LSlqsS67bdMNzBpinKCe5gd9QGcdITA2QnKI9dQW2WaGIoZMCYiT1 fywuLKERKNj7F4Pf6XNfoCGRi91PShF0/33wlBFvQnzquFPy60c1Dq33DTdkMtaApJuABR/JVYb qh0hwotd7wTMLmLjYKtVdCD+rlN3EAaDVUwChjN43NJZnaoET2HAV0Zr/ZvOU765yCG+jLR+0OG CTkLRAu5xRpzceW4UR6jXasaIZ/HanY5A3J2+rBF5JAw5MVCE39YqbAv/YRizVt+3vpFdRnUHng ga03f4Pz0mxP9+B3W/4Vm4z9onYvo2NVxlHedN2i2Z2keyY/tr4eaAclROD5o2PKnW5e7trA1ah LuOS4Bz+nzpAL6Im2bcJYpX7CsRG1vwbB8w1Om1UN3N/bK6O1FEHMPuikTx1l8RIg4CLDveMGqL sPxivkceqO3bDY2bdDw== X-Authority-Analysis: v=2.4 cv=bLEb4f+Z c=1 sm=1 tr=0 ts=69c14641 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=A1X0JdhQAAAA:8 a=4gC5F_T_yQe02bOqTGwA:9 X-Proofpoint-GUID: TIIRIPUfpMeU2mxIgVBh32h9tJMZCKj_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-23_04,2026-03-20_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 clxscore=1015 phishscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603230107 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.156.1; envelope-from=jhkim@linux.ibm.com; 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, 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: 1774274158813158500 Content-Type: text/plain; charset="utf-8" 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 values for poll-grow and poll-shrink parameters from the grow_polling_time() and shrink_polling_time() functions, as these defaults are now properly initialized in iothread.c during IOThread creation. Signed-off-by: Jaehoon Kim Reviewed-by: Stefan Hajnoczi --- include/qemu/aio.h | 4 +++- include/system/iothread.h | 1 + iothread.c | 34 ++++++++++++++++++++++++++++++- monitor/hmp-cmds.c | 1 + qapi/misc.json | 7 +++++++ qapi/qom.json | 8 +++++++- qemu-options.hx | 7 ++++++- tests/unit/test-nested-aio-poll.c | 2 +- util/aio-posix.c | 17 +++++----------- util/aio-win32.c | 3 ++- util/async.c | 1 + 11 files changed, 67 insertions(+), 18 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..0389b8f7a8 100644 --- a/iothread.c +++ b/iothread.c @@ -32,8 +32,14 @@ * 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 =20 static void *iothread_run(void *opaque) @@ -103,6 +109,10 @@ static void iothread_instance_init(Object *obj) IOThread *iothread =3D IOTHREAD(obj); =20 iothread->poll_max_ns =3D IOTHREAD_POLL_MAX_NS_DEFAULT; + iothread->poll_grow =3D IOTHREAD_POLL_GROW_DEFAULT; + iothread->poll_shrink =3D IOTHREAD_POLL_SHRINK_DEFAULT; + iothread->poll_weight =3D IOTHREAD_POLL_WEIGHT_DEFAULT; + iothread->thread_id =3D -1; qemu_sem_init(&iothread->init_done_sem, 0); /* By default, we don't run gcontext */ @@ -164,6 +174,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 +244,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) @@ -260,7 +274,19 @@ static bool iothread_set_param(Object *obj, Visitor *v, return false; } =20 - *field =3D value; + if (value =3D=3D 0) { + if (info->offset =3D=3D offsetof(IOThread, poll_grow)) { + *field =3D IOTHREAD_POLL_GROW_DEFAULT; + } else if (info->offset =3D=3D offsetof(IOThread, poll_shrink)) { + *field =3D IOTHREAD_POLL_SHRINK_DEFAULT; + } else if (info->offset =3D=3D offsetof(IOThread, poll_weight)) { + *field =3D IOTHREAD_POLL_WEIGHT_DEFAULT; + } else { + *field =3D value; + } + } else { + *field =3D value; + } =20 return true; } @@ -288,6 +314,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 +338,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 +387,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 bad034937a..75b6e7fa65 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -206,6 +206,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..39d17010bc 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -85,6 +85,12 @@ # @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. 0 selects the system default value which is current 3 +# (since 10.2) +# # @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 +102,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 c653248f85..feb80b6cfe 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. Valid values are 1 or +# greater. If set to 0, the default value of 3 is used. +# # 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 69e5a874c1..8ddf6c8d36 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -6413,7 +6413,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. @@ -6449,6 +6449,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..4c38f36fd4 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, 3, &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 2b3522f2f9..13b7f94911 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -29,7 +29,6 @@ =20 /* 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) =20 static void adjust_block_ns(AioContext *ctx, int64_t block_ns); static void grow_polling_time(AioContext *ctx, int64_t block_ns); @@ -593,10 +592,6 @@ static void shrink_polling_time(AioContext *ctx, int64= _t block_ns) int64_t old =3D ctx->poll_ns; int64_t shrink =3D ctx->poll_shrink; =20 - if (shrink =3D=3D 0) { - shrink =3D 2; - } - if (block_ns < (ctx->poll_ns / shrink)) { ctx->poll_ns /=3D shrink; } @@ -610,10 +605,6 @@ static void grow_polling_time(AioContext *ctx, int64_t= block_ns) int64_t old =3D ctx->poll_ns; int64_t grow =3D ctx->poll_grow; =20 - if (grow =3D=3D 0) { - grow =3D 2; - } - if (block_ns > ctx->poll_ns * grow) { ctx->poll_ns =3D block_ns; } else { @@ -640,8 +631,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 >> ctx->poll_weight)) + + (block_ns >> ctx->poll_weight) : block_ns; =20 if (node->poll.ns > ctx->poll_max_ns) { node->poll.ns =3D 0; @@ -831,7 +822,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 @@ -848,6 +840,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