It's useful for hardware vhost backend (like vDPA devices) to set
multiqueue configuration accordingly.

Signed-off-by: Xiaolong Ye <xiaolong...@intel.com>
Signed-off-by: Andy Pei <andy....@intel.com>
---
 lib/librte_vhost/rte_vhost.h | 12 ++++++++++++
 lib/librte_vhost/vhost.c     | 19 +++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 7fb1729..28811b0 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -525,6 +525,18 @@ int rte_vhost_driver_callback_register(const char *path,
 uint16_t rte_vhost_get_vring_num(int vid);
 
 /**
+ * Get the number of active vrings of the device.
+ *
+ * @param vid
+ *  vhost device ID
+ *
+ * @return
+ *  The number of active vrings, 0 on failure
+ */
+uint16_t
+rte_vhost_get_active_vring_num(int vid);
+
+/**
  * Get the virtio net device's ifname, which is the vhost-user socket
  * file path.
  *
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 981837b..c714818 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -674,6 +674,25 @@
        return dev->nr_vring;
 }
 
+uint16_t
+rte_vhost_get_active_vring_num(int vid)
+{
+       struct virtio_net *dev = get_device(vid);
+       struct vhost_virtqueue *vq;
+       uint16_t qid;
+
+       if (dev == NULL)
+               return 0;
+
+       for (qid = 0; qid < dev->nr_vring; qid++) {
+               vq = dev->virtqueue[qid];
+               if (!vq->enabled)
+                       break;
+       }
+
+       return qid;
+}
+
 int
 rte_vhost_get_ifname(int vid, char *buf, size_t len)
 {
-- 
1.8.3.1

Reply via email to