Skip to contentSkip to conversation

config: use one single config option for C11 memory model

PATCH New [email protected] 8 participants 30 messages Sep 19, 2018 – Oct 26, 2018 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 config: use one single config option for C11 memory model

From: Phil Yang <[email protected]>

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

Fixes 39368eb ("ring: introduce C11 memory model barrier option")
---
 config/arm/meson.build                       | 2 +-
 config/common_armv8a_linuxapp                | 2 +-
 config/common_base                           | 2 +-
 config/defconfig_arm64-thunderx-linuxapp-gcc | 2 +-
 lib/librte_ring/rte_ring.h                   | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
config/arm/meson.build +1 -1
index 94cca49..4b23b39 100644
@@ -53,7 +53,7 @@ flags_cavium = [
 	['RTE_MAX_NUMA_NODES', 2],
 	['RTE_MAX_LCORE', 96],
 	['RTE_MAX_VFIO_GROUPS', 128],
-	['RTE_RING_USE_C11_MEM_MODEL', false]]
+	['RTE_USE_C11_MEM_MODEL', false]]
 flags_dpaa = [
 	['RTE_MACHINE', '"dpaa"'],
 	['RTE_CACHE_LINE_SIZE', 64],
config/common_armv8a_linuxapp +1 -1
index 111c005..54e6987 100644
@@ -29,7 +29,7 @@ CONFIG_RTE_ARCH_ARM64_MEMCPY=n
 #CONFIG_RTE_ARM64_MEMCPY_ALIGN_MASK=0xF
 #CONFIG_RTE_ARM64_MEMCPY_STRICT_ALIGN=n
 
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+CONFIG_RTE_USE_C11_MEM_MODEL=y
 
 CONFIG_RTE_LIBRTE_FM10K_PMD=n
 CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n
config/common_base +1 -1
index 155c7d4..ccd2670 100644
@@ -661,7 +661,7 @@ CONFIG_RTE_LIBRTE_PMD_IFPGA_RAWDEV=y
 # Compile librte_ring
 #
 CONFIG_RTE_LIBRTE_RING=y
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile librte_mempool
config/defconfig_arm64-thunderx-linuxapp-gcc +1 -1
index 2bed66c..f11e758 100644
@@ -10,7 +10,7 @@ CONFIG_RTE_CACHE_LINE_SIZE=128
 CONFIG_RTE_MAX_NUMA_NODES=2
 CONFIG_RTE_MAX_LCORE=96
 CONFIG_RTE_MAX_VFIO_GROUPS=128
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile PMD for octeontx sso event device
lib/librte_ring/rte_ring.h +2 -2
index 7a731d0..af5444a 100644
@@ -303,11 +303,11 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
  * There are 2 choices for the users
  * 1.use rmb() memory barrier
  * 2.use one-direcion load_acquire/store_release barrier,defined by
- * CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+ * CONFIG_RTE_USE_C11_MEM_MODEL=y
  * It depends on performance test results.
  * By default, move common functions to rte_ring_generic.h
  */
-#ifdef RTE_RING_USE_C11_MEM_MODEL
+#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_ring_c11_mem.h"
 #else
 #include "rte_ring_generic.h"
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/3 kni: fix kni fifo synchronization

From: Phil Yang <[email protected]>

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")
---
 .../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(-)
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
index cfa9448..1fd713b 100644
@@ -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 */
lib/librte_kni/rte_kni_fifo.h +29 -1
index ac26a8c..f4171a1 100644
@@ -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
 }
Signature · 1 line
2.7.4
#2 lore raw

PATCH 3/3 kni: fix kni kernel fifo synchronization

In reply to [email protected]

From: Phil Yang <[email protected]>

Adding memory barrier to make sure the values being synced before updating fifo_write in kni_fifo_put and fifo_read in kni_fifo_get.

Fixes 3fc5ca2 ("kni: initial import")
---
 kernel/linux/kni/kni_fifo.h                              | 16 ++++++++++------
 .../linuxapp/eal/include/exec-env/rte_kni_common.h       |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)
kernel/linux/kni/kni_fifo.h +10 -6
index 9a4762d..2cb3a4a 100644
@@ -16,7 +16,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 {
 	uint32_t i = 0;
 	uint32_t fifo_write = fifo->write;
-	uint32_t fifo_read = fifo->read;
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
 	uint32_t new_write = fifo_write;
 
 	for (i = 0; i < num; i++) {
@@ -27,7 +27,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 		fifo->buffer[fifo_write] = data[i];
 		fifo_write = new_write;
 	}
-	fifo->write = fifo_write;
+	smp_store_release(&fifo->write, fifo_write);
 
 	return i;
 }
@@ -40,7 +40,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 {
 	uint32_t i = 0;
 	uint32_t new_read = fifo->read;
-	uint32_t fifo_write = fifo->write;
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
 
 	for (i = 0; i < num; i++) {
 		if (new_read == fifo_write)
@@ -49,7 +49,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 		data[i] = fifo->buffer[new_read];
 		new_read = (new_read + 1) & (fifo->len - 1);
 	}
-	fifo->read = new_read;
+	smp_store_release(&fifo->read, new_read);
 
 	return i;
 }
@@ -60,7 +60,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 static inline uint32_t
 kni_fifo_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
+	return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1);
 }
 
 /**
@@ -69,7 +71,9 @@ kni_fifo_count(struct rte_kni_fifo *fifo)
 static inline uint32_t
 kni_fifo_free_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->read - fifo->write - 1) & (fifo->len - 1);
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
+	return (fifo_read - fifo_write - 1) & (fifo->len - 1);
 }
 
 #endif /* _KNI_FIFO_H_ */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
index 1fd713b..5902ae4 100644
@@ -8,6 +8,7 @@
 
 #ifdef __KERNEL__
 #include <linux/if.h>
+#include <asm/barrier.h>
 #define RTE_STD_C11
 #else
 #include <rte_common.h>
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 1/3 config: use one single config option for C11 memory model

In reply to [email protected]

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

Fixes 39368eb ("ring: introduce C11 memory model barrier option")
---
 config/arm/meson.build                       | 2 +-
 config/common_armv8a_linuxapp                | 2 +-
 config/common_base                           | 2 +-
 config/defconfig_arm64-thunderx-linuxapp-gcc | 2 +-
 lib/librte_ring/rte_ring.h                   | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
