Patch set 111124–111125 v2

[v2,1/2] vhost: support clear in-flight packets for async dequeue

Submitter
Yuan Wang
Applied on
dpdk (c0c305ee9e0e7c9feca6412266a778f330d20c19)
Date submitted
May 13, 2022, 4:35 p.m.

Test Results Apply Error

Checking patch doc/guides/prog_guide/vhost_lib.rst...
error: while searching for:

* ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count, dma_id, vchan_id)``

  Clear inflight packets which are submitted to DMA engine in vhost async data
  path. Completed packets are returned to applications through ``pkts``.

* ``rte_vhost_async_try_dequeue_burst(int vid, uint16_t queue_id,

error: patch failed: doc/guides/prog_guide/vhost_lib.rst:279
Checking patch doc/guides/rel_notes/release_22_07.rst...
error: while searching for:
  Added vhost async dequeue API which can leverage DMA devices to
  accelerate receiving pkts from guest.

Removed Items
-------------


error: patch failed: doc/guides/rel_notes/release_22_07.rst:75
Checking patch lib/vhost/rte_vhost_async.h...
Hunk #1 succeeded at 166 (offset -17 lines).
Checking patch lib/vhost/version.map...
error: while searching for:
	# added in 22.07
	rte_vhost_async_get_inflight_thread_unsafe;
	rte_vhost_async_try_dequeue_burst;
};

INTERNAL {

error: patch failed: lib/vhost/version.map:91
Checking patch lib/vhost/virtio_net.c...
Hunk #2 succeeded at 2088 (offset -19 lines).
Hunk #3 succeeded at 2109 (offset -19 lines).
Applying patch doc/guides/prog_guide/vhost_lib.rst with 1 reject...
Rejected hunk #1.
Applying patch doc/guides/rel_notes/release_22_07.rst with 1 reject...
Rejected hunk #1.
Applied patch lib/vhost/rte_vhost_async.h cleanly.
Applying patch lib/vhost/version.map with 1 reject...
Rejected hunk #1.
Applied patch lib/vhost/virtio_net.c cleanly.
diff a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst	(rejected hunks)
@@ -279,7 +279,13 @@ The following is an overview of some key Vhost API functions:
 
 * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count, dma_id, vchan_id)``
 
-  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, vchan_id)``
+
+  Clear in-flight packets which are submitted to async channel in vhost async data
   path. Completed packets are returned to applications through ``pkts``.
 
 * ``rte_vhost_async_try_dequeue_burst(int vid, uint16_t queue_id,
diff a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst	(rejected hunks)
@@ -75,6 +75,11 @@ New Features
   Added vhost async dequeue API which can leverage DMA devices to
   accelerate receiving pkts from guest.
 
+* **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
 -------------
 
diff a/lib/vhost/version.map b/lib/vhost/version.map	(rejected hunks)
@@ -91,6 +91,7 @@ EXPERIMENTAL {
 	# added in 22.07
 	rte_vhost_async_get_inflight_thread_unsafe;
 	rte_vhost_async_try_dequeue_burst;
+	rte_vhost_clear_queue;
 };
 
 INTERNAL {
Checking patch examples/vhost/main.c...
error: while searching for:
	}
}

/*
 * Remove a device from the specific data core linked list and from the
 * main linked list. Synchronization  occurs through the use of the

error: patch failed: examples/vhost/main.c:1537
error: while searching for:
		vdev->vid);

	if (dma_bind[vid].dmas[VIRTIO_RXQ].async_enabled) {
		vhost_clear_queue_thread_unsafe(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);
		rte_vhost_async_channel_unregister(vid, VIRTIO_TXQ);
		dma_bind[vid].dmas[VIRTIO_TXQ].async_enabled = false;
	}

error: patch failed: examples/vhost/main.c:1594
error: while searching for:
	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);

error: patch failed: examples/vhost/main.c:1759
Applying patch examples/vhost/main.c with 3 rejects...
Rejected hunk #1.
Rejected hunk #2.
Rejected hunk #3.
diff a/examples/vhost/main.c b/examples/vhost/main.c	(rejected hunks)
@@ -1537,6 +1537,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;
+
+	uint16_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
@@ -1594,13 +1613,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;
 	}
@@ -1759,9 +1778,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);