[dpdk-dev] [PATCH v6 08/25] lib/librte_vhost: calculate mbuf size

Huawei Xie huawei.xie at intel.com
Wed Oct 8 20:54:42 CEST 2014


As a lib, we have no idea the app defined mbuf size. This patch will calculate
mbuf size dynamically.

Signed-off-by: Huawei Xie <huawei.xie at intel.com>
---
 lib/librte_vhost/vhost_rxtx.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 07fb085..b0b3f95 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -524,8 +524,6 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool, struc
 	uint32_t i;
 	uint16_t free_entries, entry_success = 0;
 	uint16_t avail_idx;
-	uint32_t buf_size = MBUF_SIZE - (sizeof(struct rte_mbuf)
-			+ RTE_PKTMBUF_HEADROOM);
 
 	vq = dev->virtqueue[VIRTIO_TXQ];
 	avail_idx =  *((volatile uint16_t *)&vq->avail->idx);
@@ -589,12 +587,6 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool, struc
 
 		vb_offset = 0;
 		vb_avail = desc->len;
-		seg_offset = 0;
-		seg_avail = buf_size;
-		cpy_len = RTE_MIN(vb_avail, seg_avail);
-
-		PRINT_PACKET(dev, (uintptr_t)vb_addr, desc->len, 0);
-
 		/* Allocate an mbuf and populate the structure. */
 		m = rte_pktmbuf_alloc(mbuf_pool);
 		if (unlikely(m == NULL)) {
@@ -602,6 +594,11 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool, struc
 				"Failed to allocate memory for mbuf.\n");
 			return entry_success;
 		}
+		seg_offset = 0;
+		seg_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
+		cpy_len = RTE_MIN(vb_avail, seg_avail);
+
+		PRINT_PACKET(dev, (uintptr_t)vb_addr, desc->len, 0);
 
 		seg_num++;
 		cur = m;
@@ -638,7 +635,7 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool, struc
 				prev->next = cur;
 				prev = cur;
 				seg_offset = 0;
-				seg_avail = buf_size;
+				seg_avail = cur->buf_len - RTE_PKTMBUF_HEADROOM;
 			} else {
 				if (desc->flags & VRING_DESC_F_NEXT) {
 					/*
@@ -672,7 +669,7 @@ virtio_dev_merge_tx(struct virtio_net *dev, struct rte_mempool *mbuf_pool, struc
 						prev->next = cur;
 						prev = cur;
 						seg_offset = 0;
-						seg_avail = buf_size;
+						seg_avail = cur->buf_len - RTE_PKTMBUF_HEADROOM;
 					}
 
 					desc = &vq->desc[desc->next];
-- 
1.8.1.4



More information about the dev mailing list