>From d57ad96083fc57205336af1b5ea777e5185f1581 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Wed, 20 Sep 2017 11:44:49 +0800 Subject: [PATCH] vhost_net: avoid unnecessary wakeups during tx Signed-off-by: Jason Wang --- drivers/vhost/net.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index ed476fa..e7349cf 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -444,8 +444,11 @@ static bool vhost_exceeds_maxpend(struct vhost_net *net) * read-size critical section for our kind of RCU. */ static void handle_tx(struct vhost_net *net) { + struct vhost_net_virtqueue *rx_nvq = &net->vqs[VHOST_NET_VQ_RX]; struct vhost_net_virtqueue *nvq = &net->vqs[VHOST_NET_VQ_TX]; struct vhost_virtqueue *vq = &nvq->vq; + struct vhost_virtqueue *rx_vq = &rx_nvq->vq; + unsigned out, in; int head; struct msghdr msg = { @@ -462,6 +465,10 @@ static void handle_tx(struct vhost_net *net) struct vhost_net_ubuf_ref *uninitialized_var(ubufs); bool zcopy, zcopy_used; + mutex_lock(&rx_vq->mutex); + vhost_net_disable_vq(net, rx_vq); + mutex_unlock(&rx_vq->mutex); + mutex_lock(&vq->mutex); sock = vq->private_data; if (!sock) @@ -574,13 +581,21 @@ static void handle_tx(struct vhost_net *net) else vhost_zerocopy_signal_used(net, vq); vhost_net_tx_packet(net); - if (unlikely(total_len >= VHOST_NET_WEIGHT)) { - vhost_poll_queue(&vq->poll); + if (unlikely(total_len >= VHOST_NET_WEIGHT)) break; - } } out: mutex_unlock(&vq->mutex); + + mutex_lock(&rx_vq->mutex); + vhost_net_enable_vq(net, rx_vq); + mutex_unlock(&rx_vq->mutex); + + if (unlikely(total_len >= VHOST_NET_WEIGHT)) { + mutex_lock(&vq->mutex); + vhost_poll_queue(&vq->poll); + mutex_unlock(&vq->mutex); + } } static int peek_head_len(struct vhost_net_virtqueue *rvq, struct sock *sk) -- 1.8.3.1