config/arm/meson.build +1 -1
index 94cca49..4b23b39 100644
@@ -53,7 +53,7 @@ flags_cavium = [
 	['RTE_MAX_NUMA_NODES', 2],
 	['RTE_MAX_LCORE', 96],
 	['RTE_MAX_VFIO_GROUPS', 128],
-	['RTE_RING_USE_C11_MEM_MODEL', false]]
+	['RTE_USE_C11_MEM_MODEL', false]]
 flags_dpaa = [
 	['RTE_MACHINE', '"dpaa"'],
 	['RTE_CACHE_LINE_SIZE', 64],
config/common_armv8a_linuxapp +1 -1
index 111c005..54e6987 100644
@@ -29,7 +29,7 @@ CONFIG_RTE_ARCH_ARM64_MEMCPY=n
 #CONFIG_RTE_ARM64_MEMCPY_ALIGN_MASK=0xF
 #CONFIG_RTE_ARM64_MEMCPY_STRICT_ALIGN=n
 
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+CONFIG_RTE_USE_C11_MEM_MODEL=y
 
 CONFIG_RTE_LIBRTE_FM10K_PMD=n
 CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n
config/common_base +1 -1
index 155c7d4..ccd2670 100644
@@ -661,7 +661,7 @@ CONFIG_RTE_LIBRTE_PMD_IFPGA_RAWDEV=y
 # Compile librte_ring
 #
 CONFIG_RTE_LIBRTE_RING=y
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile librte_mempool
config/defconfig_arm64-thunderx-linuxapp-gcc +1 -1
index 2bed66c..f11e758 100644
@@ -10,7 +10,7 @@ CONFIG_RTE_CACHE_LINE_SIZE=128
 CONFIG_RTE_MAX_NUMA_NODES=2
 CONFIG_RTE_MAX_LCORE=96
 CONFIG_RTE_MAX_VFIO_GROUPS=128
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile PMD for octeontx sso event device
lib/librte_ring/rte_ring.h +2 -2
index 7a731d0..af5444a 100644
@@ -303,11 +303,11 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
  * There are 2 choices for the users
  * 1.use rmb() memory barrier
  * 2.use one-direcion load_acquire/store_release barrier,defined by
- * CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+ * CONFIG_RTE_USE_C11_MEM_MODEL=y
  * It depends on performance test results.
  * By default, move common functions to rte_ring_generic.h
  */
-#ifdef RTE_RING_USE_C11_MEM_MODEL
+#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_ring_c11_mem.h"
 #else
 #include "rte_ring_generic.h"
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 2/3 kni: fix kni fifo synchronization

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")
---
 .../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(-)
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
index cfa9448..1fd713b 100644
@@ -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 */
lib/librte_kni/rte_kni_fifo.h +29 -1
index ac26a8c..f4171a1 100644
@@ -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
 }
Signature · 1 line
2.7.4
#17 lore raw

PATCH v2 3/3 kni: fix kni kernel fifo synchronization

In reply to Phil Yang

Adding memory barrier to make sure the values being synced before updating fifo_write in kni_fifo_put and fifo_read in kni_fifo_get.

Fixes 3fc5ca2 ("kni: initial import")
---
 kernel/linux/kni/kni_fifo.h                              | 16 ++++++++++------
 .../linuxapp/eal/include/exec-env/rte_kni_common.h       |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)
kernel/linux/kni/kni_fifo.h +10 -6
index 9a4762d..2cb3a4a 100644
@@ -16,7 +16,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 {
 	uint32_t i = 0;
 	uint32_t fifo_write = fifo->write;
-	uint32_t fifo_read = fifo->read;
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
 	uint32_t new_write = fifo_write;
 
 	for (i = 0; i < num; i++) {
@@ -27,7 +27,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 		fifo->buffer[fifo_write] = data[i];
 		fifo_write = new_write;
 	}
-	fifo->write = fifo_write;
+	smp_store_release(&fifo->write, fifo_write);
 
 	return i;
 }
@@ -40,7 +40,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 {
 	uint32_t i = 0;
 	uint32_t new_read = fifo->read;
-	uint32_t fifo_write = fifo->write;
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
 
 	for (i = 0; i < num; i++) {
 		if (new_read == fifo_write)
@@ -49,7 +49,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 		data[i] = fifo->buffer[new_read];
 		new_read = (new_read + 1) & (fifo->len - 1);
 	}
-	fifo->read = new_read;
+	smp_store_release(&fifo->read, new_read);
 
 	return i;
 }
@@ -60,7 +60,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 static inline uint32_t
 kni_fifo_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
+	return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1);
 }
 
 /**
@@ -69,7 +71,9 @@ kni_fifo_count(struct rte_kni_fifo *fifo)
 static inline uint32_t
 kni_fifo_free_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->read - fifo->write - 1) & (fifo->len - 1);
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
+	return (fifo_read - fifo_write - 1) & (fifo->len - 1);
 }
 
 #endif /* _KNI_FIFO_H_ */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
index 1fd713b..5902ae4 100644
@@ -8,6 +8,7 @@
 
 #ifdef __KERNEL__
 #include <linux/if.h>
+#include <asm/barrier.h>
 #define RTE_STD_C11
 #else
 #include <rte_common.h>
Signature · 1 line
2.7.4
Acked-by on v2 1/3
#18 lore raw
In reply to Phil Yang

-----Original Message-----

Quoted 10 lines

Date: Wed, 19 Sep 2018 21:42:38 +0800
From: Phil Yang <[email protected]>
To: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected], [email protected]
Subject: [PATCH v2 1/3] config: use one single config option for C11 memory
model
X-Mailer: git-send-email 2.7.4

Quoted 7 lines

External Email

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

Fixes 39368eb ("ring: introduce C11 memory model barrier option")

IMO, Fixes is not required as you are not fixing anything in the existing code.

Other than that, it looks good.

With above change:

Quoted 84 lines
---
 config/arm/meson.build                       | 2 +-
 config/common_armv8a_linuxapp                | 2 +-
 config/common_base                           | 2 +-
 config/defconfig_arm64-thunderx-linuxapp-gcc | 2 +-
 lib/librte_ring/rte_ring.h                   | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
config/arm/meson.build +1 -1
index 94cca49..4b23b39 100644
@@ -53,7 +53,7 @@ flags_cavium = [
        ['RTE_MAX_NUMA_NODES', 2],
        ['RTE_MAX_LCORE', 96],
        ['RTE_MAX_VFIO_GROUPS', 128],
-       ['RTE_RING_USE_C11_MEM_MODEL', false]]
+       ['RTE_USE_C11_MEM_MODEL', false]]
 flags_dpaa = [
        ['RTE_MACHINE', '"dpaa"'],
        ['RTE_CACHE_LINE_SIZE', 64],
config/common_armv8a_linuxapp +1 -1
index 111c005..54e6987 100644
@@ -29,7 +29,7 @@ CONFIG_RTE_ARCH_ARM64_MEMCPY=n
 #CONFIG_RTE_ARM64_MEMCPY_ALIGN_MASK=0xF
 #CONFIG_RTE_ARM64_MEMCPY_STRICT_ALIGN=n
 
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+CONFIG_RTE_USE_C11_MEM_MODEL=y
 
 CONFIG_RTE_LIBRTE_FM10K_PMD=n
 CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n
config/common_base +1 -1
index 155c7d4..ccd2670 100644
@@ -661,7 +661,7 @@ CONFIG_RTE_LIBRTE_PMD_IFPGA_RAWDEV=y
 # Compile librte_ring
 #
 CONFIG_RTE_LIBRTE_RING=y
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile librte_mempool
config/defconfig_arm64-thunderx-linuxapp-gcc +1 -1
index 2bed66c..f11e758 100644
@@ -10,7 +10,7 @@ CONFIG_RTE_CACHE_LINE_SIZE=128
 CONFIG_RTE_MAX_NUMA_NODES=2
 CONFIG_RTE_MAX_LCORE=96
 CONFIG_RTE_MAX_VFIO_GROUPS=128
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile PMD for octeontx sso event device
lib/librte_ring/rte_ring.h +2 -3
index 7a731d0..af5444a 100644
@@ -303,11 +303,11 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
  * There are 2 choices for the users
  * 1.use rmb() memory barrier
  * 2.use one-direcion load_acquire/store_release barrier,defined by
- * CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+ * CONFIG_RTE_USE_C11_MEM_MODEL=y
  * It depends on performance test results.
  * By default, move common functions to rte_ring_generic.h
  */
-#ifdef RTE_RING_USE_C11_MEM_MODEL
+#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_ring_c11_mem.h"
 #else
 #include "rte_ring_generic.h"
--

2.7.4

#5 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

In reply to Phil Yang

-----Original Message-----

Quoted 9 lines

Date: Wed, 19 Sep 2018 21:42:39 +0800
From: Phil Yang <[email protected]>
To: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected], [email protected]
Subject: [PATCH v2 2/3] kni: fix kni fifo synchronization
X-Mailer: git-send-email 2.7.4

