]> git.droids-corp.org - dpdk.git/commitdiff
examples/vhost: support clear in-flight for async dequeue
authorYuan Wang <yuanx.wang@intel.com>
Thu, 9 Jun 2022 17:34:04 +0000 (01:34 +0800)
committerMaxime Coquelin <maxime.coquelin@redhat.com>
Fri, 17 Jun 2022 13:19:58 +0000 (15:19 +0200)
This patch allows vring_state_changed() to clear in-flight
dequeue packets. It also clears the in-flight packets in
a thread-safe way in destroy_device().

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Jiayu Hu <jiayu.hu@intel.com>
examples/vhost/main.c

index e7fee5aa1bc25b7082d273544aa27e7f16815acf..a679ef738c08a1a8d61a17b7bb035c11b0a1a217 100644 (file)
@@ -1543,6 +1543,25 @@ vhost_clear_queue_thread_unsafe(struct vhost_dev *vdev, uint16_t queue_id)
        }
 }
 
+static void
+vhost_clear_queue(struct vhost_dev *vdev, uint16_t queue_id)
+{
+       uint16_t n_pkt = 0;
+       int pkts_inflight;
+
+       int16_t dma_id = dma_bind[vid2socketid[vdev->vid]].dmas[queue_id].dev_id;
+       pkts_inflight = rte_vhost_async_get_inflight(vdev->vid, queue_id);
+
+       struct rte_mbuf *m_cpl[pkts_inflight];
+
+       while (pkts_inflight) {
+               n_pkt = rte_vhost_clear_queue(vdev->vid, queue_id, m_cpl,
+                                               pkts_inflight, dma_id, 0);
+               free_pkts(m_cpl, n_pkt);
+               pkts_inflight = rte_vhost_async_get_inflight(vdev->vid, queue_id);
+       }
+}
+
 /*
  * Remove a device from the specific data core linked list and from the
  * main linked list. Synchronization  occurs through the use of the
@@ -1600,13 +1619,13 @@ destroy_device(int vid)
                vdev->vid);
 
        if (dma_bind[vid].dmas[VIRTIO_RXQ].async_enabled) {
-               vhost_clear_queue_thread_unsafe(vdev, VIRTIO_RXQ);
+               vhost_clear_queue(vdev, VIRTIO_RXQ);
                rte_vhost_async_channel_unregister(vid, VIRTIO_RXQ);
                dma_bind[vid].dmas[VIRTIO_RXQ].async_enabled = false;
        }
 
        if (dma_bind[vid].dmas[VIRTIO_TXQ].async_enabled) {
-               vhost_clear_queue_thread_unsafe(vdev, VIRTIO_TXQ);
+               vhost_clear_queue(vdev, VIRTIO_TXQ);
                rte_vhost_async_channel_unregister(vid, VIRTIO_TXQ);
                dma_bind[vid].dmas[VIRTIO_TXQ].async_enabled = false;
        }
@@ -1765,9 +1784,6 @@ vring_state_changed(int vid, uint16_t queue_id, int enable)
        if (!vdev)
                return -1;
 
-       if (queue_id != VIRTIO_RXQ)
-               return 0;
-
        if (dma_bind[vid2socketid[vid]].dmas[queue_id].async_enabled) {
                if (!enable)
                        vhost_clear_queue_thread_unsafe(vdev, queue_id);