DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tiwei Bie <tiwei.bie@intel.com>
To: dev@dpdk.org
Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [RFC 13/29] net/virtio: implement the Rx code path
Date: Wed, 21 Jun 2017 10:57:49 +0800	[thread overview]
Message-ID: <1498013885-102779-14-git-send-email-tiwei.bie@intel.com> (raw)
In-Reply-To: <1498013885-102779-1-git-send-email-tiwei.bie@intel.com>

From: Yuanhan Liu <yuanhan.liu@linux.intel.com>

Just make it stick to the non-mergeable code path now, though it's likely
it would  be really easy to add such support.

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 drivers/net/virtio/virtio_ethdev.c |   5 +-
 drivers/net/virtio/virtio_rxtx.c   | 121 ++++++++++++++++++++++++++++++++++---
 drivers/net/virtio/virtqueue.h     |   1 +
 3 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 35ce07d..8b754ac 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1241,7 +1241,7 @@ static void
 rx_func_get(struct rte_eth_dev *eth_dev)
 {
 	struct virtio_hw *hw = eth_dev->data->dev_private;
-	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF))
+	if (0 && vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF))
 		eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts;
 	else
 		eth_dev->rx_pkt_burst = &virtio_recv_pkts;
@@ -1373,7 +1373,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 
 	/* Setting up rx_header size for the device */
 	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
-	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1))
+	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1) ||
+	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1_1))
 		hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf);
 	else
 		hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr);
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index c49ac0d..3be64da 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -115,8 +115,8 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx)
 	dp->next = VQ_RING_DESC_CHAIN_END;
 }
 
-static uint16_t
-virtqueue_dequeue_burst_rx(struct virtqueue *vq, struct rte_mbuf **rx_pkts,
+static inline uint16_t
+virtqueue_dequeue_burst_rx_1_0(struct virtqueue *vq, struct rte_mbuf **rx_pkts,
 			   uint32_t *len, uint16_t num)
 {
 	struct vring_used_elem *uep;
@@ -149,6 +149,51 @@ virtqueue_dequeue_burst_rx(struct virtqueue *vq, struct rte_mbuf **rx_pkts,
 	return i;
 }
 
+static inline uint16_t
+virtqueue_dequeue_burst_rx_1_1(struct virtqueue *vq, struct rte_mbuf **rx_pkts,
+			   uint32_t *len, uint16_t num)
+{
+	struct vring_desc_1_1 *desc = vq->vq_ring.desc_1_1;
+	struct rte_mbuf *cookie;
+	uint16_t used_idx;
+	uint16_t i;
+
+	for (i = 0; i < num ; i++) {
+		used_idx = (uint16_t)(vq->vq_used_cons_idx & (vq->vq_nentries - 1));
+		if ((desc[used_idx].flags & DESC_HW))
+			break;
+
+		len[i] = desc[used_idx].len;
+		cookie = vq->vq_descx[used_idx].cookie;
+
+		if (unlikely(cookie == NULL)) {
+			PMD_DRV_LOG(ERR, "vring descriptor with no mbuf cookie at %u\n",
+				vq->vq_used_cons_idx);
+			break;
+		}
+		vq->vq_descx[used_idx].cookie = NULL;
+
+		rte_prefetch0(cookie);
+		rte_packet_prefetch(rte_pktmbuf_mtod(cookie, void *));
+		rx_pkts[i]  = cookie;
+
+		vq->vq_used_cons_idx++;
+		vq->vq_free_cnt++;
+	}
+
+	return i;
+}
+
+static inline uint16_t
+virtqueue_dequeue_burst_rx(struct virtqueue *vq, struct rte_mbuf **rx_pkts,
+			   uint32_t *len, uint16_t num)
+{
+	if (vtpci_version_1_1(vq->hw))
+		return virtqueue_dequeue_burst_rx_1_1(vq, rx_pkts, len, num);
+	else
+		return virtqueue_dequeue_burst_rx_1_0(vq, rx_pkts, len, num);
+}
+
 #ifndef DEFAULT_TX_FREE_THRESH
 #define DEFAULT_TX_FREE_THRESH 32
 #endif
@@ -179,7 +224,7 @@ virtio_xmit_cleanup(struct virtqueue *vq, uint16_t num)
 
 
 static inline int
-virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie)
+virtqueue_enqueue_recv_refill_1_0(struct virtqueue *vq, struct rte_mbuf *cookie)
 {
 	struct vq_desc_extra *dxp;
 	struct virtio_hw *hw = vq->hw;
@@ -218,6 +263,53 @@ virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie)
 	return 0;
 }
 
+static inline int
+virtqueue_enqueue_recv_refill_1_1(struct virtqueue *vq, struct rte_mbuf *cookie)
+{
+	struct vq_desc_extra *dxp;
+	struct virtio_hw *hw = vq->hw;
+	uint16_t needed = 1;
+	uint16_t idx;
+	struct vring_desc_1_1 *desc = vq->vq_ring.desc_1_1;
+
+	if (unlikely(vq->vq_free_cnt == 0))
+		return -ENOSPC;
+	if (unlikely(vq->vq_free_cnt < needed))
+		return -EMSGSIZE;
+
+	idx = vq->vq_desc_head_idx & (vq->vq_nentries - 1);
+	if (unlikely(desc[idx].flags & DESC_HW))
+		return -EFAULT;
+
+	dxp = &vq->vq_descx[idx];
+	dxp->cookie = cookie;
+	dxp->ndescs = needed;
+
+	desc[idx].addr =
+		VIRTIO_MBUF_ADDR(cookie, vq) +
+		RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
+	desc[idx].len =
+		cookie->buf_len - RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
+	desc[idx].flags =  VRING_DESC_F_WRITE;
+	vq->vq_desc_head_idx++;
+
+	vq->vq_free_cnt -= needed;
+
+	rte_smp_wmb();
+	desc[idx].flags |= DESC_HW;
+
+	return 0;
+}
+
+static inline int
+virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie)
+{
+	if (vtpci_version_1_1(vq->hw))
+		return virtqueue_enqueue_recv_refill_1_1(vq, cookie);
+	else
+		return virtqueue_enqueue_recv_refill_1_0(vq, cookie);
+}
+
 static inline void
 virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
 		       uint16_t needed)