+ Ferruh Yigit <[email protected]>

Quoted 42 lines

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")
---
 .../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(-)
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
index cfa9448..1fd713b 100644
@@ -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 */
lib/librte_kni/rte_kni_fifo.h +0 -0
index ac26a8c..f4171a1 100644
@@ -28,8 +28,13 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
 {

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 37

Quoted 10 lines
lib/librte_kni/rte_kni_fifo.h +6 -1
        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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 13 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
        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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 68

Quoted 12 lines
lib/librte_kni/rte_kni_fifo.h +4 -0
        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

Correct.

Quoted 5 lines
lib/librte_kni/rte_kni_fifo.h +1 -0
+
        for (i = 0; i < num; i++) {
                if (new_read == fifo_write)
                        break;

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 82

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
@@ -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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 96

Quoted 12 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
        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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 8 lines
lib/librte_kni/rte_kni_fifo.h +3 -1
+       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

#6 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 60 lines

-----Original Message-----

Quoted 9 lines

Date: Wed, 19 Sep 2018 21:42:39 +0800
From: Phil Yang <[email protected]>
To: [email protected]
CC: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v2 2/3] kni: fix kni fifo synchronization
X-Mailer: git-send-email 2.7.4

+ Ferruh Yigit <[email protected]>

Quoted 47 lines

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")
---
 .../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

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
@@ -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 */
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..f4171a1 100644

lib/librte_kni/rte_kni_fifo.h +0 -1
@@ -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;
Quoted 8 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
        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

Correct.

My apologies, did not follow your comment here. Do you want us to correct anything here? '#endif' is not appearing on the correct line in the email, but it shows up fine on the patch work.

Quoted 54 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void · line 35

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +0 -1
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
                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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 68

Quoted 12 lines
        return i;

}

lib/librte_kni/rte_kni_fifo.h +4 -0
@@ -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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data,

Quoted 5 lines
lib/librte_kni/rte_kni_fifo.h +1 -0
+
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 82

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
                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

Correct.

Quoted 3 lines
lib/librte_kni/rte_kni_fifo.h +0 -0
        return i;
 }
 
Quoted 14 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 95

Quoted 8 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
@@ -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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.
2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 6 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

I prefer to change this as well, I am open for suggestions.
Introducing two separate files would be too much for this library. A better way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

Quoted 10 lines
Quoted 10 lines
lib/librte_kni/rte_kni_fifo.h +3 -1
+       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

#7 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

-----Original Message-----

Quoted 80 lines

Date: Thu, 20 Sep 2018 15:20:53 +0000
From: Honnappa Nagarahalli <[email protected]>
To: Jerin Jacob <[email protected]>, "Phil Yang (Arm
Technology China)" <[email protected]>
CC: "[email protected]" <[email protected]>, nd <[email protected]>,
"[email protected]" <[email protected]>, "Gavin Hu (Arm Technology China)" <[email protected]>, "[email protected]" <[email protected]>
Subject: RE: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 60 lines

-----Original Message-----

Quoted 9 lines

Date: Wed, 19 Sep 2018 21:42:39 +0800
From: Phil Yang <[email protected]>
To: [email protected]
CC: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v2 2/3] kni: fix kni fifo synchronization
X-Mailer: git-send-email 2.7.4

+ Ferruh Yigit <[email protected]>

Quoted 47 lines

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")
---
 .../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

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
@@ -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 */
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..f4171a1 100644

lib/librte_kni/rte_kni_fifo.h +0 -1
@@ -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;
Quoted 8 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
        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

Correct.

Quoted 1 line

My apologies, did not follow your comment here. Do you want us to correct anything here? '#endif' is not appearing on the correct line in the email, but it shows up fine on the patch work.

No. What I meant is, code is correct.

Quoted 69 lines
Quoted 55 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void · line 35

Quoted 7 lines
lib/librte_kni/rte_kni_fifo.h +0 -1
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
                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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 68

Quoted 12 lines
        return i;

}

lib/librte_kni/rte_kni_fifo.h +4 -0
@@ -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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data,

Quoted 5 lines
lib/librte_kni/rte_kni_fifo.h +1 -0
+
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 82

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
                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

Correct.

Quoted 3 lines
lib/librte_kni/rte_kni_fifo.h +0 -0
        return i;
 }
 
Quoted 14 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 95

Quoted 8 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
@@ -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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Quoted 2 lines

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

Quoted 2 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

Quoted 10 lines
Quoted 7 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

I prefer to change this as well, I am open for suggestions.
Introducing two separate files would be too much for this library. A better way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
lib/librte_kni/rte_kni_fifo.h +3 -1
+       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

#8 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 149 lines
Quoted 71 lines
Quoted 62 lines

-----Original Message-----

Quoted 9 lines

Date: Wed, 19 Sep 2018 21:42:39 +0800
From: Phil Yang <[email protected]>
To: [email protected]
CC: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v2 2/3] kni: fix kni fifo synchronization
X-Mailer: git-send-email 2.7.4

+ Ferruh Yigit <[email protected]>

Quoted 49 lines

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")
---
 .../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

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
@@ -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 */
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..f4171a1 100644

lib/librte_kni/rte_kni_fifo.h +0 -1
@@ -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;
Quoted 8 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
        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

Correct.

Quoted 1 line

My apologies, did not follow your comment here. Do you want us to correct

anything here? '#endif' is not appearing on the correct line in the email, but it shows up fine on the patch work.

No. What I meant is, code is correct.

Quoted 72 lines
Quoted 72 lines
Quoted 8 lines
lib/librte_kni/rte_kni_fifo.h +0 -1
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 9 lines
                fifo->buffer[fifo_write] = data[i];
                fifo_write = new_write;
        }
lib/librte_kni/rte_kni_fifo.h +5 -0
+#ifdef RTE_USE_C11_MEM_MODEL
+       __atomic_store_n(&fifo->write, fifo_write,
+__ATOMIC_RELEASE); #else
+       rte_smp_wmb();
        fifo->write = fifo_write;
+#endif

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 68

Quoted 12 lines
        return i;

}

lib/librte_kni/rte_kni_fifo.h +4 -0
@@ -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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 74

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +1 -0
+
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 82

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
                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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 96

Quoted 12 lines
lib/librte_kni/rte_kni_fifo.h +6 -0
        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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Quoted 7 lines
Quoted 2 lines

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not optimal. 'LDAR' is a better option which is generated when C11 atomics are used.

Quoted 9 lines
Quoted 4 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 5 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of this function. I see the following usage:

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||                              
                        kni_fifo_count(kni->alloc_q) == 0) {                    
                /**                                                             
                 * If no free entry in tx_q or no entry in alloc_q,             
                 * drops skb and goes out.                                      
                 */                                                             
                goto drop;                                                      
        }

There is no retry here, the packet is dropped.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 7 lines
Quoted 2 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 4 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
lib/librte_kni/rte_kni_fifo.h +3 -2
+       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

#9 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

-----Original Message-----

Quoted 161 lines

