DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huawei Xie <huawei.xie@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 07/14] patch virtio_tx_route
Date: Mon, 20 Oct 2014 12:38:19 +0800
Message-ID: <1413779906-28113-8-git-send-email-huawei.xie@intel.com> (raw)
In-Reply-To: <1413779906-28113-1-git-send-email-huawei.xie@intel.com>

in new vhost example, the packet passed to virtio_tx_route has been allocated 
mbuf, so there is no need to allocate mbuf for it.
use vlan offload to transmit vlan tagged packet.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 examples/vhost/main.c | 65 ++++++++-------------------------------------------
 1 file changed, 10 insertions(+), 55 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index aad86f3..bbfdef6 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1091,9 +1091,7 @@ static inline void __attribute__((always_inline))
 virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, struct rte_mempool *mbuf_pool, uint16_t vlan_tag)
 {
 	struct mbuf_table *tx_q;
-	struct vlan_ethhdr *vlan_hdr;
 	struct rte_mbuf **m_table;
-	struct rte_mbuf *mbuf, *prev;
 	unsigned len, ret, offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
 	struct virtio_net_data_ll *dev_ll = ll_root_used;
@@ -1101,8 +1099,10 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, struct rte_mempool *
 	struct virtio_net *dev = vdev->dev;
 
 	/*check if destination is local VM*/
-	if ((vm2vm_mode == VM2VM_SOFTWARE) && (virtio_tx_local(vdev, m) == 0))
+	if ((vm2vm_mode == VM2VM_SOFTWARE) && (virtio_tx_local(vdev, m) == 0)) {
+		rte_pktmbuf_free(m);
 		return;
+	}
 
 	if (vm2vm_mode == VM2VM_HARDWARE) {
 		while (dev_ll != NULL) {
@@ -1118,7 +1118,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, struct rte_mempool *
 					"(%"PRIu64") TX: Source and destination"
 					" MAC addresses are the same. Dropping "
 					"packet.\n",
-					dev_ll->vdev->device_fh);
+					dev_ll->vdev->dev->device_fh);
+					rte_pktmbuf_free(m);
 					return;
 				}
 				offset = 4;
@@ -1144,58 +1145,12 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, struct rte_mempool *
 	tx_q = &lcore_tx_queue[lcore_id];
 	len = tx_q->len;
 
-	/* Allocate an mbuf and populate the structure. */
-	mbuf = rte_pktmbuf_alloc(mbuf_pool);
-	if (unlikely(mbuf == NULL)) {
-		RTE_LOG(ERR, VHOST_DATA,
-			"Failed to allocate memory for mbuf.\n");
-		return;
-	}
-
-	mbuf->data_len = m->data_len + VLAN_HLEN + offset;
-	mbuf->pkt_len = m->pkt_len + VLAN_HLEN + offset;
-	mbuf->nb_segs = m->nb_segs;
+	m->ol_flags = PKT_TX_VLAN_PKT;
+	/*FIXME: offset*/
+	m->data_len += offset;
+	m->vlan_tci = vlan_tag;
 
-	/* Copy ethernet header to mbuf. */
-	rte_memcpy(rte_pktmbuf_mtod(mbuf, void *),
-		rte_pktmbuf_mtod(m, const void *),
-		ETH_HLEN);
-
-
-	/* Setup vlan header. Bytes need to be re-ordered for network with htons()*/
-	vlan_hdr = rte_pktmbuf_mtod(mbuf, struct vlan_ethhdr *);
-	vlan_hdr->h_vlan_encapsulated_proto = vlan_hdr->h_vlan_proto;
-	vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q);
-	vlan_hdr->h_vlan_TCI = htons(vlan_tag);
-
-	/* Copy the remaining packet contents to the mbuf. */
-	rte_memcpy((void *)(rte_pktmbuf_mtod(mbuf, uint8_t *) + VLAN_ETH_HLEN),
-		(const void *)(rte_pktmbuf_mtod(m, uint8_t *) + ETH_HLEN),
-		(m->data_len - ETH_HLEN));
-
-	/* Copy the remaining segments for the whole packet. */
-	prev = mbuf;
-	while (m->next) {
-		/* Allocate an mbuf and populate the structure. */
-		struct rte_mbuf *next_mbuf = rte_pktmbuf_alloc(mbuf_pool);
-		if (unlikely(next_mbuf == NULL)) {
-			rte_pktmbuf_free(mbuf);
-			RTE_LOG(ERR, VHOST_DATA,
-				"Failed to allocate memory for mbuf.\n");
-			return;
-		}
-
-		m = m->next;
-		prev->next = next_mbuf;
-		prev = next_mbuf;
-		next_mbuf->data_len = m->data_len;
-
-		/* Copy data to next mbuf. */
-		rte_memcpy(rte_pktmbuf_mtod(next_mbuf, void *),
-			rte_pktmbuf_mtod(m, const void *), m->data_len);
-	}
-
-	tx_q->m_table[len] = mbuf;
+	tx_q->m_table[len] = m;
 	len++;
 	if (enable_stats) {
 		dev_statistics[dev->device_fh].tx_total++;
-- 
1.8.1.4

  parent reply	other threads:[~2014-10-20  4:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20  4:38 [dpdk-dev] [PATCH 00/14] new vhost example Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 01/14] copy old " Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 02/14] remove virtio_dev_rx, virtio_dev_merge_rx, copy_from_mbuf_to_ring, virtio_dev_tx, virtio_dev_merge_tx Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 03/14] add bak two hpa region functions Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 04/14] dev->vdev Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 05/14] hpa region Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 06/14] enqueue_burst, dequeue_burst, mac learning Huawei Xie
2014-10-20  4:38 ` Huawei Xie [this message]
2014-10-20  4:38 ` [dpdk-dev] [PATCH 08/14] remove gpa_to_vva, base_index Huawei Xie
2014-10-23  9:43   ` Thomas Monjalon
2014-10-20  4:38 ` [dpdk-dev] [PATCH 09/14] other APIs Huawei Xie
2014-10-23  9:44   ` Thomas Monjalon
2014-10-20  4:38 ` [dpdk-dev] [PATCH 10/14] vmdq_rx_q Huawei Xie
2014-10-23  9:45   ` Thomas Monjalon
2014-10-20  4:38 ` [dpdk-dev] [PATCH 11/14] minor fixes Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 12/14] add branch hint Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 13/14] INC_VEC Huawei Xie
2014-10-20  4:38 ` [dpdk-dev] [PATCH 14/14] Makefile Huawei Xie
2014-10-23  9:48   ` Thomas Monjalon
2014-10-20  5:21 ` [dpdk-dev] [PATCH 00/14] new vhost example Ouyang, Changchun
2014-10-23 11:10 ` Thomas Monjalon
2014-10-23 16:17   ` Xie, Huawei

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=1413779906-28113-8-git-send-email-huawei.xie@intel.com \
    --to=huawei.xie@intel.com \
    --cc=dev@dpdk.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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git