[RFC 2/2] example/vhost: support to clear in-flight packets for async dequeue

Yuan Wang yuanx.wang at intel.com
Mon Jan 17 14:28:47 CET 2022


This patch allows vhost_clear_queue_thread_unsafe() to clear
in-flight dequeue packets.

Signed-off-by: Yuan Wang <yuanx.wang at intel.com>
---
 examples/vhost/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 04a85262bc..050f983fd6 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1495,6 +1495,7 @@ vhost_clear_queue_thread_unsafe(struct vhost_dev *vdev, uint16_t queue_id)
 	uint16_t n_pkt = 0;
 	uint16_t dma_id = dma_bind[vid2socketid[vdev->vid]].dmas[queue_id].dev_id;
 	struct rte_mbuf *m_enq_cpl[vdev->pkts_enq_inflight];
+	struct rte_mbuf *m_deq_cpl[vdev->pkts_deq_inflight];
 
 	if (queue_id % 2 == 0) {
 		while (vdev->pkts_enq_inflight) {
@@ -1503,6 +1504,13 @@ vhost_clear_queue_thread_unsafe(struct vhost_dev *vdev, uint16_t queue_id)
 			free_pkts(m_enq_cpl, n_pkt);
 			__atomic_sub_fetch(&vdev->pkts_enq_inflight, n_pkt, __ATOMIC_SEQ_CST);
 		}
+	} else {
+		while (vdev->pkts_deq_inflight) {
+			n_pkt = rte_vhost_clear_queue_thread_unsafe(vdev->vid,
+				queue_id, m_deq_cpl, vdev->pkts_deq_inflight, dma_id, 0);
+			free_pkts(m_deq_cpl, n_pkt);
+			__atomic_sub_fetch(&vdev->pkts_deq_inflight, n_pkt, __ATOMIC_SEQ_CST);
+		}
 	}
 }
 
-- 
2.25.1



More information about the dev mailing list