Date: Fri, 21 Sep 2018 05:48:44 +0000
From: Honnappa Nagarahalli <[email protected]>
To: Jerin Jacob <[email protected]>
CC: "Phil Yang (Arm Technology China)" <[email protected]>, "[email protected]"
<[email protected]>, nd <[email protected]>, "[email protected]" <[email protected]>, "Gavin Hu (Arm Technology China)" <[email protected]>, "[email protected]" <[email protected]>
Subject: RE: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 151 lines
Quoted 71 lines
Quoted 62 lines

-----Original Message-----

Quoted 9 lines

Date: Wed, 19 Sep 2018 21:42:39 +0800
From: Phil Yang <[email protected]>
To: [email protected]
CC: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: [PATCH v2 2/3] kni: fix kni fifo synchronization
X-Mailer: git-send-email 2.7.4

+ Ferruh Yigit <[email protected]>

Quoted 49 lines

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")
---
 .../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

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
@@ -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 */
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..f4171a1 100644

lib/librte_kni/rte_kni_fifo.h +0 -1
@@ -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;
Quoted 8 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
        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

Correct.

Quoted 1 line

My apologies, did not follow your comment here. Do you want us to correct

anything here? '#endif' is not appearing on the correct line in the email, but it shows up fine on the patch work.

No. What I meant is, code is correct.

Quoted 74 lines
Quoted 57 lines
Quoted 8 lines
lib/librte_kni/rte_kni_fifo.h +0 -1
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 9 lines
                fifo->buffer[fifo_write] = data[i];
                fifo_write = new_write;
        }
lib/librte_kni/rte_kni_fifo.h +5 -0
+#ifdef RTE_USE_C11_MEM_MODEL
+       __atomic_store_n(&fifo->write, fifo_write,
+__ATOMIC_RELEASE); #else
+       rte_smp_wmb();
        fifo->write = fifo_write;
+#endif

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 68

Quoted 12 lines
        return i;

}

lib/librte_kni/rte_kni_fifo.h +4 -0
@@ -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

Correct.

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 74

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +1 -0
+
        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)

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 82

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
                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

Correct.

Quoted 3 lines
lib/librte_kni/rte_kni_fifo.h +0 -0
        return i;
 }
Quoted 15 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void · line 96

Quoted 9 lines
lib/librte_kni/rte_kni_fifo.h +6 -0
@@ -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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

Quoted 7 lines
Quoted 5 lines

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not optimal. 'LDAR' is a better option which is generated when C11 atomics are used.

Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ?

Quoted 29 lines
Quoted 10 lines
Quoted 5 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 5 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of this function. I see the following usage:

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||
                        kni_fifo_count(kni->alloc_q) == 0) {
                /**
                 * If no free entry in tx_q or no entry in alloc_q,
                 * drops skb and goes out.
                 */
                goto drop;
        }
Quoted 1 line

There is no retry here, the packet is dropped.

OK. Then pick an implementation which is an optimal this case. I think, then rte_smp_rmb() makes sense here as
a) no #ifdef clutter
b) it is optimal compared to 2 x LDAR

Quoted 37 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 7 lines
Quoted 2 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 4 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
lib/librte_kni/rte_kni_fifo.h +3 -2
+       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

#10 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 16 lines
Quoted 16 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 96

Quoted 10 lines
(quoted diff) +0 -0
@@ -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) {

lib/librte_kni/rte_kni_fifo.h +6 -0
+#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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Quoted 3 lines

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not optimal.

'LDAR' is a better option which is generated when C11 atomics are used.

Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ?

Good point. I am not sure which one is optimal, it needs to be measured. 'DMB ISHLD' orders 'all' earlier loads against 'all' later loads and stores. 'LDAR' orders the 'specific' load with 'all' later loads and stores.

Quoted 31 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 7 lines
Quoted 5 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of

this function. I see the following usage:

Quoted 12 lines

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||
                        kni_fifo_count(kni->alloc_q) == 0) {
                /**
                 * If no free entry in tx_q or no entry in alloc_q,
                 * drops skb and goes out.
                 */
                goto drop;
        }
Quoted 7 lines
Quoted 1 line

There is no retry here, the packet is dropped.

OK. Then pick an implementation which is an optimal this case. I think, then rte_smp_rmb() makes sense here as
a) no #ifdef clutter
b) it is optimal compared to 2 x LDAR

As I understand, one of the principals of using C11 model is to match the store releases and load acquires. IMO, combining C11 memory model with barrier based functions makes the code unreadable. I realized rte_smp_rmb() is required for x86 as well to prevent compiler reordering. We can add that in the non-C11 case. This way, we will have clean code for both the options (similar to rte_ring). So, if 'RTE_USE_C11_MEM_MODEL' is set to 'n', then the 'rte_smp_rmb' would be used.

We can look at handling the #ifdef clutter based on Ferruh's feedback.

Quoted 31 lines
Quoted 31 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 8 lines
Quoted 3 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 5 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+       return (fifo->len + fifo_write - fifo_read) &
+(fifo->len - 1); #else
        return (fifo->len + fifo->write - fifo->read) &

(fifo->len
- 1);

Requires rte_smp_rmb() for x86 to prevent compiler reordering.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+#endif
}
--
2.7.4

#11 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

+ Ola Liljedahl <[email protected]>

Thanks,
Phil Yang

Quoted 136 lines

-----Original Message-----
From: Honnappa Nagarahalli
Sent: Friday, September 21, 2018 2:37 PM
To: Jerin Jacob <[email protected]>
Cc: Phil Yang (Arm Technology China) <[email protected]>; [email protected]; nd <[email protected]>; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Subject: RE: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 16 lines
Quoted 16 lines

Review

Quoted 10 lines
(quoted diff) +0 -0
@@ -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) {

(quoted diff) +6 -0
+#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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Quoted 3 lines

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not optimal.

'LDAR' is a better option which is generated when C11 atomics are used.

Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ?

Good point. I am not sure which one is optimal, it needs to be measured. 'DMB ISHLD' orders 'all' earlier loads against 'all' later loads and stores. 'LDAR' orders the 'specific' load with 'all' later loads and stores.

Quoted 32 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 8 lines
Quoted 5 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of

this function. I see the following usage:

Quoted 12 lines

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||
                        kni_fifo_count(kni->alloc_q) == 0) {
                /**
                 * If no free entry in tx_q or no entry in alloc_q,
                 * drops skb and goes out.
                 */
                goto drop;
        }
Quoted 7 lines
Quoted 1 line

There is no retry here, the packet is dropped.

OK. Then pick an implementation which is an optimal this case. I think, then rte_smp_rmb() makes sense here as
a) no #ifdef clutter
b) it is optimal compared to 2 x LDAR

As I understand, one of the principals of using C11 model is to match the store releases and load acquires. IMO, combining C11 memory model with barrier based functions makes the code unreadable.
I realized rte_smp_rmb() is required for x86 as well to prevent compiler reordering. We can add that in the non-C11 case. This way, we will have clean code for both the options (similar to rte_ring).
So, if 'RTE_USE_C11_MEM_MODEL' is set to 'n', then the 'rte_smp_rmb' would be used.

We can look at handling the #ifdef clutter based on Ferruh's feedback.

Quoted 31 lines
Quoted 31 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 8 lines
Quoted 3 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 5 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+       return (fifo->len + fifo_write - fifo_read) &
+(fifo->len - 1); #else
        return (fifo->len + fifo->write - fifo->read) &

(fifo->len
- 1);

Requires rte_smp_rmb() for x86 to prevent compiler reordering.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+#endif
}
--
2.7.4

#12 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

In reply to Honnappa Nagarahalli

