DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Charles (Chas) Williams" <ciwillia@brocade.com>
To: <dev@dpdk.org>
Cc: <mtetsuyah@gmail.com>, <yuanhan.liu@linux.intel.com>,
	"Charles (Chas) Williams" <ciwillia@brocade.com>
Subject: [dpdk-dev] [PATCH v3 2/2] net/vhost: emulate device start/stop behavior
Date: Sun, 1 Jan 2017 14:01:57 -0500	[thread overview]
Message-ID: <1483297317-20315-2-git-send-email-ciwillia@brocade.com> (raw)
In-Reply-To: <1483297317-20315-1-git-send-email-ciwillia@brocade.com>

.dev_start()/.dev_stop() roughly corresponds to the local device's
port being up or down.  This is different from the remote client being
connected which is roughtly link up or down.  Emulate the behavior by
separately tracking the local start/stop state to determine if we should
allow packets to be queued to the remote client.

Signed-off-by: Chas Williams <ciwillia@brocade.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 65 ++++++++++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 11 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 6b11e40..d5a4540 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -100,7 +100,8 @@ struct vhost_stats {
 
 struct vhost_queue {
 	int vid;
-	rte_atomic32_t allow_queuing;
+	rte_atomic32_t connected;
+	rte_atomic32_t ready;
 	rte_atomic32_t while_queuing;
 	struct pmd_internal *internal;
 	struct rte_mempool *mb_pool;
@@ -383,18 +384,25 @@ vhost_update_packet_xstats(struct vhost_queue *vq,
 	}
 }
 
+static inline bool
+queuing_stopped(struct vhost_queue *r)
+{
+	return unlikely(rte_atomic32_read(&r->connected) == 0 ||
+			rte_atomic32_read(&r->ready) == 0);
+}
+
 static uint16_t
 eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 {
 	struct vhost_queue *r = q;
 	uint16_t i, nb_rx = 0;
 
-	if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0))
+	if (queuing_stopped(r))
 		return 0;
 
 	rte_atomic32_set(&r->while_queuing, 1);
 
-	if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0))
+	if (queuing_stopped(r))
 		goto out;
 
 	/* Dequeue packets from guest TX queue */
@@ -422,12 +430,12 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
 	struct vhost_queue *r = q;
 	uint16_t i, nb_tx = 0;
 
-	if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0))
+	if (queuing_stopped(r))
 		return 0;
 
 	rte_atomic32_set(&r->while_queuing, 1);
 
-	if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0))
+	if (queuing_stopped(r))
 		goto out;
 
 	/* Enqueue packets to guest RX queue */
@@ -546,13 +554,13 @@ new_device(int vid)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		rte_atomic32_set(&vq->allow_queuing, 1);
+		rte_atomic32_set(&vq->connected, 1);
 	}
 	for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		rte_atomic32_set(&vq->allow_queuing, 1);
+		rte_atomic32_set(&vq->connected, 1);
 	}
 
 	RTE_LOG(INFO, PMD, "New connection established\n");
@@ -585,7 +593,7 @@ destroy_device(int vid)
 		vq = eth_dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		rte_atomic32_set(&vq->allow_queuing, 0);
+		rte_atomic32_set(&vq->connected, 0);
 		while (rte_atomic32_read(&vq->while_queuing))
 			rte_pause();
 	}
@@ -593,7 +601,7 @@ destroy_device(int vid)
 		vq = eth_dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		rte_atomic32_set(&vq->allow_queuing, 0);
+		rte_atomic32_set(&vq->connected, 0);
 		while (rte_atomic32_read(&vq->while_queuing))
 			rte_pause();
 	}
@@ -770,14 +778,49 @@ vhost_driver_session_stop(void)
 }
 
 static int
-eth_dev_start(struct rte_eth_dev *dev __rte_unused)
+eth_dev_start(struct rte_eth_dev *dev)
 {
+	struct vhost_queue *vq;
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		vq = dev->data->rx_queues[i];
+		if (vq == NULL)
+			continue;
+		rte_atomic32_set(&vq->ready, 1);
+	}
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		vq = dev->data->tx_queues[i];
+		if (vq == NULL)
+			continue;
+		rte_atomic32_set(&vq->ready, 1);
+	}
+
 	return 0;
 }
 
 static void
-eth_dev_stop(struct rte_eth_dev *dev __rte_unused)
+eth_dev_stop(struct rte_eth_dev *dev)
 {
+	struct vhost_queue *vq;
+	unsigned int i;
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		vq = dev->data->rx_queues[i];
+		if (vq == NULL)
+			continue;
+		rte_atomic32_set(&vq->ready, 0);
+		while (rte_atomic32_read(&vq->while_queuing))
+			rte_pause();
+	}
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		vq = dev->data->tx_queues[i];
+		if (vq == NULL)
+			continue;
+		rte_atomic32_set(&vq->ready, 0);
+		while (rte_atomic32_read(&vq->while_queuing))
+			rte_pause();
+	}
 }
 
 static int
-- 
2.1.4

  reply	other threads:[~2017-01-01 19:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-01 19:01 [dpdk-dev] [PATCH v3 1/2] net/vhost: create datagram sockets immediately Charles (Chas) Williams
2017-01-01 19:01 ` Charles (Chas) Williams [this message]
2017-01-03  8:29   ` [dpdk-dev] [PATCH v3 2/2] net/vhost: emulate device start/stop behavior Yuanhan Liu
2017-01-03  8:22 ` [dpdk-dev] [PATCH v3 1/2] net/vhost: create datagram sockets immediately Yuanhan Liu
2017-01-03 13:52   ` Charles (Chas) Williams

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=1483297317-20315-2-git-send-email-ciwillia@brocade.com \
    --to=ciwillia@brocade.com \
    --cc=dev@dpdk.org \
    --cc=mtetsuyah@gmail.com \
    --cc=yuanhan.liu@linux.intel.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).