DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async
@ 2021-09-09  6:58 Yuan Wang
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-09  6:58 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, Sunil.Pai.G, jiayu.hu, xuan.ding,
	cheng1.jiang, wenwux.ma, yvonnex.yang, Yuan Wang

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue
  2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
@ 2021-09-09  6:58 ` Yuan Wang
  2021-09-15  7:02   ` Xia, Chenbo
  2021-09-22  2:18   ` Yang, YvonneX
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost Yuan Wang
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-09  6:58 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, Sunil.Pai.G, jiayu.hu, xuan.ding,
	cheng1.jiang, wenwux.ma, yvonnex.yang, Yuan Wang

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.

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
---
 lib/vhost/virtio_net.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index e0159b53e3..7f6183a929 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost
  2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
@ 2021-09-09  6:58 ` Yuan Wang
  2021-09-15  7:23   ` Xia, Chenbo
  2021-09-22  2:17   ` Yang, YvonneX
  2021-09-15  7:00 ` [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Xia, Chenbo
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-09  6:58 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, Sunil.Pai.G, jiayu.hu, xuan.ding,
	cheng1.jiang, wenwux.ma, yvonnex.yang, Yuan Wang

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

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
---
 lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++++++
 lib/vhost/version.map       |  1 +
 lib/vhost/virtio_net.c      | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+)

diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h
index 5e2429ab70..a418e0a03d 100644
--- a/lib/vhost/rte_vhost_async.h
+++ b/lib/vhost/rte_vhost_async.h
@@ -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
diff --git a/lib/vhost/version.map b/lib/vhost/version.map
index 3d566a6d5f..f78cc89b58 100644
--- a/lib/vhost/version.map
+++ b/lib/vhost/version.map
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 7f6183a929..51693a7c35 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -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)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async
  2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost Yuan Wang
@ 2021-09-15  7:00 ` Xia, Chenbo
  2021-09-17  8:12 ` [dpdk-dev] [PATCH v2 " Yuan Wang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 18+ messages in thread
From: Xia, Chenbo @ 2021-09-15  7:00 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Pai G, Sunil, Hu, Jiayu, Ding, Xuan, Jiang,
	Cheng1, Ma, WenwuX, Yang, YvonneX

Hi Yuan,

> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Thursday, September 9, 2021 2:58 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Pai G,
> Sunil <sunil.pai.g@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ding, Xuan
> <xuan.ding@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>; Ma, WenwuX
> <wenwux.ma@intel.com>; Yang, YvonneX <yvonnex.yang@intel.com>; Wang, YuanX
> <yuanx.wang@intel.com>
> 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.

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

> 
> 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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
@ 2021-09-15  7:02   ` Xia, Chenbo
  2021-09-22  2:18   ` Yang, YvonneX
  1 sibling, 0 replies; 18+ messages in thread
From: Xia, Chenbo @ 2021-09-15  7:02 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Pai G, Sunil, Hu, Jiayu, Ding, Xuan, Jiang,
	Cheng1, Ma, WenwuX, Yang, YvonneX

Hi Yuan,

> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Thursday, September 9, 2021 2:58 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Pai G,
> Sunil <sunil.pai.g@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ding, Xuan
> <xuan.ding@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>; Ma, WenwuX
> <wenwux.ma@intel.com>; Yang, YvonneX <yvonnex.yang@intel.com>; Wang, YuanX
> <yuanx.wang@intel.com>
> 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.
> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---
>  lib/vhost/virtio_net.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
> index e0159b53e3..7f6183a929 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -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)

You can remove the internal '()'.

> +		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

> +						dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
> 
>  	return n_pkts_cpl;
>  }
> --
> 2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost Yuan Wang
@ 2021-09-15  7:23   ` Xia, Chenbo
  2021-09-22  2:17   ` Yang, YvonneX
  1 sibling, 0 replies; 18+ messages in thread
From: Xia, Chenbo @ 2021-09-15  7:23 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Pai G, Sunil, Hu, Jiayu, Ding, Xuan, Jiang,
	Cheng1, Ma, WenwuX, Yang, YvonneX

Hi Yuan,

> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Thursday, September 9, 2021 2:58 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Pai G,
> Sunil <sunil.pai.g@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ding, Xuan
> <xuan.ding@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>; Ma, WenwuX
> <wenwux.ma@intel.com>; Yang, YvonneX <yvonnex.yang@intel.com>; Wang, YuanX
> <yuanx.wang@intel.com>
> Subject: [PATCH 2/2] vhost: support thread-safe API for clearing in-flight
> packets in async vhost

support -> add

> 
> This patch adds thread-safe version for
> clearing in-flight packets function.
> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---
>  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.

> 
> diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h
> index 5e2429ab70..a418e0a03d 100644
> --- a/lib/vhost/rte_vhost_async.h
> +++ b/lib/vhost/rte_vhost_async.h
> @@ -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
> diff --git a/lib/vhost/version.map b/lib/vhost/version.map
> index 3d566a6d5f..f78cc89b58 100644
> --- a/lib/vhost/version.map
> +++ b/lib/vhost/version.map
> @@ -88,4 +88,5 @@ EXPERIMENTAL {
> 
>  	# added in 21.11
>  	rte_vhost_async_try_dequeue_burst;
> +	rte_vhost_clear_queue;
>  };
> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
> index 7f6183a929..51693a7c35 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -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__);
> +

Should check queue id here.

> +	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");

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

> +		return 0;
> +	}
> +
> +	if ((queue_id % 2) == 0)

You can remove internal '()'

> +		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,

Add check to make sure it's split queue.

Thanks,
Chenbo

> +						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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 0/2] support to clear in-flight packets for async
  2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
                   ` (2 preceding siblings ...)
  2021-09-15  7:00 ` [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Xia, Chenbo
@ 2021-09-17  8:12 ` Yuan Wang
  2021-09-17  8:12   ` [dpdk-dev] [PATCH v2 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
  2021-09-17  8:12   ` [dpdk-dev] [PATCH v2 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
  2021-09-22  2:19 ` [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yang, YvonneX
  2021-09-22  8:55 ` [dpdk-dev] [PATCH v3 " Yuan Wang
  5 siblings, 2 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-17  8:12 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, jiayu.hu, xuan.ding, cheng1.jiang,
	wenwux.ma, yvonnex.yang, sunil.pai.g

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/20210917192703.385510-2-wenwux.ma@intel.com/)

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 1/2] vhost: support to clear in-flight packets for async dequeue
  2021-09-17  8:12 ` [dpdk-dev] [PATCH v2 " Yuan Wang
@ 2021-09-17  8:12   ` Yuan Wang
  2021-09-17  8:12   ` [dpdk-dev] [PATCH v2 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
  1 sibling, 0 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-17  8:12 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, jiayu.hu, xuan.ding, cheng1.jiang,
	wenwux.ma, yvonnex.yang, sunil.pai.g

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.

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
---
 lib/vhost/virtio_net.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 4bc69b9081..cc84a9d21e 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost
  2021-09-17  8:12 ` [dpdk-dev] [PATCH v2 " Yuan Wang
  2021-09-17  8:12   ` [dpdk-dev] [PATCH v2 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
@ 2021-09-17  8:12   ` Yuan Wang
  1 sibling, 0 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-17  8:12 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, jiayu.hu, xuan.ding, cheng1.jiang,
	wenwux.ma, yvonnex.yang, sunil.pai.g

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

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
---
 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(-)

diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst
index 9ed544db7a..bc21c879f3 100644
--- a/doc/guides/prog_guide/vhost_lib.rst
+++ b/doc/guides/prog_guide/vhost_lib.rst
@@ -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)``
diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h
index 973efa19b1..887fc2fa47 100644
--- a/lib/vhost/rte_vhost_async.h
+++ b/lib/vhost/rte_vhost_async.h
@@ -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
diff --git a/lib/vhost/version.map b/lib/vhost/version.map
index 8eb7e92c32..b87d5906b8 100644
--- a/lib/vhost/version.map
+++ b/lib/vhost/version.map
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index cc84a9d21e..e7292332a8 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -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;
+
+	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",
+			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",
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	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);
+	}
+
+	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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost Yuan Wang
  2021-09-15  7:23   ` Xia, Chenbo
@ 2021-09-22  2:17   ` Yang, YvonneX
  1 sibling, 0 replies; 18+ messages in thread