Hi Ferruh,
Just wanted to get your attention to this conversation. Appreciate your feedback on handling the #ifdef clutter.

Thank you,
Honnappa

Quoted 138 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Honnappa Nagarahalli
Sent: Friday, September 21, 2018 1:37 AM
To: Jerin Jacob <[email protected]>
Cc: Phil Yang (Arm Technology China) <[email protected]>; [email protected]; nd <[email protected]>; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 16 lines

Review

Quoted 10 lines
(quoted diff) +0 -0
@@ -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) {

(quoted diff) +6 -0
+#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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not

optimal.

Quoted 3 lines

'LDAR' is a better option which is generated when C11 atomics are used.

Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ?

Good point. I am not sure which one is optimal, it needs to be measured. 'DMB ISHLD' orders 'all' earlier loads against 'all' later loads and stores. 'LDAR' orders the 'specific' load with 'all' later loads and stores.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this

API.

Quoted 22 lines
Quoted 9 lines
Quoted 6 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of

this function. I see the following usage:

Quoted 12 lines

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||
                        kni_fifo_count(kni->alloc_q) == 0) {
                /**
                 * If no free entry in tx_q or no entry in alloc_q,
                 * drops skb and goes out.
                 */
                goto drop;
        }
Quoted 7 lines
Quoted 1 line

There is no retry here, the packet is dropped.

OK. Then pick an implementation which is an optimal this case. I think, then rte_smp_rmb() makes sense here as
a) no #ifdef clutter
b) it is optimal compared to 2 x LDAR

As I understand, one of the principals of using C11 model is to match the store releases and load acquires. IMO, combining C11 memory model with barrier based functions makes the code unreadable.
I realized rte_smp_rmb() is required for x86 as well to prevent compiler reordering. We can add that in the non-C11 case. This way, we will have clean code for both the options (similar to rte_ring).
So, if 'RTE_USE_C11_MEM_MODEL' is set to 'n', then the 'rte_smp_rmb' would be used.

We can look at handling the #ifdef clutter based on Ferruh's feedback.

Quoted 31 lines
Quoted 31 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 8 lines
Quoted 3 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 5 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+       return (fifo->len + fifo_write - fifo_read) &
+(fifo->len - 1); #else
        return (fifo->len + fifo->write - fifo->read) &

(fifo->len
- 1);

Requires rte_smp_rmb() for x86 to prevent compiler reordering.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+#endif
}
--
2.7.4

#13 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

In reply to Honnappa Nagarahalli
Quoted 70 lines · Honnappa Nagarahalli
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 16 lines
Quoted 16 lines

Review

Quoted 10 lines
(quoted diff) +0 -0
@@ -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) {

(quoted diff) +6 -0
+#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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Quoted 3 lines

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not optimal.

'LDAR' is a better option which is generated when C11 atomics are used.

Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ?

Good point. I am not sure which one is optimal, it needs to be measured. 'DMB ISHLD' orders 'all' earlier loads against 'all' later loads and stores. 'LDAR' orders the 'specific' load with 'all' later loads and stores.

Quoted 31 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 7 lines
Quoted 5 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of

this function. I see the following usage:

Quoted 12 lines

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||
                        kni_fifo_count(kni->alloc_q) == 0) {
                /**
                 * If no free entry in tx_q or no entry in alloc_q,
                 * drops skb and goes out.
                 */
                goto drop;
        }
Quoted 7 lines
Quoted 1 line

There is no retry here, the packet is dropped.

OK. Then pick an implementation which is an optimal this case. I think, then rte_smp_rmb() makes sense here as
a) no #ifdef clutter
b) it is optimal compared to 2 x LDAR

Quoted 5 lines

As I understand, one of the principals of using C11 model is to match the store releases and load acquires. IMO, combining C11 memory model with barrier based functions makes the code unreadable. I realized rte_smp_rmb() is required for x86 as well to prevent compiler reordering. We can add that in the non-C11 case. This way, we will have clean code for both the options (similar to rte_ring). So, if 'RTE_USE_C11_MEM_MODEL' is set to 'n', then the 'rte_smp_rmb' would be used.

We can look at handling the #ifdef clutter based on Ferruh's feedback.

Hi Honnappa, Jerin,

Sorry for delay, I missed that this is waiting my input.

+1 to remove #ifdef, but I don't think a separate file is required for this, specially when it will be duplication of same implementation, nothing arch specific implementation.
+1 Honnappa's suggestion to hide ifdef's behind APIs, plus those APIs can be reused later...

And +1 to split into two patches, one for fix to current code and one for c11 atomic implementation support.

I have some basic questions on the patch, will send in different thread.

Thanks,
ferruh

Quoted 44 lines
Quoted 32 lines
Quoted 32 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 8 lines
Quoted 3 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 5 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+       return (fifo->len + fifo_write - fifo_read) &
+(fifo->len - 1); #else
        return (fifo->len + fifo->write - fifo->read) &

(fifo->len
- 1);

Requires rte_smp_rmb() for x86 to prevent compiler reordering.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+#endif
}
--
2.7.4

#15 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

In reply to Phil Yang
Quoted 41 lines · On 9/19/2018 2:42 PM, [email protected] wrote:

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")
---
 .../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(-)
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
index cfa9448..1fd713b 100644
@@ -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 */
lib/librte_kni/rte_kni_fifo.h +0 -0
index ac26a8c..f4171a1 100644
@@ -28,8 +28,13 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
 {

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 37

Quoted 10 lines
lib/librte_kni/rte_kni_fifo.h +6 -1
 	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

Why atomic load preferred against "volatile", won't both end up accessing memory, is atomic load faster?

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 13 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
 	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

How atomic store guaranties "fifo->buffer[fifo_write] = data[i];" will wait "fifo->write = fifo_write;"? Is atomic store also behave as write memory barrier?

#14 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

In reply to Ferruh Yigit

Thanks for your comments.

I'll update it in the next version.

Quoted 107 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, September 26, 2018 7:43 PM
To: Honnappa Nagarahalli <[email protected]>; Jerin Jacob <[email protected]>
Cc: Phil Yang (Arm Technology China) <[email protected]>; [email protected]; nd <[email protected]>; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>
Subject: Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

Quoted 25 lines · Honnappa Nagarahalli
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 16 lines
Quoted 16 lines

Review kni_fifo_get(struct rte_kni_fifo *fifo, void · line 96

Quoted 10 lines
(quoted diff) +6 -0
@@ -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);

Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple rte_smp_rmb() would be enough here. Right?
or
Do we need __ATOMIC_ACQUIRE for fifo_write case?

Quoted 3 lines

We also had some amount of debate internally on this:
1) We do not want to use rte_smp_rmb() as we want to keep the memory

models separated (for ex: while using C11, use C11 everywhere). It is also not sufficient, please see 3) below.

But Nothing technically wrong in using rte_smp_rmb() here in terms functionally and code generated by the compiler.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not optimal.

'LDAR' is a better option which is generated when C11 atomics are used.

Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ?

Good point. I am not sure which one is optimal, it needs to be measured. 'DMB

ISHLD' orders 'all' earlier loads against 'all' later loads and stores. 'LDAR' orders the 'specific' load with 'all' later loads and stores.

Quoted 33 lines
Quoted 33 lines
Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

2) This API can get called from writer or reader, so both the loads have to be __ATOMIC_ACQUIRE
3) Other option is to use __ATOMIC_RELAXED. That would allow any

loads/stores around of this API to get reordered, especially since this is an inline function. This would put burden on the application to manage the ordering depending on its usage. It will also require the application to understand the implementation of this API.

