[v6,08/10] eal: implement functions for thread barrier management
Checks
Commit Message
From: Narcisa Vasile <navasile@microsoft.com>
Add functions for barrier init, destroy, wait.
Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
---
lib/librte_eal/common/rte_thread.c | 16 +++++++
lib/librte_eal/include/rte_thread.h | 46 +++++++++++++++++++
lib/librte_eal/include/rte_thread_types.h | 2 +
.../include/rte_windows_thread_types.h | 3 ++
lib/librte_eal/windows/rte_thread.c | 27 +++++++++++
5 files changed, 94 insertions(+)
Comments
2021-04-02 18:39 (UTC-0700), Narcisa Ana Maria Vasile:
> [...]
> diff --git a/lib/librte_eal/include/rte_thread_types.h b/lib/librte_eal/include/rte_thread_types.h
> index 37bc7af2b..b055bbf67 100644
> --- a/lib/librte_eal/include/rte_thread_types.h
> +++ b/lib/librte_eal/include/rte_thread_types.h
> @@ -7,6 +7,7 @@
>
> #include <pthread.h>
>
> +#define RTE_THREAD_BARRIER_SERIAL_THREAD PTHREAD_BARRIER_SERIAL_THREAD
> #define RTE_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
>
> #define EAL_THREAD_PRIORITY_NORMAL 0
> @@ -14,5 +15,6 @@
>
> typedef pthread_t rte_thread_t;
> typedef pthread_mutex_t rte_thread_mutex_t;
> +typedef pthread_barrier_t rte_thread_barrier_t;
>
> #endif /* _RTE_THREAD_TYPES_H_ */
> diff --git a/lib/librte_eal/windows/include/rte_windows_thread_types.h b/lib/librte_eal/windows/include/rte_windows_thread_types.h
> index 47c6b2664..b6209e6eb 100644
> --- a/lib/librte_eal/windows/include/rte_windows_thread_types.h
> +++ b/lib/librte_eal/windows/include/rte_windows_thread_types.h
> @@ -7,10 +7,13 @@
>
> #include <rte_windows.h>
>
> +#define RTE_THREAD_BARRIER_SERIAL_THREAD TRUE
> +
> #define EAL_THREAD_PRIORITY_NORMAL THREAD_PRIORITY_NORMAL
> #define EAL_THREAD_PRIORITY_REALTIME_CIRTICAL THREAD_PRIORITY_TIME_CRITICAL
>
> typedef DWORD rte_thread_t;
> typedef CRITICAL_SECTION rte_thread_mutex_t;
> +typedef SYNCHRONIZATION_BARRIER rte_thread_barrier_t;
>
> #endif /* _RTE_THREAD_TYPES_H_ */
Please ensure that for both backends
sizeof(rte_thread_barrier_t) is the same
and RTE_THREAD_BARRIER_SERIAL_THREAD has same value.
@@ -244,6 +244,22 @@ rte_thread_mutex_destroy(rte_thread_mutex_t *mutex)
return pthread_mutex_destroy(mutex);
}
+int
+rte_thread_barrier_init(rte_thread_barrier_t *barrier, int count)
+{
+ return pthread_barrier_init(barrier, NULL, count);
+}
+
+int rte_thread_barrier_wait(rte_thread_barrier_t *barrier)
+{
+ return pthread_barrier_wait(barrier);
+}
+
+int rte_thread_barrier_destroy(rte_thread_barrier_t *barrier)
+{
+ return pthread_barrier_destroy(barrier);
+}
+
int rte_thread_cancel(rte_thread_t thread_id)
{
/*
@@ -292,6 +292,52 @@ int rte_thread_mutex_unlock(rte_thread_mutex_t *mutex);
__rte_experimental
int rte_thread_mutex_destroy(rte_thread_mutex_t *mutex);
+/**
+ * Initializes a synchronization barrier.
+ *
+ * @param barrier
+ * A pointer that references the newly created 'barrier' object.
+ *
+ * @param count
+ * The number of threads that must enter the barrier before
+ * the threads can continue execution.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
+ */
+__rte_experimental
+int rte_thread_barrier_init(rte_thread_barrier_t *barrier, int count);
+
+/**
+ * Causes the calling thread to wait at the synchronization barrier 'barrier'.
+ *
+ * @param barrier
+ * The barrier used for synchronizing the threads.
+ *
+ * @return
+ * Return RTE_THREAD_BARRIER_SERIAL_THREAD for the thread synchronized
+ * at the barrier.
+ * Return 0 for all other threads.
+ * Return a positive errno-style error number, in case of failure.
+ */
+__rte_experimental
+int rte_thread_barrier_wait(rte_thread_barrier_t *barrier);
+
+/**
+ * Releases all resources used by a synchronization barrier
+ * and uninitializes it.
+ *
+ * @param barrier
+ * The barrier to be destroyed.
+ *
+ * @return
+ * On success, return 0.
+ * On failure, return a positive errno-style error number.
+ */
+__rte_experimental
+int rte_thread_barrier_destroy(rte_thread_barrier_t *barrier);
+
/**
* Terminates a thread.
*
@@ -7,6 +7,7 @@
#include <pthread.h>
+#define RTE_THREAD_BARRIER_SERIAL_THREAD PTHREAD_BARRIER_SERIAL_THREAD
#define RTE_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define EAL_THREAD_PRIORITY_NORMAL 0
@@ -14,5 +15,6 @@
typedef pthread_t rte_thread_t;
typedef pthread_mutex_t rte_thread_mutex_t;
+typedef pthread_barrier_t rte_thread_barrier_t;
#endif /* _RTE_THREAD_TYPES_H_ */
@@ -7,10 +7,13 @@
#include <rte_windows.h>
+#define RTE_THREAD_BARRIER_SERIAL_THREAD TRUE
+
#define EAL_THREAD_PRIORITY_NORMAL THREAD_PRIORITY_NORMAL
#define EAL_THREAD_PRIORITY_REALTIME_CIRTICAL THREAD_PRIORITY_TIME_CRITICAL
typedef DWORD rte_thread_t;
typedef CRITICAL_SECTION rte_thread_mutex_t;
+typedef SYNCHRONIZATION_BARRIER rte_thread_barrier_t;
#endif /* _RTE_THREAD_TYPES_H_ */
@@ -449,6 +449,33 @@ rte_thread_mutex_destroy(rte_thread_mutex_t *mutex)
return 0;
}
+int
+rte_thread_barrier_init(rte_thread_barrier_t *barrier, int count)
+{
+ int ret = 0;
+
+ if (!InitializeSynchronizationBarrier(barrier, count, -1)) {
+ ret = rte_thread_translate_win32_error();
+ RTE_LOG_WIN32_ERR("InitializeSynchronizationBarrier()");
+ return ret;
+ }
+ return 0;
+}
+
+int
+rte_thread_barrier_wait(rte_thread_barrier_t *barrier)
+{
+ return EnterSynchronizationBarrier(barrier,
+ SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY);
+}
+
+int
+rte_thread_barrier_destroy(rte_thread_barrier_t *barrier)
+{
+ DeleteSynchronizationBarrier(barrier);
+ return 0;
+}
+
int
rte_thread_cancel(rte_thread_t thread_id)
{