]> git.droids-corp.org - dpdk.git/commitdiff
vhost: add unsafe API to check in-flight packets
authorXuan Ding <xuan.ding@intel.com>
Fri, 8 Apr 2022 10:22:13 +0000 (10:22 +0000)
committerMaxime Coquelin <maxime.coquelin@redhat.com>
Mon, 9 May 2022 19:15:38 +0000 (21:15 +0200)
In async data path, when vring state changes or device is destroyed,
it is necessary to know the number of in-flight packets in DMA engine.
This patch provides a thread unsafe API to return the number of
in-flight packets for a vhost queue without using any lock.

Signed-off-by: Xuan Ding <xuan.ding@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
doc/guides/prog_guide/vhost_lib.rst
doc/guides/rel_notes/release_22_07.rst
lib/vhost/rte_vhost_async.h
lib/vhost/version.map
lib/vhost/vhost.c

index 886f8f5e727aeabef8e93bdcb06e336cf77b312d..f287b76ebfdcd065fce397373f559c9a5171d326 100644 (file)
@@ -271,6 +271,12 @@ 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. It should only be used within the vhost ops, which already
+  holds the lock.
+
 * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count, dma_id, vchan_id)``
 
   Clear inflight packets which are submitted to DMA engine in vhost async data
index 4ae91dd94d6bbfe1650af8bc8e101112b57c2d22..ca708eadfbddb92ee7e7b008e178e778b5b5a474 100644 (file)
@@ -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 in-flight packets.**
+
+  Added an API which can get the number of in-flight packets in
+  vhost async data path without using lock.
+
 * **Updated Intel iavf driver.**
 
   * Added Tx QoS queue rate limitation support.
index f1293c6a9ddbec30be78fcdcabda9888f528a9bd..70234debf9b35c4e01f4927289b3ba033a6ad8da 100644 (file)
@@ -139,6 +139,23 @@ 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.
+ *
+ * @note This function does not perform any locking, it should only be
+ * used within the vhost ops, which already holds the lock.
+ *
+ * @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
index 0a66c5840cca649321e804a0761196b5919bd641..58413153869ba48742522edc212ffd6d3b66cad9 100644 (file)
@@ -87,6 +87,10 @@ EXPERIMENTAL {
 
        # added in 22.03
        rte_vhost_async_dma_configure;
+
+       # added in 22.07
+       rte_vhost_async_get_inflight_thread_unsafe;
+
 };
 
 INTERNAL {
index bc88148347a946ded5c87f82e4ad4a40fe911db2..cf4bac277a3dde844f374ebd7434b1123753243e 100644 (file)
@@ -1903,6 +1903,32 @@ 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)
+               return ret;
+
+       ret = vq->async->pkts_inflight_n;
+
+       return ret;
+}
+
 int
 rte_vhost_get_monitor_addr(int vid, uint16_t queue_id,
                struct rte_vhost_power_monitor_cond *pmc)