From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by dpdk.org (Postfix) with ESMTP id A08984C93 for ; Wed, 19 Sep 2018 15:30:59 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C8F5A7A9; Wed, 19 Sep 2018 06:30:58 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5A9833F703; Wed, 19 Sep 2018 06:30:56 -0700 (PDT) From: Phil Yang Date: Wed, 19 Sep 2018 21:30:19 +0800 Message-Id: <1537363820-3827-2-git-send-email-phil.yang@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537363820-3827-1-git-send-email-phil.yang@arm.com> References: <1537363820-3827-1-git-send-email-phil.yang@arm.com> Subject: [dpdk-dev] [PATCH 2/3] kni: fix kni fifo synchronization 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: , X-List-Received-Date: Wed, 19 Sep 2018 13:31:00 -0000 From: Phil Yang With existing code in kni_fifo_put, rx_q values are not being updated before updating fifo_write. While reading rx_q in kni_net_rx_normal, This is causing the sync issue on other core. The same situation happens in kni_fifo_get as well. So syncing the values by adding C11 atomic memory barriers to make sure the values being synced before updating fifo_write and fifo_read. Fixes: 3fc5ca2 ("kni: initial import") Signed-off-by: Phil Yang Reviewed-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- .../linuxapp/eal/include/exec-env/rte_kni_common.h | 5 ++++ lib/librte_kni/rte_kni_fifo.h | 30 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h index cfa9448..1fd713b 100644 --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h @@ -54,8 +54,13 @@ struct rte_kni_request { * Writing should never overwrite the read position */ struct rte_kni_fifo { +#ifndef RTE_USE_C11_MEM_MODEL volatile unsigned write; /**< Next position to be written*/ volatile unsigned read; /**< Next position to be read */ +#else + unsigned write; /**< Next position to be written*/ + unsigned read; /**< Next position to be read */ +#endif unsigned len; /**< Circular buffer length */ unsigned elem_size; /**< Pointer size - for 32/64 bit OS */ void *volatile buffer[]; /**< The buffer contains mbuf pointers */ diff --git a/lib/librte_kni/rte_kni_fifo.h b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..f4171a1 100644 --- a/lib/librte_kni/rte_kni_fifo.h +++ b/lib/librte_kni/rte_kni_fifo.h @@ -28,8 +28,13 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) { unsigned i = 0; unsigned fifo_write = fifo->write; - unsigned fifo_read = fifo->read; unsigned new_write = fifo_write; +#ifdef RTE_USE_C11_MEM_MODEL + unsigned fifo_read = __atomic_load_n(&fifo->read, + __ATOMIC_ACQUIRE); +#else + unsigned fifo_read = fifo->read; +#endif for (i = 0; i < num; i++) { new_write = (new_write + 1) & (fifo->len - 1); @@ -39,7 +44,12 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) fifo->buffer[fifo_write] = data[i]; fifo_write = new_write; } +#ifdef RTE_USE_C11_MEM_MODEL + __atomic_store_n(&fifo->write, fifo_write, __ATOMIC_RELEASE); +#else + rte_smp_wmb(); fifo->write = fifo_write; +#endif return i; } @@ -51,7 +61,12 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) { unsigned i = 0; unsigned new_read = fifo->read; +#ifdef RTE_USE_C11_MEM_MODEL + unsigned fifo_write = __atomic_load_n(&fifo->write, __ATOMIC_ACQUIRE); +#else unsigned fifo_write = fifo->write; +#endif + for (i = 0; i < num; i++) { if (new_read == fifo_write) break; @@ -59,7 +74,12 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) data[i] = fifo->buffer[new_read]; new_read = (new_read + 1) & (fifo->len - 1); } +#ifdef RTE_USE_C11_MEM_MODEL + __atomic_store_n(&fifo->read, new_read, __ATOMIC_RELEASE); +#else + rte_smp_wmb(); fifo->read = new_read; +#endif return i; } @@ -69,5 +89,13 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) static inline uint32_t kni_fifo_count(struct rte_kni_fifo *fifo) { +#ifdef RTE_USE_C11_MEM_MODEL + unsigned fifo_write = __atomic_load_n(&fifo->write, + __ATOMIC_ACQUIRE); + unsigned fifo_read = __atomic_load_n(&fifo->read, + __ATOMIC_ACQUIRE); + return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1); +#else return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1); +#endif } -- 2.7.4