public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v4 3/4] vhost-user: introduce vhost-user API
Date: Thu, 12 Sep 2024 15:40:35 +0200	[thread overview]
Message-ID: <20240912154035.78de6334@elisabeth> (raw)
In-Reply-To: <2a0d56e9-9c7d-4f22-bc61-4177d69032ae@redhat.com>

On Thu, 12 Sep 2024 14:41:53 +0200
Laurent Vivier <lvivier@redhat.com> wrote:

> On 10/09/2024 17:47, Stefano Brivio wrote:
> > Nits and a couple of questions only:
> > 
> > On Fri,  6 Sep 2024 18:04:48 +0200
> > Laurent Vivier <lvivier@redhat.com> wrote:
> >   
> >> Add vhost_user.c and vhost_user.h that define the functions needed
> >> to implement vhost-user backend.
> >>
> >> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> >> ---
> >>   Makefile     |    4 +-
> >>   iov.c        |    1 -
> >>   vhost_user.c | 1265 ++++++++++++++++++++++++++++++++++++++++++++++++++
> >>   vhost_user.h |  203 ++++++++
> >>   virtio.c     |    5 -
> >>   virtio.h     |    2 +-
> >>   6 files changed, 1471 insertions(+), 9 deletions(-)
> >>   create mode 100644 vhost_user.c
> >>   create mode 100644 vhost_user.h  
> ...
> >> diff --git a/vhost_user.c b/vhost_user.c
> >> new file mode 100644
> >> index 000000000000..6008a8adc967
> >> --- /dev/null
> >> +++ b/vhost_user.c  
> ...
> >> +/**
> >> + * vu_wait_queue() - wait for new free entries in the virtqueue
> >> + * @vq:		virtqueue to wait on
> >> + */
> >> +static int vu_wait_queue(const struct vu_virtq *vq)
> >> +{
> >> +	eventfd_t kick_data;
> >> +	ssize_t rc;
> >> +	int status;
> >> +
> >> +	/* wait for the kernel to put new entries in the queue */
> >> +	status = fcntl(vq->kick_fd, F_GETFL);
> >> +	if (status == -1)
> >> +		return -1;  
> > 
> > Same as on v3 (I see you changed this below, but not here): if you
> > don't use status later, you can omit storing it.  
> 
> We need status with F_SETFL below:

Oops, sorry, of course!

> >> +
> >> +	if (fcntl(vq->kick_fd, F_SETFL, status & ~O_NONBLOCK))
> >> +		return -1;
> >> +
> >> +	rc = eventfd_read(vq->kick_fd, &kick_data);
> >> +
> >> +	if (fcntl(vq->kick_fd, F_SETFL, status))
> >> +		return -1;
> >> +
> >> +	if (rc == -1)
> >> +		return -1;
> >> +
> >> +	return 0;
> >> +}  
> ...
> >> +/**
> >> + * vu_handle_tx() - Receive data from the TX virtqueue
> >> + * @vdev:	vhost-user device
> >> + * @index:	index of the virtqueue
> >> + * @now:	Current timestamp
> >> + */
> >> +static void vu_handle_tx(struct vu_dev *vdev, int index,
> >> +			 const struct timespec *now)
> >> +{
> >> +	struct vu_virtq_element elem[VIRTQUEUE_MAX_SIZE];
> >> +	struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
> >> +	struct vu_virtq *vq = &vdev->vq[index];
> >> +	int hdrlen = vdev->hdrlen;
> >> +	int out_sg_count;
> >> +	int count;
> >> +  
> > 
> > Excess newline (same as v3).  
> 
> Done.
> 
> >   
> >> +
> >> +	if (!VHOST_USER_IS_QUEUE_TX(index)) {
> >> +		debug("vhost-user: index %d is not a TX queue", index);
> >> +		return;
> >> +	}
> >> +
> >> +	tap_flush_pools();
> >> +
> >> +	count = 0;
> >> +	out_sg_count = 0;
> >> +	while (count < VIRTQUEUE_MAX_SIZE) {  
> > 
> > So, I see that this is limited to 1024 iterations now (it was limited
> > also earlier, but I didn't realise that).
> > 
> > If we loop at most VIRTQUEUE_MAX_SIZE times, that means, I guess, that
> > while we're popping elements, the queue can't be written to, correct?  
> 
> No, I think the queue can be read and write at the same time.
> 
> > Or it can be written to, but we'll get an additional kick after
> > vu_queue_notify() if that happens?  
> 
> I could check the protocol and the code, but I think it should work like that.

Well, okay, it should be obvious enough.

-- 
Stefano


  reply	other threads:[~2024-09-12 13:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06 16:04 [PATCH v4 0/4] Add vhost-user support to passt. (part 3) Laurent Vivier
2024-09-06 16:04 ` [PATCH v4 1/4] packet: replace struct desc by struct iovec Laurent Vivier
2024-09-06 16:04 ` [PATCH v4 2/4] vhost-user: introduce virtio API Laurent Vivier
2024-09-10 15:47   ` Stefano Brivio
2024-09-12 11:23     ` Laurent Vivier
2024-09-12 13:36       ` Stefano Brivio
2024-09-12 14:03         ` Laurent Vivier
2024-09-12 14:08           ` Stefano Brivio
2024-09-06 16:04 ` [PATCH v4 3/4] vhost-user: introduce vhost-user API Laurent Vivier
2024-09-10 15:47   ` Stefano Brivio
2024-09-12 12:41     ` Laurent Vivier
2024-09-12 13:40       ` Stefano Brivio [this message]
2024-09-06 16:04 ` [PATCH v4 4/4] vhost-user: add vhost-user Laurent Vivier
2024-09-10 15:47   ` Stefano Brivio
2024-09-12 14:05     ` Laurent Vivier

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=20240912154035.78de6334@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /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).