From nobody Sun Nov 29 02:09: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1795709311; cv=none; d=zohomail.com; s=zohoarc; b=CprbTCPmTkQnyFB3JEFr737dd/wshntIHrANqXeWPNtJyxcs4tJLHXlHU+djsSbjy+G7GPZ/vkiDViwOFubN+YAFM1kL6KJDYe+mEwDAKXMe2PFBtfsS8H++dpLMH7F3O0fND9OenoFiUEPjfBS+RwLnYFqKpvyp8TERh+h5320= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795709311; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=r+/T5sojzmwmGAddGK2jCTDPemGITbEtqr1SdPYTXzc=; b=UVGkZD5mLT7gnPWPbzB2cNIxKcfmNveiqp4wgjyYFtXKjSekmNPDS1uNReZiA4J3c4IzhbdGMOu2BzygTIX8FhJ1+lFHN6of1DU9mYZqFt/CyoIa8sIb8NDzRAaBvw/u0MAD/OplgAsW+LBrQS5lF0vbKdo+5/BLsgy0fmsTJIQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795709311916579.489747969153; Thu, 26 Nov 2026 08:08:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xWc15-0001L3-6v; Thu, 26 Nov 2026 11:08:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWc0r-0001FI-7z for qemu-devel@nongnu.org; Thu, 26 Nov 2026 11:07:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xWc0o-00008a-A6 for qemu-devel@nongnu.org; Thu, 26 Nov 2026 11:07:57 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-326-vfCQRdY-PWWvDn5IoMS52w-1; Thu, 26 Nov 2026 16:07:48 +0000 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E97051944B2A; Thu, 26 Nov 2026 16:07:46 +0000 (UTC) Received: from thuth-p1g4.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 132091956045; Thu, 26 Nov 2026 16:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795709270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=r+/T5sojzmwmGAddGK2jCTDPemGITbEtqr1SdPYTXzc=; b=InWx0Jhbbip4Xeyqa0cp++dRcHT9eS/ySF7LPlfL3UoWmF0luVeV61bnxNS4WfdRPx4V9x rMcxx3pNcYGtIKXdKC73iq1n/wsg3GM3McvkS3rgWF5zlFF4+3FunNGORhVEexNl8YiZDi Wkru3RZOYQtUb7CiDH89FYgzv/lwUQM= X-MC-Unique: vfCQRdY-PWWvDn5IoMS52w-1 X-Mimecast-MFC-AGG-ID: vfCQRdY-PWWvDn5IoMS52w_1795709267 From: Thomas Huth To: Fabiano Rosas , qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , berrange@redhat.com Subject: [PATCH for-12.0] tests/qtest: Speed up qmp_fd_receive() by doing fewer systemcalls Date: Thu, 26 Nov 2026 17:07:43 +0100 Message-ID: <20261126160743.276957-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @redhat.com) X-ZM-MESSAGEID: 1795709313153158500 Content-Type: text/plain; charset="utf-8" qmp_fd_receive() currently reads each byte individually via recv() from the socket. For tests that do a lot of traffic via QMP, this can be a significant overhead. Unfortunately, we cannot easily use a buffer for storing characters here, since we don't know the amount of characters in the current QMP reply yet, and thus we might read into the next reply already, i.e. the data that is required for the next call to qmp_fd_receive() instead. A buffer would be required to be stored on the caller side, and implementing this would be a major rework in this library and the code using it. So this patch follows a slightly different approach instead: Read the bytes into a buffer with MSG_PEEK first - this does not remove the bytes from the socket queue yet. Then we try to consume as many bytes from the buffer as possible until a full response has been recognized or the buffer has been fully consumed. At the end, we then can finally remove the amount of consumed bytes from the socket queue. This improvement especially speeds up the device-introspect-test in thorough mode. Before the change: $ export QTEST_QEMU_BINARY=3D./qemu-system-aarch64 $ time tests/qtest/device-introspect-test -m thorough >/dev/null real 5m8,861s user 2m37,489s sys 2m33,150s With this change included: $ export QTEST_QEMU_BINARY=3D./qemu-system-aarch64 $ time tests/qtest/device-introspect-test -m thorough >/dev/null real 3m21,598s user 2m11,187s sys 1m11,032s Signed-off-by: Thomas Huth Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/qtest/libqmp.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c index cd12bd26782..9dddeb1eed5 100644 --- a/tests/qtest/libqmp.c +++ b/tests/qtest/libqmp.c @@ -68,23 +68,27 @@ QDict *qmp_fd_receive(int fd) qmp.response =3D NULL; json_message_parser_init(&qmp.parser, qmp_response, &qmp, NULL); while (!qmp.response) { - ssize_t len; - char c; + ssize_t len, consumed; + char buf[512]; =20 - len =3D recv(fd, &c, 1, 0); - if (len =3D=3D -1 && errno =3D=3D EINTR) { - continue; - } - - if (len =3D=3D -1 || len =3D=3D 0) { + /* Get copy of the available data without removing it from the que= ue */ + len =3D RETRY_ON_EINTR(recv(fd, buf, sizeof(buf), MSG_PEEK)); + if (len <=3D 0) { fprintf(stderr, "Broken pipe\n"); abort(); } =20 + for (consumed =3D 0; consumed < len && !qmp.response; consumed++) { + json_message_parser_feed(&qmp.parser, &buf[consumed], 1); + } + if (log) { - g_assert(write(2, &c, 1) =3D=3D 1); + g_assert(write(2, buf, consumed) =3D=3D consumed); } - json_message_parser_feed(&qmp.parser, &c, 1); + + /* Remove the handled characters from the queue */ + len =3D RETRY_ON_EINTR(recv(fd, buf, consumed, 0)); + g_assert_cmpint(len, =3D=3D, consumed); } if (log) { g_assert(write(2, "\n", 1) =3D=3D 1); --=20 2.56.1