Quoted 8 lines
Quoted 5 lines

__ATOMIC_RELAXED may be fine too for _count() case as it may not very important to get the exact count for the exact very moment, Application can retry.

I am in favor of performance effective implementation.

The requirement on the correctness of the count depends on the usage of

this function. I see the following usage:

Quoted 12 lines

In the file kni_net.c, function: kni_net_tx:

       if (kni_fifo_free_count(kni->tx_q) == 0 ||
                        kni_fifo_count(kni->alloc_q) == 0) {
                /**
                 * If no free entry in tx_q or no entry in alloc_q,
                 * drops skb and goes out.
                 */
                goto drop;
        }
Quoted 8 lines
Quoted 7 lines
Quoted 1 line

There is no retry here, the packet is dropped.

OK. Then pick an implementation which is an optimal this case. I think, then rte_smp_rmb() makes sense here as
a) no #ifdef clutter
b) it is optimal compared to 2 x LDAR

As I understand, one of the principals of using C11 model is to match the store

releases and load acquires. IMO, combining C11 memory model with barrier based functions makes the code unreadable.

Quoted 1 line

I realized rte_smp_rmb() is required for x86 as well to prevent compiler

reordering. We can add that in the non-C11 case. This way, we will have clean code for both the options (similar to rte_ring).

Quoted 1 line

So, if 'RTE_USE_C11_MEM_MODEL' is set to 'n', then the 'rte_smp_rmb' would

be used.

Quoted 2 lines

We can look at handling the #ifdef clutter based on Ferruh's feedback.

Hi Honnappa, Jerin,

Sorry for delay, I missed that this is waiting my input.

+1 to remove #ifdef, but I don't think a separate file is required for +this,
specially when it will be duplication of same implementation, nothing arch specific implementation.
+1 Honnappa's suggestion to hide ifdef's behind APIs, plus those APIs +can be
reused later...

Quoted 52 lines

And +1 to split into two patches, one for fix to current code and one for c11 atomic implementation support.

I have some basic questions on the patch, will send in different thread.

Thanks,
ferruh

Quoted 44 lines
Quoted 32 lines
Quoted 32 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

Other than that, I prefer to avoid ifdef clutter by introducing two separate file just like ring C11 implementation.

I don't have strong opinion on this this part, I let KNI MAINTAINER to decide on how to accommodate this change.

Quoted 8 lines
Quoted 3 lines

I prefer to change this as well, I am open for suggestions. Introducing two separate files would be too much for this library. A better

way would be to have something similar to 'smp_store_release' provided by the kernel. i.e. create #defines for loads/stores. Hide the clutter behind the #defines.

No Strong opinion on this, leaving to KNI Maintainer.

Will wait on this before re-spinning the patch

Quoted 5 lines

This patch needs to split by two,
a) Fixes for non C11 implementation(i.e new addition to rte_smp_wmb())
b) add support for C11 implementation.

Agree

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +2 -0
+       return (fifo->len + fifo_write - fifo_read) & (fifo->len
+- 1); #else
        return (fifo->len + fifo->write - fifo->read) &

(fifo->len
- 1);

Requires rte_smp_rmb() for x86 to prevent compiler reordering.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+#endif
}
--
2.7.4

Thanks
Phil

#16 lore raw

Re: [PATCH v2 2/3] kni: fix kni fifo synchronization

In reply to Ferruh Yigit
Quoted 50 lines · On 9/19/2018 2:42 PM, [email protected] wrote:
Quoted 48 lines

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")
---
 .../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

lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
@@ -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 */
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..f4171a1 100644

lib/librte_kni/rte_kni_fifo.h +1 -1
@@ -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
Quoted 9 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 37

Quoted 5 lines
lib/librte_kni/rte_kni_fifo.h +5 -0
+	unsigned fifo_read = __atomic_load_n(&fifo->read,
+						 __ATOMIC_ACQUIRE);
+#else
+	unsigned fifo_read = fifo->read;
+#endif

Why atomic load preferred against "volatile", won't both end up accessing memory, is atomic load faster?

My understanding is that with the introduction of C11 atomics, 'volatile' was recommended to be used for memory-mapped I/O locations only. Hence, we removed the 'volatile' for the variables while using C11 (keeping it does not hurt either). However, this also means that every load and store of the variable has to be done using the C11 atomics including relaxed loads.

The '__atomic_load_n' above is providing the memory ordering which the normal load will not provide. For relaxed memory ordered architectures like Arm, the ordering needs to be done explicitly to provide correct functionality.

Quoted 11 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void · line 39

Quoted 3 lines
lib/librte_kni/rte_kni_fifo.h +0 -0
 	for (i = 0; i < num; i++) {
 		new_write = (new_write + 1) & (fifo->len - 1); @@ -39,7

+44,12 @@

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 48

Quoted 6 lines
lib/librte_kni/rte_kni_fifo.h +0 -0
 kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
lib/librte_kni/rte_kni_fifo.h +2 -0
 		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

Quoted 7 lines

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 52

Quoted 3 lines
lib/librte_kni/rte_kni_fifo.h +2 -0
+	rte_smp_wmb();
 	fifo->write = fifo_write;
+#endif

How atomic store guaranties "fifo->buffer[fifo_write] = data[i];" will wait "fifo->write = fifo_write;"? Is atomic store also behave as write memory barrier?

__atomic_store_n with __ATOMIC_RELEASE will prevent memory reordering of fifo->write with any preceding loads or stores. This is called one-way barrier providing load-store and store-store fence [1].

[1] https://preshing.com/20120913/acquire-and-release-semantics/

#19 lore raw

PATCH v3 1/4 config: use one single config option for C11 memory model

In reply to Phil Yang

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

---
 config/arm/meson.build                       | 2 +-
 config/common_armv8a_linuxapp                | 2 +-
 config/common_base                           | 2 +-
 config/defconfig_arm64-thunderx-linuxapp-gcc | 2 +-
 lib/librte_ring/rte_ring.h                   | 4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
config/arm/meson.build +1 -1
index 94cca49..4b23b39 100644
@@ -53,7 +53,7 @@ flags_cavium = [
 	['RTE_MAX_NUMA_NODES', 2],
 	['RTE_MAX_LCORE', 96],
 	['RTE_MAX_VFIO_GROUPS', 128],
-	['RTE_RING_USE_C11_MEM_MODEL', false]]
+	['RTE_USE_C11_MEM_MODEL', false]]
 flags_dpaa = [
 	['RTE_MACHINE', '"dpaa"'],
 	['RTE_CACHE_LINE_SIZE', 64],
config/common_armv8a_linuxapp +1 -1
index 111c005..54e6987 100644
@@ -29,7 +29,7 @@ CONFIG_RTE_ARCH_ARM64_MEMCPY=n
 #CONFIG_RTE_ARM64_MEMCPY_ALIGN_MASK=0xF
 #CONFIG_RTE_ARM64_MEMCPY_STRICT_ALIGN=n
 
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+CONFIG_RTE_USE_C11_MEM_MODEL=y
 
 CONFIG_RTE_LIBRTE_FM10K_PMD=n
 CONFIG_RTE_LIBRTE_SFC_EFX_PMD=n
config/common_base +1 -1
index 155c7d4..ccd2670 100644
@@ -661,7 +661,7 @@ CONFIG_RTE_LIBRTE_PMD_IFPGA_RAWDEV=y
 # Compile librte_ring
 #
 CONFIG_RTE_LIBRTE_RING=y
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile librte_mempool
config/defconfig_arm64-thunderx-linuxapp-gcc +1 -1
index 2bed66c..f11e758 100644
@@ -10,7 +10,7 @@ CONFIG_RTE_CACHE_LINE_SIZE=128
 CONFIG_RTE_MAX_NUMA_NODES=2
 CONFIG_RTE_MAX_LCORE=96
 CONFIG_RTE_MAX_VFIO_GROUPS=128
-CONFIG_RTE_RING_USE_C11_MEM_MODEL=n
+CONFIG_RTE_USE_C11_MEM_MODEL=n
 
 #
 # Compile PMD for octeontx sso event device
lib/librte_ring/rte_ring.h +2 -2
index 7a731d0..af5444a 100644
@@ -303,11 +303,11 @@ void rte_ring_dump(FILE *f, const struct rte_ring *r);
  * There are 2 choices for the users
  * 1.use rmb() memory barrier
  * 2.use one-direcion load_acquire/store_release barrier,defined by
- * CONFIG_RTE_RING_USE_C11_MEM_MODEL=y
+ * CONFIG_RTE_USE_C11_MEM_MODEL=y
  * It depends on performance test results.
  * By default, move common functions to rte_ring_generic.h
  */
-#ifdef RTE_RING_USE_C11_MEM_MODEL
+#ifdef RTE_USE_C11_MEM_MODEL
 #include "rte_ring_c11_mem.h"
 #else
 #include "rte_ring_generic.h"
Signature · 1 line
2.7.4
#20 lore raw

PATCH v3 2/4 kni: fix kni fifo synchronization

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 memory barriers to make sure the values being synced before updating fifo_write and fifo_read.

Fixes 3fc5ca2 ("kni: initial import")
---
 lib/librte_kni/rte_kni_fifo.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
lib/librte_kni/rte_kni_fifo.h +10 -2
index ac26a8c..70ac14e 100644
@@ -28,8 +28,9 @@ 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;
+	rte_smp_rmb();
+	unsigned fifo_read = fifo->read;
 
 	for (i = 0; i < num; i++) {
 		new_write = (new_write + 1) & (fifo->len - 1);
@@ -39,6 +40,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
 		fifo->buffer[fifo_write] = data[i];
 		fifo_write = new_write;
 	}
+	rte_smp_wmb();
 	fifo->write = fifo_write;
 	return i;
 }
