This patch makes virtio_dev_merge_tx return the received packets to app layer. Previously virtio_tx_route is called to route these packets and then free them.
Signed-off-by: Huawei Xie <huawei.xie at intel.com> --- lib/librte_vhost/vhost_rxtx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index c9e3b1e..07fb085 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -512,8 +512,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, struct rte_mbuf **pkts, } /* This function works for TX packets with mergeable feature enabled. */ -static inline void __attribute__((always_inline)) -virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool) +static uint16_t void __attribute__((always_inline)) +virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count) { struct rte_mbuf *m, *prev; struct vhost_virtqueue *vq; @@ -532,7 +532,7 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool) /* If there are no available buffers then return. */ if (vq->last_used_idx == avail_idx) - return; + return 0; LOG_DEBUG(VHOST_DATA, "(%"PRIu64") virtio_dev_merge_tx()\n", dev->device_fh); @@ -543,6 +543,7 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool) /*get the number of free entries in the ring*/ free_entries = (avail_idx - vq->last_used_idx); + free_entries = RTE_MIN(free_entries, count); /* Limit to MAX_PKT_BURST. */ free_entries = RTE_MIN(free_entries, MAX_PKT_BURST); @@ -599,7 +600,7 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool) if (unlikely(m == NULL)) { RTE_LOG(ERR, VHOST_DATA, "Failed to allocate memory for mbuf.\n"); - return; + return entry_success; } seg_num++; @@ -701,9 +702,9 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool) m->nb_segs = seg_num; + pkts[entry_success] = m; vq->last_used_idx++; entry_success++; - rte_pktmbuf_free(m); } rte_compiler_barrier(); @@ -711,5 +712,6 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool) /* Kick guest if required. */ if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) eventfd_write((int)vq->kickfd, 1); + return entry_success; } -- 1.8.1.4