summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2018-07-20 08:15:17 +0800
committerDavid S. Miller <davem@davemloft.net>2018-07-22 09:43:31 -0700
commitc92a8a8cb7d499a352ebb625667a780bfc99ba77 (patch)
treeb5782fc0544017b141347dc084b140620777043e
parenta2a91a137ad4e9c538c9b63b2bfcf7a105924143 (diff)
vhost_net: introduce tx_can_batch()
Introduce tx_can_batch() to determine whether TX could be batched. This will help to reduce the code duplication in the future. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/vhost/net.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index a014ca042390..f59b615e2989 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -514,6 +514,12 @@ static int get_tx_bufs(struct vhost_net *net,
return ret;
}
+static bool tx_can_batch(struct vhost_virtqueue *vq, size_t total_len)
+{
+ return total_len < VHOST_NET_WEIGHT &&
+ !vhost_vq_avail_empty(vq->dev, vq);
+}
+
/* 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)
@@ -598,8 +604,7 @@ static void handle_tx(struct vhost_net *net)
ubufs = NULL;
}
total_len += len;
- if (total_len < VHOST_NET_WEIGHT &&
- !vhost_vq_avail_empty(&net->dev, vq) &&
+ if (tx_can_batch(vq, total_len) &&
likely(!vhost_exceeds_maxpend(net))) {
msg.msg_flags |= MSG_MORE;
} else {