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

in switch_worker and virtio_tx_local, rte_vhost_enqueue_burst is called to
push host packets to guest VM.
before enqueue packets to guest VM, vhost example uses configure-able retry logic to wait for
enough vring entries.
in switch_worker, rte_vhost_dequeue_burst is called to get packets from guest VM,
then virtio device will be bound to a queue in VMDQ for the first transmitted
packet.

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

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index e161282..aad86f3 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1061,17 +1061,8 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 				/*drop the packet if the device is marked for removal*/
 				LOG_DEBUG(VHOST_DATA, "(%"PRIu64") Device is marked for removal\n", tdev->device_fh);
 			} else {
-				uint32_t mergeable =
-					dev_ll->dev->features &
-					(1 << VIRTIO_NET_F_MRG_RXBUF);
-
 				/*send the packet to the local virtio device*/
-				if (likely(mergeable == 0))
-					ret = virtio_dev_rx(dev_ll->dev, &m, 1);
-				else
-					ret = virtio_dev_merge_rx(dev_ll->dev,
-						&m, 1);
-
+				ret = rte_vhost_enqueue_burst(tdev, VIRTIO_RXQ, &m, 1);
 				if (enable_stats) {
 					rte_atomic64_add(
 					&dev_statistics[tdev->device_fh].rx_total_atomic,
@@ -1248,7 +1239,8 @@ switch_worker(__attribute__((unused)) void *arg)
 	const uint16_t lcore_id = rte_lcore_id();
 	const uint16_t num_cores = (uint16_t)rte_lcore_count();
 	uint16_t rx_count = 0;
-	uint32_t mergeable = 0;
+	uint16_t tx_count;
+	uint32_t retry = 0;
 
 	RTE_LOG(INFO, VHOST_DATA, "Procesing on Core %u started\n", lcore_id);
 	lcore_ll = lcore_info[lcore_id].lcore_ll;
@@ -1307,8 +1299,6 @@ switch_worker(__attribute__((unused)) void *arg)
 			/*get virtio device ID*/
 			vdev = dev_ll->vdev;
 			dev = vdev->dev;
-			mergeable =
-				dev->features & (1 << VIRTIO_NET_F_MRG_RXBUF);
 
 			if (vdev->remove) {
 				dev_ll = dev_ll->next;
@@ -1322,15 +1312,18 @@ switch_worker(__attribute__((unused)) void *arg)
 					vdev->vmdq_rx_q, pkts_burst, MAX_PKT_BURST);
 
 				if (rx_count) {
-					if (likely(mergeable == 0))
-						ret_count =
-							virtio_dev_rx(dev,
-							pkts_burst, rx_count);
-					else
-						ret_count =
-							virtio_dev_merge_rx(dev,
-							pkts_burst, rx_count);
-
+					/*
+					* Retry is enabled and the queue is full then we wait and retry to avoid packet loss
+					* Here MAX_PKT_BURST must be less than virtio queue size
+					*/
+					if (enable_retry && unlikely(rx_count > rte_vring_available_entries(dev, VIRTIO_RXQ))) {
+						for (retry = 0; retry < burst_rx_retry_num; retry++) {
+							rte_delay_us(burst_rx_delay_time);
+							if (rx_count <= rte_vring_available_entries(dev, VIRTIO_RXQ))
+								break;
+						}
+					}
+					ret_count = rte_vhost_enqueue_burst(dev, VIRTIO_RXQ, pkts_burst, rx_count);
 					if (enable_stats) {
 						rte_atomic64_add(
 						&dev_statistics[dev_ll->vdev->dev->device_fh].rx_total_atomic,
@@ -1347,11 +1340,17 @@ switch_worker(__attribute__((unused)) void *arg)
 			}
 
 			if (!vdev->remove) {
-				/*Handle guest TX*/
-				if (likely(mergeable == 0))
-					virtio_dev_tx(dev, mbuf_pool);
-				else
-					virtio_dev_merge_tx(dev, mbuf_pool);
+				/* Handle guest TX*/
+				tx_count = rte_vhost_dequeue_burst(dev, VIRTIO_TXQ, mbuf_pool, pkts_burst, MAX_PKT_BURST);
+				/* If this is the first received packet we need to learn the MAC and setup VMDQ */
+				if (unlikely(vdev->ready == DEVICE_MAC_LEARNING) && tx_count) {
+					if (vdev->remove || (link_vmdq(vdev, pkts_burst[0]) == -1)) {
+						while (tx_count--)
+							rte_pktmbuf_free(pkts_burst[tx_count]);
+					}
+				}
+				while (tx_count)
+					virtio_tx_route(vdev, pkts_burst[--tx_count], mbuf_pool, (uint16_t)dev->device_fh);
 			}
 
 			/*move to the next device in the list*/
-- 
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 ` Huawei Xie [this message]
2014-10-20  4:38 ` [dpdk-dev] [PATCH 07/14] patch virtio_tx_route Huawei Xie
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-7-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