public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 5/5] tap: Improve handling of partially received frames on qemu socket
Date: Fri, 26 Jul 2024 22:33:09 +1000	[thread overview]
Message-ID: <ZqOXhQMYyTwxioir@zatzit> (raw)
In-Reply-To: <20240726133913.6cfa11f5@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 2704 bytes --]

On Fri, Jul 26, 2024 at 01:39:13PM +0200, Stefano Brivio wrote:
> On Fri, 26 Jul 2024 17:20:31 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > Because the Unix socket to qemu is a stream socket, we have no guarantee
> > of where the boundaries between recv() calls will lie.  Typically they
> > will lie on frame boundaries, because that's how qemu will send then, but
> > we can't rely on it.
> > 
> > Currently we handle this case by detecting when we have received a partial
> > frame and performing a blocking recv() to get the remainder, and only then
> > processing the frames. Change it so instead we save the partial frame
> > persistently and include it as the first thing processed next time we
> > receive data from the socket.  This handles a number of (unlikely) cases
> > which previously would not be dealt with correctly:
> > 
> > * If qemu sent a partial frame then waited some time before sending the
> >   remainder, previously we could block here for an unacceptably long time
> > * If qemu sent a tiny partial frame (< 4 bytes) we'd leave the loop without
> >   doing the partial frame handling, which would put us out of sync with
> >   the stream from qemu
> > * If a the blocking recv() only received some of the remainder of the
> >   frame, not all of it, we'd return leaving us out of sync with the
> >   stream again
> > 
> > Caveat: This could memmove() a moderate amount of data (ETH_MAX_MTU).  This
> > is probably acceptable because it's an unlikely case in practice.  If
> > necessary we could mitigate this by using a true ring buffer.
> 
> I don't think that that memmove() is a problem if we have a single
> recv(), even if it happens to be one memmove() for every recv() (guest
> filling up the buffer, common in throughput tests and bulk transfers),
> because it's very small in relative terms anyway.
> 
> I think the ringbuffer would be worth it with multiple recv() calls per
> epoll wakeup, with EPOLLET.

So first, as noted on the earlier patch, I don't think multiple
recv()s per wakeup requires EPOLLET, though the reverse is true.

Regardless, AFAICT the proportion of memmove()s to data received would
not vary regardless of whether we do multiple recv()s per wakeup or
the same number of recv()s split across multiple wakeups.

Of course, if the recv()s line up with frame boundaries, as we expect,
then it doesn't matter anyway, since we won't get partial frames and
we won't need memmove()s.

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-07-26 12:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-26  7:20 [PATCH 0/5] Fix assorted errors in the Qemu socket tap receive handler David Gibson
2024-07-26  7:20 ` [PATCH 1/5] tap: Better report errors receiving from QEMU socket David Gibson
2024-07-26 11:25   ` Stefano Brivio
2024-07-26 11:50     ` Stefano Brivio
2024-07-26 12:02     ` David Gibson
2024-07-26  7:20 ` [PATCH 2/5] tap: Don't attempt to carry on if we get a bad frame length from qemu David Gibson
2024-07-26 11:26   ` Stefano Brivio
2024-07-26  7:20 ` [PATCH 3/5] tap: Don't use EPOLLET on Qemu sockets David Gibson
2024-07-26  8:00   ` Stefano Brivio
2024-07-26 10:44     ` Stefano Brivio
2024-07-26 12:12     ` David Gibson
2024-07-26 13:25       ` Stefano Brivio
2024-07-29  1:15         ` David Gibson
2024-07-26  7:20 ` [PATCH 4/5] tap: Correctly handle frames of odd length David Gibson
2024-07-26  7:20 ` [PATCH 5/5] tap: Improve handling of partially received frames on qemu socket David Gibson
2024-07-26 11:39   ` Stefano Brivio
2024-07-26 12:33     ` David Gibson [this message]
2024-07-26 13:19 ` [PATCH 0/5] Fix assorted errors in the Qemu socket tap receive handler Stefano Brivio

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=ZqOXhQMYyTwxioir@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).