DPDK patches and discussions
 help / color / mirror / Atom feed
From: Xuan Ding <xuan.ding@intel.com>
To: dev@dpdk.org, maxime.coquelin@redhat.com, chenbo.xia@intel.com,
	ktraynor@redhat.com
Cc: jiayu.hu@intel.com, cheng1.jiang@intel.com,
	bruce.richardson@intel.com, sunil.pai.g@intel.com,
	yinan.wang@intel.com, YvonneX.Yang@intel.com,
	Xuan Ding <xuan.ding@intel.com>
Subject: [dpdk-dev] [PATCH v5 2/2] examples/vhost: use API to check inflight packets
Date: Tue, 28 Sep 2021 06:24:46 +0000	[thread overview]
Message-ID: <20210928062446.101264-3-xuan.ding@intel.com> (raw)
In-Reply-To: <20210928062446.101264-1-xuan.ding@intel.com>

In async data path, call rte_vhost_async_get_inflight_thread_unsafe()
API to directly return the number of inflight packets instead of
maintaining a local variable.

Signed-off-by: Xuan Ding <xuan.ding@intel.com>
---
 examples/vhost/main.c | 25 +++++++++++--------------
 examples/vhost/main.h |  1 -
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index d0bf1f31e3..3faac6d053 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -842,11 +842,8 @@ complete_async_pkts(struct vhost_dev *vdev)
 
 	complete_count = rte_vhost_poll_enqueue_completed(vdev->vid,
 					VIRTIO_RXQ, p_cpl, MAX_PKT_BURST);
-	if (complete_count) {
+	if (complete_count)
 		free_pkts(p_cpl, complete_count);
-		__atomic_sub_fetch(&vdev->pkts_inflight, complete_count, __ATOMIC_SEQ_CST);
-	}
-
 }
 
 static __rte_always_inline void
@@ -886,7 +883,6 @@ drain_vhost(struct vhost_dev *vdev)
 
 		complete_async_pkts(vdev);
 		ret = rte_vhost_submit_enqueue_burst(vdev->vid, VIRTIO_RXQ, m, nr_xmit);
-		__atomic_add_fetch(&vdev->pkts_inflight, ret, __ATOMIC_SEQ_CST);
 
 		enqueue_fail = nr_xmit - ret;
 		if (enqueue_fail)
@@ -1212,7 +1208,6 @@ drain_eth_rx(struct vhost_dev *vdev)
 		complete_async_pkts(vdev);
 		enqueue_count = rte_vhost_submit_enqueue_burst(vdev->vid,
 					VIRTIO_RXQ, pkts, rx_count);
-		__atomic_add_fetch(&vdev->pkts_inflight, enqueue_count, __ATOMIC_SEQ_CST);
 
 		enqueue_fail = rx_count - enqueue_count;
 		if (enqueue_fail)
@@ -1338,6 +1333,7 @@ destroy_device(int vid)
 	struct vhost_dev *vdev = NULL;
 	int lcore;
 	uint16_t i;
