diff mbox series

[v3] vhost: add unsafe API to check inflight packets

Message ID 20210916025807.72941-1-xuan.ding@intel.com (mailing list archive)
State Superseded
Delegated to: Maxime Coquelin
Headers show
Series [v3] vhost: add unsafe API to check inflight packets | expand

Checks

Context Check Description
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing fail Testing issues
ci/Intel-compilation success Compilation OK
ci/iol-spell-check-testing warning Testing issues
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Xuan Ding Sept. 16, 2021, 2:58 a.m. UTC
In async data path, when vring state changes, it is necessary to
know the number of inflight packets in DMA engine. This patch
provides a thread unsafe API to return the number of inflight
packets without using any lock.

Signed-off-by: Xuan Ding <xuan.ding@intel.com>
---
v3:
* Fixed one typo.
* Revised the doc to be more accuracy.

v2:
* Fixed some format issues.
---
 doc/guides/prog_guide/vhost_lib.rst    |  5 +++++
 doc/guides/rel_notes/release_21_11.rst |  5 +++++
 lib/vhost/rte_vhost_async.h            | 14 ++++++++++++++
 lib/vhost/version.map                  |  3 +++
 lib/vhost/vhost.c                      | 26 ++++++++++++++++++++++++++
 5 files changed, 53 insertions(+)

Comments

Kevin Traynor Sept. 21, 2021, 5:27 p.m. UTC | #1
On 16/09/2021 03:58, Xuan Ding wrote:
> In async data path, when vring state changes, it is necessary to
> know the number of inflight packets in DMA engine. This patch
> provides a thread unsafe API to return the number of inflight
> packets without using any lock.
> 
> Signed-off-by: Xuan Ding <xuan.ding@intel.com>
> ---
> v3:
> * Fixed one typo.
> * Revised the doc to be more accuracy.
> 
> v2:
> * Fixed some format issues.
> ---
>   doc/guides/prog_guide/vhost_lib.rst    |  5 +++++
>   doc/guides/rel_notes/release_21_11.rst |  5 +++++
>   lib/vhost/rte_vhost_async.h            | 14 ++++++++++++++
>   lib/vhost/version.map                  |  3 +++
>   lib/vhost/vhost.c                      | 26 ++++++++++++++++++++++++++
>   5 files changed, 53 insertions(+)
> 

<snip>

Should there be a change to the vring_state_changed() in vhost example 
app to go along with this patch? It would help to understand the 
operation if this API was used.
Xuan Ding Sept. 23, 2021, 2:40 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Kevin Traynor <ktraynor@redhat.com>
> Sent: Wednesday, September 22, 2021 1:28 AM
> To: Ding, Xuan <xuan.ding@intel.com>; dev@dpdk.org;
> maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>
> Cc: Hu, Jiayu <jiayu.hu@intel.com>; Jiang, Cheng1 <cheng1.jiang@intel.com>;
> Richardson, Bruce <bruce.richardson@intel.com>; Pai G, Sunil
> <sunil.pai.g@intel.com>; Yang, YvonneX <yvonnex.yang@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v3] vhost: add unsafe API to check inflight
> packets
> 
> On 16/09/2021 03:58, Xuan Ding wrote:
> > In async data path, when vring state changes, it is necessary to
> > know the number of inflight packets in DMA engine. This patch
> > provides a thread unsafe API to return the number of inflight
> > packets without using any lock.
> >
> > Signed-off-by: Xuan Ding <xuan.ding@intel.com>
> > ---
> > v3:
> > * Fixed one typo.
> > * Revised the doc to be more accuracy.
> >
> > v2:
> > * Fixed some format issues.
> > ---
> >   doc/guides/prog_guide/vhost_lib.rst    |  5 +++++
> >   doc/guides/rel_notes/release_21_11.rst |  5 +++++
> >   lib/vhost/rte_vhost_async.h            | 14 ++++++++++++++
> >   lib/vhost/version.map                  |  3 +++
> >   lib/vhost/vhost.c                      | 26 ++++++++++++++++++++++++++
> >   5 files changed, 53 insertions(+)
> >
> 
> <snip>
> 
> Should there be a change to the vring_state_changed() in vhost example
> app to go along with this patch? It would help to understand the
> operation if this API was used.

Thanks Kevin, will add it in vhost example in next version.

Regards,
Xuan
diff mbox series

Patch

diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst
index 8874033165..0c4fb9ea91 100644
--- a/doc/guides/prog_guide/vhost_lib.rst
+++ b/doc/guides/prog_guide/vhost_lib.rst
@@ -305,6 +305,11 @@  The following is an overview of some key Vhost API functions:
   This function returns the amount of in-flight packets for the vhost
   queue using async acceleration.
 
+* ``rte_vhost_async_get_inflight_thread_unsafe(vid, queue_id)``
+
+  Get the number of inflight packets for a vhost queue without
+  performing any locking.
+
 * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count)``
 
   Clear inflight packets which are submitted to DMA engine in vhost async data
diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst
index 675b573834..c9814c68df 100644
--- a/doc/guides/rel_notes/release_21_11.rst
+++ b/doc/guides/rel_notes/release_21_11.rst
@@ -55,6 +55,11 @@  New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added vhost API to get the number of inflight packets.**
+
+  Added an API which can get the number of inflight packets in
+  vhost async data path without using lock.
+
 * **Enabled new devargs parser.**
 
   * Enabled devargs syntax
diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h
index b25ff446f7..0af414bf78 100644
--- a/lib/vhost/rte_vhost_async.h
+++ b/lib/vhost/rte_vhost_async.h
@@ -246,6 +246,20 @@  uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
 __rte_experimental
 int rte_vhost_async_get_inflight(int vid, uint16_t queue_id);
 
+/**
+ * This function is lock-free version to return the amount of in-flight
+ * packets for the vhost queue which uses async channel acceleration.
+ *
+ * @param vid
+ *  id of vhost device to enqueue data
+ * @param queue_id
+ *  queue id to enqueue data
+ * @return
+ *  the amount of in-flight packets on success; -1 on failure
+ */
+__rte_experimental
+int rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id);
+
 /**
  * This function checks async completion status and clear packets for
  * a specific vhost device queue. Packets which are inflight will be
diff --git a/lib/vhost/version.map b/lib/vhost/version.map
index c92a9d4962..b150dc408d 100644
--- a/lib/vhost/version.map
+++ b/lib/vhost/version.map
@@ -85,4 +85,7 @@  EXPERIMENTAL {
 	rte_vhost_async_channel_register_thread_unsafe;
 	rte_vhost_async_channel_unregister_thread_unsafe;
 	rte_vhost_clear_queue_thread_unsafe;
+
+	#added in 21.11
+	rte_vhost_async_get_inflight_thread_unsafe;
 };
diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 355ff37651..24ae1025ea 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -1886,5 +1886,31 @@  int rte_vhost_async_get_inflight(int vid, uint16_t queue_id)
 	return ret;
 }
 
+int
+rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id)
+{
+	struct vhost_virtqueue *vq;
+	struct virtio_net *dev = get_device(vid);
+	int ret = -1;
+
+	if (dev == NULL)
+		return ret;
+
+	if (queue_id >= VHOST_MAX_VRING)
+		return ret;
+
+	vq = dev->virtqueue[queue_id];
+
+	if (vq == NULL)
+		return ret;
+
+	if (!vq->async_registered)
+		return ret;
+
+	ret = vq->async_pkts_inflight_n;
+
+	return ret;
+}
+
 RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO);
 RTE_LOG_REGISTER_SUFFIX(vhost_data_log_level, data, WARNING);