All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Wang <xiao.w.wang@intel.com>
To: yliu@fridaylinux.org, thomas@monjalon.net
Cc: tiwei.bie@intel.com, dev@dpdk.org, stephen@networkplumber.org,
	Xiao Wang <xiao.w.wang@intel.com>
Subject: [PATCH v8 2/5] net/virtio: add packet injection method
Date: Tue,  9 Jan 2018 21:26:51 +0800	[thread overview]
Message-ID: <20180109132654.3504-3-xiao.w.wang@intel.com> (raw)
In-Reply-To: <20180109132654.3504-1-xiao.w.wang@intel.com>

This patch adds dev_pause, dev_resume and inject_pkts APIs to allow
driver to pause the worker threads and inject special packets into
Tx queue. The next patch will be based on this.

Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c      | 56 +++++++++++++++++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.h      |  5 +++
 drivers/net/virtio/virtio_pci.h         |  7 +++++
 drivers/net/virtio/virtio_rxtx.c        |  2 +-
 drivers/net/virtio/virtio_rxtx_simple.c |  2 +-
 5 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 4e613ce30..e8ff1e449 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -26,6 +26,7 @@
 #include <rte_memory.h>
 #include <rte_eal.h>
 #include <rte_dev.h>
+#include <rte_cycles.h>
 
 #include "virtio_ethdev.h"
 #include "virtio_pci.h"
@@ -1220,6 +1221,57 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 	return 0;
 }
 
+int
+virtio_dev_pause(struct rte_eth_dev *dev)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+
+	rte_spinlock_lock(&hw->state_lock);
+
+	if (hw->started == 0) {
+		/* Device is just stopped. */
+		rte_spinlock_unlock(&hw->state_lock);
+		return -1;
+	}
+	hw->started = 0;
+	/*
+	 * Prevent the worker threads from touching queues to avoid contention,
+	 * 1 ms should be enough for the ongoing Tx function to finish.
+	 */
+	rte_delay_ms(1);
+	return 0;
+}
+
+/*
+ * Recover hw state to let the worker threads continue.
+ */
+void
+virtio_dev_resume(struct rte_eth_dev *dev)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+/*
+ * Should be called only after device is paused.
+ */
+int
+virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
+		int nb_pkts)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_tx *txvq = dev->data->tx_queues[0];
+	int ret;
+
+	hw->inject_pkts = tx_pkts;
+	ret = dev->tx_pkt_burst(txvq, tx_pkts, nb_pkts);
+	hw->inject_pkts = NULL;
+
+	return ret;
+}
+
 /*
  * Process Virtio Config changed interrupt and call the callback
  * if link state changed.
@@ -1757,6 +1809,8 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	hw->use_simple_rx = 1;
 	hw->use_simple_tx = 1;
 
@@ -1923,12 +1977,14 @@ virtio_dev_stop(struct rte_eth_dev *dev)
 
 	PMD_INIT_LOG(DEBUG, "stop");
 
+	rte_spinlock_lock(&hw->state_lock);
 	if (intr_conf->lsc || intr_conf->rxq)
 		virtio_intr_disable(dev);
 
 	hw->started = 0;
 	memset(&link, 0, sizeof(link));
 	virtio_dev_atomic_write_link_status(dev, &link);
+	rte_spinlock_unlock(&hw->state_lock);
 }
 
 static int
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index 765d249e6..69b30b7e1 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -92,4 +92,9 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev);
 
 void virtio_interrupt_handler(void *param);
 
+int virtio_dev_pause(struct rte_eth_dev *dev);
+void virtio_dev_resume(struct rte_eth_dev *dev);
+int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
+		int nb_pkts);
+
 #endif /* _VIRTIO_ETHDEV_H_ */
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index fb1f6a9ec..9d810a599 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -241,6 +241,13 @@ struct virtio_hw {
 	struct virtio_pci_common_cfg *common_cfg;
 	struct virtio_net_config *dev_cfg;
 	void	    *virtio_user_dev;
+	/*
+	 * App management thread and virtio interrupt handler thread
+	 * both can change device state, this lock is meant to avoid
+	 * such a contention.
+	 */
+	rte_spinlock_t state_lock;
+	struct rte_mbuf **inject_pkts;
 
 	struct virtqueue **vqs;
 };
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 265debf20..80e996d06 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -988,7 +988,7 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 	uint16_t nb_used, nb_tx = 0;
 	int error;
 
