From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEE92606A325 for ; Mon, 30 Nov 2026 10:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=gKnlCeWt; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=mvsEKm9I; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=HqENqayY; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=0Z4wT7Mw Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xXyLB-0006yN-M1; Mon, 30 Nov 2026 05:10:33 -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 1xXyL7-0006w4-8h for qemu-devel@nongnu.org; Mon, 30 Nov 2026 05:10:29 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xXyL5-0003rS-FX for qemu-devel@nongnu.org; Mon, 30 Nov 2026 05:10:29 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1D7B61F390; Mon, 30 Nov 2026 10:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796033422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YAVuiwJnmXlafLCnmmn1+c3nLbTUbvmuTdgO6szMlfs=; b=gKnlCeWtAjijCq1Gl9DsYJ10rZ9sz4NaUg0L1PEEVybacDPHNYEEs4o/yRCd3BwhLQ4xtu uuK3UaFKMQK/2HwB0MPJTvjcIagLrI7Tl9Eat4D57BMdc1qQdGBmD80Bg3AMxO1twYj24n sKXtOl6Ms8Ty0s0qocbfviEuwqFaXWo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796033422; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YAVuiwJnmXlafLCnmmn1+c3nLbTUbvmuTdgO6szMlfs=; b=mvsEKm9IwoGKyd2LvIHUM8ZjdjHTfcobVahM5Yp1zbU+hXs7Z8pCNpcRdxoIE/T2yvxif/ zPcf/LZPvUip23Dw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=HqENqayY; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=0Z4wT7Mw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796033421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YAVuiwJnmXlafLCnmmn1+c3nLbTUbvmuTdgO6szMlfs=; b=HqENqayYcnScIwbI4dsgw11pLJ/IMNISVXqLD243T0QdKs22VvZ9oiEGzxMajkAsPyXHqL i/65/7NRgEe78X+jtQsyZVQPr1rlRNxlL2UdqVNMmm+dlx6q6ASrClW5Vdf9+tbWV1R0CY grCRZavlOhS8xnQN74NVptgfao2XC3I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796033421; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YAVuiwJnmXlafLCnmmn1+c3nLbTUbvmuTdgO6szMlfs=; b=0Z4wT7Mw6x4xmP7DzUTk2nt+RDwy2BL3pd6tWAUp7KicLCP/Y/WQKo2yfTlwdehiKPpCNl nmxqi4yfsqdTE5CA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 86D5713408; Mon, 30 Nov 2026 10:10:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5ZtGCIxLDWtcfgAAD6G6ig (envelope-from ); Mon, 30 Nov 2026 10:10:20 +0000 From: Fabiano Rosas To: Thomas Huth , qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , Alex =?utf-8?Q?Benn=C3=A9e?= , berrange@redhat.com Subject: Re: [PATCH for-12.0] tests/qtest: Speed up qmp_fd_receive() by doing fewer systemcalls In-Reply-To: <20261126160743.276957-1-thuth@redhat.com> References: <20261126160743.276957-1-thuth@redhat.com> Date: Mon, 30 Nov 2026 07:10:18 -0300 Message-ID: <87pkvmfx4l.fsf@suse.de> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-Spamd-Result: default: False [-13.51 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo,suse.de:email,suse.de:dkim]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -13.51 X-Rspamd-Queue-Id: 1D7B61F390 Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Thomas Huth writes: > 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=./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=./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 > --- > 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 = 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]; > > - len = recv(fd, &c, 1, 0); > - if (len == -1 && errno == EINTR) { > - continue; > - } > - > - if (len == -1 || len == 0) { > + /* Get copy of the available data without removing it from the queue */ > + len = RETRY_ON_EINTR(recv(fd, buf, sizeof(buf), MSG_PEEK)); > + if (len <= 0) { > fprintf(stderr, "Broken pipe\n"); > abort(); > } > > + for (consumed = 0; consumed < len && !qmp.response; consumed++) { > + json_message_parser_feed(&qmp.parser, &buf[consumed], 1); > + } > + > if (log) { > - g_assert(write(2, &c, 1) == 1); > + g_assert(write(2, buf, consumed) == consumed); > } > - json_message_parser_feed(&qmp.parser, &c, 1); > + > + /* Remove the handled characters from the queue */ > + len = RETRY_ON_EINTR(recv(fd, buf, consumed, 0)); > + g_assert_cmpint(len, ==, consumed); > } > if (log) { > g_assert(write(2, "\n", 1) == 1); Tested-by: Fabiano Rosas Queued for qtest-next.