@@ -269,7 +269,12 @@ The following is an overview of some key Vhost API functions:
* ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count, dma_id, dma_vchan)``
- 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, dma_id, dma_vchan)``
+ Clear in-flight packets which are submitted to async channel in vhost async data
path. Completed packets are returned to applications through ``pkts``.
Vhost-user Implementations
@@ -55,6 +55,11 @@ New Features
Also, make sure to start the actual text at the margin.
=======================================================
+* **Added thread-safe version of inflight packet clear API in vhost library.**
+
+ Added an API which can clear the inflight packets submitted to
+ the async channel in a thread-safe manner in the vhost async data path.
+
Removed Items
-------------
@@ -186,6 +186,32 @@ __rte_experimental
uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id,
struct rte_mbuf **pkts, uint16_t count, int16_t dma_id,
uint16_t vchan);
+
+/**
+ * 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
+ * @param dma_id
+ * the identifier of the DMA device
+ * @param vchan
+ * the identifier of virtual DMA channel
+ * @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, int16_t dma_id,
+ uint16_t vchan);
+
/**
* The DMA vChannels used in asynchronous data path must be configured
* first. So this function needs to be called before enabling DMA
@@ -88,6 +88,7 @@ EXPERIMENTAL {
# added in 22.03
rte_vhost_async_dma_configure;
rte_vhost_async_try_dequeue_burst;
+ rte_vhost_clear_queue;
};
INTERNAL {
@@ -26,6 +26,11 @@
#define MAX_BATCH_LEN 256
+static __rte_always_inline uint16_t
+async_poll_dequeue_completed_split(struct virtio_net *dev, uint16_t queue_id,
+ struct rte_mbuf **pkts, uint16_t count, uint16_t dma_id, uint16_t dma_vchan,
+ bool legacy_ol_flags);
+
/* DMA device copy operation tracking array. */
struct async_dma_info dma_copy_track[RTE_DMADEV_DEFAULT_MAX];
@@ -2042,7 +2047,49 @@ 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;
+ }
+
+ vq = dev->virtqueue[queue_id];
+
+ if (unlikely(!vq->async)) {
+ VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue id %d.\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, dma_id, vchan);
+ 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, queue_id, pkts, count,
+ dma_id, vchan, dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
+ }
+
+ return n_pkts_cpl;
+}
+
+uint16_t
+rte_vhost_clear_queue(int vid, uint16_t queue_id, struct rte_mbuf **pkts,
+ uint16_t count, int16_t dma_id, uint16_t vchan)
+{
+ 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;
@@ -2056,7 +2103,27 @@ 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, dma_id, vchan);
+ 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, dma_id, vchan);
+ 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, queue_id, pkts, count,
+ dma_id, vchan, dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS);
+ }
+
+ rte_spinlock_unlock(&vq->access_lock);
return n_pkts_cpl;
}