From: Jason Wang <jasowang@redhat.com>
To: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>,
"David S. Miller" <davem@davemloft.net>,
"Michael S. Tsirkin" <mst@redhat.com>
Cc: netdev@vger.kernel.org, kvm@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v2 net-next 3/4] vhost_net: Avoid rx queue wake-ups during busypoll
Date: Wed, 4 Jul 2018 11:26:35 +0800 [thread overview]
Message-ID: <1d96dc18-de3f-4974-4bc5-5390caf24779@redhat.com> (raw)
In-Reply-To: <1530603094-2476-4-git-send-email-makita.toshiaki@lab.ntt.co.jp>
On 2018年07月03日 15:31, Toshiaki Makita wrote:
> We may run handle_rx() while rx work is queued. For example a packet can
> push the rx work during the window before handle_rx calls
> vhost_net_disable_vq().
> In that case busypoll immediately exits due to vhost_has_work()
> condition and enables vq again. This can lead to another unnecessary rx
> wake-ups, so poll rx work instead of enabling the vq.
>
> Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
> ---
> drivers/vhost/net.c | 26 +++++++++++++++++++-------
> 1 file changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index 811c0e5..791bc8b 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -653,7 +653,8 @@ static void vhost_rx_signal_used(struct vhost_net_virtqueue *nvq)
> nvq->done_idx = 0;
> }
>
> -static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk)
> +static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk,
> + bool *busyloop_intr)
> {
> struct vhost_net_virtqueue *rnvq = &net->vqs[VHOST_NET_VQ_RX];
> struct vhost_net_virtqueue *tnvq = &net->vqs[VHOST_NET_VQ_TX];
> @@ -671,11 +672,16 @@ static int vhost_net_rx_peek_head_len(struct vhost_net *net, struct sock *sk)
> preempt_disable();
> endtime = busy_clock() + tvq->busyloop_timeout;
>
> - while (vhost_can_busy_poll(endtime) &&
> - !vhost_has_work(&net->dev) &&
> - !sk_has_rx_data(sk) &&
> - vhost_vq_avail_empty(&net->dev, tvq))
> + while (vhost_can_busy_poll(endtime)) {
> + if (vhost_has_work(&net->dev)) {
> + *busyloop_intr = true;
> + break;
> + }
> + if (sk_has_rx_data(sk) ||
> + !vhost_vq_avail_empty(&net->dev, tvq))
> + break;
> cpu_relax();
> + }
>
> preempt_enable();
>
> @@ -795,6 +801,7 @@ static void handle_rx(struct vhost_net *net)
> s16 headcount;
> size_t vhost_hlen, sock_hlen;
> size_t vhost_len, sock_len;
> + bool busyloop_intr = false;
> struct socket *sock;
> struct iov_iter fixup;
> __virtio16 num_buffers;
> @@ -818,7 +825,9 @@ static void handle_rx(struct vhost_net *net)
> vq->log : NULL;
> mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF);
>
> - while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk))) {
> + while ((sock_len = vhost_net_rx_peek_head_len(net, sock->sk,
> + &busyloop_intr))) {
> + busyloop_intr = false;
> sock_len += sock_hlen;
> vhost_len = sock_len + vhost_hlen;
> headcount = get_rx_bufs(vq, vq->heads + nvq->done_idx,
> @@ -905,7 +914,10 @@ static void handle_rx(struct vhost_net *net)
> goto out;
> }
> }
> - vhost_net_enable_vq(net, vq);
> + if (unlikely(busyloop_intr))
> + vhost_poll_queue(&vq->poll);
> + else
> + vhost_net_enable_vq(net, vq);
> out:
> vhost_rx_signal_used(nvq);
> mutex_unlock(&vq->mutex);
Acked-by: Jason Wang <jasowang@redhat.com>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2018-07-04 3:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 7:31 [PATCH v2 net-next 0/4] vhost_net: Avoid vq kicks during busyloop Toshiaki Makita
2018-07-03 7:31 ` [PATCH v2 net-next 1/4] vhost_net: Rename local variables in vhost_net_rx_peek_head_len Toshiaki Makita
2018-07-03 9:03 ` Jason Wang
2018-07-03 7:31 ` [PATCH v2 net-next 2/4] vhost_net: Avoid tx vring kicks during busyloop Toshiaki Makita
2018-07-03 9:04 ` Jason Wang
2018-07-03 7:31 ` [PATCH v2 net-next 3/4] vhost_net: Avoid rx queue wake-ups during busypoll Toshiaki Makita
2018-07-03 7:31 ` [PATCH v2 net-next 4/4] vhost_net: Avoid rx vring kicks during busyloop Toshiaki Makita
[not found] ` <1530603094-2476-4-git-send-email-makita.toshiaki@lab.ntt.co.jp>
2018-07-04 3:26 ` Jason Wang [this message]
[not found] ` <1530603094-2476-5-git-send-email-makita.toshiaki@lab.ntt.co.jp>
2018-07-03 9:05 ` Jason Wang
2018-07-04 1:21 ` Toshiaki Makita
2018-07-04 3:26 ` Jason Wang
2018-07-04 3:27 ` Jason Wang
2018-07-04 5:35 ` [PATCH v2 net-next 0/4] vhost_net: Avoid vq " Michael S. Tsirkin
2018-07-04 12:31 ` 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=1d96dc18-de3f-4974-4bc5-5390caf24779@redhat.com \
--to=jasowang@redhat.com \
--cc=davem@davemloft.net \
--cc=kvm@vger.kernel.org \
--cc=makita.toshiaki@lab.ntt.co.jp \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
/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).