From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F1DEDA034F; Tue, 30 Mar 2021 00:41:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1AE85140EA0; Tue, 30 Mar 2021 00:40:56 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id A6267140E42 for ; Tue, 30 Mar 2021 00:40:45 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1059) id 42C7820B5688; Mon, 29 Mar 2021 15:40:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 42C7820B5688 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1617057644; bh=1Yi8/sDeNgqIK6+ca1ytYi9BVDUg6s2WLisc/0grUYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SI6+ttwC9hGVlhETlZ8NYpNwOBANsOhKR2gUbrMaR7OLKhEWreav4bVwMZ5rB94s/ k9qmqIqeXft2FGCiyzOfNUQyqDRyBNAFHlw/sFUhS9j6hil/jv7J4/o4DQNxn+hi8p 14qAEKXJqnV9WdbCnRJbWUqkpyP2K2Ut7x1k4hyE= From: Narcisa Ana Maria Vasile To: dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com, khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com, roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com Cc: bruce.richardson@intel.com, david.marchand@redhat.com, pallavi.kadam@intel.com Date: Mon, 29 Mar 2021 15:40:38 -0700 Message-Id: <1617057640-24301-9-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1617057640-24301-1-git-send-email-navasile@linux.microsoft.com> References: <1616802771-31578-10-git-send-email-navasile@linux.microsoft.com> <1617057640-24301-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v5 08/10] eal: implement functions for thread barrier management X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Narcisa Vasile Add functions for barrier init, destroy, wait. Signed-off-by: Narcisa Vasile --- 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(+) diff --git a/lib/librte_eal/common/rte_thread.c b/lib/librte_eal/common/rte_thread.c index 8e963ed65..d23d3b868 100644 --- a/lib/librte_eal/common/rte_thread.c +++ b/lib/librte_eal/common/rte_thread.c @@ -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) { /* diff --git a/lib/librte_eal/include/rte_thread.h b/lib/librte_eal/include/rte_thread.h index 2b8d81005..5b4da8053 100644 --- a/lib/librte_eal/include/rte_thread.h +++ b/lib/librte_eal/include/rte_thread.h @@ -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. * 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 +#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 +#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_ */ diff --git a/lib/librte_eal/windows/rte_thread.c b/lib/librte_eal/windows/rte_thread.c index a26b8c08f..c3c198663 100644 --- a/lib/librte_eal/windows/rte_thread.c +++ b/lib/librte_eal/windows/rte_thread.c @@ -445,6 +445,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(GetLastError()); + 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) { -- 2.30.0.vfs.0.2