@@ -288,9 +380,6 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
-	if (vtpci_version_1_1(hw))
-		return 0;
-
 	if (nb_desc == 0 || nb_desc > vq->vq_nentries)
 		nb_desc = vq->vq_nentries;
 	vq->vq_free_cnt = RTE_MIN(vq->vq_free_cnt, nb_desc);
@@ -343,7 +432,8 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 		nbufs++;
 	}
 
-	vq_update_avail_idx(vq);
+	if (!vtpci_version_1_1(hw))
+		vq_update_avail_idx(vq);
 
 	PMD_INIT_LOG(DEBUG, "Allocated %d bufs", nbufs);
 
@@ -368,6 +458,10 @@ virtio_update_rxtx_handler(struct rte_eth_dev *dev,
 	if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON))
 		use_simple_rxtx = 1;
 #endif
+
+	if (vtpci_version_1_1(hw))
+		use_simple_rxtx = 0;
+
 	/* Use simple rx/tx func if single segment and no offloads */
 	if (use_simple_rxtx &&
 	    (tx_conf->txq_flags & VIRTIO_SIMPLE_FLAGS) == VIRTIO_SIMPLE_FLAGS &&
@@ -604,7 +698,16 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	if (unlikely(hw->started == 0))
 		return nb_rx;
 
-	nb_used = VIRTQUEUE_NUSED(vq);
+	/*
+	 * we have no idea to know how many used entries without scanning
+	 * the desc for virtio 1.1. Thus, let's simply set nb_used to nb_pkts
+	 * and let virtqueue_dequeue_burst_rx() to figure out the real
+	 * number.
+	 */
+	if (vtpci_version_1_1(hw))
+		nb_used = nb_pkts;
+	else
+		nb_used = VIRTQUEUE_NUSED(vq);
 
 	virtio_rmb();
 
@@ -681,7 +784,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 		nb_enqueued++;
 	}
 
-	if (likely(nb_enqueued)) {
+	if (likely(nb_enqueued) && !vtpci_version_1_1(hw)) {
 		vq_update_avail_idx(vq);
 
 		if (unlikely(virtqueue_kick_prepare(vq))) {
diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index 91d2db7..45f49d7 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -272,6 +272,7 @@ vring_desc_init_1_1(struct vring *vr, int n)
 	int i;
 	for (i = 0; i < n; i++) {
 		struct vring_desc_1_1 *desc = &vr->desc_1_1[i];
+		desc->flags = 0;
 		desc->index = i;
 	}
 }
-- 
2.7.4

  parent reply	other threads:[~2017-06-21  2:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21  2:57 [dpdk-dev] [RFC 00/29] latest virtio1.1 prototype Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 01/29] net/virtio: vring init for 1.1 Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 02/29] net/virtio: implement 1.1 guest Tx Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 03/29] net/virtio-user: add option to enable 1.1 Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 04/29] vhost: enable 1.1 for testing Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 05/29] vhost: set desc addr for 1.1 Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 06/29] vhost: implement virtio 1.1 dequeue path Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 07/29] vhost: mark desc being used Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 08/29] xxx: batch the desc_hw update? Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 09/29] xxx: virtio: remove overheads Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 10/29] vhost: prefetch desc Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 11/29] add virtio 1.1 test guide Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 12/29] testpmd: add s-txonly Tiwei Bie
2017-06-21  2:57 ` Tiwei Bie [this message]
2017-06-21  2:57 ` [dpdk-dev] [RFC 14/29] vhost: a rough implementation on enqueue code path Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 15/29] vhost: descriptor length should include vhost header Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 16/29] net/virtio: avoid touching packet data Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 17/29] net/virtio: fix virtio1.1 feature negotiation Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 18/29] net/virtio: the Rx support for virtio1.1 has been added now Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 19/29] vhost: VIRTIO_NET_F_MRG_RXBUF is not supported for now Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 20/29] vhost: fix vring addr setup Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 21/29] net/virtio: free mbuf when need to use Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 22/29] vhost: don't copy descs during Rx Tiwei Bie
2017-06-21  2:57 ` [dpdk-dev] [RFC 23/29] vhost: fix mbuf leak Tiwei Bie
2017-06-21  2:58 ` [dpdk-dev] [RFC 24/29] net/virtio: cleanup txd when free count below threshold Tiwei Bie
2017-06-21  2:58 ` [dpdk-dev] [RFC 25/29] net/virtio: refill descs for vhost in batch Tiwei Bie
2017-06-21  2:58 ` [dpdk-dev] [RFC 26/29] vhost: remove dead code Tiwei Bie
2017-06-21  2:58 ` [dpdk-dev] [RFC 27/29] vhost: various optimizations for Tx Tiwei Bie
2017-06-21  2:58 ` [dpdk-dev] [RFC 28/29] vhost: make the code more readable Tiwei Bie
2017-06-21  2:58 ` [dpdk-dev] [RFC 29/29] vhost: update and return descs in batch Tiwei Bie

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=1498013885-102779-14-git-send-email-tiwei.bie@intel.com \
    --to=tiwei.bie@intel.com \
    --cc=dev@dpdk.org \
    --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).