Re: [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost
From: Xia, Chenbo <hidden>
Date: 2021-09-15 07:23:20
Hi Yuan,
-----Original Message----- From: Wang, YuanX <redacted> Sent: Thursday, September 9, 2021 2:58 PM To: dev@dpdk.org Cc: maxime.coquelin@redhat.com; Xia, Chenbo <redacted>; Pai G, Sunil [off-list ref]; Hu, Jiayu [off-list ref]; Ding, Xuan [off-list ref]; Jiang, Cheng1 [off-list ref]; Ma, WenwuX [off-list ref]; Yang, YvonneX [off-list ref]; Wang, YuanX [off-list ref] Subject: [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost
support -> add
This patch adds thread-safe version for clearing in-flight packets function. Signed-off-by: Yuan Wang <redacted> --- lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++++++ lib/vhost/version.map | 1 + lib/vhost/virtio_net.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+)
Miss update of release note.
quoted hunk ↗ jump to hunk
diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index 5e2429ab70..a418e0a03d 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h@@ -261,6 +261,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_tqueue_id); __rte_experimental uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count); + +/** + * 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 + * @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); + /** * This function tries to receive packets from the guest with offloading * copies to the async channel. The packets that are transfer completeddiff --git a/lib/vhost/version.map b/lib/vhost/version.map index 3d566a6d5f..f78cc89b58 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map@@ -88,4 +88,5 @@ EXPERIMENTAL { # added in 21.11 rte_vhost_async_try_dequeue_burst; + rte_vhost_clear_queue; };diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 7f6183a929..51693a7c35 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c@@ -2142,6 +2142,42 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_tqueue_id, return n_pkts_cpl; } +uint16_t +rte_vhost_clear_queue(int vid, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count) +{ + struct virtio_net *dev = get_device(vid); + struct vhost_virtqueue *vq; + uint16_t n_pkts_cpl; + + if (!dev) + return 0; + + VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__); +
Should check queue id here.
+ vq = dev->virtqueue[queue_id];
+
+ if (unlikely(!vq->async_registered)) {
+ VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue
id %d.\n",
+ dev->vid, __func__, queue_id);
+ return 0;
+ }
+
+ if (!rte_spinlock_trylock(&vq->access_lock)) {
+ VHOST_LOG_CONFIG(ERR, "Failed to clear async queue, virt queue
busy.\n");Should be VHOST_LOG_DATA. And please add vid and qid info in the log.
+ return 0; + } + + if ((queue_id % 2) == 0)
You can remove internal '()'
+ n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count); + else + n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts, count,
Add check to make sure it's split queue. Thanks, Chenbo
+ dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS); + + rte_spinlock_unlock(&vq->access_lock); + + return n_pkts_cpl; +} + static __rte_always_inline uint32_t virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id, struct rte_mbuf **pkts, uint32_t count) -- 2.25.1