vhost: allow to check in-flight packets for async vhost
authorJiayu Hu <jiayu.hu@intel.com>
Thu, 8 Jul 2021 10:21:22 +0000 (06:21 -0400)
committerChenbo Xia <chenbo.xia@intel.com>
Wed, 21 Jul 2021 05:56:13 +0000 (07:56 +0200)
This patch allows to check the amount of in-flight packets
for the vhost queue using async acceleration.

Signed-off-by: Jiayu Hu <jiayu.hu@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
doc/guides/prog_guide/vhost_lib.rst
lib/vhost/rte_vhost_async.h
lib/vhost/version.map
lib/vhost/vhost.c

index d18fb98..5094999 100644 (file)
@@ -281,6 +281,11 @@ The following is an overview of some key Vhost API functions:
   Poll enqueue completion status from async data path. Completed packets
   are returned to applications through ``pkts``.
 
+* ``rte_vhost_async_get_inflight(vid, queue_id)``
+
+  This function returns the amount of in-flight packets for the vhost
+  queue using async acceleration.
+
 Vhost-user Implementations
 --------------------------
 
index 6faa31f..7c55825 100644 (file)
@@ -193,4 +193,18 @@ __rte_experimental
 uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
                struct rte_mbuf **pkts, uint16_t count);
 
+/**
+ * This function returns 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(int vid, uint16_t queue_id);
+
 #endif /* _RTE_VHOST_ASYNC_H_ */
index 9103a23..28238cb 100644 (file)
@@ -79,4 +79,7 @@ EXPERIMENTAL {
 
        # added in 21.05
        rte_vhost_get_negotiated_protocol_features;
+
+       # added in 21.08
+       rte_vhost_async_get_inflight;
 };
index 53a470f..3f82d3f 100644 (file)
@@ -1778,5 +1778,38 @@ out:
        return ret;
 }
 
+int rte_vhost_async_get_inflight(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;
+
+       if (!rte_spinlock_trylock(&vq->access_lock)) {
+               VHOST_LOG_CONFIG(DEBUG, "Failed to check in-flight packets. "
+                       "virt queue busy.\n");
+               return ret;
+       }
+
+       ret = vq->async_pkts_inflight_n;
+       rte_spinlock_unlock(&vq->access_lock);
+
+       return ret;
+
+}
+
 RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO);
 RTE_LOG_REGISTER_SUFFIX(vhost_data_log_level, data, WARNING);