DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huawei Xie <huawei.xie@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 6/7] virtio: simple tx routine
Date: Thu, 22 Oct 2015 20:09:50 +0800	[thread overview]
Message-ID: <1445515791-25909-7-git-send-email-huawei.xie@intel.com> (raw)
In-Reply-To: <1445515791-25909-1-git-send-email-huawei.xie@intel.com>

Changes in v4:
- move virtio_xmit_cleanup ahead to free descriptors earlier

Changes in v3:
- Remove return at the end of void function
- Remove always_inline attribute for virtio_xmit_cleanup
bulk free of mbufs when clean used ring.
shift operation of idx could be saved if vq_free_cnt means
free slots rather than free descriptors.

TODO: rearrange vq data structure, pack the stats var together so that we
could use one vec instruction to update all of them.

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 drivers/net/virtio/virtio_ethdev.h      |  3 ++
 drivers/net/virtio/virtio_rxtx_simple.c | 93 +++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index d7797ab..ae2d47d 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -111,6 +111,9 @@ uint16_t virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
 		uint16_t nb_pkts);
 
+uint16_t virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
+		uint16_t nb_pkts);
+
 /*
  * The VIRTIO_NET_F_GUEST_TSO[46] features permit the host to send us
  * frames larger than 1514 bytes. We do not yet support software LRO
diff --git a/drivers/net/virtio/virtio_rxtx_simple.c b/drivers/net/virtio/virtio_rxtx_simple.c
index ef17562..79b4f7f 100644
--- a/drivers/net/virtio/virtio_rxtx_simple.c
+++ b/drivers/net/virtio/virtio_rxtx_simple.c
@@ -288,6 +288,99 @@ virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
 	return nb_pkts_received;
 }
 
+#define VIRTIO_TX_FREE_THRESH 32
+#define VIRTIO_TX_MAX_FREE_BUF_SZ 32
+#define VIRTIO_TX_FREE_NR 32
+/* TODO: vq->tx_free_cnt could mean num of free slots so we could avoid shift */
+static inline void
+virtio_xmit_cleanup(struct virtqueue *vq)
+{
+	uint16_t i, desc_idx;
+	int nb_free = 0;
+	struct rte_mbuf *m, *free[VIRTIO_TX_MAX_FREE_BUF_SZ];
+
+	desc_idx = (uint16_t)(vq->vq_used_cons_idx &
+		((vq->vq_nentries >> 1) - 1));
+	free[0] = (struct rte_mbuf *)vq->vq_descx[desc_idx++].cookie;
+	nb_free = 1;
+
+	for (i = 1; i < VIRTIO_TX_FREE_NR; i++) {
+		m = (struct rte_mbuf *)vq->vq_descx[desc_idx++].cookie;
+		if (likely(m->pool == free[0]->pool))
+			free[nb_free++] = m;
+		else {
+			rte_mempool_put_bulk(free[0]->pool, (void **)free,
+				nb_free);
+			free[0] = m;
+			nb_free = 1;
+		}
+	}
+
+	rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
+	vq->vq_used_cons_idx += VIRTIO_TX_FREE_NR;
+	vq->vq_free_cnt += (VIRTIO_TX_FREE_NR << 1);
+}
+
+uint16_t
+virtio_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
+	uint16_t nb_pkts)
+{
+	struct virtqueue *txvq = tx_queue;
+	uint16_t nb_used;
+	uint16_t desc_idx;
+	struct vring_desc *start_dp;
+	uint16_t nb_tail, nb_commit;
+	int i;
+	uint16_t desc_idx_max = (txvq->vq_nentries >> 1) - 1;
+
+	nb_used = VIRTQUEUE_NUSED(txvq);
+	rte_compiler_barrier();
+
+	if (nb_used >= VIRTIO_TX_FREE_THRESH)
+		virtio_xmit_cleanup(tx_queue);
+
+	nb_commit = nb_pkts = RTE_MIN((txvq->vq_free_cnt >> 1), nb_pkts);
+	desc_idx = (uint16_t) (txvq->vq_avail_idx & desc_idx_max);
+	start_dp = txvq->vq_ring.desc;
+	nb_tail = (uint16_t) (desc_idx_max + 1 - desc_idx);
+
+	if (nb_commit >= nb_tail) {
+		for (i = 0; i < nb_tail; i++)
+			txvq->vq_descx[desc_idx + i].cookie = tx_pkts[i];
+		for (i = 0; i < nb_tail; i++) {
+			start_dp[desc_idx].addr =
+				RTE_MBUF_DATA_DMA_ADDR(*tx_pkts);
+			start_dp[desc_idx].len = (*tx_pkts)->pkt_len;
+			tx_pkts++;
+			desc_idx++;
+		}
+		nb_commit -= nb_tail;
+		desc_idx = 0;
+	}
+	for (i = 0; i < nb_commit; i++)
+		txvq->vq_descx[desc_idx + i].cookie = tx_pkts[i];
+	for (i = 0; i < nb_commit; i++) {
+		start_dp[desc_idx].addr = RTE_MBUF_DATA_DMA_ADDR(*tx_pkts);
+		start_dp[desc_idx].len = (*tx_pkts)->pkt_len;
+		tx_pkts++;
+		desc_idx++;
+	}
+
+	rte_compiler_barrier();
+
+	txvq->vq_free_cnt -= (uint16_t)(nb_pkts << 1);
+	txvq->vq_avail_idx += nb_pkts;
+	txvq->vq_ring.avail->idx = txvq->vq_avail_idx;
+	txvq->packets += nb_pkts;
+
+	if (likely(nb_pkts)) {
+		if (unlikely(virtqueue_kick_prepare(txvq)))
+			virtqueue_notify(txvq);
+	}
+
+	return nb_pkts;
+}
+
 int __attribute__((cold))
 virtio_rxq_vec_setup(struct virtqueue *rxq)
 {
-- 
1.8.1.4

  parent reply	other threads:[~2015-10-22 12:10 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 14:45 [dpdk-dev] [PATCH 0/8] virtio: virtio ring layout optimization and RX vector processing Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 1/8] virtio: add configure for simple virtio rx/tx Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 2/8] virtio: add virtio_rxtx.h header file Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 3/8] virtio: add software rx ring, fake_buf, simple_rxtx into virtqueue Huawei Xie