-	if (unlikely(hw->started == 0))
+	if (unlikely(hw->started == 0 && tx_pkts != hw->inject_pkts))
 		return nb_tx;
 
 	if (unlikely(nb_pkts < 1))
diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c
index 8ef3c0c04..98a9da5d8 100644
--- a/drivers/net/virtio/virtio_rxtx_simple.c
+++ b/drivers/net/virtio/virtio_rxtx_simple.c
@@ -70,7 +70,7 @@ virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
 	uint16_t desc_idx_max = (vq->vq_nentries >> 1) - 1;
 	uint16_t nb_tx = 0;
 
-	if (unlikely(hw->started == 0))
+	if (unlikely(hw->started == 0 && tx_pkts != hw->inject_pkts))
 		return nb_tx;
 
 	nb_used = VIRTQUEUE_NUSED(vq);
-- 
2.15.1

  parent reply	other threads:[~2018-01-09 13:28 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-24 11:03 [PATCH 0/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2017-11-24 11:03 ` [PATCH 1/2] net/virtio: make control queue thread-safe Xiao Wang
2017-11-24  5:38   ` Tiwei Bie
2017-11-30  2:10     ` Wang, Xiao W
2017-11-30  2:59   ` Stephen Hemminger
2017-12-01  1:38     ` Wang, Xiao W
2017-12-04 14:02   ` [PATCH v2 0/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2017-12-04 14:02     ` [PATCH v2 1/2] net/virtio: make control queue thread-safe Xiao Wang
2017-12-04 14:02     ` [PATCH v2 2/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2017-12-04  8:46       ` Tiwei Bie
2018-01-03  1:37         ` Wang, Xiao W
2018-01-03  8:42         ` Wang, Xiao W
2017-12-06 11:23       ` Tiwei Bie
2017-12-06 14:22         ` Yuanhan Liu
2018-01-03  1:41         ` Wang, Xiao W
2018-01-04  7:41       ` [PATCH v3 0/2] " Xiao Wang
2018-01-04  7:41         ` [PATCH v3 1/2] net/virtio: make control queue thread-safe Xiao Wang
2018-01-04  7:41         ` [PATCH v3 2/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-04  2:51           ` Tiwei Bie
2018-01-04  7:11             ` Wang, Xiao W
2018-01-04 15:59           ` [PATCH v4 0/3] " Xiao Wang
2018-01-04 15:59             ` [PATCH v4 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-04 15:59             ` [PATCH v4 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-04  7:56               ` Tiwei Bie
2018-01-05 16:46               ` [PATCH v5 0/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-05 16:46                 ` [PATCH v5 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-05 16:46                 ` [PATCH v5 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-05 18:00                   ` Tiwei Bie
2018-01-07  2:37                     ` Wang, Xiao W
2018-01-05 16:46                 ` [PATCH v5 3/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-05 17:56                   ` Tiwei Bie
2018-01-07  2:29                     ` Wang, Xiao W
2018-01-07 12:05                   ` [PATCH v6 0/3] " Xiao Wang
2018-01-07 12:05                     ` [PATCH v6 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-08 13:06                       ` Yuanhan Liu
2018-01-08 15:25                         ` Wang, Xiao W
2018-01-07 12:05                     ` [PATCH v6 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-08 13:03                       ` Yuanhan Liu
2018-01-08 15:11                         ` Wang, Xiao W
2018-01-09  2:55                           ` Wang, Xiao W
2018-01-09 14:26                       ` [PATCH v7 0/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 14:26                         ` [PATCH v7 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-09 14:26                         ` [PATCH v7 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-09 14:26                         ` [PATCH v7 3/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09  8:49                           ` Maxime Coquelin
2018-01-09 10:58                             ` Wang, Xiao W
2018-01-09 11:03                             ` Wang, Xiao W
2018-01-09 11:41                               ` Thomas Monjalon
2018-01-09 13:36                                 ` Yuanhan Liu
2018-01-09 13:26                           ` [PATCH v8 0/5] " Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-09 13:26                             ` Xiao Wang [this message]
2018-01-09 13:26                             ` [PATCH v8 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-09 13:48                               ` Thomas Monjalon
2018-01-09 15:52                                 ` Wang, Xiao W
2018-01-09 16:09                               ` [PATCH v9 0/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-09 17:22                                   ` Thomas Monjalon
2018-01-10  1:23                                   ` [PATCH v10 0/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-10 13:06                                       ` Yuanhan Liu
2018-01-10 14:10                                         ` Thomas Monjalon
2018-01-16  9:01                                       ` Olivier Matz
2018-01-16  9:43                                         ` Wang, Xiao W
2018-01-16 10:42                                           ` Olivier Matz
2018-01-16 11:03                                             ` Wang, Xiao W
2018-01-16 11:42                                             ` Wang, Xiao W
2018-01-16 21:40                                       ` [PATCH v11 0/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-16 21:40                                         ` [PATCH v11 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-16 21:41                                         ` [PATCH v11 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-16 21:41                                         ` [PATCH v11 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-16 14:29                                           ` Olivier Matz
2018-01-16 21:41                                         ` [PATCH v11 4/5] vhost: use lib API to make " Xiao Wang
2018-01-16 21:41                                         ` [PATCH v11 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-19 17:33                                           ` Ferruh Yigit
2018-01-20 14:31                                             ` Ferruh Yigit
2018-01-21  1:31                                               ` Wang, Xiao W
2018-01-18  3:09                                         ` [PATCH v11 0/5] " Yuanhan Liu
2018-01-18  3:14                                           ` [PATCH 1/2] net: fixup RARP generation Yuanhan Liu
2018-01-18  3:14                                             ` [PATCH 2/2] net: fix build error Yuanhan Liu
2018-01-18  7:38                                               ` Thomas Monjalon
2018-01-18  7:45                                                 ` Wang, Xiao W
2018-01-18  8:03                                                   ` Yuanhan Liu
2018-01-18  8:36                                                     ` Thomas Monjalon
2018-01-18  8:48                                                       ` Yuanhan Liu
2018-01-18  8:38                                             ` [PATCH 1/2] net: fixup RARP generation Thomas Monjalon
2018-01-18  8:51                                               ` Yuanhan Liu
2018-01-18  8:53                                                 ` Wang, Xiao W
2018-01-19 16:04                                             ` Ferruh Yigit
2018-01-10  1:23                                     ` [PATCH v10 4/5] vhost: use lib API to make RARP packet Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 4/5] vhost: use lib API to make RARP packet Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 4/5] vhost: use lib API to make RARP packet Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 14:38                             ` [PATCH v8 0/5] " Maxime Coquelin
2018-01-07 12:05                     ` [PATCH v6 3/3] " Xiao Wang
2018-01-05 20:27               ` [PATCH v4 2/3] net/virtio: add packet injection method Stephen Hemminger
2018-01-06  4:41                 ` Tiwei Bie
2018-01-04 15:59             ` [PATCH v4 3/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-04 11:13               ` Tiwei Bie
2017-11-24 11:04 ` [PATCH 2/2] " Xiao Wang
2017-11-24  6:04   ` Tiwei Bie
2017-11-30  2:37     ` Wang, Xiao W
2017-11-27 12:48   ` Yuanhan Liu
2017-11-30  2:41     ` Wang, Xiao W
2017-12-05 14:26       ` Yuanhan Liu
2018-01-03  1:43         ` Wang, Xiao W

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=20180109132654.3504-3-xiao.w.wang@intel.com \
    --to=xiao.w.wang@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    --cc=tiwei.bie@intel.com \
    --cc=yliu@fridaylinux.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.