From: Yang, YvonneX @ 2021-09-22  2:17 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Xia, Chenbo, Pai G, Sunil, Hu, Jiayu, Ding,
	Xuan, Jiang, Cheng1, Ma, WenwuX



> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Thursday, September 9, 2021 2:58 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> Pai G, Sunil <sunil.pai.g@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ding,
> Xuan <xuan.ding@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>; Ma,
> WenwuX <wenwux.ma@intel.com>; Yang, YvonneX
> <yvonnex.yang@intel.com>; Wang, YuanX <yuanx.wang@intel.com>
> Subject: [PATCH 2/2] vhost: support thread-safe API for clearing in-flight
> packets in async vhost
> 
> This patch adds thread-safe version for
> clearing in-flight packets function.
> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---

Tested-by: Yvonne Yang <yvonnex.yang@intel.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue
  2021-09-09  6:58 ` [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
  2021-09-15  7:02   ` Xia, Chenbo
@ 2021-09-22  2:18   ` Yang, YvonneX
  1 sibling, 0 replies; 18+ messages in thread
From: Yang, YvonneX @ 2021-09-22  2:18 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Xia, Chenbo, Pai G, Sunil, Hu, Jiayu, Ding,
	Xuan, Jiang, Cheng1, Ma, WenwuX



> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Thursday, September 9, 2021 2:58 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> Pai G, Sunil <sunil.pai.g@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ding,
> Xuan <xuan.ding@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>; Ma,
> WenwuX <wenwux.ma@intel.com>; Yang, YvonneX
> <yvonnex.yang@intel.com>; Wang, YuanX <yuanx.wang@intel.com>
> 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.
> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---

Tested-by: Yvonne Yang <yvonnex.yang@intel.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async
  2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
                   ` (3 preceding siblings ...)
  2021-09-17  8:12 ` [dpdk-dev] [PATCH v2 " Yuan Wang
@ 2021-09-22  2:19 ` Yang, YvonneX
  2021-09-22  8:55 ` [dpdk-dev] [PATCH v3 " Yuan Wang
  5 siblings, 0 replies; 18+ messages in thread
From: Yang, YvonneX @ 2021-09-22  2:19 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Xia, Chenbo, Pai G, Sunil, Hu, Jiayu, Ding,
	Xuan, Jiang, Cheng1, Ma, WenwuX



> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Thursday, September 9, 2021 2:58 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>;
> Pai G, Sunil <sunil.pai.g@intel.com>; Hu, Jiayu <jiayu.hu@intel.com>; Ding,
> Xuan <xuan.ding@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>; Ma,
> WenwuX <wenwux.ma@intel.com>; Yang, YvonneX
> <yvonnex.yang@intel.com>; Wang, YuanX <yuanx.wang@intel.com>
> 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
> 
>  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

Tested-by: Yvonne Yang <yvonnex.yang@intel.com>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v3 0/2] support to clear in-flight packets for async
  2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
                   ` (4 preceding siblings ...)
  2021-09-22  2:19 ` [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yang, YvonneX
@ 2021-09-22  8:55 ` Yuan Wang
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
  5 siblings, 2 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-22  8:55 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, jiayu.hu, xuan.ding, cheng1.jiang,
	wenwux.ma, yvonnex.yang, sunil.pai.g

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/20210917192703.385510-2-wenwux.ma@intel.com/)
---
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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue
  2021-09-22  8:55 ` [dpdk-dev] [PATCH v3 " Yuan Wang
@ 2021-09-22  8:55   ` Yuan Wang
  2021-09-23  2:43     ` Yang, YvonneX
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
  1 sibling, 1 reply; 18+ messages in thread
From: Yuan Wang @ 2021-09-22  8:55 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, jiayu.hu, xuan.ding, cheng1.jiang,
	wenwux.ma, yvonnex.yang, sunil.pai.g

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.

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
---
 lib/vhost/virtio_net.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 39399d2d31..21afcd1854 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost
  2021-09-22  8:55 ` [dpdk-dev] [PATCH v3 " Yuan Wang
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
@ 2021-09-22  8:55   ` Yuan Wang
  2021-09-23  2:43     ` Yang, YvonneX
  2021-09-30  6:54     ` Ding, Xuan
  1 sibling, 2 replies; 18+ messages in thread
From: Yuan Wang @ 2021-09-22  8:55 UTC (permalink / raw)
  To: dev
  Cc: maxime.coquelin, chenbo.xia, jiayu.hu, xuan.ding, cheng1.jiang,
	wenwux.ma, yvonnex.yang, sunil.pai.g

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

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
---
 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(-)

diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst
index 9ed544db7a..bc21c879f3 100644
--- a/doc/guides/prog_guide/vhost_lib.rst
+++ b/doc/guides/prog_guide/vhost_lib.rst
@@ -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)``
diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h
index 5e2429ab70..a418e0a03d 100644
--- a/lib/vhost/rte_vhost_async.h
+++ b/lib/vhost/rte_vhost_async.h
@@ -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
diff --git a/lib/vhost/version.map b/lib/vhost/version.map
index 8eb7e92c32..b87d5906b8 100644
--- a/lib/vhost/version.map
+++ b/lib/vhost/version.map
@@ -88,4 +88,5 @@ EXPERIMENTAL {
 
 	# added in 21.11
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 21afcd1854..2bf8a511d5 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -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",
+			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",
+			dev->vid, __func__, queue_id);
+		return 0;
+	}
+
+	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);
+	}
+
+	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


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
@ 2021-09-23  2:43     ` Yang, YvonneX
  0 siblings, 0 replies; 18+ messages in thread
From: Yang, YvonneX @ 2021-09-23  2:43 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Xia, Chenbo, Hu, Jiayu, Ding, Xuan, Jiang,
	Cheng1, Ma, WenwuX, Pai G, Sunil



> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Wednesday, September 22, 2021 4:56 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Hu,
> Jiayu <jiayu.hu@intel.com>; Ding, Xuan <xuan.ding@intel.com>; Jiang,
> Cheng1 <cheng1.jiang@intel.com>; Ma, WenwuX <wenwux.ma@intel.com>;
> Yang, YvonneX <yvonnex.yang@intel.com>; Pai G, Sunil
> <sunil.pai.g@intel.com>
> Subject: [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.
> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---

Tested-by: Yvonne Yang <yvonnex.yang@intel.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
@ 2021-09-23  2:43     ` Yang, YvonneX
  2021-09-30  6:54     ` Ding, Xuan
  1 sibling, 0 replies; 18+ messages in thread
From: Yang, YvonneX @ 2021-09-23  2:43 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Xia, Chenbo, Hu, Jiayu, Ding, Xuan, Jiang,
	Cheng1, Ma, WenwuX, Pai G, Sunil



> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Wednesday, September 22, 2021 4:56 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Hu,
> Jiayu <jiayu.hu@intel.com>; Ding, Xuan <xuan.ding@intel.com>; Jiang,
> Cheng1 <cheng1.jiang@intel.com>; Ma, WenwuX <wenwux.ma@intel.com>;
> Yang, YvonneX <yvonnex.yang@intel.com>; Pai G, Sunil
> <sunil.pai.g@intel.com>
> Subject: [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight
> packets in async vhost
> 
> This patch adds thread safe version for
> clearing in-flight packets function.
> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---

Tested-by: Yvonne Yang <yvonnex.yang@intel.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost
  2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
  2021-09-23  2:43     ` Yang, YvonneX
@ 2021-09-30  6:54     ` Ding, Xuan
  1 sibling, 0 replies; 18+ messages in thread
From: Ding, Xuan @ 2021-09-30  6:54 UTC (permalink / raw)
  To: Wang, YuanX, dev
  Cc: maxime.coquelin, Xia, Chenbo, Hu, Jiayu, Jiang, Cheng1, Ma,
	WenwuX, Yang, YvonneX, Pai G, Sunil

Hi Yuan,

> -----Original Message-----
> From: Wang, YuanX <yuanx.wang@intel.com>
> Sent: Wednesday, September 22, 2021 4:56 PM
> To: dev@dpdk.org
> Cc: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>; Hu,
> Jiayu <jiayu.hu@intel.com>; Ding, Xuan <xuan.ding@intel.com>; Jiang,
> Cheng1 <cheng1.jiang@intel.com>; Ma, WenwuX <wenwux.ma@intel.com>;
> Yang, YvonneX <yvonnex.yang@intel.com>; Pai G, Sunil
> <sunil.pai.g@intel.com>
> Subject: [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight
> packets in async vhost
> 
> 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).

> 
> Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
> ---
>  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

> 
> diff --git a/doc/guides/prog_guide/vhost_lib.rst
> b/doc/guides/prog_guide/vhost_lib.rst
> index 9ed544db7a..bc21c879f3 100644
> --- a/doc/guides/prog_guide/vhost_lib.rst
> +++ b/doc/guides/prog_guide/vhost_lib.rst
> @@ -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)``
> diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h
> index 5e2429ab70..a418e0a03d 100644
> --- a/lib/vhost/rte_vhost_async.h
> +++ b/lib/vhost/rte_vhost_async.h
> @@ -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
> diff --git a/lib/vhost/version.map b/lib/vhost/version.map
> index 8eb7e92c32..b87d5906b8 100644
> --- a/lib/vhost/version.map
> +++ b/lib/vhost/version.map
> @@ -88,4 +88,5 @@ EXPERIMENTAL {
> 
>  	# added in 21.11
>  	rte_vhost_async_try_dequeue_burst;
> +	rte_vhost_clear_queue;
>  };
> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
> index 21afcd1854..2bf8a511d5 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -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",
> +			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",
> +			dev->vid, __func__, queue_id);
> +		return 0;
> +	}
> +
> +	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);
> +	}
> +
> +	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


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-09-30  6:54 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09  6:58 [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yuan Wang
2021-09-09  6:58 ` [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
2021-09-15  7:02   ` Xia, Chenbo
2021-09-22  2:18   ` Yang, YvonneX
2021-09-09  6:58 ` [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost Yuan Wang
2021-09-15  7:23   ` Xia, Chenbo
2021-09-22  2:17   ` Yang, YvonneX
2021-09-15  7:00 ` [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Xia, Chenbo
2021-09-17  8:12 ` [dpdk-dev] [PATCH v2 " Yuan Wang
2021-09-17  8:12   ` [dpdk-dev] [PATCH v2 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
2021-09-17  8:12   ` [dpdk-dev] [PATCH v2 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
2021-09-22  2:19 ` [dpdk-dev] [PATCH 0/2] support to clear in-flight packets for async Yang, YvonneX
2021-09-22  8:55 ` [dpdk-dev] [PATCH v3 " Yuan Wang
2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 1/2] vhost: support to clear in-flight packets for async dequeue Yuan Wang
2021-09-23  2:43     ` Yang, YvonneX
2021-09-22  8:55   ` [dpdk-dev] [PATCH v3 2/2] vhost: add thread-safe API for clearing in-flight packets in async vhost Yuan Wang
2021-09-23  2:43     ` Yang, YvonneX
2021-09-30  6:54     ` Ding, Xuan

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).