@@ -51,7 +53,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
 {
 	unsigned i = 0;
 	unsigned new_read = fifo->read;
+	rte_smp_rmb();
 	unsigned fifo_write = fifo->write;
+
 	for (i = 0; i < num; i++) {
 		if (new_read == fifo_write)
 			break;
@@ -59,6 +63,7 @@ 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);
 	}
+	rte_smp_rmb();
 	fifo->read = new_read;
 	return i;
 }
@@ -69,5 +74,8 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
 static inline uint32_t
 kni_fifo_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
+	unsigned fifo_write = fifo->write;
+	rte_smp_rmb();
+	unsigned fifo_read = fifo->read;
+	return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1);
 }
Signature · 1 line
2.7.4
#25 lore raw

PATCH v3 3/4 kni: fix kni kernel fifo synchronization

In reply to Phil Yang

Adding memory barrier to make sure the values being synced before updating fifo_write in kni_fifo_put and fifo_read in kni_fifo_get.

Fixes 3fc5ca2 ("kni: initial import")
---
 kernel/linux/kni/kni_fifo.h                              | 16 ++++++++++------
 .../linuxapp/eal/include/exec-env/rte_kni_common.h       |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)
kernel/linux/kni/kni_fifo.h +10 -6
index 9a4762d..2cb3a4a 100644
@@ -16,7 +16,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 {
 	uint32_t i = 0;
 	uint32_t fifo_write = fifo->write;
-	uint32_t fifo_read = fifo->read;
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
 	uint32_t new_write = fifo_write;
 
 	for (i = 0; i < num; i++) {
@@ -27,7 +27,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 		fifo->buffer[fifo_write] = data[i];
 		fifo_write = new_write;
 	}
-	fifo->write = fifo_write;
+	smp_store_release(&fifo->write, fifo_write);
 
 	return i;
 }
@@ -40,7 +40,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 {
 	uint32_t i = 0;
 	uint32_t new_read = fifo->read;
-	uint32_t fifo_write = fifo->write;
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
 
 	for (i = 0; i < num; i++) {
 		if (new_read == fifo_write)
@@ -49,7 +49,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 		data[i] = fifo->buffer[new_read];
 		new_read = (new_read + 1) & (fifo->len - 1);
 	}
-	fifo->read = new_read;
+	smp_store_release(&fifo->read, new_read);
 
 	return i;
 }
@@ -60,7 +60,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
 static inline uint32_t
 kni_fifo_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
+	return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1);
 }
 
 /**
@@ -69,7 +71,9 @@ kni_fifo_count(struct rte_kni_fifo *fifo)
 static inline uint32_t
 kni_fifo_free_count(struct rte_kni_fifo *fifo)
 {
-	return (fifo->read - fifo->write - 1) & (fifo->len - 1);
+	uint32_t fifo_write = smp_load_acquire(&fifo->write);
+	uint32_t fifo_read = smp_load_acquire(&fifo->read);
+	return (fifo_read - fifo_write - 1) & (fifo->len - 1);
 }
 
 #endif /* _KNI_FIFO_H_ */
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +1 -0
index cfa9448..58e8533 100644
@@ -8,6 +8,7 @@
 
 #ifdef __KERNEL__
 #include <linux/if.h>
+#include <asm/barrier.h>
 #define RTE_STD_C11
 #else
 #include <rte_common.h>
Signature · 1 line
2.7.4
#26 lore raw

PATCH v3 4/4 kni: introduce c11 atomic into kni fifo synchronization

In reply to Phil Yang

Syncing the values by adding c11 atomic memory barriers to make sure the values being synced before updating fifo_write and fifo_read.

---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h |  5 +++
 lib/librte_kni/rte_kni_fifo.h                      | 47 +++++++++++++++++-----
 2 files changed, 41 insertions(+), 11 deletions(-)
lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +5 -0
index 58e8533..5afa087 100644
@@ -55,8 +55,13 @@ struct rte_kni_request {
  * Writing should never overwrite the read position
  */
 struct rte_kni_fifo {
+#ifdef RTE_USE_C11_MEM_MODEL
+	unsigned write;              /**< Next position to be written*/
+	unsigned read;               /**< Next position to be read */
+#else
 	volatile unsigned write;     /**< Next position to be written*/
 	volatile 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 */
lib/librte_kni/rte_kni_fifo.h +36 -11

82 lines not on this page · raw message

Signature · 1 line
2.7.4
#21 lore raw

Re: [PATCH v3 2/4] kni: fix kni fifo synchronization

In reply to Phil Yang

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) · line 34

Quoted 13 lines · On Mon, 8 Oct 2018 17:11:44 +0800 Phil Yang <[email protected]> wrote:
lib/librte_kni/rte_kni_fifo.h +2 -1
index ac26a8c..70ac14e 100644
@@ -28,8 +28,9 @@ 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;
+	rte_smp_rmb();
+	unsigned fifo_read = fifo->read;
 

The patch makes sense, but this function should be changed to match kernel code style. That means no declarations after initial block, and use 'unsigned int' rather than 'unsigned'

Also. why is i initialized? Best practice now is to not do gratitious initialization since it defeats compiler checks for accidental use of uninitialized variables.

What makes sense is something like:

kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)