2015-09-29 16:15   ` Stephen Hemminger
2015-09-29 14:45 ` [dpdk-dev] [PATCH 4/8] virtio: rx/tx ring layout optimization Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 5/8] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 6/8] virtio: virtio vec rx Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 7/8] virtio: simple tx routine Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 8/8] virtio: rxtx_func_get Huawei Xie
2015-09-29 15:41 ` [dpdk-dev] [PATCH 0/8] virtio: virtio ring layout optimization and RX vector processing Xie, Huawei
2015-10-18  6:28 ` [dpdk-dev] [PATCH v2 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-18  6:28 ` Huawei Xie
2015-10-18  6:28   ` [dpdk-dev] [PATCH v2 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-18  6:28   ` [dpdk-dev] [PATCH v2 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-19  4:20     ` Stephen Hemminger
2015-10-19  5:06       ` Xie, Huawei
2015-10-20 15:32         ` Xie, Huawei
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 5/7] virtio: virtio vec rx Huawei Xie
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 6/7] virtio: simple tx routine Huawei Xie
2015-10-19  4:16     ` Stephen Hemminger
2015-10-19  5:22       ` Xie, Huawei
2015-10-19  4:18     ` Stephen Hemminger
2015-10-19  5:15       ` Xie, Huawei
2015-10-19  4:19     ` Stephen Hemminger
2015-10-19  5:12       ` Xie, Huawei
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-20 15:30 ` [dpdk-dev] [PATCH v3 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 5/7] virtio: virtio vec rx Huawei Xie
2015-10-22  4:04     ` Wang, Zhihong
2015-10-22  5:48       ` Xie, Huawei
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 6/7] virtio: simple tx routine Huawei Xie
2015-10-20 18:58     ` Stephen Hemminger
2015-10-22  5:43       ` Xie, Huawei
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-22  2:50     ` Tan, Jianfeng
2015-10-22 11:40       ` Xie, Huawei
2015-10-22 12:09 ` [dpdk-dev] [PATCH v4 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-23  5:56     ` Tan, Jianfeng
2015-10-25 15:40       ` Xie, Huawei
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 5/7] virtio: virtio vec rx Huawei Xie
2015-10-22 12:09   ` Huawei Xie [this message]
2015-10-22 16:57     ` [dpdk-dev] [PATCH v4 6/7] virtio: simple tx routine Stephen Hemminger
2015-10-23  2:17       ` Xie, Huawei
2015-10-23  2:20         ` Xie, Huawei
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-22 16:58     ` Stephen Hemminger
2015-10-23  1:38       ` Xie, Huawei
2015-10-25 15:34 ` [dpdk-dev] [PATCH v5 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-25 15:34   ` [dpdk-dev] [PATCH v5 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-25 15:34   ` [dpdk-dev] [PATCH v5 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 5/7] virtio: virtio vec rx Huawei Xie
2015-10-26  8:34     ` Wang, Zhihong
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 6/7] virtio: simple tx routine Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-27  1:44   ` [dpdk-dev] [PATCH v5 0/7] virtio ring layout optimization and simple rx/tx processing Tan, Jianfeng
2015-10-27  2:15     ` Yuanhan Liu
2015-10-27 10:17       ` Bruce Richardson
2015-10-29 14:53 ` [dpdk-dev] [PATCH v6 0/8] " Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 1/8] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 2/8] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-30 18:13     ` Thomas Monjalon
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 3/8] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 4/8] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 5/8] virtio: virtio vec rx Huawei Xie
2015-10-30 18:19     ` Thomas Monjalon
2015-11-02  2:18       ` Xie, Huawei
2015-11-02  7:28         ` Thomas Monjalon
2015-11-02  8:49           ` Xie, Huawei
2015-11-02  9:03             ` Thomas Monjalon
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 6/8] virtio: simple tx routine Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 7/8] virtio: pick simple rx/tx func Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 8/8] doc: update release notes 2.2 about virtio performance optimization Huawei Xie
2015-10-30  2:05   ` [dpdk-dev] [PATCH v6 0/8] virtio ring layout optimization and simple rx/tx processing Tan, Jianfeng
2015-11-02 22:09     ` Thomas Monjalon
2015-11-02 22:10       ` Thomas Monjalon
2015-11-03 10:30         ` Xie, Huawei
2015-11-27  6:03   ` Xu, Qian Q
2015-12-17  5:22     ` Xie, Huawei
2015-12-17  9:08       ` Thomas Monjalon

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=1445515791-25909-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
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).