All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: "Fabiano Rosas" <farosas@suse.de>,
	qemu-devel@nongnu.org, "Laurent Vivier" <lvivier@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH for-12.0] tests/qtest: Speed up qmp_fd_receive() by doing fewer systemcalls
Date: Thu, 26 Nov 2026 16:15:03 +0000	[thread overview]
Message-ID: <awhbBycacvXwUVp-@redhat.com> (raw)
In-Reply-To: <20261126160743.276957-1-thuth@redhat.com>

On Thu, Nov 26, 2026 at 05:07:43PM +0100, Thomas Huth wrote:
> 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 <thuth@redhat.com>
> ---
>  tests/qtest/libqmp.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


That's a nicer approach than my 5 minute PoC from a few months back
that tried to keep around a buffer statically.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



  reply	other threads:[~2026-11-26 16:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:07 [PATCH for-12.0] tests/qtest: Speed up qmp_fd_receive() by doing fewer systemcalls Thomas Huth
2026-11-26 16:15 ` Daniel P. Berrangé [this message]
2026-11-30 10:10 ` Fabiano Rosas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awhbBycacvXwUVp-@redhat.com \
    --to=berrange@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.