{
	unsigned int i, fifo_read, fifo_write, new_write;

	fifo_write = fifo->write;
	new_write = fifo_write;
	rte_smb_rmb();
	fifo_read = fifo->read;

Sorry, blaming you for issues which are inherited from original KNI code. Maybe someone should run kernel checkpatch (not DPDK checkpatch) on it and fix those.

#22 lore raw

Re: [PATCH v3 2/4] kni: fix kni fifo synchronization

Hi Hemminger,

Quoted 40 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 9, 2018 5:53 AM
To: Phil Yang (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ola Liljedahl <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v3 2/4] kni: fix kni fifo synchronization

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void **data, · line 34

Quoted 13 lines · On Mon, 8 Oct 2018 17:11:44 +0800 Phil Yang <[email protected]> wrote:
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..70ac14e 100644

lib/librte_kni/rte_kni_fifo.h +2 -1
@@ -28,8 +28,9 @@ 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;
+rte_smp_rmb();
+unsigned fifo_read = fifo->read;
 

The patch makes sense, but this function should be changed to match kernel code style.
That means no declarations after initial block, and use 'unsigned int' rather than 'unsigned'

Also. why is i initialized? Best practice now is to not do gratitious initialization since it defeats compiler checks for accidental use of uninitialized variables.

What makes sense is something like:

kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) { unsigned int i, fifo_read, fifo_write, new_write;

Quoted 8 lines

fifo_write = fifo->write;
new_write = fifo_write;
rte_smb_rmb();
fifo_read = fifo->read;

Sorry, blaming you for issues which are inherited from original KNI code. Maybe someone should run kernel checkpatch (not DPDK checkpatch) on it and fix those.

Thanks for your comment.

I think I can submit a new separate patch to fix this historical issue.

Thanks,
Phil Yang
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#23 lore raw

Re: [PATCH v3 2/4] kni: fix kni fifo synchronization

Quoted 65 lines

-----Original Message-----
From: Phil Yang (Arm Technology China)
Sent: Wednesday, October 10, 2018 5:59 PM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ola Liljedahl <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH v3 2/4] kni: fix kni fifo synchronization

Hi Hemminger,

Quoted 33 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 9, 2018 5:53 AM
To: Phil Yang (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ola Liljedahl <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v3 2/4] kni: fix kni fifo synchronization

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void · line 34

Quoted 13 lines · On Mon, 8 Oct 2018 17:11:44 +0800 Phil Yang <[email protected]> wrote:
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..70ac14e 100644

lib/librte_kni/rte_kni_fifo.h +2 -1
@@ -28,8 +28,9 @@ 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;
+rte_smp_rmb();
+unsigned fifo_read = fifo->read;
 

The patch makes sense, but this function should be changed to match kernel code style.
That means no declarations after initial block, and use 'unsigned int' rather than 'unsigned'

Quoted 2 lines

Also. why is i initialized? Best practice now is to not do gratitious initialization since it defeats compiler checks for accidental use of

uninitialized variables.

Quoted 6 lines

What makes sense is something like:

kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) { unsigned int i, fifo_read, fifo_write, new_write;

Quoted 8 lines

fifo_write = fifo->write;
new_write = fifo_write;
rte_smb_rmb();
fifo_read = fifo->read;

Sorry, blaming you for issues which are inherited from original KNI code. Maybe someone should run kernel checkpatch (not DPDK checkpatch) on it and fix those.

Quoted 6 lines

Thanks for your comment.

I think I can submit a new separate patch to fix this historical issue.

Thanks,
Phil Yang

I advised a separate patch to make this patch to the point and clean.

-Gavin
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#24 lore raw

Re: [PATCH v3 2/4] kni: fix kni fifo synchronization

Quoted 65 lines · Gavin Hu (Arm Technology China)
Quoted 65 lines

-----Original Message-----
From: Phil Yang (Arm Technology China)
Sent: Wednesday, October 10, 2018 5:59 PM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ola Liljedahl <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH v3 2/4] kni: fix kni fifo synchronization

Hi Hemminger,

Quoted 33 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 9, 2018 5:53 AM
To: Phil Yang (Arm Technology China) <[email protected]>
Cc: [email protected]; [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ola Liljedahl <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v3 2/4] kni: fix kni fifo synchronization

lib/librte_kni/rte_kni_fifo.h kni_fifo_put(struct rte_kni_fifo *fifo, void · line 34

Quoted 13 lines · On Mon, 8 Oct 2018 17:11:44 +0800 Phil Yang <[email protected]> wrote:
(quoted diff) +0 -0

b/lib/librte_kni/rte_kni_fifo.h index ac26a8c..70ac14e 100644

lib/librte_kni/rte_kni_fifo.h +2 -1
@@ -28,8 +28,9 @@ 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;
+rte_smp_rmb();
+unsigned fifo_read = fifo->read;
 

The patch makes sense, but this function should be changed to match kernel code style.
That means no declarations after initial block, and use 'unsigned int' rather than 'unsigned'

Quoted 2 lines

Also. why is i initialized? Best practice now is to not do gratitious initialization since it defeats compiler checks for accidental use of

uninitialized variables.

Quoted 14 lines

What makes sense is something like:

kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num) { unsigned int i, fifo_read, fifo_write, new_write;

fifo_write = fifo->write;
new_write = fifo_write;
rte_smb_rmb();
fifo_read = fifo->read;

Sorry, blaming you for issues which are inherited from original KNI code. Maybe someone should run kernel checkpatch (not DPDK checkpatch) on it and fix those.

Quoted 8 lines
Quoted 6 lines

Thanks for your comment.

I think I can submit a new separate patch to fix this historical issue.

Thanks,
Phil Yang

I advised a separate patch to make this patch to the point and clean.

+1 to separate patch for clean up.

Reviewed-by on v3 1/4
#27 lore raw
In reply to Phil Yang
Quoted 8 lines · On 10/8/2018 10:11 AM, [email protected] wrote:

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

For series,

Are you planning to send a new version to include the clean up, or get this one first an do the cleanup on top of it? I think both are OK but please let us know. And if there will be a new version with cleanup, please keep the review tag.

#28 lore raw
Quoted 20 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, October 10, 2018 10:48 PM
To: Phil Yang (Arm Technology China) <[email protected]>; [email protected]
Cc: [email protected]; Gavin Hu (Arm Technology China) <[email protected]>; Honnappa Nagarahalli <[email protected]>; Ola Liljedahl <[email protected]>
Subject: Re: [PATCH v3 1/4] config: use one single config option for C11 memory model

Quoted 8 lines · On 10/8/2018 10:11 AM, [email protected] wrote:

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

Quoted 6 lines

For series,

Are you planning to send a new version to include the clean up, or get this one first an do the cleanup on top of it? I think both are OK but please let us know. And if there will be a new version with cleanup, please keep the review tag.

Hi Ferruh,

Thanks for your remind.

I think it is better to merge this series first. Because the cleanup patch won't block any functionality. I will do it on top of this series.

Thanks
Phil Yang
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#29 lore raw
In reply to Ferruh Yigit

10/10/2018 16:48, Ferruh Yigit:

Quoted 5 lines · On 10/8/2018 10:11 AM, [email protected] wrote:
Quoted 4 lines

Keep only single config option RTE_USE_C11_MEM_MODEL for C11 memory model, so all modules can leverage C11 atomic extension by enable this option.

Quoted 7 lines
Quoted 4 lines

For series,

Series applied, thanks