Skip to contentSkip to conversation

ethdev: make rte flow API thread safe

PATCH Superseded Suanming Mou 10 participants 40 messages Sep 27, 2020 – Oct 15, 2020 Network drivers

lore
Share & tools
lore
#0 lore raw

cover ethdev: make rte flow API thread safe

Currently, the rte flow functions are not defined as thread safety. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte flow operation functions.

And the restriction of thread safety not guaranteed for the rte flow functions also limits the applications' expectation.

This feature is going to change the rte flow functions to be thread safety. As different PMDs have different flow operations, some may support thread safety already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte flow level functions will skip the thread safe helper lock for these PMDs. Again the rte flow level thread safe lock only works when PMD operation functions are not thread safety.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the perfer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. If no lock contention with the added rte flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Suanming Mou (2):
eal/windows: add pthread mutex lock
ethdev: make rte flow API thread safe

 doc/guides/prog_guide/rte_flow.rst       |  7 ++-
 drivers/net/mlx5/linux/mlx5_os.c         |  2 +
 lib/librte_eal/windows/include/pthread.h | 46 +++++++++++++++++
 lib/librte_ethdev/rte_ethdev.c           |  2 +
 lib/librte_ethdev/rte_ethdev.h           |  2 +
 lib/librte_ethdev/rte_ethdev_core.h      |  4 ++
 lib/librte_ethdev/rte_flow.c             | 84 ++++++++++++++++++++++++--------
 7 files changed, 124 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 eal/windows: add pthread mutex lock

Add pthread mutex lock as it is needed for the thread safe rte flow functions.

---
 lib/librte_eal/windows/include/pthread.h | 46 ++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