+	int pkts_inflight;
 
 	TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) {
 		if (vdev->vid == vid)
@@ -1384,13 +1380,13 @@ destroy_device(int vid)
 
 	if (async_vhost_driver) {
 		uint16_t n_pkt = 0;
-		struct rte_mbuf *m_cpl[vdev->pkts_inflight];
+		pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, VIRTIO_RXQ);
+		struct rte_mbuf *m_cpl[pkts_inflight];
 
-		while (vdev->pkts_inflight) {
+		while (pkts_inflight) {
 			n_pkt = rte_vhost_clear_queue_thread_unsafe(vid, VIRTIO_RXQ,
-						m_cpl, vdev->pkts_inflight);
+						m_cpl, pkts_inflight);
 			free_pkts(m_cpl, n_pkt);
-			__atomic_sub_fetch(&vdev->pkts_inflight, n_pkt, __ATOMIC_SEQ_CST);
 		}
 
 		rte_vhost_async_channel_unregister(vid, VIRTIO_RXQ);
@@ -1486,6 +1482,7 @@ static int
 vring_state_changed(int vid, uint16_t queue_id, int enable)
 {
 	struct vhost_dev *vdev = NULL;
+	int pkts_inflight;
 
 	TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) {
 		if (vdev->vid == vid)
@@ -1500,13 +1497,13 @@ vring_state_changed(int vid, uint16_t queue_id, int enable)
 	if (async_vhost_driver) {
 		if (!enable) {
 			uint16_t n_pkt = 0;
-			struct rte_mbuf *m_cpl[vdev->pkts_inflight];
+			pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, queue_id);
+			struct rte_mbuf *m_cpl[pkts_inflight];
 
-			while (vdev->pkts_inflight) {
+			while (pkts_inflight) {
 				n_pkt = rte_vhost_clear_queue_thread_unsafe(vid, queue_id,
-							m_cpl, vdev->pkts_inflight);
+							m_cpl, pkts_inflight);
 				free_pkts(m_cpl, n_pkt);
-				__atomic_sub_fetch(&vdev->pkts_inflight, n_pkt, __ATOMIC_SEQ_CST);
 			}
 		}
 	}
diff --git a/examples/vhost/main.h b/examples/vhost/main.h
index e7b1ac60a6..0ccdce4b4a 100644
--- a/examples/vhost/main.h
+++ b/examples/vhost/main.h
@@ -51,7 +51,6 @@ struct vhost_dev {
 	uint64_t features;
 	size_t hdr_len;
 	uint16_t nr_vrings;
-	uint16_t pkts_inflight;
 	struct rte_vhost_memory *mem;
 	struct device_statistics stats;
 	TAILQ_ENTRY(vhost_dev) global_vdev_entry;
-- 
2.17.1


  parent reply	other threads:[~2021-09-28  6:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09  5:57 [dpdk-dev] [PATCH] vhost: add unsafe " Xuan Ding
2021-09-15  6:49 ` Xia, Chenbo
2021-09-15  7:10   ` Ding, Xuan
2021-09-15  8:52 ` [dpdk-dev] [PATCH v2 v2] " Xuan Ding
2021-09-16  2:58 ` [dpdk-dev] [PATCH v3] " Xuan Ding
2021-09-21 17:27   ` Kevin Traynor
2021-09-23  2:40     ` Ding, Xuan
2021-09-27  1:42 ` [dpdk-dev] [PATCH v4 0/2] add unsafe API to get " Xuan Ding
2021-09-27  1:42   ` [dpdk-dev] [PATCH v4 1/2] vhost: add unsafe API to check " Xuan Ding
2021-09-27  1:42   ` [dpdk-dev] [PATCH v4 2/2] examples/vhost: use " Xuan Ding
2021-09-28  6:24 ` [dpdk-dev] [PATCH v5 0/2] add unsafe API to get " Xuan Ding
2021-09-28  6:24   ` [dpdk-dev] [PATCH v5 1/2] vhost: add unsafe API to check " Xuan Ding
2021-09-28  6:24   ` Xuan Ding [this message]
2021-09-28  9:17     ` [dpdk-dev] [PATCH v5 2/2] examples/vhost: use " Kevin Traynor
2021-09-28 11:50       ` Ding, Xuan
2021-09-28 11:59         ` Ding, Xuan
2021-09-28 15:55 ` [dpdk-dev] [PATCH v6 0/2] add unsafe API to get " Xuan Ding
2021-09-28 15:55   ` [dpdk-dev] [PATCH v6 1/2] vhost: add unsafe API to check " Xuan Ding
2021-09-28 15:55   ` [dpdk-dev] [PATCH v6 2/2] examples/vhost: use " Xuan Ding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210928062446.101264-3-xuan.ding@intel.com \
    --to=xuan.ding@intel.com \
    --cc=YvonneX.Yang@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=cheng1.jiang@intel.com \
    --cc=dev@dpdk.org \
    --cc=jiayu.hu@intel.com \
    --cc=ktraynor@redhat.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=sunil.pai.g@intel.com \
    --cc=yinan.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).