From patchwork Mon Dec 21 14:23:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joyce Kong X-Patchwork-Id: 85601 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C0371A09EF; Mon, 21 Dec 2020 15:24:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4C3A0CB7F; Mon, 21 Dec 2020 15:23:51 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 16893CB76 for ; Mon, 21 Dec 2020 15:23:50 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 815861042; Mon, 21 Dec 2020 06:23:48 -0800 (PST) Received: from net-arm-thunderx2-03.shanghai.arm.com (net-arm-thunderx2-03.shanghai.arm.com [10.169.208.206]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 53B4B3F6CF; Mon, 21 Dec 2020 06:23:46 -0800 (PST) From: Joyce Kong To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com Cc: dev@dpdk.org, nd@arm.com Date: Mon, 21 Dec 2020 22:23:18 +0800 Message-Id: <20201221142321.51606-2-joyce.kong@arm.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221142321.51606-1-joyce.kong@arm.com> References: <20201221142321.51606-1-joyce.kong@arm.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 1/4] net/virtio: remove unnecessary rmb barrier X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" As desc_is_used has a load-acquire or rte_io_rmb inside and wait for used desc in virtqueue, it is ok to remove virtio_rmb behind it. Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_ethdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 6c233b75b..0d91f7a50 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -209,12 +209,12 @@ virtio_send_command_packed(struct virtnet_ctl *cvq, virtio_wmb(vq->hw->weak_barriers); virtqueue_notify(vq); - /* wait for used descriptors in virtqueue */ + /* wait for used desc in virtqueue + * desc_is_used has a load-acquire or rte_io_rmb inside + */ while (!desc_is_used(&desc[head], vq)) usleep(100); - virtio_rmb(vq->hw->weak_barriers); - /* now get used descriptors */ vq->vq_free_cnt += nb_descs; vq->vq_used_cons_idx += nb_descs; From patchwork Mon Dec 21 14:23:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joyce Kong X-Patchwork-Id: 85602 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 96A7AA09EF; Mon, 21 Dec 2020 15:24:31 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4D794CC17; Mon, 21 Dec 2020 15:23:54 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id BEC6BCBB4 for ; Mon, 21 Dec 2020 15:23:52 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 317F01FB; Mon, 21 Dec 2020 06:23:51 -0800 (PST) Received: from net-arm-thunderx2-03.shanghai.arm.com (net-arm-thunderx2-03.shanghai.arm.com [10.169.208.206]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0D5983F6CF; Mon, 21 Dec 2020 06:23:48 -0800 (PST) From: Joyce Kong To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com Cc: dev@dpdk.org, nd@arm.com Date: Mon, 21 Dec 2020 22:23:19 +0800 Message-Id: <20201221142321.51606-3-joyce.kong@arm.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221142321.51606-1-joyce.kong@arm.com> References: <20201221142321.51606-1-joyce.kong@arm.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 2/4] net/virtio: replace smp barrier with IO barrier X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Replace rte_smp_wmb/rmb with rte_io_wmb/rmb as they are the same on x86 and ppc platforms. Then, for function virtqueue_fetch_flags_packed/ virtqueue_store_flags_packed, the if and else branch are still identical for the platforms except Arm. Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtqueue.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 42c4c9882..ac3d9e750 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -66,16 +66,15 @@ virtqueue_fetch_flags_packed(struct vring_packed_desc *dp, uint16_t flags; if (weak_barriers) { -/* x86 prefers to using rte_smp_rmb over __atomic_load_n as it reports +/* x86 prefers to using rte_io_rmb over __atomic_load_n as it reports * a better perf(~1.5%), which comes from the saved branch by the compiler. - * The if and else branch are identical with the smp and io barriers both - * defined as compiler barriers on x86. + * The if and else branch are identical on the platforms except Arm. */ -#ifdef RTE_ARCH_X86_64 - flags = dp->flags; - rte_smp_rmb(); -#else +#ifdef RTE_ARCH_ARM flags = __atomic_load_n(&dp->flags, __ATOMIC_ACQUIRE); +#else + flags = dp->flags; + rte_io_rmb(); #endif } else { flags = dp->flags; @@ -90,22 +89,22 @@ virtqueue_store_flags_packed(struct vring_packed_desc *dp, uint16_t flags, uint8_t weak_barriers) { if (weak_barriers) { -/* x86 prefers to using rte_smp_wmb over __atomic_store_n as it reports +/* x86 prefers to using rte_io_wmb over __atomic_store_n as it reports * a better perf(~1.5%), which comes from the saved branch by the compiler. - * The if and else branch are identical with the smp and io barriers both - * defined as compiler barriers on x86. + * The if and else branch are identical on the platforms except Arm. */ -#ifdef RTE_ARCH_X86_64 - rte_smp_wmb(); - dp->flags = flags; -#else +#ifdef RTE_ARCH_ARM __atomic_store_n(&dp->flags, flags, __ATOMIC_RELEASE); +#else + rte_io_wmb(); + dp->flags = flags; #endif } else { rte_io_wmb(); dp->flags = flags; } } + #ifdef RTE_PMD_PACKET_PREFETCH #define rte_packet_prefetch(p) rte_prefetch1(p) #else From patchwork Mon Dec 21 14:23:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joyce Kong X-Patchwork-Id: 85603 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DF7E2A09EF; Mon, 21 Dec 2020 15:24:49 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DFC3BCC4D; Mon, 21 Dec 2020 15:23:56 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 682BCCC48 for ; Mon, 21 Dec 2020 15:23:55 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DEEC41FB; Mon, 21 Dec 2020 06:23:53 -0800 (PST) Received: from net-arm-thunderx2-03.shanghai.arm.com (net-arm-thunderx2-03.shanghai.arm.com [10.169.208.206]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B1A903F6CF; Mon, 21 Dec 2020 06:23:51 -0800 (PST) From: Joyce Kong To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com Cc: dev@dpdk.org, nd@arm.com Date: Mon, 21 Dec 2020 22:23:20 +0800 Message-Id: <20201221142321.51606-4-joyce.kong@arm.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221142321.51606-1-joyce.kong@arm.com> References: <20201221142321.51606-1-joyce.kong@arm.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 3/4] net/virtio: replace full barrier with relaxed barrier for Arm platform X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Relax the full write barriers to one-way barriers for virtio control path for Arm platform Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_ethdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 0d91f7a50..b3e5cba70 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -203,8 +203,8 @@ virtio_send_command_packed(struct virtnet_ctl *cvq, vq->vq_packed.cached_flags ^= VRING_PACKED_DESC_F_AVAIL_USED; } - virtio_wmb(vq->hw->weak_barriers); - desc[head].flags = VRING_DESC_F_NEXT | flags; + virtqueue_store_flags_packed(&desc[head], VRING_DESC_F_NEXT | flags, + vq->hw->weak_barriers); virtio_wmb(vq->hw->weak_barriers); virtqueue_notify(vq); From patchwork Mon Dec 21 14:23:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joyce Kong X-Patchwork-Id: 85604 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C2917A09EF; Mon, 21 Dec 2020 15:25:07 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 77ED0CB7B; Mon, 21 Dec 2020 15:23:59 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 2012ECC64 for ; Mon, 21 Dec 2020 15:23:58 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8F4CA1042; Mon, 21 Dec 2020 06:23:56 -0800 (PST) Received: from net-arm-thunderx2-03.shanghai.arm.com (net-arm-thunderx2-03.shanghai.arm.com [10.169.208.206]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6B2603F6CF; Mon, 21 Dec 2020 06:23:54 -0800 (PST) From: Joyce Kong To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, honnappa.nagarahalli@arm.com, ruifeng.wang@arm.com Cc: dev@dpdk.org, nd@arm.com Date: Mon, 21 Dec 2020 22:23:21 +0800 Message-Id: <20201221142321.51606-5-joyce.kong@arm.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201221142321.51606-1-joyce.kong@arm.com> References: <20201221142321.51606-1-joyce.kong@arm.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 4/4] net/virtio: replace full barrier with thread fence X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Replace the smp barriers with atomic thread fence for synchronization between different threads, if there are no load/store operations. Signed-off-by: Joyce Kong Reviewed-by: Ruifeng Wang Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtqueue.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index ac3d9e750..d78b94344 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -26,7 +26,7 @@ struct rte_mbuf; /* * Per virtio_ring.h in Linux. * For virtio_pci on SMP, we don't need to order with respect to MMIO - * accesses through relaxed memory I/O windows, so smp_mb() et al are + * accesses through relaxed memory I/O windows, so thread_fence is * sufficient. * * For using virtio to talk to real devices (eg. vDPA) we do need real @@ -36,7 +36,7 @@ static inline void virtio_mb(uint8_t weak_barriers) { if (weak_barriers) - rte_smp_mb(); + rte_atomic_thread_fence(__ATOMIC_SEQ_CST); else rte_mb(); } @@ -45,7 +45,7 @@ static inline void virtio_rmb(uint8_t weak_barriers) { if (weak_barriers) - rte_smp_rmb(); + rte_atomic_thread_fence(__ATOMIC_ACQUIRE); else rte_io_rmb(); } @@ -54,7 +54,7 @@ static inline void virtio_wmb(uint8_t weak_barriers) { if (weak_barriers) - rte_smp_wmb(); + rte_atomic_thread_fence(__ATOMIC_RELEASE); else rte_io_wmb(); }