From: Marvin Liu <yong.liu@intel.com>
To: tiwei.bie@intel.com, maxime.coquelin@redhat.com, dev@dpdk.org
Cc: Marvin Liu <yong.liu@intel.com>
Subject: [dpdk-dev] [RFC PATCH 10/13] add vhost fast zero copy dequeue packed ring function
Date: Tue, 9 Jul 2019 01:13:17 +0800 [thread overview]
Message-ID: <20190708171320.38802-11-yong.liu@intel.com> (raw)
In-Reply-To: <20190708171320.38802-1-yong.liu@intel.com>
Modified vhost zero copy dequeue function which followed fast dequeue
function.
Signed-off-by: Marvin Liu <yong.liu@intel.com>
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index a3b1e85fe..7094944cf 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -2143,6 +2143,147 @@ virtio_dev_tx_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,
return i;
}
+static __rte_always_inline void
+free_zmbuf(struct vhost_virtqueue *vq) {
+ struct zcopy_mbuf *next = NULL;
+ struct zcopy_mbuf *zmbuf;
+
+ for (zmbuf = TAILQ_FIRST(&vq->zmbuf_list);
+ zmbuf != NULL; zmbuf = next) {
+ next = TAILQ_NEXT(zmbuf, next);
+
+ uint16_t last_used_idx = vq->last_used_idx;
+
+ if (mbuf_is_consumed(zmbuf->mbuf)) {
+ uint16_t flags = 0;
+
+ if (vq->used_wrap_counter)
+ flags = VIRTIO_TX_FLAG_PACKED;
+ else
+ flags = VIRTIO_TX_WRAP_FLAG_PACKED;
+
+ vq->desc_packed[last_used_idx].id = zmbuf->desc_idx;
+ vq->desc_packed[last_used_idx].len = 0;
+
+ rte_smp_wmb();
+ vq->desc_packed[last_used_idx].flags = flags;
+
+ vq->last_used_idx += zmbuf->desc_count;
+ if (vq->last_used_idx >= vq->size) {
+ vq->used_wrap_counter ^= 1;
+ vq->last_used_idx -= vq->size;
+ }
+
+ TAILQ_REMOVE(&vq->zmbuf_list, zmbuf, next);
+ restore_mbuf(zmbuf->mbuf);
+ rte_pktmbuf_free(zmbuf->mbuf);
+ put_zmbuf(zmbuf);
+ vq->nr_zmbuf -= 1;
+ }
+ }
+}
+
+static __rte_always_inline int
+virtio_dev_tx_fast_packed_zmbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
+ struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts)
+{
+ struct zcopy_mbuf *zmbuf, *zmbuf1, *zmbuf2, *zmbuf3;
+ int ret;
+ uintptr_t desc_addr[4];
+ uint16_t ids[4];
+
+ uint16_t avail_idx = vq->last_avail_idx;
+
+ ret = vhost_dequeue_fast_packed(dev, vq, mbuf_pool, pkts, avail_idx,
+ desc_addr, ids);
+
+ if (ret)
+ return ret;
+
+ zmbuf = get_zmbuf(vq);
+ zmbuf1 = get_zmbuf(vq);
+ zmbuf2 = get_zmbuf(vq);
+ zmbuf3 = get_zmbuf(vq);
+
+ if (!zmbuf || !zmbuf1 || !zmbuf2 || !zmbuf3) {
+ rte_pktmbuf_free(pkts[0]);
+ rte_pktmbuf_free(pkts[1]);
+ rte_pktmbuf_free(pkts[2]);
+ rte_pktmbuf_free(pkts[3]);
+ return -1;
+ }
+
+ zmbuf->mbuf = pkts[0];
+ zmbuf->desc_idx = avail_idx;
+ zmbuf->desc_count = 1;
+
+ zmbuf1->mbuf = pkts[1];
+ zmbuf1->desc_idx = avail_idx + 1;
+ zmbuf1->desc_count = 1;
+
+ zmbuf2->mbuf = pkts[2];
+ zmbuf2->desc_idx = avail_idx + 2;
+ zmbuf2->desc_count = 1;
+
+ zmbuf3->mbuf = pkts[3];
+ zmbuf3->desc_idx = avail_idx + 3;
+ zmbuf3->desc_count = 1;
+
+ rte_mbuf_refcnt_update(pkts[0], 1);
+ rte_mbuf_refcnt_update(pkts[1], 1);
+ rte_mbuf_refcnt_update(pkts[2], 1);
+ rte_mbuf_refcnt_update(pkts[3], 1);
+
+ vq->nr_zmbuf += PACKED_DESC_PER_CACHELINE;
+ TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next);
+ TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf1, next);
+ TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf2, next);
+ TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf3, next);
+
+ vq->last_avail_idx += PACKED_DESC_PER_CACHELINE;
+ if (vq->last_avail_idx >= vq->size) {
+ vq->last_avail_idx -= vq->size;
+ vq->avail_wrap_counter ^= 1;
+ }
+
+ return 0;
+}
+
+static __rte_always_inline int
+virtio_dev_tx_normal_packed_zmbuf(struct virtio_net *dev,
+ struct vhost_virtqueue *vq,
+ struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts)
+{
+ uint16_t buf_id, desc_count;
+ struct zcopy_mbuf *zmbuf;
+
+ if (vhost_dequeue_normal_packed(dev, vq, mbuf_pool, pkts, &buf_id,
+ &desc_count))
+ return -1;
+
+ zmbuf = get_zmbuf(vq);
+ if (!zmbuf) {
+ rte_pktmbuf_free(*pkts);
+ return -1;
+ }
+ zmbuf->mbuf = *pkts;
+ zmbuf->desc_idx = vq->last_avail_idx;
+ zmbuf->desc_count = desc_count;
+
+ rte_mbuf_refcnt_update(*pkts, 1);
+
+ vq->nr_zmbuf += 1;
+ TAILQ_INSERT_TAIL(&vq->zmbuf_list, zmbuf, next);
+
+ vq->last_avail_idx += desc_count;
+ if (vq->last_avail_idx >= vq->size) {
+ vq->last_avail_idx -= vq->size;
+ vq->avail_wrap_counter ^= 1;
+ }
+
+ return 0;
+}
+
uint16_t
rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
--
2.17.1
next prev parent reply other threads:[~2019-07-08 9:31 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-08 17:13 [dpdk-dev] [RFC] vhost packed ring performance optimization Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 01/13] add vhost normal enqueue function Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 02/13] add vhost packed ring fast " Marvin Liu
[not found] ` <CGME20190708113801eucas1p25d89717d8b298790326077852c9933c8@eucas1p2.samsung.com>
2019-07-08 11:37 ` Ilya Maximets
2019-07-09 1:15 ` Liu, Yong
2019-07-10 4:28 ` Jason Wang
2019-07-10 7:30 ` Liu, Yong
2019-07-11 4:11 ` Jason Wang
2019-07-11 9:49 ` Liu, Yong
2019-07-11 9:54 ` Jason Wang
2019-08-13 9:02 ` Liu, Yong
2019-07-11 8:35 ` Jason Wang
2019-07-11 9:37 ` Liu, Yong
2019-07-11 9:44 ` Jason Wang
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 03/13] add vhost packed ring normal dequeue function Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 04/13] add vhost packed ring fast " Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 05/13] add enqueue shadow used descs update and flush functions Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 06/13] add vhost fast enqueue flush function Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 07/13] add vhost dequeue shadow descs update function Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 08/13] add vhost fast dequeue flush function Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 09/13] replace vhost enqueue packed ring function Marvin Liu
2019-07-08 17:13 ` Marvin Liu [this message]
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 11/13] replace vhost dequeue " Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 12/13] support inorder in vhost dequeue path Marvin Liu
2019-07-08 17:13 ` [dpdk-dev] [RFC PATCH 13/13] remove useless vhost functions Marvin Liu
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=20190708171320.38802-11-yong.liu@intel.com \
--to=yong.liu@intel.com \
--cc=dev@dpdk.org \
--cc=maxime.coquelin@redhat.com \
--cc=tiwei.bie@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).