DPDK patches and discussions
 help / color / mirror / Atom feed
From: Joyce Kong <joyce.kong@arm.com>
To: maxime.coquelin@redhat.com, chenbo.xia@intel.com,
	honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com
Cc: dev@dpdk.org, nd@arm.com
Subject: [dpdk-dev] [PATCH v1 1/8] examples/vhost: relax memory ordering when enqueue/dequeue
Date: Mon, 21 Dec 2020 23:50:26 +0800	[thread overview]
Message-ID: <20201221155033.6771-2-joyce.kong@arm.com> (raw)
In-Reply-To: <20201221155033.6771-1-joyce.kong@arm.com>

Use C11 atomic APIs with one-way barriers to replace two-way
barriers when operating enqueue/dequeue. Used->idx and avail->idx
are the synchronization points for split vring.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
 examples/vhost/virtio_net.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/examples/vhost/virtio_net.c b/examples/vhost/virtio_net.c
index 8ea6b36d5..64bf3d19f 100644
--- a/examples/vhost/virtio_net.c
+++ b/examples/vhost/virtio_net.c
@@ -191,7 +191,7 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,
 	queue = &dev->queues[queue_id];
 	vr    = &queue->vr;
 
-	avail_idx = *((volatile uint16_t *)&vr->avail->idx);
+	avail_idx = __atomic_load_n(&vr->avail->idx, __ATOMIC_ACQUIRE);
 	start_idx = queue->last_used_idx;
 	free_entries = avail_idx - start_idx;
 	count = RTE_MIN(count, free_entries);
@@ -224,9 +224,7 @@ vs_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,
 			rte_prefetch0(&vr->desc[desc_indexes[i+1]]);
 	}
 
-	rte_smp_wmb();
-
-	*(volatile uint16_t *)&vr->used->idx += count;
+	__atomic_add_fetch(&vr->used->idx, count, __ATOMIC_RELEASE);
 	queue->last_used_idx += count;
 
 	rte_vhost_vring_call(dev->vid, queue_id);
@@ -374,7 +372,7 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,
 	queue = &dev->queues[queue_id];
 	vr    = &queue->vr;
 
-	free_entries = *((volatile uint16_t *)&vr->avail->idx) -
+	free_entries = __atomic_load_n(&vr->avail->idx, __ATOMIC_ACQUIRE) -
 			queue->last_avail_idx;
 	if (free_entries == 0)
 		return 0;
@@ -429,10 +427,8 @@ vs_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,
 
 	queue->last_avail_idx += i;
 	queue->last_used_idx += i;
-	rte_smp_wmb();
-	rte_smp_rmb();
 
-	vr->used->idx += i;
+	__atomic_add_fetch(&vr->used->idx, i, __ATOMIC_ACQ_REL);
 
 	rte_vhost_vring_call(dev->vid, queue_id);
 
-- 
2.29.2


  reply	other threads:[~2020-12-21 15:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21 15:50 [dpdk-dev] [PATCH v1 0/8] replace smp barriers in vhost with C11 atomic Joyce Kong
2020-12-21 15:50 ` Joyce Kong [this message]
2021-01-07 16:33   ` [dpdk-dev] [PATCH v1 1/8] examples/vhost: relax memory ordering when enqueue/dequeue Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 2/8] examples/vhost_blk: replace smp with thread fence Joyce Kong
2021-01-07 16:35   ` Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 3/8] vhost: remove unnecessary smp barrier for desc flags Joyce Kong
2021-01-07 16:38   ` Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 4/8] vhost: remove unnecessary smp barrier for avail idx Joyce Kong
2021-01-07 16:43   ` Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 5/8] vhost: relax full barriers for desc flags Joyce Kong
2021-01-07 16:45   ` Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 6/8] vhost: relax full barriers for used idx Joyce Kong
2021-01-07 16:46   ` Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 7/8] vhost: replace smp with thread fence for packed vring Joyce Kong
2021-01-07 17:06   ` Maxime Coquelin
2020-12-21 15:50 ` [dpdk-dev] [PATCH v1 8/8] vhost: replace smp with thread fence for control path Joyce Kong
2021-01-07 17:15   ` Maxime Coquelin
2021-01-08  9:16 ` [dpdk-dev] [PATCH v1 0/8] replace smp barriers in vhost with C11 atomic Maxime Coquelin

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=20201221155033.6771-2-joyce.kong@arm.com \
    --to=joyce.kong@arm.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=honnappa.nagarahalli@arm.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=nd@arm.com \
    --cc=ruifeng.wang@arm.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).