lib/librte_eal/windows/include/pthread.h +46 -0
index 99013dc..4e2e0b3 100644
@@ -28,6 +28,10 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef HANDLE pthread_mutex_t;
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +143,48 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	*mutex = CreateMutex(NULL, FALSE, NULL);
+	if (*mutex == NULL) {
+		RTE_LOG_WIN32_ERR("CreateMutex()");
+		return -1;
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	if (WaitForSingleObject(*mutex, INFINITE) != WAIT_OBJECT_0) {
+		RTE_LOG_WIN32_ERR("WaitForSingleObject()");
+		return -1;
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	if (!ReleaseMutex(*mutex)) {
+		RTE_LOG_WIN32_ERR("ReleaseMutex()");
+		return -1;
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	if (!CloseHandle(*mutex)) {
+		RTE_LOG_WIN32_ERR("CloseHandle()");
+		return -1;
+	}
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] eal/windows: add pthread mutex lock

Hi Suanming,

There's a remark in patch 2/2 and cover letter:

Quoted 4 lines

If no lock contention
with the added rte flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Is this property important? To get the described behavior on Windows, you should've used CRITICAL_SECTION (preferably wrapped in a struct). Mutexes are kernel objects on Windows and always require syscalls. Otherwise, if mutexes are sufficient, see a comment inline.

Quoted 35 lines

Add pthread mutex lock as it is needed for the thread safe rte flow functions.

---
 lib/librte_eal/windows/include/pthread.h | 46 ++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
lib/librte_eal/windows/include/pthread.h +12 -0
index 99013dc..4e2e0b3 100644
@@ -28,6 +28,10 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef HANDLE pthread_mutex_t;
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +143,48 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	*mutex = CreateMutex(NULL, FALSE, NULL);
+	if (*mutex == NULL) {
+		RTE_LOG_WIN32_ERR("CreateMutex()");
+		return -1;

lib/librte_eal/windows/include/pthread.h line 163

Quoted 10 lines
lib/librte_eal/windows/include/pthread.h +10 -0
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	if (WaitForSingleObject(*mutex, INFINITE) != WAIT_OBJECT_0) {
+		RTE_LOG_WIN32_ERR("WaitForSingleObject()");
+		return -1;

A relevant error code must be returned according to POSIX. Searching the code for pthread_mutex_lock() calls, I can see that hinic PMD checks for EOWNERDEAD (corresponding to WAIT_OBJECT_ABANDONED in Windows) and failsafe PMD supplies return value of pthread_mutex_unlock() to strerror(), i.e. it should be an errno. Same applies to other functions.

Quoted 27 lines
lib/librte_eal/windows/include/pthread.h +24 -0
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	if (!ReleaseMutex(*mutex)) {
+		RTE_LOG_WIN32_ERR("ReleaseMutex()");
+		return -1;
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	if (!CloseHandle(*mutex)) {
+		RTE_LOG_WIN32_ERR("CloseHandle()");
+		return -1;
+	}
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
#3 lore raw

Re: [dpdk-dev] [PATCH 1/2] eal/windows: add pthread mutex lock

Hi Dmitry,

Quoted 18 lines

-----Original Message-----
From: Dmitry Kozlyuk <[email protected]>
Sent: Sunday, September 27, 2020 11:57 PM
To: Suanming Mou <[email protected]>
Cc: Narcisa Ana Maria Vasile <[email protected]>; Dmitry Malloy <[email protected]>; Pallavi Kadam <[email protected]>; [email protected]
Subject: Re: [PATCH 1/2] eal/windows: add pthread mutex lock

Hi Suanming,

There's a remark in patch 2/2 and cover letter:

Quoted 4 lines

If no lock contention
with the added rte flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Quoted 4 lines

Is this property important? To get the described behavior on Windows, you should've used CRITICAL_SECTION (preferably wrapped in a struct). Mutexes are kernel objects on Windows and always require syscalls. Otherwise, if mutexes are sufficient, see a comment inline.

The description was valid only for the standard posix pthread functions. Good to know that there are similar functions on Windows.
I will prefer to change it to CRICTIAL_SECTION functions, in this case the pthread wrap functions on Windows will also have less impact with the current applications. Thank you very much for the information.

Quoted 44 lines
Quoted 44 lines

Add pthread mutex lock as it is needed for the thread safe rte flow functions.

---
 lib/librte_eal/windows/include/pthread.h | 46
++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
lib/librte_eal/windows/include/pthread.h +19 -0
index 99013dc..4e2e0b3 100644
@@ -28,6 +28,10 @@
 /* defining pthread_attr_t type on Windows since there is no in
 Microsoft libc*/  typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef HANDLE pthread_mutex_t;
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \ @@ -139,6
+143,48 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr) {
+	*mutex = CreateMutex(NULL, FALSE, NULL);
+	if (*mutex == NULL) {
+		RTE_LOG_WIN32_ERR("CreateMutex()");
+		return -1;
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex) {
+	if (WaitForSingleObject(*mutex, INFINITE) != WAIT_OBJECT_0) {
Quoted 8 lines

lib/librte_eal/windows/include/pthread.h

Quoted 2 lines
lib/librte_eal/windows/include/pthread.h +2 -0
+		RTE_LOG_WIN32_ERR("WaitForSingleObject()");
+		return -1;

A relevant error code must be returned according to POSIX. Searching the code for pthread_mutex_lock() calls, I can see that hinic PMD checks for EOWNERDEAD (corresponding to WAIT_OBJECT_ABANDONED in Windows) and failsafe PMD supplies return value of pthread_mutex_unlock() to strerror(), i.e. it should be an errno. Same applies to other functions.

These PMDs should not be valid on Windows now, or the build will be failed as no pthread_mutex on Windows. I guess we will have a much general solution with the posix APIs support on Windows?
Now the wrap functions solution is much like a WA to fix the build.

Quoted 26 lines
Quoted 26 lines
lib/librte_eal/windows/include/pthread.h +22 -0
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex) {
+	if (!ReleaseMutex(*mutex)) {
+		RTE_LOG_WIN32_ERR("ReleaseMutex()");
+		return -1;
+	}
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex) {
+	if (!CloseHandle(*mutex)) {
+		RTE_LOG_WIN32_ERR("CloseHandle()");
+		return -1;
+	}
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
#4 lore raw

PATCH 2/2 ethdev: make rte flow API thread safe

In reply to Suanming Mou

Currently, the rte flow functions are not defined as thread safety. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte flow operation functions.

And the restriction of thread safety not guaranteed for the rte flow functions also limits the applications' expectation.

This feature is going to change the rte flow functions to be thread safety. As different PMDs have different flow operations, some may support thread safety already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte flow level functions will skip the thread safe helper lock for these PMDs. Again the rte flow level thread safe lock only works when PMD operation functions are not thread safety.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the perfer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. If no lock contention with the added rte flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---
 doc/guides/prog_guide/rte_flow.rst  |  7 ++--
 drivers/net/mlx5/linux/mlx5_os.c    |  2 +
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---------
 6 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +3 -4
index 119b128..6f7997a 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3101,6 +3097,9 @@ This interface additionally defines the following helper function:
 - ``rte_flow_ops_get()``: get generic flow operations structure from a
   port.
 
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte flow
+level functions will do it by mutex.
+
 More will be added over time.
 
 Device compatibility
drivers/net/mlx5/linux/mlx5_os.c +2 -0
index 2a4beb0..daefb7d 100644
@@ -1351,6 +1351,8 @@
 			goto error;
 		}
 	}
+	if (priv->config.dv_flow_en)
+		eth_dev->data->dev_flags = RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
 	return eth_dev;
 error:
 	if (priv) {
lib/librte_ethdev/rte_ethdev.c +2 -0
index dfe5c1b..d6fd17e 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -562,6 +563,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->fts_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index 645a186..61bd09f 100644
@@ -1669,6 +1669,8 @@ struct rte_eth_dev_owner {
 #define RTE_ETH_DEV_REPRESENTOR  0x0010
 /** Device does not support MAC change after started */
 #define RTE_ETH_DEV_NOLIVE_MAC_ADDR  0x0020
+/** Device PMD supports thread safety flow operation */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0040
 
 /**
  * Iterates over valid ethdev ports owned by a specific owner.
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +65 -19

160 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

Hi Suanming,

Small comments,
PSB,

Best,
Ori

Quoted 7 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Sunday, September 27, 2020 11:20 AM
Cc: [email protected]
Subject: [PATCH 2/2] ethdev: make rte flow API thread safe

Currently, the rte flow functions are not defined as thread safety.

For a given port. (between ports they are thread safe)

Quoted 7 lines

DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte flow operation functions.

Quoted 5 lines

And the restriction of thread safety not guaranteed for the rte flow functions also limits the applications' expectation.

This feature is going to change the rte flow functions to be thread safety. As different PMDs have different flow operations, some may

Safety => safe I think this is true also to other places in this patch.

Quoted 11 lines

support thread safety already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte flow level functions will skip the thread safe helper lock for these PMDs. Again the rte flow level thread safe lock only works when PMD operation functions are not thread safety.

safe

Quoted 42 lines

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the perfer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. If no lock contention with the added rte flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---
 doc/guides/prog_guide/rte_flow.rst  |  7 ++--
 drivers/net/mlx5/linux/mlx5_os.c    |  2 +
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---------
 6 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +0 -4
index 119b128..6f7997a 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3101,6 +3097,9 @@ This interface additionally defines the following

helper function:
- ``rte_flow_ops_get()``: get generic flow operations structure from a port.

doc/guides/prog_guide/rte_flow.rst This interface additionally defines the following helper function: · line 3102

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +3 -0
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte flow
+level functions will do it by mutex.
+

I think you should add which flag the app should test to see if the PMD support thread safe.

Quoted 9 lines

More will be added over time.

Device compatibility

drivers/net/mlx5/linux/mlx5_os.c +0 -0
index 2a4beb0..daefb7d 100644

drivers/net/mlx5/linux/mlx5_os.c line 1357

Quoted 7 lines
drivers/net/mlx5/linux/mlx5_os.c +2 -0
@@ -1351,6 +1351,8 @@
 			goto error;
 		}
 	}
+	if (priv->config.dv_flow_en)
+		eth_dev->data->dev_flags =
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
 	return eth_dev;

I don't think this code is relevant for this patch. I also think you are missing the | when assigning the value.

Quoted 63 lines
drivers/net/mlx5/linux/mlx5_os.c +0 -0
 error:
drivers/net/mlx5/linux/mlx5_os.c +0 -0
 	if (priv) {
lib/librte_ethdev/rte_ethdev.c +2 -0
index dfe5c1b..d6fd17e 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -562,6 +563,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->fts_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index 645a186..61bd09f 100644
@@ -1669,6 +1669,8 @@ struct rte_eth_dev_owner {
 #define RTE_ETH_DEV_REPRESENTOR  0x0010
 /** Device does not support MAC change after started */
 #define RTE_ETH_DEV_NOLIVE_MAC_ADDR  0x0020
+/** Device PMD supports thread safety flow operation */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0040
 
 /**
  * Iterates over valid ethdev ports owned by a specific owner.
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +0 -0
index f8fdd68..ca80b12 100644

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 216

Quoted 10 lines
lib/librte_ethdev/rte_flow.c +6 -0
@@ -207,6 +207,20 @@ struct rte_flow_desc_data {
 	return -rte_errno;
 }
 
+static void
+flow_lock(struct rte_eth_dev *dev)
+{
+	if (!(dev->data->dev_flags &
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+		pthread_mutex_lock(&dev->data->fts_mutex);
+}

Why not inline function?
Also I don't think you should check the PMD support in this function when this function is called it should lock.

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 222

Quoted 8 lines
lib/librte_ethdev/rte_flow.c +7 -0
+
+static void
+flow_unlock(struct rte_eth_dev *dev)
+{
+	if (!(dev->data->dev_flags &
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+		pthread_mutex_unlock(&dev->data->fts_mutex);
+}

Same comments as above.

Quoted 154 lines
lib/librte_ethdev/rte_flow.c +1 -0
+
 static int

flow_err(uint16_t port_id, int ret, struct rte_flow_error *error) {

lib/librte_ethdev/rte_flow.c +51 -20
@@ -346,12 +360,16 @@ struct rte_flow_desc_data {
 {
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->validate))
-		return flow_err(port_id, ops->validate(dev, attr, pattern,
-						       actions, error), error);
+	if (likely(!!ops->validate)) {
+		flow_lock(dev);
+		ret = ops->validate(dev, attr, pattern, actions, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -372,7 +390,9 @@ struct rte_flow *
 	if (unlikely(!ops))
 		return NULL;
 	if (likely(!!ops->create)) {
+		flow_lock(dev);
 		flow = ops->create(dev, attr, pattern, actions, error);
+		flow_unlock(dev);
 		if (flow == NULL)
 			flow_err(port_id, -rte_errno, error);
 		return flow;
@@ -390,12 +410,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->destroy))
-		return flow_err(port_id, ops->destroy(dev, flow, error),
-				error);
+	if (likely(!!ops->destroy)) {
+		flow_lock(dev);
+		ret = ops->destroy(dev, flow, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -408,11 +432,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->flush))
-		return flow_err(port_id, ops->flush(dev, error), error);
+	if (likely(!!ops->flush)) {
+		flow_lock(dev);
+		ret = ops->flush(dev, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -428,12 +457,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (!ops)
 		return -rte_errno;
-	if (likely(!!ops->query))
-		return flow_err(port_id, ops->query(dev, flow, action, data,
-						    error), error);
+	if (likely(!!ops->query)) {
+		flow_lock(dev);
+		ret = ops->query(dev, flow, action, data, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -447,11 +480,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (!ops)
 		return -rte_errno;
-	if (likely(!!ops->isolate))
-		return flow_err(port_id, ops->isolate(dev, set, error), error);
+	if (likely(!!ops->isolate)) {
+		flow_lock(dev);
+		ret = ops->isolate(dev, set, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -1224,12 +1262,16 @@ enum rte_flow_conv_item_spec_type {
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->dev_dump))
-		return flow_err(port_id, ops->dev_dump(dev, file, error),
-				error);
+	if (likely(!!ops->dev_dump)) {
+		flow_lock(dev);
+		ret = ops->dev_dump(dev, file, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -1241,12 +1283,16 @@ enum rte_flow_conv_item_spec_type {
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->get_aged_flows))
-		return flow_err(port_id, ops->get_aged_flows(dev, contexts,
-				nb_contexts, error), error);
+	if (likely(!!ops->get_aged_flows)) {
+		flow_lock(dev);
+		ret = ops->get_aged_flows(dev, contexts, nb_contexts, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOTSUP,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOTSUP));
--

1.8.3.1

#6 lore raw

Hi Ori,

Thanks for the comments.
Will update the next V2 version.

BR,
SuanmingMou

Quoted 21 lines

-----Original Message-----
From: Ori Kam <[email protected]>
Sent: Wednesday, September 30, 2020 6:56 PM
To: Suanming Mou <[email protected]>; Ori Kam <[email protected]>; John McNamara <[email protected]>; Marko Kovacevic <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Viacheslav Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH 2/2] ethdev: make rte flow API thread safe

Hi Suanming,

Small comments,
PSB,

Best,
Ori

#7 lore raw

v2 cover ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Suanming Mou (2):
eal/windows: add pthread mutex lock
ethdev: make rte_flow API thread safe

---

v2:
- Using critical section for windows pthread mutex.
- Update ethdev commnets.

---

 doc/guides/prog_guide/rte_flow.rst       |  9 ++--
 lib/librte_eal/windows/include/pthread.h | 33 +++++++++++++
 lib/librte_ethdev/rte_ethdev.c           |  2 +
 lib/librte_ethdev/rte_ethdev.h           |  2 +
 lib/librte_ethdev/rte_ethdev_core.h      |  4 ++
 lib/librte_ethdev/rte_flow.c             | 84 ++++++++++++++++++++++++--------
 6 files changed, 111 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v2 1/2 eal/windows: add pthread mutex lock

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v2:
- Using critical section for windows pthread mutex.

---
 lib/librte_eal/windows/include/pthread.h | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
lib/librte_eal/windows/include/pthread.h +33 -0
index 99013dc..644fd49 100644
@@ -28,6 +28,10 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +143,35 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	InitializeCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	EnterCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	LeaveCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	DeleteCriticalSection(mutex);
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v2 2/2 ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---
 doc/guides/prog_guide/rte_flow.rst  |  9 ++--
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---------
 5 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +5 -4
index 119b128..ae2ddb3 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3101,6 +3097,11 @@ This interface additionally defines the following helper function:
 - ``rte_flow_ops_get()``: get generic flow operations structure from a
   port.
 
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte_flow
+level functions will do it by mutex. The application can test the dev_flags
+with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct rte_eth_dev_data to know
+if the rte_flow thread-safe works under rte_flow level or PMD level.
+
 More will be added over time.
 
 Device compatibility
lib/librte_ethdev/rte_ethdev.c +2 -0
index dfe5c1b..d6fd17e 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -562,6 +563,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->fts_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index 645a186..61bd09f 100644
@@ -1669,6 +1669,8 @@ struct rte_eth_dev_owner {
 #define RTE_ETH_DEV_REPRESENTOR  0x0010
 /** Device does not support MAC change after started */
 #define RTE_ETH_DEV_NOLIVE_MAC_ADDR  0x0020
+/** Device PMD supports thread safety flow operation */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0040
 
 /**
  * Iterates over valid ethdev ports owned by a specific owner.
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +65 -19

160 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Hi Suanming,

PSB,
Best,
Ori

Quoted 8 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Subject: [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

[Snip ...]

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 211

Quoted 10 lines
lib/librte_ethdev/rte_flow.c +2 -0
index f8fdd68..2ac966d 100644
@@ -207,6 +207,20 @@ struct rte_flow_desc_data {
 	return -rte_errno;
 }
 
+static inline void
+flow_lock(struct rte_eth_dev *dev)

Maybe change the name to flow_safe_enter
Since this function doesn't always lock.

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 218

Quoted 8 lines
lib/librte_ethdev/rte_flow.c +7 -0
+{
+	if (!(dev->data->dev_flags &
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+		pthread_mutex_lock(&dev->data->fts_mutex);
+}
+
+static inline void
+flow_unlock(struct rte_eth_dev *dev)

Maybe change the name flow_safe_leave
Same reason as above.

Quoted 159 lines
lib/librte_ethdev/rte_flow.c +5 -0
+{
+	if (!(dev->data->dev_flags &
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+		pthread_mutex_unlock(&dev->data->fts_mutex);
+}
+
 static int

flow_err(uint16_t port_id, int ret, struct rte_flow_error *error) {

lib/librte_ethdev/rte_flow.c +51 -20
@@ -346,12 +360,16 @@ struct rte_flow_desc_data {
 {
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->validate))
-		return flow_err(port_id, ops->validate(dev, attr, pattern,
-						       actions, error), error);
+	if (likely(!!ops->validate)) {
+		flow_lock(dev);
+		ret = ops->validate(dev, attr, pattern, actions, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -372,7 +390,9 @@ struct rte_flow *
 	if (unlikely(!ops))
 		return NULL;
 	if (likely(!!ops->create)) {
+		flow_lock(dev);
 		flow = ops->create(dev, attr, pattern, actions, error);
+		flow_unlock(dev);
 		if (flow == NULL)
 			flow_err(port_id, -rte_errno, error);
 		return flow;
@@ -390,12 +410,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->destroy))
-		return flow_err(port_id, ops->destroy(dev, flow, error),
-				error);
+	if (likely(!!ops->destroy)) {
+		flow_lock(dev);
+		ret = ops->destroy(dev, flow, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -408,11 +432,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->flush))
-		return flow_err(port_id, ops->flush(dev, error), error);
+	if (likely(!!ops->flush)) {
+		flow_lock(dev);
+		ret = ops->flush(dev, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -428,12 +457,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (!ops)
 		return -rte_errno;
-	if (likely(!!ops->query))
-		return flow_err(port_id, ops->query(dev, flow, action, data,
-						    error), error);
+	if (likely(!!ops->query)) {
+		flow_lock(dev);
+		ret = ops->query(dev, flow, action, data, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -447,11 +480,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (!ops)
 		return -rte_errno;
-	if (likely(!!ops->isolate))
-		return flow_err(port_id, ops->isolate(dev, set, error), error);
+	if (likely(!!ops->isolate)) {
+		flow_lock(dev);
+		ret = ops->isolate(dev, set, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -1224,12 +1262,16 @@ enum rte_flow_conv_item_spec_type {
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->dev_dump))
-		return flow_err(port_id, ops->dev_dump(dev, file, error),
-				error);
+	if (likely(!!ops->dev_dump)) {
+		flow_lock(dev);
+		ret = ops->dev_dump(dev, file, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -1241,12 +1283,16 @@ enum rte_flow_conv_item_spec_type {
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->get_aged_flows))
-		return flow_err(port_id, ops->get_aged_flows(dev, contexts,
-				nb_contexts, error), error);
+	if (likely(!!ops->get_aged_flows)) {
+		flow_lock(dev);
+		ret = ops->get_aged_flows(dev, contexts, nb_contexts, error);
+		flow_unlock(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOTSUP,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOTSUP));
--

1.8.3.1

#11 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Quoted 5 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 211

Quoted 2 lines
lib/librte_ethdev/rte_flow.c +2 -0
+static inline void
+flow_lock(struct rte_eth_dev *dev)

Maybe change the name to flow_safe_enter
Since this function doesn't always lock.

I feel fts_enter() sounds better.

Quoted 12 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 218

Quoted 9 lines
(quoted diff) +2 -0
+{
+     if (!(dev->data->dev_flags &

RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))

lib/librte_ethdev/rte_flow.c +5 -0
+             pthread_mutex_lock(&dev->data->fts_mutex);
+}
+
+static inline void
+flow_unlock(struct rte_eth_dev *dev)

Maybe change the name flow_safe_leave
Same reason as above.

On the same lines.. fts_exit()

#12 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Quoted 14 lines

-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Wednesday, October 7, 2020 7:18 AM
To: Ori Kam <[email protected]>
Cc: Suanming Mou <[email protected]>; Ori Kam <[email protected]>; John McNamara <[email protected]>; Marko Kovacevic <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Quoted 6 lines
Quoted 5 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 211

Quoted 2 lines
lib/librte_ethdev/rte_flow.c +2 -0
+static inline void
+flow_lock(struct rte_eth_dev *dev)

Maybe change the name to flow_safe_enter
Since this function doesn't always lock.

I feel fts_enter() sounds better.

I would prefer to take that one if no other better names. : )

Quoted 14 lines
Quoted 13 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 218

Quoted 10 lines
(quoted diff) +2 -0
+{
+     if (!(dev->data->dev_flags &

RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))

lib/librte_ethdev/rte_flow.c +5 -0
+             pthread_mutex_lock(&dev->data->fts_mutex);
+}
+
+static inline void
+flow_unlock(struct rte_eth_dev *dev)

Maybe change the name flow_safe_leave
Same reason as above.

On the same lines.. fts_exit()

#13 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Hi Suanming,

Quoted 13 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Wednesday, October 7, 2020 3:50 AM
Subject: RE: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Quoted 6 lines

-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Wednesday, October 7, 2020 7:18 AM
Subject: Re: [dpdk-dev] [PATCH v2 2/2] ethdev: make rte_flow API thread safe

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 211

Quoted 2 lines
lib/librte_ethdev/rte_flow.c +2 -0
+static inline void
+flow_lock(struct rte_eth_dev *dev)

Maybe change the name to flow_safe_enter
Since this function doesn't always lock.

I feel fts_enter() sounds better.

I would prefer to take that one if no other better names. : )

Good suggestion.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

lib/librte_ethdev/rte_flow.c struct rte_flow_desc_data { · line 218

Quoted 10 lines
(quoted diff) +2 -0
+{
+     if (!(dev->data->dev_flags &

RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))

lib/librte_ethdev/rte_flow.c +5 -0
+             pthread_mutex_lock(&dev->data->fts_mutex);
+}
+
+static inline void
+flow_unlock(struct rte_eth_dev *dev)

Maybe change the name flow_safe_leave
Same reason as above.

On the same lines.. fts_exit()

#14 lore raw

v3 cover ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Suanming Mou (2):
eal/windows: add pthread mutex lock
ethdev: make rte_flow API thread safe

---

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Using critical section for windows pthread mutex.
- Update ethdev commnets.

---

 doc/guides/prog_guide/rte_flow.rst       |  9 ++--
 lib/librte_eal/windows/include/pthread.h | 33 +++++++++++++
 lib/librte_ethdev/rte_ethdev.c           |  2 +
 lib/librte_ethdev/rte_ethdev.h           |  2 +
 lib/librte_ethdev/rte_ethdev_core.h      |  4 ++
 lib/librte_ethdev/rte_flow.c             | 84 ++++++++++++++++++++++++--------
 6 files changed, 111 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH v3 1/2 eal/windows: add pthread mutex lock

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
lib/librte_eal/windows/include/pthread.h +33 -0
index 99013dc..644fd49 100644
@@ -28,6 +28,10 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +143,35 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	InitializeCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	EnterCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	LeaveCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	DeleteCriticalSection(mutex);
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.8.3.1
#17 lore raw

Re: [dpdk-dev] [PATCH v3 1/2] eal/windows: add pthread mutex lock

Hi Dmitry,

Thank you very much.
I also got some messages that they wish the PTHREAD_MUTEX_INITIALIZER macro can also be supported.

Refer to [1], we found that with critical section solution, maybe the macro can be defined as this:
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1,-1,0,0,0,0}

We have tested that works, so I would prefer to add that if the macro is also OK with you. What do you think about that?

The explanation from [1]:
" The pthreads API has an initialization macro that has no correspondence to anything in the windows API. By investigating the internal definition of the critical section type, one may work out how to initialize one without calling InitializeCriticalSection(). The trick here is that InitializeCriticalSection() is not allowed to fail. It tries to allocate a critical section debug object, but if no memory is available, it sets the pointer to a specific value. (One would expect that value to be NULL, but it is actually (void *)-1 for some reason.) Thus we can use this special value for that pointer, and the critical section code will work.

The other important part of the critical section type to initialize is the number of waiters. This controls whether or not the mutex is locked. Fortunately, this part of the critical section is unlikely to change. Apparently, many programs already test critical sections to see if they are locked using this value, so Microsoft felt that it was necessary to keep it set at -1 for an unlocked critical section, even when they changed the underlying algorithm to be more scalable. The final parts of the critical section object are unimportant, and can be set to zero for their defaults."

[1] https://locklessinc.com/articles/pthreads_on_windows/

BR,
SuanmingMou

Quoted 16 lines

-----Original Message-----
From: Dmitry Kozlyuk <[email protected]>
Sent: Thursday, October 8, 2020 12:54 AM
To: Suanming Mou <[email protected]>
Cc: Narcisa Ana Maria Vasile <[email protected]>; Dmitry Malloy <[email protected]>; Pallavi Kadam <[email protected]>; [email protected]
Subject: Re: [PATCH v3 1/2] eal/windows: add pthread mutex lock

Quoted 4 lines · Suanming Mou

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

#18 lore raw

Re: [dpdk-dev] [PATCH v3 1/2] eal/windows: add pthread mutex lock

Hi DmitryM, Naty,

We would like to know if the macro added below for PTHREAD_MUTEX_INITIALIZER is a safe initialization of a CRITICAL_SECTION.

Can you please review the code and explanation below and check it internally?

Quoted 67 lines

Subject: Re: [dpdk-dev] [PATCH v3 1/2] eal/windows: add pthread mutex lock

External email: Use caution opening links or attachments

Hi Dmitry,

Thank you very much.
I also got some messages that they wish the PTHREAD_MUTEX_INITIALIZER macro can also be supported.

Refer to [1], we found that with critical section solution, maybe the macro can be defined as this:
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1,-1,0,0,0,0}

We have tested that works, so I would prefer to add that if the macro is also OK with you.
What do you think about that?

The explanation from [1]:
" The pthreads API has an initialization macro that has no correspondence to anything in the windows API. By investigating the internal definition of the critical section type, one may work out how to initialize one without calling InitializeCriticalSection(). The trick here is that InitializeCriticalSection() is not allowed to fail. It tries to allocate a critical section debug object, but if no memory is available, it sets the pointer to a specific value. (One would expect that value to be NULL, but it is actually (void *)-1 for some reason.) Thus we can use this special value for that pointer, and the critical section code will work.

The other important part of the critical section type to initialize is the number of waiters. This controls whether or not the mutex is locked. Fortunately, this part of the critical section is unlikely to change. Apparently, many programs already test critical sections to see if they are locked using this value, so Microsoft felt that it was necessary to keep it set at -1 for an unlocked critical section, even when they changed the underlying algorithm to be more scalable. The final parts of the critical section object are unimportant, and can be set to zero for their defaults."

[1]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flockl
essinc.com%2Farticles%2Fpthreads_on_windows%2F&amp;data=02%7C01% 7Ctalshn%40nvidia.com%7C4533970f5c964751eeea08d86b3483e3%7C43083d 15727340c1b7db39efd9ccc17a%7C0%7C0%7C637377220576713708&amp;sdat a=qELFpXSw7%2Fk8m9FMIidiQsnTq%2BeyJRII8C1sDyrHJe4%3D&amp;reserv ed=0

BR,
SuanmingMou

Quoted 16 lines

-----Original Message-----
From: Dmitry Kozlyuk <[email protected]>
Sent: Thursday, October 8, 2020 12:54 AM
To: Suanming Mou <[email protected]>
Cc: Narcisa Ana Maria Vasile <[email protected]>; Dmitry Malloy <[email protected]>; Pallavi Kadam <[email protected]>; [email protected]
Subject: Re: [PATCH v3 1/2] eal/windows: add pthread mutex lock

Quoted 4 lines · Suanming Mou

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

#19 lore raw

PATCH v3 2/2 ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---

 doc/guides/prog_guide/rte_flow.rst  |  9 ++--
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---------
 5 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +5 -4
index 119b128..ae2ddb3 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3101,6 +3097,11 @@ This interface additionally defines the following helper function:
 - ``rte_flow_ops_get()``: get generic flow operations structure from a
   port.
 
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte_flow
+level functions will do it by mutex. The application can test the dev_flags
+with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct rte_eth_dev_data to know
+if the rte_flow thread-safe works under rte_flow level or PMD level.
+
 More will be added over time.
 
 Device compatibility
lib/librte_ethdev/rte_ethdev.c +2 -0
index 0f56541..60677fe 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -564,6 +565,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->fts_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index d2bf74f..03612fd 100644
@@ -1664,6 +1664,8 @@ struct rte_eth_dev_owner {
 #define RTE_ETH_DEV_REPRESENTOR  0x0010
 /** Device does not support MAC change after started */
 #define RTE_ETH_DEV_NOLIVE_MAC_ADDR  0x0020
+/** Device PMD supports thread safety flow operation */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0040
 
 /**
  * Iterates over valid ethdev ports owned by a specific owner.
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +65 -19

160 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Acked-by on v3 2/2
#20 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] ethdev: make rte_flow API thread safe

Quoted 30 lines · Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

Quoted 8 lines

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Quoted 277 lines

---

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---

 doc/guides/prog_guide/rte_flow.rst  |  9 ++--
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---------
 5 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +5 -4
index 119b128..ae2ddb3 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3101,6 +3097,11 @@ This interface additionally defines the following helper function:
 - ``rte_flow_ops_get()``: get generic flow operations structure from a
   port.
 
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte_flow
+level functions will do it by mutex. The application can test the dev_flags
+with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct rte_eth_dev_data to know
+if the rte_flow thread-safe works under rte_flow level or PMD level.
+
 More will be added over time.
 
 Device compatibility
lib/librte_ethdev/rte_ethdev.c +2 -0
index 0f56541..60677fe 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
        strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
        eth_dev->data->port_id = port_id;
        eth_dev->data->mtu = RTE_ETHER_MTU;
+       pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
        rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -564,6 +565,7 @@ struct rte_eth_dev *
                rte_free(eth_dev->data->mac_addrs);
                rte_free(eth_dev->data->hash_mac_addrs);
                rte_free(eth_dev->data->dev_private);
+               pthread_mutex_destroy(&eth_dev->data->fts_mutex);
                memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
        }
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index d2bf74f..03612fd 100644
@@ -1664,6 +1664,8 @@ struct rte_eth_dev_owner {
 #define RTE_ETH_DEV_REPRESENTOR  0x0010
 /** Device does not support MAC change after started */
 #define RTE_ETH_DEV_NOLIVE_MAC_ADDR  0x0020
+/** Device PMD supports thread safety flow operation */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0040
 
 /**
  * Iterates over valid ethdev ports owned by a specific owner.
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
                         *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
                         */
 
+       pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */
        uint64_t reserved_64s[4]; /**< Reserved for future fields */
        void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +65 -20
index f8fdd68..6823458 100644
@@ -207,6 +207,20 @@ struct rte_flow_desc_data {
        return -rte_errno;
 }
 
+static inline void
+fts_enter(struct rte_eth_dev *dev)
+{
+       if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+               pthread_mutex_lock(&dev->data->fts_mutex);
+}
+
+static inline void
+fts_exit(struct rte_eth_dev *dev)
+{
+       if (!(dev->data->dev_flags & RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+               pthread_mutex_unlock(&dev->data->fts_mutex);
+}
+
 static int
 flow_err(uint16_t port_id, int ret, struct rte_flow_error *error)
 {
@@ -346,12 +360,16 @@ struct rte_flow_desc_data {
 {
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       int ret;
 
        if (unlikely(!ops))
                return -rte_errno;
-       if (likely(!!ops->validate))
-               return flow_err(port_id, ops->validate(dev, attr, pattern,
-                                                      actions, error), error);
+       if (likely(!!ops->validate)) {
+               fts_enter(dev);
+               ret = ops->validate(dev, attr, pattern, actions, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOSYS,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOSYS));
@@ -372,7 +390,9 @@ struct rte_flow *
        if (unlikely(!ops))
                return NULL;
        if (likely(!!ops->create)) {
+               fts_enter(dev);
                flow = ops->create(dev, attr, pattern, actions, error);
+               fts_exit(dev);
                if (flow == NULL)
                        flow_err(port_id, -rte_errno, error);
                return flow;
@@ -390,12 +410,16 @@ struct rte_flow *
 {
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+       int ret;
 
        if (unlikely(!ops))
                return -rte_errno;
-       if (likely(!!ops->destroy))
-               return flow_err(port_id, ops->destroy(dev, flow, error),
-                               error);
+       if (likely(!!ops->destroy)) {
+               fts_enter(dev);
+               ret = ops->destroy(dev, flow, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOSYS,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOSYS));
@@ -408,11 +432,16 @@ struct rte_flow *
 {
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+       int ret;
 
        if (unlikely(!ops))
                return -rte_errno;
-       if (likely(!!ops->flush))
-               return flow_err(port_id, ops->flush(dev, error), error);
+       if (likely(!!ops->flush)) {
+               fts_enter(dev);
+               ret = ops->flush(dev, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOSYS,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOSYS));
@@ -428,12 +457,16 @@ struct rte_flow *
 {
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+       int ret;
 
        if (!ops)
                return -rte_errno;
-       if (likely(!!ops->query))
-               return flow_err(port_id, ops->query(dev, flow, action, data,
-                                                   error), error);
+       if (likely(!!ops->query)) {
+               fts_enter(dev);
+               ret = ops->query(dev, flow, action, data, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOSYS,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOSYS));
@@ -447,11 +480,16 @@ struct rte_flow *
 {
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+       int ret;
 
        if (!ops)
                return -rte_errno;
-       if (likely(!!ops->isolate))
-               return flow_err(port_id, ops->isolate(dev, set, error), error);
+       if (likely(!!ops->isolate)) {
+               fts_enter(dev);
+               ret = ops->isolate(dev, set, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOSYS,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOSYS));
@@ -1224,12 +1262,16 @@ enum rte_flow_conv_item_spec_type {
 {
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+       int ret;
 
        if (unlikely(!ops))
                return -rte_errno;
-       if (likely(!!ops->dev_dump))
-               return flow_err(port_id, ops->dev_dump(dev, file, error),
-                               error);
+       if (likely(!!ops->dev_dump)) {
+               fts_enter(dev);
+               ret = ops->dev_dump(dev, file, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOSYS,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOSYS));
@@ -1241,12 +1283,16 @@ enum rte_flow_conv_item_spec_type {
 {
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
        const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+       int ret;
 
        if (unlikely(!ops))
                return -rte_errno;
-       if (likely(!!ops->get_aged_flows))
-               return flow_err(port_id, ops->get_aged_flows(dev, contexts,
-                               nb_contexts, error), error);
+       if (likely(!!ops->get_aged_flows)) {
+               fts_enter(dev);
+               ret = ops->get_aged_flows(dev, contexts, nb_contexts, error);
+               fts_exit(dev);
+               return flow_err(port_id, ret, error);
+       }
        return rte_flow_error_set(error, ENOTSUP,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOTSUP));
--

1.8.3.1

Acked-by
#21 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] ethdev: make rte_flow API thread safe

Hi Suanming,

Quoted 44 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Ajit Khaparde
Sent: Wednesday, October 7, 2020 5:43 PM
Subject: Re: [dpdk-dev] [PATCH v3 2/2] ethdev: make rte_flow API thread safe

Quoted 37 lines · Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Quoted 3 lines
Quoted 1 line

Thanks,
Ori

Acked-by on v3 2/2
#22 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] ethdev: make rte_flow API thread safe

In reply to Suanming Mou

From: Suanming Mou

Quoted 4 lines

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

Better to write here "or protect any concurrent calling for the rte_flow operations using a lock."

Quoted 5 lines

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions

not => is not

Quoted 70 lines

also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---

 doc/guides/prog_guide/rte_flow.rst  |  9 ++--
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---
------
 5 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +0 -4
index 119b128..ae2ddb3 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing

flow
rules. If this cannot be achieved naturally or with workarounds (such as temporarily replacing the burst function pointers), an appropriate error @@
-3101,6 +3097,11 @@ This interface additionally defines the following helper function:
- ``rte_flow_ops_get()``: get generic flow operations structure from a port.

doc/guides/prog_guide/rte_flow.rst

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+If PMD interfaces do not support re-entrancy/multi-thread safety,
+rte_flow level functions will do it by mutex. The application can test

Good to mention mutex per port.

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+the dev_flags with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct
+rte_eth_dev_data to know if the rte_flow thread-safe works under

rte_flow level or PMD level.
+

If think it will be helpful to add here a note saying that it is unsafe to call other control commands In parallel to rte_flow operations.

Quoted 234 lines

More will be added over time.

Device compatibility

lib/librte_ethdev/rte_ethdev.c +1 -0
index 0f56541..60677fe 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data-
 >name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
lib/librte_ethdev/rte_ethdev.c +1 -0
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -564,6 +565,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->fts_mutex);
 		memset(eth_dev->data, 0, sizeof(struct
 rte_eth_dev_data));
 	}
lib/librte_ethdev/rte_ethdev.h +0 -0
index d2bf74f..03612fd 100644
@@ -1664,6 +1664,8 @@ struct rte_eth_dev_owner {  #define

RTE_ETH_DEV_REPRESENTOR 0x0010
/** Device does not support MAC change after started */ #define
RTE_ETH_DEV_NOLIVE_MAC_ADDR 0x0020

lib/librte_ethdev/rte_ethdev.h +2 -0
+/** Device PMD supports thread safety flow operation */ #define
+RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0040
 
 /**
  * Iterates over valid ethdev ports owned by a specific owner.
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex.
 */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */

} __rte_cache_aligned;

lib/librte_ethdev/rte_flow.c index renamed from lib/librte_ethdev/rte_flow.c +0 -0

f8fdd68..6823458 100644

lib/librte_ethdev/rte_flow.c +14 -0
@@ -207,6 +207,20 @@ struct rte_flow_desc_data {
 	return -rte_errno;
 }
 
+static inline void
+fts_enter(struct rte_eth_dev *dev)
+{
+	if (!(dev->data->dev_flags &
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+		pthread_mutex_lock(&dev->data->fts_mutex);
+}
+
+static inline void
+fts_exit(struct rte_eth_dev *dev)
+{
+	if (!(dev->data->dev_flags &
 RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE))
+		pthread_mutex_unlock(&dev->data->fts_mutex);
+}
+
 static int

flow_err(uint16_t port_id, int ret, struct rte_flow_error *error) { @@ -
346,12 +360,16 @@ struct rte_flow_desc_data { {

lib/librte_ethdev/rte_flow.c +51 -19
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->validate))
-		return flow_err(port_id, ops->validate(dev, attr, pattern,
-						       actions, error), error);
+	if (likely(!!ops->validate)) {
+		fts_enter(dev);
+		ret = ops->validate(dev, attr, pattern, actions, error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -372,7 +390,9 @@ struct rte_flow *
 	if (unlikely(!ops))
 		return NULL;
 	if (likely(!!ops->create)) {
+		fts_enter(dev);
 		flow = ops->create(dev, attr, pattern, actions, error);
+		fts_exit(dev);
 		if (flow == NULL)
 			flow_err(port_id, -rte_errno, error);
 		return flow;
@@ -390,12 +410,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->destroy))
-		return flow_err(port_id, ops->destroy(dev, flow, error),
-				error);
+	if (likely(!!ops->destroy)) {
+		fts_enter(dev);
+		ret = ops->destroy(dev, flow, error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -408,11 +432,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->flush))
-		return flow_err(port_id, ops->flush(dev, error), error);
+	if (likely(!!ops->flush)) {
+		fts_enter(dev);
+		ret = ops->flush(dev, error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -428,12 +457,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (!ops)
 		return -rte_errno;
-	if (likely(!!ops->query))
-		return flow_err(port_id, ops->query(dev, flow, action, data,
-						    error), error);
+	if (likely(!!ops->query)) {
+		fts_enter(dev);
+		ret = ops->query(dev, flow, action, data, error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -447,11 +480,16 @@ struct rte_flow *
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (!ops)
 		return -rte_errno;
-	if (likely(!!ops->isolate))
-		return flow_err(port_id, ops->isolate(dev, set, error), error);
+	if (likely(!!ops->isolate)) {
+		fts_enter(dev);
+		ret = ops->isolate(dev, set, error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -1224,12 +1262,16 @@ enum rte_flow_conv_item_spec_type {  {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->dev_dump))
-		return flow_err(port_id, ops->dev_dump(dev, file, error),
-				error);
+	if (likely(!!ops->dev_dump)) {
+		fts_enter(dev);
+		ret = ops->dev_dump(dev, file, error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOSYS,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOSYS));
@@ -1241,12 +1283,16 @@ enum rte_flow_conv_item_spec_type {  {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+	int ret;
 
 	if (unlikely(!ops))
 		return -rte_errno;
-	if (likely(!!ops->get_aged_flows))
-		return flow_err(port_id, ops->get_aged_flows(dev,
 contexts,
-				nb_contexts, error), error);
+	if (likely(!!ops->get_aged_flows)) {
+		fts_enter(dev);
+		ret = ops->get_aged_flows(dev, contexts, nb_contexts,
 error);
+		fts_exit(dev);
+		return flow_err(port_id, ret, error);
+	}
 	return rte_flow_error_set(error, ENOTSUP,
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
Quoted 3 lines

NULL, rte_strerror(ENOTSUP));
--
1.8.3.1

Besides the above (not must) suggestion, looks good,

#23 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] ethdev: make rte_flow API thread safe

Quoted 120 lines

-----Original Message-----
From: Matan Azrad <[email protected]>
Sent: Thursday, October 8, 2020 4:11 AM
To: Suanming Mou <[email protected]>; Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: [email protected]
Subject: RE: [dpdk-dev] [PATCH v3 2/2] ethdev: make rte_flow API thread safe

From: Suanming Mou

Quoted 4 lines

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

Better to write here "or protect any concurrent calling for the rte_flow operations using a lock."

Quoted 6 lines

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions

not => is not

Quoted 73 lines

also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---

 doc/guides/prog_guide/rte_flow.rst  |  9 ++--
 lib/librte_ethdev/rte_ethdev.c      |  2 +
 lib/librte_ethdev/rte_ethdev.h      |  2 +
 lib/librte_ethdev/rte_ethdev_core.h |  4 ++
 lib/librte_ethdev/rte_flow.c        | 84 ++++++++++++++++++++++++++++---
------
 5 files changed, 78 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +0 -1
index 119b128..ae2ddb3 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although

nothing

doc/guides/prog_guide/rte_flow.rst +0 -3
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when

managing flow
rules. If this cannot be achieved naturally or with workarounds (such as temporarily replacing the burst function pointers), an appropriate
error @@
-3101,6 +3097,11 @@ This interface additionally defines the following helper
function:
- ``rte_flow_ops_get()``: get generic flow operations structure from a port.

doc/guides/prog_guide/rte_flow.rst

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +3 -0
+If PMD interfaces do not support re-entrancy/multi-thread safety,
+rte_flow level functions will do it by mutex. The application can
+test

Good to mention mutex per port.

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+the dev_flags with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct
+rte_eth_dev_data to know if the rte_flow thread-safe works under

rte_flow level or PMD level.
+

If think it will be helpful to add here a note saying that it is unsafe to call other control commands In parallel to rte_flow operations.

Quoted 3 lines

More will be added over time.

Device compatibility

[snip]

Quoted 4 lines
Quoted 1 line

1.8.3.1

Besides the above (not must) suggestion, looks good,

Thanks for the suggestions, I will update that in the next version.

#24 lore raw

v4 cover ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Suanming Mou (2):
eal/windows: add pthread mutex lock
ethdev: make rte_flow API thread safe

---

v4:
- Add PTHREAD_MUTEX_INITIALIZER for windows pthread mutex.
- Change RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE to 0x0001, since RTE_ETH_DEV_CLOSE_REMOVE has been removed.
- Update small comments.
- Update release notes.

v3:
- Update flow_lock/unlock -> fts_enter/exit.

v2:
- Using critical section for windows pthread mutex.
- Update ethdev commnets.

---

 doc/guides/prog_guide/rte_flow.rst       | 11 +++--
 doc/guides/rel_notes/release_20_11.rst   |  6 +++
 lib/librte_eal/windows/include/pthread.h | 35 +++++++++++++
 lib/librte_ethdev/rte_ethdev.c           |  2 +
 lib/librte_ethdev/rte_ethdev.h           |  2 +
 lib/librte_ethdev/rte_ethdev_core.h      |  4 ++
 lib/librte_ethdev/rte_flow.c             | 84 ++++++++++++++++++++++++--------
 7 files changed, 121 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.3.1
#25 lore raw

PATCH v4 1/2 eal/windows: add pthread mutex lock

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 35 ++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/librte_eal/windows/include/pthread.h +35 -0
index 99013dc..c62251f 100644
@@ -28,6 +28,12 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+#define PTHREAD_MUTEX_INITIALIZER {(void *)-1, -1, 0, 0, 0, 0}
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +145,35 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	InitializeCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	EnterCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	LeaveCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	DeleteCriticalSection(mutex);
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.8.3.1
Tested-by Acked-by on v4 1/2
#26 lore raw

Re: [dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock

Quoted 74 lines

Subject: [dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 35
++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/librte_eal/windows/include/pthread.h +6 -0
index 99013dc..c62251f 100644
@@ -28,6 +28,12 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft
 libc*/  typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+#define PTHREAD_MUTEX_INITIALIZER {(void *)-1, -1, 0, 0, 0, 0}
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \ @@ -139,6 +145,35 @@
lib/librte_eal/windows/include/pthread.h +25 -1
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr) {
+	InitializeCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex) {
+	EnterCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex) {
+	LeaveCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex) {
+	DeleteCriticalSection(mutex);
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
--
Quoted 1 line

1.8.3.1

Acked-by on v4 1/2
#27 lore raw

Re: [dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock

In reply to Suanming Mou
Quoted 64 lines · Suanming Mou

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

  lib/librte_eal/windows/include/pthread.h | 35 ++++++++++++++++++++++++++++++++
  1 file changed, 35 insertions(+)
lib/librte_eal/windows/include/pthread.h +28 -0
index 99013dc..c62251f 100644
@@ -28,6 +28,12 @@
  /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
  typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+#define PTHREAD_MUTEX_INITIALIZER {(void *)-1, -1, 0, 0, 0, 0}
+
  typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
  #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +145,35 @@
  	return 0;
  }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	InitializeCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	EnterCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	LeaveCriticalSection(mutex);
+	return 0;
+}
+

lib/librte_eal/windows/include/pthread.h line 179

Quoted 10 lines
lib/librte_eal/windows/include/pthread.h +7 -0
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	DeleteCriticalSection(mutex);
+	return 0;
+}
+
  #ifdef __cplusplus
  }
  #endif
Acked-by on v4 1/2
#28 lore raw

Re: [dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock

In reply to Suanming Mou
Quoted 26 lines · Suanming Mou

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 35 ++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/librte_eal/windows/include/pthread.h +0 -0
index 99013dc..c62251f 100644

lib/librte_eal/windows/include/pthread.h line 36

Quoted 9 lines
lib/librte_eal/windows/include/pthread.h +6 -0
@@ -28,6 +28,12 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+#define PTHREAD_MUTEX_INITIALIZER {(void *)-1, -1, 0, 0, 0, 0}
+

Regarding the question on the static initializer, adding the guidance from DmitryM:
"If you choose to do the static initializer, you will be relying on implementation specifics, (which may have not changed ever, or may not ever change, or may change in the next release). This would be a hack (although potentially long term)."

Otherwise,

#29 lore raw

Re: [dpdk-dev] [PATCH v4 1/2] eal/windows: add pthread mutex lock

Quoted 43 lines

-----Original Message-----
From: Narcisa Ana Maria Vasile <[email protected]>
Sent: Thursday, October 15, 2020 10:16 AM
To: Suanming Mou <[email protected]>
Cc: Dmitry Kozlyuk <[email protected]>; Dmitry Malloy <[email protected]>; Pallavi Kadam <[email protected]>; [email protected]
Subject: Re: [PATCH v4 1/2] eal/windows: add pthread mutex lock

Quoted 31 lines · Suanming Mou

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 35
++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/librte_eal/windows/include/pthread.h +0 -0
index 99013dc..c62251f 100644
@@ -28,6 +28,12 @@
 /* defining pthread_attr_t type on Windows since there is no in
 Microsoft libc*/  typedef void *pthread_attr_t;
 
Quoted 13 lines

lib/librte_eal/windows/include/pthread.h line 36

Quoted 6 lines
lib/librte_eal/windows/include/pthread.h +6 -0
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+#define PTHREAD_MUTEX_INITIALIZER {(void *)-1, -1, 0, 0, 0, 0}
+

Regarding the question on the static initializer, adding the guidance from DmitryM:
"If you choose to do the static initializer, you will be relying on implementation specifics, (which may have not changed ever, or may not ever change, or may change in the next release).
This would be a hack (although potentially long term)."

Yes, thanks. So we have removed that hack in the latest v5.
https://patches.dpdk.org/patch/80814/

Quoted 3 lines

Otherwise,

#30 lore raw

PATCH v4 2/2 ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or protect any concurrent calling for the rte_flow operations using a lock.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe is not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---

v4:
- Change RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE to 0x0001, since RTE_ETH_DEV_CLOSE_REMOVE has been removed.
- Update small comments.
- Update release notes.

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---

 doc/guides/prog_guide/rte_flow.rst     | 11 +++--
 doc/guides/rel_notes/release_20_11.rst |  6 +++
 lib/librte_ethdev/rte_ethdev.c         |  2 +
 lib/librte_ethdev/rte_ethdev.h         |  2 +
 lib/librte_ethdev/rte_ethdev_core.h    |  4 ++
 lib/librte_ethdev/rte_flow.c           | 84 ++++++++++++++++++++++++++--------
 6 files changed, 86 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +7 -4
index 119b128..b4ae9cc 100644
@@ -3046,10 +3046,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3101,6 +3097,13 @@ This interface additionally defines the following helper function:
 - ``rte_flow_ops_get()``: get generic flow operations structure from a
   port.
 
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte_flow
+level functions will do it by mutex per port. The application can test the
+dev_flags with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct rte_eth_dev_data
+to know if the rte_flow thread-safe works under rte_flow level or PMD level.
+Please note that the mutex only protects rte_flow level functions, other
+control path functions are not in scope.
+
 More will be added over time.
 
 Device compatibility
doc/guides/rel_notes/release_20_11.rst +6 -0
index 0b2a370..364306d 100644
@@ -109,6 +109,12 @@ New Features
   * Extern objects and functions can be plugged into the pipeline.
   * Transaction-oriented table updates.
 
+* **Added thread safe support to rte_flow functions.**
+
+  Added ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE`` device flag to indicate
+  if PMD support thread safe operations. If PMD doesn't set the flag,
+  rte_flow level functions will protect the flow operations with mutex.
+
 
 Removed Items
 -------------
lib/librte_ethdev/rte_ethdev.c +2 -0
index 0f56541..60677fe 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->fts_mutex, NULL);
 
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -564,6 +565,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->fts_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index d2bf74f..4dc2b85 100644
@@ -1654,6 +1654,8 @@ struct rte_eth_dev_owner {
 	char name[RTE_ETH_MAX_OWNER_NAME_LEN]; /**< The owner name. */
 };
 
+/** Device PMD supports thread safety flow operation */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0001
 /** Device supports link state interrupt */
 #define RTE_ETH_DEV_INTR_LSC     0x0002
 /** Device is a bonded slave */
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..89df65a 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +65 -19

160 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#31 lore raw

Re: [dpdk-dev] [PATCH v4 2/2] ethdev: make rte_flow API thread safe

09/10/2020 03:17, Suanming Mou:

doc/guides/prog_guide/rte_flow.rst This interface additionally defines the following helper function: · line 3100

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +1 -0
+If PMD interfaces do not support re-entrancy/multi-thread safety, rte_flow

"API" should be inserted here to make clear which layer we talk about.

Quoted 1 line

+level functions will do it by mutex per port. The application can test the

"do it" is too vague. I suggest "protect threads".

Quoted 1 line

+dev_flags with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct rte_eth_dev_data

The application access it through dev_info.

Quoted 1 line

+to know if the rte_flow thread-safe works under rte_flow level or PMD level.

Again insert "API": rte_flow API level

This sentence can be confusing. Better to say explicitly that if RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE is set, it means the protection at API level is disabled.

doc/guides/prog_guide/rte_flow.rst This interface additionally defines the following helper function: · line 3105

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+Please note that the mutex only protects rte_flow level functions, other
+control path functions are not in scope.

Please find a complete rewording with sentences split after punctuation:

If PMD interfaces do not support re-entrancy/multi-thread safety, the rte_flow API functions will protect threads by mutex per port. The application can check whether ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE`` is set in ``dev_flags``, meaning the PMD is thread-safe regarding rte_flow, so the API level protection is disabled.
Please note that this API-level mutex protects only rte_flow functions, other control path functions are not in scope.

[...]

doc/guides/rel_notes/release_20_11.rst New Features · line 117

Quoted 12 lines
doc/guides/rel_notes/release_20_11.rst +6 -0
@@ -109,6 +109,12 @@ New Features
   * Extern objects and functions can be plugged into the pipeline.
   * Transaction-oriented table updates.
 
+* **Added thread safe support to rte_flow functions.**
+
+  Added ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE`` device flag to indicate
+  if PMD support thread safe operations. If PMD doesn't set the flag,
+  rte_flow level functions will protect the flow operations with mutex.
+

Should be sorted before drivers with other ethdev features if any.

[...]

lib/librte_ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 1657

Quoted 3 lines
lib/librte_ethdev/rte_ethdev.h +1 -0
+/** Device PMD supports thread safety flow operation */

"Device" is useless
safety -> safe (adjective before "flow operation")

It becomes:
/** PMD supports thread-safe flow operations */

Quoted 1 line

+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE 0x0001

OK for the name of the flag.

[...]

lib/librte_ethdev/rte_ethdev_core.h struct rte_eth_dev_data { · line 186

Quoted 7 lines
lib/librte_ethdev/rte_ethdev_core.h +1 -0
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */

"ts" or "safety" is redundant for a mutex.
I suggest "flow_ops_mutex" as a name.

#32 lore raw

Re: [dpdk-dev] [PATCH v4 2/2] ethdev: make rte_flow API thread safe

Hi Thomas,

Thanks, will update the next version when Windows mutex macro solution is confirmed.

BR,
SuanmingMou

Quoted 92 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, October 14, 2020 6:19 PM
To: Suanming Mou <[email protected]>
Cc: Ori Kam <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4 2/2] ethdev: make rte_flow API thread safe

09/10/2020 03:17, Suanming Mou:

doc/guides/prog_guide/rte_flow.rst

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+If PMD interfaces do not support re-entrancy/multi-thread safety,
+rte_flow

"API" should be inserted here to make clear which layer we talk about.

doc/guides/prog_guide/rte_flow.rst

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+level functions will do it by mutex per port. The application can
+test the

"do it" is too vague. I suggest "protect threads".

doc/guides/prog_guide/rte_flow.rst

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+dev_flags with RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE in struct
+rte_eth_dev_data

The application access it through dev_info.

Quoted 1 line

+to know if the rte_flow thread-safe works under rte_flow level or PMD level.

Again insert "API": rte_flow API level

This sentence can be confusing. Better to say explicitly that if RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE is set, it means the protection at API level is disabled.

doc/guides/prog_guide/rte_flow.rst

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+Please note that the mutex only protects rte_flow level functions,
+other control path functions are not in scope.

Please find a complete rewording with sentences split after punctuation:

If PMD interfaces do not support re-entrancy/multi-thread safety, the rte_flow API functions will protect threads by mutex per port.
The application can check whether ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE`` is set in ``dev_flags``, meaning the PMD is thread-safe regarding rte_flow, so the API level protection is disabled.
Please note that this API-level mutex protects only rte_flow functions, other control path functions are not in scope.

[...]

doc/guides/rel_notes/release_20_11.rst New Features · line 117

Quoted 12 lines
doc/guides/rel_notes/release_20_11.rst +6 -0
@@ -109,6 +109,12 @@ New Features
   * Extern objects and functions can be plugged into the pipeline.
   * Transaction-oriented table updates.
 
+* **Added thread safe support to rte_flow functions.**
+
+  Added ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE`` device flag to indicate
+ if PMD support thread safe operations. If PMD doesn't set the flag,
+ rte_flow level functions will protect the flow operations with mutex.
+

Should be sorted before drivers with other ethdev features if any.

[...]

lib/librte_ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 1657

Quoted 3 lines
lib/librte_ethdev/rte_ethdev.h +1 -0
+/** Device PMD supports thread safety flow operation */

"Device" is useless
safety -> safe (adjective before "flow operation")

It becomes:
/** PMD supports thread-safe flow operations */

Quoted 1 line

+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE 0x0001

OK for the name of the flag.

[...]

lib/librte_ethdev/rte_ethdev_core.h struct rte_eth_dev_data { · line 186

Quoted 7 lines
lib/librte_ethdev/rte_ethdev_core.h +1 -0
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t fts_mutex; /**< rte flow ops thread safety mutex. */

"ts" or "safety" is redundant for a mutex.
I suggest "flow_ops_mutex" as a name.

#33 lore raw

v5 cover ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Suanming Mou (2):
eal/windows: add pthread mutex lock
ethdev: make rte_flow API thread safe

---

v5:
- Update ethdev patch commnets, doc and release notes.
- Update fts_mutex -> flow_ops_mutex.
- Remove PTHREAD_MUTEX_INITIALIZER for windows added in v4.

v4:
- Add PTHREAD_MUTEX_INITIALIZER for windows pthread mutex.
- Change RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE to 0x0001, since RTE_ETH_DEV_CLOSE_REMOVE has been removed.
- Update small comments.
- Update release notes.

v3:
- Update flow_lock/unlock -> fts_enter/exit.

v2:
- Using critical section for windows pthread mutex.
- Update ethdev commnets.

---

 doc/guides/prog_guide/rte_flow.rst       | 12 +++--
 doc/guides/rel_notes/release_20_11.rst   |  6 +++
 lib/librte_eal/windows/include/pthread.h | 33 +++++++++++++
 lib/librte_ethdev/rte_ethdev.c           |  2 +
 lib/librte_ethdev/rte_ethdev.h           |  2 +
 lib/librte_ethdev/rte_ethdev_core.h      |  4 ++
 lib/librte_ethdev/rte_flow.c             | 84 ++++++++++++++++++++++++--------
 7 files changed, 120 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH v5 1/2 eal/windows: add pthread mutex lock

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v5:
- Remove PTHREAD_MUTEX_INITIALIZER macro added in v4.

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
lib/librte_eal/windows/include/pthread.h +33 -0
index 99013dc..644fd49 100644
@@ -28,6 +28,10 @@
 /* defining pthread_attr_t type on Windows since there is no in Microsoft libc*/
 typedef void *pthread_attr_t;
 
+typedef void *pthread_mutexattr_t;
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
 typedef SYNCHRONIZATION_BARRIER pthread_barrier_t;
 
 #define pthread_barrier_init(barrier, attr, count) \
@@ -139,6 +143,35 @@
 	return 0;
 }
 
+static inline int
+pthread_mutex_init(pthread_mutex_t *mutex,
+		   __rte_unused pthread_mutexattr_t *attr)
+{
+	InitializeCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	EnterCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	LeaveCriticalSection(mutex);
+	return 0;
+}
+
+static inline int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	DeleteCriticalSection(mutex);
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.8.3.1
Acked-by on v5 1/2
#35 lore raw

Re: [dpdk-dev] [PATCH v5 1/2] eal/windows: add pthread mutex lock

Quoted 18 lines · Suanming Mou

Add pthread mutex lock as it is needed for the thread safe rte_flow functions.

---

v5:
- Remove PTHREAD_MUTEX_INITIALIZER macro added in v4.

v4:
- Add PTHREAD_MUTEX_INITIALIZER macro.

v3:
- No updates.

Quoted 8 lines

v2:
- Using critical section for windows pthread mutex.

---

 lib/librte_eal/windows/include/pthread.h | 33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
#36 lore raw

PATCH v5 2/2 ethdev: make rte_flow API thread safe

In reply to Suanming Mou

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or protect any concurrent calling for the rte_flow operations using a lock.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe is not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

---

v5:
- Update ethdev patch commnets, doc and release notes.
- Update fts_mutex -> flow_ops_mutex.

v4:
- Change RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE to 0x0001, since RTE_ETH_DEV_CLOSE_REMOVE has been removed.
- Update small comments.
- Update release notes.

v3:
- update flow_lock/unlock -> fts_enter/exit

v2:
- Update commit info and description doc.
- Add inline for the flow lock and unlock functions.
- Remove the PMD sample part flag configuration.

---

 doc/guides/prog_guide/rte_flow.rst     | 12 +++--
 doc/guides/rel_notes/release_20_11.rst |  6 +++
 lib/librte_ethdev/rte_ethdev.c         |  2 +
 lib/librte_ethdev/rte_ethdev.h         |  2 +
 lib/librte_ethdev/rte_ethdev_core.h    |  4 ++
 lib/librte_ethdev/rte_flow.c           | 84 ++++++++++++++++++++++++++--------
 6 files changed, 87 insertions(+), 23 deletions(-)
doc/guides/prog_guide/rte_flow.rst +8 -4
index f26a6c2..a446b51 100644
@@ -3088,10 +3088,6 @@ Caveats
 - API operations are synchronous and blocking (``EAGAIN`` cannot be
   returned).
 
-- There is no provision for re-entrancy/multi-thread safety, although nothing
-  should prevent different devices from being configured at the same
-  time. PMDs may protect their control path functions accordingly.
-
 - Stopping the data path (TX/RX) should not be necessary when managing flow
   rules. If this cannot be achieved naturally or with workarounds (such as
   temporarily replacing the burst function pointers), an appropriate error
@@ -3143,6 +3139,14 @@ This interface additionally defines the following helper function:
 - ``rte_flow_ops_get()``: get generic flow operations structure from a
   port.
 
+If PMD interfaces don't support re-entrancy/multi-thread safety,
+the rte_flow API functions will protect threads by mutex per port.
+The application can check whether ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE``
+is set in ``dev_flags``, meaning the PMD is thread-safe regarding rte_flow,
+so the API level protection is disabled.
+Please note that this API-level mutex protects only rte_flow functions,
+other control path functions are not in scope.
+
 More will be added over time.
 
 Device compatibility
doc/guides/rel_notes/release_20_11.rst +6 -0
index 30db8f2..ae3381f 100644
@@ -67,6 +67,12 @@ New Features
   Added the FEC API which provides functions for query FEC capabilities and
   current FEC mode from device. Also, API for configuring FEC mode is also provided.
 
+* **Added thread safe support to rte_flow functions.**
+
+  Added ``RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE`` device flag to indicate
+  if PMD support thread safe operations. If PMD doesn't set the flag,
+  rte_flow API level functions will protect the flow operations with mutex.
+
 * **Updated Broadcom bnxt driver.**
 
   Updated the Broadcom bnxt driver with new features and improvements, including:
lib/librte_ethdev/rte_ethdev.c +2 -0
index 5b7979a..7817224 100644
@@ -500,6 +500,7 @@ struct rte_eth_dev *
 	strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
 	eth_dev->data->port_id = port_id;
 	eth_dev->data->mtu = RTE_ETHER_MTU;
+	pthread_mutex_init(&eth_dev->data->flow_ops_mutex, NULL);
 
 unlock:
 	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
@@ -564,6 +565,7 @@ struct rte_eth_dev *
 		rte_free(eth_dev->data->mac_addrs);
 		rte_free(eth_dev->data->hash_mac_addrs);
 		rte_free(eth_dev->data->dev_private);
+		pthread_mutex_destroy(&eth_dev->data->flow_ops_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
lib/librte_ethdev/rte_ethdev.h +2 -0
index f4cc591..f07dbc4 100644
@@ -1684,6 +1684,8 @@ struct rte_eth_dev_owner {
 	char name[RTE_ETH_MAX_OWNER_NAME_LEN]; /**< The owner name. */
 };
 
+/** PMD supports thread-safe flow operations */
+#define RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE  0x0001
 /** Device supports link state interrupt */
 #define RTE_ETH_DEV_INTR_LSC     0x0002
 /** Device is a bonded slave */
lib/librte_ethdev/rte_ethdev_core.h +4 -0
index fd3bf92..918a34e 100644
@@ -5,6 +5,9 @@
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
+#include <pthread.h>
+#include <sys/types.h>
+
 /**
  * @file
  *
@@ -180,6 +183,7 @@ struct rte_eth_dev_data {
 			 *   Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
 			 */
 
+	pthread_mutex_t flow_ops_mutex; /**< rte_flow ops mutex. */
 	uint64_t reserved_64s[4]; /**< Reserved for future fields */
 	void *reserved_ptrs[4];   /**< Reserved for future fields */
 } __rte_cache_aligned;
lib/librte_ethdev/rte_flow.c +65 -19

160 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Acked-by on v5 2/2
#37 lore raw

Re: [dpdk-dev] [PATCH v5 2/2] ethdev: make rte_flow API thread safe

15/10/2020 03:07, Suanming Mou:

Quoted 37 lines

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or protect any concurrent calling for the rte_flow operations using a lock.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe is not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Quoted 4 lines
#38 lore raw

Re: [dpdk-dev] [PATCH v5 2/2] ethdev: make rte_flow API thread safe

Quoted 38 lines · Thomas Monjalon

15/10/2020 03:07, Suanming Mou:

Quoted 37 lines

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or protect any concurrent calling for the rte_flow operations using a lock.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe is not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Quoted 5 lines
Quoted 4 lines
#39 lore raw

Re: [dpdk-dev] [PATCH v5 0/2] ethdev: make rte_flow API thread safe

In reply to Suanming Mou

15/10/2020 03:07, Suanming Mou:

Quoted 37 lines

Currently, the rte_flow functions are not defined as thread safe. DPDK applications either call the functions in single thread or add locks around the functions for the critical section.

For PMDs support the flow operations thread safe natively, the redundant protection in application hurts the performance of the rte_flow operation functions.

And the restriction of thread safe not guaranteed for the rte_flow functions also limits the applications' expectation.

This feature is going to change the rte_flow functions to be thread safe. As different PMDs have different flow operations, some may support thread safe already and others may not. For PMDs don't support flow thread safe operation, a new lock is defined in ethdev in order to protects thread unsafe PMDs from rte_flow level.

A new RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE device flag is added to determine whether the PMD supports thread safe flow operation or not. For PMDs support thread safe flow operations, set the RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE flag, rte_flow level functions will skip the thread safe helper lock for these PMDs. Again the rte_flow level thread safe lock only works when PMD operation functions are not thread safe.

For the PMDs which don't want the default mutex lock, just set the flag in the PMD, and add the prefer type of lock in the PMD. Then the default mutex lock is easily replaced by the PMD level lock.

The change has no effect on the current DPDK applications. No change is required for the current DPDK applications. For the standard posix pthread_mutex, if no lock contention with the added rte_flow level mutex, the mutex only does the atomic increasing in pthread_mutex_lock() and decreasing in pthread_mutex_unlock(). No futex() syscall will be involved.

Quoted 3 lines

Suanming Mou (2):
eal/windows: add pthread mutex lock
ethdev: make rte_flow API thread safe

Applied, thanks