From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, kvm@vger.kernel.org,
stephen@networkplumber.org, wexu@redhat.com, stefanha@redhat.com
Subject: Re: [PATCH net-next V5 2/3] vhost_net: tx batching
Date: Wed, 18 Jan 2017 19:03:16 +0200 [thread overview]
Message-ID: <20170118190312-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1484722923-7698-3-git-send-email-jasowang@redhat.com>
On Wed, Jan 18, 2017 at 03:02:02PM +0800, Jason Wang wrote:
> This patch tries to utilize tuntap rx batching by peeking the tx
> virtqueue during transmission, if there's more available buffers in
> the virtqueue, set MSG_MORE flag for a hint for backend (e.g tuntap)
> to batch the packets.
>
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> drivers/vhost/net.c | 23 ++++++++++++++++++++---
> 1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 5dc3465..c42e9c3 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -351,6 +351,15 @@ static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
> return r;
> }
>
> +static bool vhost_exceeds_maxpend(struct vhost_net *net)
> +{
> + struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX];
> + struct vhost_virtqueue *vq = &nvq->vq;
> +
> + return (nvq->upend_idx + vq->num - VHOST_MAX_PEND) % UIO_MAXIOV
> + == nvq->done_idx;
> +}
> +
> /* Expects to be always run from workqueue - which acts as
> * read-size critical section for our kind of RCU. */
> static void handle_tx(struct vhost_net *net)
> @@ -394,8 +403,7 @@ static void handle_tx(struct vhost_net *net)
> /* If more outstanding DMAs, queue the work.
> * Handle upend_idx wrap around
> */
> - if (unlikely((nvq->upend_idx + vq->num - VHOST_MAX_PEND)
> - % UIO_MAXIOV == nvq->done_idx))
> + if (unlikely(vhost_exceeds_maxpend(net)))
> break;
>
> head = vhost_net_tx_get_vq_desc(net, vq, vq->iov,
> @@ -454,6 +462,16 @@ static void handle_tx(struct vhost_net *net)
> msg.msg_control = NULL;
> ubufs = NULL;
> }
> +
> + total_len += len;
> + if (total_len < VHOST_NET_WEIGHT &&
> + !vhost_vq_avail_empty(&net->dev, vq) &&
> + likely(!vhost_exceeds_maxpend(net))) {
> + msg.msg_flags |= MSG_MORE;
> + } else {
> + msg.msg_flags &= ~MSG_MORE;
> + }
> +
> /* TODO: Check specific error and bomb out unless ENOBUFS? */
> err = sock->ops->sendmsg(sock, &msg, len);
> if (unlikely(err < 0)) {
> @@ -472,7 +490,6 @@ static void handle_tx(struct vhost_net *net)
> vhost_add_used_and_signal(&net->dev, vq, head, 0);
> else
> vhost_zerocopy_signal_used(net, vq);
> - total_len += len;
> vhost_net_tx_packet(net);
> if (unlikely(total_len >= VHOST_NET_WEIGHT)) {
> vhost_poll_queue(&vq->poll);
> --
> 2.7.4
next prev parent reply other threads:[~2017-01-18 17:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 7:02 [PATCH net-next V5 0/3] vhost_net tx batching Jason Wang
2017-01-18 7:02 ` [PATCH net-next V5 1/3] vhost: better detection of available buffers Jason Wang
2017-01-18 17:03 ` Michael S. Tsirkin
2017-01-18 7:02 ` [PATCH net-next V5 2/3] vhost_net: tx batching Jason Wang
2017-01-18 17:03 ` Michael S. Tsirkin [this message]
2017-01-18 7:02 ` [PATCH net-next V5 3/3] tun: rx batching Jason Wang
2017-01-18 17:03 ` Michael S. Tsirkin
2017-01-18 21:35 ` [PATCH net-next V5 0/3] vhost_net tx batching David Miller
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=20170118190312-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stefanha@redhat.com \
--cc=stephen@networkplumber.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=wexu@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 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 NNTP newsgroup(s).