Skip to contentSkip to conversation

support to clear in-flight packets for async

PATCH Superseded Yuan Wang 4 participants 18 messages Sep 9, 2021 – Sep 30, 2021

lore
Share & tools
lore

Yuan Wang

author
#0 lore raw

cover support to clear in-flight packets for async

This patch supports to clear in-flight packets for aysnc dequeue and introduces thread-safe version of this function.

Yuan Wang (2):
vhost: support to clear in-flight packets for async dequeue
vhost: support thread-safe API for clearing in-flight packets in async
vhost

 lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++
 lib/vhost/version.map       |  1 +
 lib/vhost/virtio_net.c      | 46 ++++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 vhost: support to clear in-flight packets for async dequeue

rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too.

---
 lib/vhost/virtio_net.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
lib/vhost/virtio_net.c +10 -6
index e0159b53e3..7f6183a929 100644
@@ -27,6 +27,11 @@
 
 #define VHOST_ASYNC_BATCH_THRESHOLD 32
 
+static __rte_always_inline uint16_t
+async_poll_dequeue_completed_split(struct virtio_net *dev,
+		struct vhost_virtqueue *vq, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count, bool legacy_ol_flags);
+
 static  __rte_always_inline bool
 rxvq_is_mergeable(struct virtio_net *dev)
 {
@@ -2119,11 +2124,6 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		return 0;
 
 	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
-	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
-		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->vid, __func__, queue_id);
-		return 0;
-	}
 
 	vq = dev->virtqueue[queue_id];
 
@@ -2133,7 +2133,11 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		return 0;
 	}
 
-	n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	if ((queue_id % 2) == 0)
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	else
+		n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts, count,
+						dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
 
 	return n_pkts_cpl;
 }
Signature · 1 line
2.25.1
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue

Hi Yuan,

Quoted 51 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Thursday, September 9, 2021 2:58 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Pai G, Sunil <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Wang, YuanX <[email protected]>
Subject: [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue

rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too.

---
 lib/vhost/virtio_net.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
lib/vhost/virtio_net.c +5 -5
index e0159b53e3..7f6183a929 100644
@@ -27,6 +27,11 @@
 
 #define VHOST_ASYNC_BATCH_THRESHOLD 32
 
+static __rte_always_inline uint16_t
+async_poll_dequeue_completed_split(struct virtio_net *dev,
+		struct vhost_virtqueue *vq, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count, bool legacy_ol_flags);
+
 static  __rte_always_inline bool
 rxvq_is_mergeable(struct virtio_net *dev)
 {
@@ -2119,11 +2124,6 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t
 queue_id,
 		return 0;
 
 	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
-	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
-		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n",
-			dev->vid, __func__, queue_id);
-		return 0;
-	}
 
 	vq = dev->virtqueue[queue_id];

lib/vhost/virtio_net.c rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t · line 2137

Quoted 6 lines
lib/vhost/virtio_net.c +1 -1
@@ -2133,7 +2133,11 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t
 queue_id,
 		return 0;
 	}
 
-	n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	if ((queue_id % 2) == 0)

You can remove the internal '()'.

lib/vhost/virtio_net.c rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t · line 2142

Quoted 5 lines
lib/vhost/virtio_net.c +3 -0
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts,
 count);
+	else
+		n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id,
 pkts, count,

You should check we are using split queue before entering this split queue function.

Thanks,
Chenbo

Quoted 6 lines
lib/vhost/virtio_net.c +1 -0
+						dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);

return n_pkts_cpl;
}
--
2.25.1

Tested-by on v1 1/2
#3 lore raw

Re: [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue

In reply to Yuan Wang
Quoted 14 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Thursday, September 9, 2021 2:58 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Pai G, Sunil <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Wang, YuanX <[email protected]>
Subject: [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue

Quoted 6 lines

rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too.

---

author
#4 lore raw

PATCH 2/2 vhost: support thread-safe API for clearing in-flight packets in async vhost

In reply to Yuan Wang

This patch adds thread-safe version for
clearing in-flight packets function.

---
 lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++++++
 lib/vhost/version.map       |  1 +
 lib/vhost/virtio_net.c      | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+)
lib/vhost/rte_vhost_async.h +21 -0
index 5e2429ab70..a418e0a03d 100644
@@ -261,6 +261,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
 __rte_experimental
 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		struct rte_mbuf **pkts, uint16_t count);
+
+/**
+ * This function checks async completion status and clear packets for
+ * a specific vhost device queue. Packets which are inflight will be
+ * returned in an array.
+ *
+ * @param vid
+ *  ID of vhost device to clear data
+ * @param queue_id
+ *  Queue id to clear data
+ * @param pkts
+ *  Blank array to get return packet pointer
+ * @param count
+ *  Size of the packet array
+ * @return
+ *  Number of packets returned
+ */
+__rte_experimental
+uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count);
+
 /**
  * This function tries to receive packets from the guest with offloading
  * copies to the async channel. The packets that are transfer completed
lib/vhost/version.map +1 -0
index 3d566a6d5f..f78cc89b58 100644
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
lib/vhost/virtio_net.c +36 -0
index 7f6183a929..51693a7c35 100644
@@ -2142,6 +2142,42 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 	return n_pkts_cpl;
 }
 
+uint16_t
+rte_vhost_clear_queue(int vid, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count)
+{
+	struct virtio_net *dev = get_device(vid);
+	struct vhost_virtqueue *vq;
+	uint16_t n_pkts_cpl;
+
+	if (!dev)
+		return 0;
+
+	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
+
+	vq = dev->virtqueue[queue_id];
+
+	if (unlikely(!vq->async_registered)) {
+		VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue id %d.\n",
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	if (!rte_spinlock_trylock(&vq->access_lock)) {
+		VHOST_LOG_CONFIG(ERR, "Failed to clear async queue, virt queue busy.\n");
+		return 0;
+	}
+
+	if ((queue_id % 2) == 0)
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	else
+		n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts, count,
+						dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
+
+	rte_spinlock_unlock(&vq->access_lock);
+
+	return n_pkts_cpl;
+}
+
 static __rte_always_inline uint32_t
 virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint32_t count)
Signature · 1 line
2.25.1
#5 lore raw

Re: [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost

Hi Yuan,

Quoted 11 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Thursday, September 9, 2021 2:58 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Pai G, Sunil <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Wang, YuanX <[email protected]>
Subject: [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost

support -> add

Quoted 10 lines

This patch adds thread-safe version for
clearing in-flight packets function.

---
 lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++++++
 lib/vhost/version.map       |  1 +
 lib/vhost/virtio_net.c      | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+)

Miss update of release note.

Quoted 56 lines
lib/vhost/rte_vhost_async.h +21 -0
index 5e2429ab70..a418e0a03d 100644
@@ -261,6 +261,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_t
 queue_id);
 __rte_experimental
 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		struct rte_mbuf **pkts, uint16_t count);
+
+/**
+ * This function checks async completion status and clear packets for
+ * a specific vhost device queue. Packets which are inflight will be
+ * returned in an array.
+ *
+ * @param vid
+ *  ID of vhost device to clear data
+ * @param queue_id
+ *  Queue id to clear data
+ * @param pkts
+ *  Blank array to get return packet pointer
+ * @param count
+ *  Size of the packet array
+ * @return
+ *  Number of packets returned
+ */
+__rte_experimental
+uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count);
+
 /**
  * This function tries to receive packets from the guest with offloading

* copies to the async channel. The packets that are transfer completed

lib/vhost/version.map +1 -0
index 3d566a6d5f..f78cc89b58 100644
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
lib/vhost/virtio_net.c +2 -0
index 7f6183a929..51693a7c35 100644
@@ -2142,6 +2142,42 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t
 queue_id,
 	return n_pkts_cpl;
 }
 
+uint16_t
+rte_vhost_clear_queue(int vid, uint16_t queue_id, struct rte_mbuf **pkts,
 uint16_t count)

lib/vhost/virtio_net.c rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t · line 2158

Quoted 10 lines
lib/vhost/virtio_net.c +10 -0
+{
+	struct virtio_net *dev = get_device(vid);
+	struct vhost_virtqueue *vq;
+	uint16_t n_pkts_cpl;
+
+	if (!dev)
+		return 0;
+
+	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
+

Should check queue id here.

Quoted 11 lines
lib/vhost/virtio_net.c +10 -0
+	vq = dev->virtqueue[queue_id];
+
+	if (unlikely(!vq->async_registered)) {
+		VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue
 id %d.\n",
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	if (!rte_spinlock_trylock(&vq->access_lock)) {
+		VHOST_LOG_CONFIG(ERR, "Failed to clear async queue, virt queue
Quoted 1 line

busy.\n");

Should be VHOST_LOG_DATA. And please add vid and qid info in the log.

lib/vhost/virtio_net.c rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, · line 2170

Quoted 4 lines
lib/vhost/virtio_net.c +4 -0
+		return 0;
+	}
+
+	if ((queue_id % 2) == 0)

You can remove internal '()'

Quoted 5 lines
lib/vhost/virtio_net.c +1 -0
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts,

count);

lib/vhost/virtio_net.c +2 -0
+	else
+		n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id,

pkts, count,

Add check to make sure it's split queue.

Thanks,
Chenbo

Quoted 12 lines
lib/vhost/virtio_net.c +7 -1
+						dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
+
+	rte_spinlock_unlock(&vq->access_lock);
+
+	return n_pkts_cpl;
+}
+
 static __rte_always_inline uint32_t
 virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint32_t count)
--

2.25.1

Tested-by on v1 2/2
#6 lore raw

Re: [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost

In reply to Yuan Wang
Quoted 14 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Thursday, September 9, 2021 2:58 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Pai G, Sunil <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Wang, YuanX <[email protected]>
Subject: [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost

Quoted 5 lines

This patch adds thread-safe version for
clearing in-flight packets function.

---

#7 lore raw
In reply to Yuan Wang

Hi Yuan,

Quoted 11 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Thursday, September 9, 2021 2:58 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Pai G, Sunil <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Wang, YuanX <[email protected]>
Subject: [PATCH 0/2] support to clear in-flight packets for async

Quoted 2 lines

This patch supports to clear in-flight packets for aysnc dequeue and introduces thread-safe version of this function.

It'll be better if you can list the patchset this one depends on, otherwise it will increase overhead for reviewers. Luckily I know the dependency, but let's add it in new version.

Thanks,
Chenbo

Quoted 13 lines

Yuan Wang (2):
vhost: support to clear in-flight packets for async dequeue
vhost: support thread-safe API for clearing in-flight packets in async
vhost

 lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++
 lib/vhost/version.map       |  1 +
 lib/vhost/virtio_net.c      | 46 ++++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 3 deletions(-)

--
2.25.1

author
#8 lore raw

v2 cover support to clear in-flight packets for async

In reply to Yuan Wang

This patch supports to clear in-flight packets for aysnc dequeue and introduces thread-safe version of this function.

note: This patch depends on the following vhost patch
(http://patchwork.dpdk.org/project/dpdk/patch/[email protected]/)

v2:
- Update release note.
- Add check on queue id and split queue.

Yuan Wang (2):
vhost: support to clear in-flight packets for async dequeue
vhost: add thread-safe API for clearing in-flight packets in async
vhost

 doc/guides/prog_guide/vhost_lib.rst |  8 +++-
 lib/vhost/rte_vhost_async.h         | 21 +++++++++
 lib/vhost/version.map               |  1 +
 lib/vhost/virtio_net.c              | 68 ++++++++++++++++++++++++++++-
 4 files changed, 95 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
author
#9 lore raw

PATCH v2 1/2 vhost: support to clear in-flight packets for async dequeue

rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too.

---
 lib/vhost/virtio_net.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
lib/vhost/virtio_net.c +17 -2
index 4bc69b9081..cc84a9d21e 100644
@@ -27,6 +27,11 @@
 
 #define VHOST_ASYNC_BATCH_THRESHOLD 32
 
+static __rte_always_inline uint16_t
+async_poll_dequeue_completed_split(struct virtio_net *dev,
+		struct vhost_virtqueue *vq, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count, bool legacy_ol_flags);
+
 static  __rte_always_inline bool
 rxvq_is_mergeable(struct virtio_net *dev)
 {
@@ -2120,7 +2125,7 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		return 0;
 
 	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
-	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
+	if (unlikely(queue_id >= dev->nr_vring)) {
 		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
 		return 0;
@@ -2134,7 +2139,17 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		return 0;
 	}
 
-	n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	if (queue_id % 2 == 0)
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	else {
+		if (unlikely(vq_is_packed(dev)))
+			VHOST_LOG_DATA(ERR,
+				"(%d) %s: async dequeue does not support packed ring.\n",
+				dev->vid, __func__);
+		else
+			n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts,
+						count, dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
+	}
 
 	return n_pkts_cpl;
 }
Signature · 1 line
2.25.1
author
#10 lore raw

PATCH v2 2/2 vhost: add thread-safe API for clearing in-flight packets in async vhost

In reply to Yuan Wang

This patch adds thread safe version for
clearing in-flight packets function.

---
 doc/guides/prog_guide/vhost_lib.rst |  8 ++++-
 lib/vhost/rte_vhost_async.h         | 21 +++++++++++++
 lib/vhost/version.map               |  1 +
 lib/vhost/virtio_net.c              | 49 +++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)
doc/guides/prog_guide/vhost_lib.rst +7 -1
index 9ed544db7a..bc21c879f3 100644
@@ -300,7 +300,13 @@ The following is an overview of some key Vhost API functions:
 
 * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count)``
 
-  Clear inflight packets which are submitted to DMA engine in vhost async data
+  Clear in-flight packets which are submitted to async channel in vhost
+  async data path without performing any locking. Completed packets are
+  returned to applications through ``pkts``.
+
+* ``rte_vhost_clear_queue(vid, queue_id, **pkts, count)``
+
+  Clear in-flight packets which are submitted to async channel in vhost async data
   path. Completed packets are returned to applications through ``pkts``.
 
 * ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)``
lib/vhost/rte_vhost_async.h +21 -0
index 973efa19b1..887fc2fa47 100644
@@ -256,6 +256,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
 __rte_experimental
 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		struct rte_mbuf **pkts, uint16_t count);
+
+/**
+ * This function checks async completion status and clear packets for
+ * a specific vhost device queue. Packets which are inflight will be
+ * returned in an array.
+ *
+ * @param vid
+ *  ID of vhost device to clear data
+ * @param queue_id
+ *  Queue id to clear data
+ * @param pkts
+ *  Blank array to get return packet pointer
+ * @param count
+ *  Size of the packet array
+ * @return
+ *  Number of packets returned
+ */
+__rte_experimental
+uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count);
+
 /**
  * This function tries to receive packets from the guest with offloading
  * copies to the async channel. The packets that are transfer completed
lib/vhost/version.map +1 -0
index 8eb7e92c32..b87d5906b8 100644
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
lib/vhost/virtio_net.c +49 -0

55 lines not on this page · raw message

Signature · 1 line
2.25.1
Tested-by on the v1 series
#11 lore raw
In reply to Yuan Wang
Quoted 21 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Thursday, September 9, 2021 2:58 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Pai G, Sunil <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Wang, YuanX <[email protected]>
Subject: [PATCH 0/2] support to clear in-flight packets for async

This patch supports to clear in-flight packets for aysnc dequeue and introduces thread-safe version of this function.

Yuan Wang (2):
vhost: support to clear in-flight packets for async dequeue
vhost: support thread-safe API for clearing in-flight packets in async
vhost

Quoted 7 lines
 lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++
 lib/vhost/version.map       |  1 +
 lib/vhost/virtio_net.c      | 46 ++++++++++++++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 3 deletions(-)

--
2.25.1

author
#12 lore raw

v3 cover support to clear in-flight packets for async

In reply to Yuan Wang

This patch supports to clear in-flight packets for aysnc dequeue and introduces thread-safe version of this function.

note: This patch depends on the following patch
(http://patchwork.dpdk.org/project/dpdk/patch/[email protected]/)
---
v3:
- Fix uninitialized issue in 2/2.

v2:
- Update release note.
- Add check on queue id and split queue.

Yuan Wang (2):
vhost: support to clear in-flight packets for async dequeue
vhost: add thread-safe API for clearing in-flight packets in async
vhost

 doc/guides/prog_guide/vhost_lib.rst |  8 +++-
 lib/vhost/rte_vhost_async.h         | 21 +++++++++
 lib/vhost/version.map               |  1 +
 lib/vhost/virtio_net.c              | 68 ++++++++++++++++++++++++++++-
 4 files changed, 95 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
author
#13 lore raw

PATCH v3 1/2 vhost: support to clear in-flight packets for async dequeue

rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too.

---
 lib/vhost/virtio_net.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
lib/vhost/virtio_net.c +17 -2
index 39399d2d31..21afcd1854 100644
@@ -27,6 +27,11 @@
 
 #define VHOST_ASYNC_BATCH_THRESHOLD 32
 
+static __rte_always_inline uint16_t
+async_poll_dequeue_completed_split(struct virtio_net *dev,
+		struct vhost_virtqueue *vq, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count, bool legacy_ol_flags);
+
 static  __rte_always_inline bool
 rxvq_is_mergeable(struct virtio_net *dev)
 {
@@ -2120,7 +2125,7 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		return 0;
 
 	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
-	if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) {
+	if (unlikely(queue_id >= dev->nr_vring)) {
 		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n",
 			dev->vid, __func__, queue_id);
 		return 0;
@@ -2134,7 +2139,17 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		return 0;
 	}
 
-	n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	if (queue_id % 2 == 0)
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count);
+	else {
+		if (unlikely(vq_is_packed(dev)))
+			VHOST_LOG_DATA(ERR,
+				"(%d) %s: async dequeue does not support packed ring.\n",
+				dev->vid, __func__);
+		else
+			n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts,
+						count, dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
+	}
 
 	return n_pkts_cpl;
 }
Signature · 1 line
2.25.1
Tested-by on v3 1/2
#14 lore raw

Re: [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue

Quoted 14 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Wednesday, September 22, 2021 4:56 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Pai G, Sunil <[email protected]>
Subject: [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue

Quoted 6 lines

rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too.

---

author
#15 lore raw

PATCH v3 2/2 vhost: add thread-safe API for clearing in-flight packets in async vhost

In reply to Yuan Wang

This patch adds thread safe version for
clearing in-flight packets function.

---
 doc/guides/prog_guide/vhost_lib.rst |  8 ++++-
 lib/vhost/rte_vhost_async.h         | 21 +++++++++++++
 lib/vhost/version.map               |  1 +
 lib/vhost/virtio_net.c              | 49 +++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)
doc/guides/prog_guide/vhost_lib.rst +7 -1
index 9ed544db7a..bc21c879f3 100644
@@ -300,7 +300,13 @@ The following is an overview of some key Vhost API functions:
 
 * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count)``
 
-  Clear inflight packets which are submitted to DMA engine in vhost async data
+  Clear in-flight packets which are submitted to async channel in vhost
+  async data path without performing any locking. Completed packets are
+  returned to applications through ``pkts``.
+
+* ``rte_vhost_clear_queue(vid, queue_id, **pkts, count)``
+
+  Clear in-flight packets which are submitted to async channel in vhost async data
   path. Completed packets are returned to applications through ``pkts``.
 
 * ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts, count, nr_inflight)``
lib/vhost/rte_vhost_async.h +21 -0
index 5e2429ab70..a418e0a03d 100644
@@ -261,6 +261,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
 __rte_experimental
 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		struct rte_mbuf **pkts, uint16_t count);
+
+/**
+ * This function checks async completion status and clear packets for
+ * a specific vhost device queue. Packets which are inflight will be
+ * returned in an array.
+ *
+ * @param vid
+ *  ID of vhost device to clear data
+ * @param queue_id
+ *  Queue id to clear data
+ * @param pkts
+ *  Blank array to get return packet pointer
+ * @param count
+ *  Size of the packet array
+ * @return
+ *  Number of packets returned
+ */
+__rte_experimental
+uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count);
+
 /**
  * This function tries to receive packets from the guest with offloading
  * copies to the async channel. The packets that are transfer completed
lib/vhost/version.map +1 -0
index 8eb7e92c32..b87d5906b8 100644
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
lib/vhost/virtio_net.c +49 -0

55 lines not on this page · raw message

Signature · 1 line
2.25.1
Tested-by on v3 2/2
#16 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost

Quoted 14 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Wednesday, September 22, 2021 4:56 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Pai G, Sunil <[email protected]>
Subject: [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost

Quoted 5 lines

This patch adds thread safe version for
clearing in-flight packets function.

---

#17 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost

In reply to Yuan Wang

Hi Yuan,

Quoted 12 lines

-----Original Message-----
From: Wang, YuanX <[email protected]>
Sent: Wednesday, September 22, 2021 4:56 PM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>; Ding, Xuan <[email protected]>; Jiang, Cheng1 <[email protected]>; Ma, WenwuX <[email protected]>; Yang, YvonneX <[email protected]>; Pai G, Sunil <[email protected]>
Subject: [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost

Quoted 2 lines

This patch adds thread safe version for
clearing in-flight packets function.

Maybe the commit log can refined to be more accurate, like when will clear in-flight packets needed? What is the difference between thread safe and unsafe version(whether use lock I think).

Quoted 8 lines
---
 doc/guides/prog_guide/vhost_lib.rst |  8 ++++-
 lib/vhost/rte_vhost_async.h         | 21 +++++++++++++
 lib/vhost/version.map               |  1 +
 lib/vhost/virtio_net.c              | 49 +++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletion(-)

Remember to add the new API explanation in 21.11 rel_note.

Thanks,
Xuan

Quoted 139 lines
doc/guides/prog_guide/vhost_lib.rst +0 -0
index 9ed544db7a..bc21c879f3 100644
@@ -300,7 +300,13 @@ The following is an overview of some key Vhost API

functions:

* ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count)``

- Clear inflight packets which are submitted to DMA engine in vhost async data

doc/guides/prog_guide/vhost_lib.rst +7 -0
+  Clear in-flight packets which are submitted to async channel in vhost
+  async data path without performing any locking. Completed packets are
+  returned to applications through ``pkts``.
+
+* ``rte_vhost_clear_queue(vid, queue_id, **pkts, count)``
+
+  Clear in-flight packets which are submitted to async channel in vhost async

data
path. Completed packets are returned to applications through ``pkts``.

* ``rte_vhost_async_try_dequeue_burst(vid, queue_id, mbuf_pool, pkts,
count, nr_inflight)``

lib/vhost/rte_vhost_async.h +21 -0
index 5e2429ab70..a418e0a03d 100644
@@ -261,6 +261,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_t
 queue_id);
 __rte_experimental
 uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
 		struct rte_mbuf **pkts, uint16_t count);
+
+/**
+ * This function checks async completion status and clear packets for
+ * a specific vhost device queue. Packets which are inflight will be
+ * returned in an array.
+ *
+ * @param vid
+ *  ID of vhost device to clear data
+ * @param queue_id
+ *  Queue id to clear data
+ * @param pkts
+ *  Blank array to get return packet pointer
+ * @param count
+ *  Size of the packet array
+ * @return
+ *  Number of packets returned
+ */
+__rte_experimental
+uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id,
+		struct rte_mbuf **pkts, uint16_t count);
+
 /**
  * This function tries to receive packets from the guest with offloading

* copies to the async channel. The packets that are transfer completed

lib/vhost/version.map +1 -0
index 8eb7e92c32..b87d5906b8 100644
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
lib/vhost/virtio_net.c +21 -0
index 21afcd1854..2bf8a511d5 100644
@@ -2154,6 +2154,55 @@ rte_vhost_clear_queue_thread_unsafe(int vid,
 uint16_t queue_id,
 	return n_pkts_cpl;
 }
 
+uint16_t
+rte_vhost_clear_queue(int vid, uint16_t queue_id, struct rte_mbuf **pkts,
 uint16_t count)
+{
+	struct virtio_net *dev = get_device(vid);
+	struct vhost_virtqueue *vq;
+	uint16_t n_pkts_cpl = 0;
+
+	if (!dev)
+		return 0;
+
+	VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__);
+	if (unlikely(queue_id >= dev->nr_vring)) {
+		VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue
 idx %d.\n",
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	vq = dev->virtqueue[queue_id];
+
+	if (unlikely(!vq->async_registered)) {
+		VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for

queue id %d.\n",

lib/vhost/virtio_net.c +7 -0
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	if (!rte_spinlock_trylock(&vq->access_lock)) {
+		VHOST_LOG_DATA(ERR,
+			"(%d) %s: failed to clear async queue id %d,

virtqueue busy.\n",

lib/vhost/virtio_net.c +6 -0
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	if (queue_id % 2 == 0)
+		n_pkts_cpl = vhost_poll_enqueue_completed(dev,

queue_id, pkts, count);

lib/vhost/virtio_net.c +4 -0
+	else {
+		if (unlikely(vq_is_packed(dev)))
+			VHOST_LOG_DATA(ERR,
+				"(%d) %s: async dequeue does not support

packed ring.\n",

lib/vhost/virtio_net.c +3 -0
+				dev->vid, __func__);
+		else
+			n_pkts_cpl =

async_poll_dequeue_completed_split(dev, vq, queue_id, pkts,

lib/vhost/virtio_net.c +1 -0
+						count, dev->flags &

VIRTIO_DEV_LEGACY_OL_FLAGS);

lib/vhost/virtio_net.c +7 -1
+	}
+
+	rte_spinlock_unlock(&vq->access_lock);
+
+	return n_pkts_cpl;
+}
+
 static __rte_always_inline uint32_t
 virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id,
 	struct rte_mbuf **pkts, uint32_t count)
--

2.25.1