All of lore.kernel.org
 help / color / mirror / Atom feed
From: Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>
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
Subject: [dpdk-dev] [PATCH v2 6/6] Allow choice between internal EAL thread API and external lib
Date: Fri, 18 Jun 2021 18:57:58 -0700	[thread overview]
Message-ID: <1624067878-2130-7-git-send-email-navasile@linux.microsoft.com> (raw)
In-Reply-To: <1624067878-2130-1-git-send-email-navasile@linux.microsoft.com>

From: Narcisa Vasile <navasile@microsoft.com>

The user is offered the option of either using the RTE_THREAD_* API or
a 3rd party thread library, through a meson flag called
"use_external_thread_lib". By default, this flag is set to FALSE,
which means Windows libraries and applications will use the RTE_THREAD_*
API for managing threads.

If compiling on Windows and the "use_external_thread_lib" is *not* set,
the following files will be parsed:
* include/rte_thread.h
* windows/rte_thread.c
In all other cases, the compilation/parsing includes the following files:
* include/rte_thread.h
* common/rte_thread.c

Depends-on: series-17402 ("eal: Add EAL API for threading")

Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
---
 config/meson.build                |   1 -
 lib/eal/windows/include/pthread.h | 192 ------------------------------
 lib/eal/windows/meson.build       |   7 +-
 meson_options.txt                 |   2 +
 4 files changed, 8 insertions(+), 194 deletions(-)
 delete mode 100644 lib/eal/windows/include/pthread.h

diff --git a/config/meson.build b/config/meson.build
index 017bb2efbb..9309010f21 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -262,7 +262,6 @@ else # for 32-bit we need smaller reserved memory areas
     dpdk_conf.set('RTE_MAX_MEM_MB', 2048)
 endif
 
-
 compile_time_cpuflags = []
 subdir(arch_subdir)
 dpdk_conf.set('RTE_COMPILE_TIME_CPUFLAGS', ','.join(compile_time_cpuflags))
diff --git a/lib/eal/windows/include/pthread.h b/lib/eal/windows/include/pthread.h
deleted file mode 100644
index 27fd2cca52..0000000000
--- a/lib/eal/windows/include/pthread.h
+++ /dev/null
@@ -1,192 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019 Intel Corporation
- */
-
-#ifndef _PTHREAD_H_
-#define _PTHREAD_H_
-
-#include <stdint.h>
-#include <sched.h>
-
-/**
- * This file is required to support the common code in eal_common_proc.c,
- * eal_common_thread.c and common\include\rte_per_lcore.h as Microsoft libc
- * does not contain pthread.h. This may be removed in future releases.
- */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <rte_common.h>
-#include <rte_windows.h>
-
-#define PTHREAD_BARRIER_SERIAL_THREAD TRUE
-
-/* defining pthread_t type on Windows since there is no in Microsoft libc*/
-typedef uintptr_t pthread_t;
-
-/* 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) \
-	!InitializeSynchronizationBarrier(barrier, count, -1)
-#define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \
-	SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY)
-#define pthread_barrier_destroy(barrier) \
-	!DeleteSynchronizationBarrier(barrier)
-#define pthread_cancel(thread) !TerminateThread((HANDLE) thread, 0)
-
-/* pthread function overrides */
-#define pthread_self() \
-	((pthread_t)GetCurrentThreadId())
-
-
-static inline int
-pthread_equal(pthread_t t1, pthread_t t2)
-{
-	return t1 == t2;
-}
-
-static inline int
-pthread_setaffinity_np(pthread_t threadid, size_t cpuset_size,
-			rte_cpuset_t *cpuset)
-{
-	DWORD_PTR ret = 0;
-	HANDLE thread_handle;
-
-	if (cpuset == NULL || cpuset_size == 0)
-		return -1;
-
-	thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, threadid);
-	if (thread_handle == NULL) {
-		RTE_LOG_WIN32_ERR("OpenThread()");
-		return -1;
-	}
-
-	ret = SetThreadAffinityMask(thread_handle, *cpuset->_bits);
-	if (ret == 0) {
-		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
-		goto close_handle;
-	}
-
-close_handle:
-	if (CloseHandle(thread_handle) == 0) {
-		RTE_LOG_WIN32_ERR("CloseHandle()");
-		return -1;
-	}
-	return (ret == 0) ? -1 : 0;
-}
-
-static inline int
-pthread_getaffinity_np(pthread_t threadid, size_t cpuset_size,
-			rte_cpuset_t *cpuset)
-{
-	/* Workaround for the lack of a GetThreadAffinityMask()
-	 *API in Windows
-	 */
-	DWORD_PTR prev_affinity_mask;
-	HANDLE thread_handle;
-	DWORD_PTR ret = 0;
-
-	if (cpuset == NULL || cpuset_size == 0)
-		return -1;
-
-	thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, threadid);
-	if (thread_handle == NULL) {
-		RTE_LOG_WIN32_ERR("OpenThread()");
-		return -1;
-	}
-
-	/* obtain previous mask by setting dummy mask */
-	prev_affinity_mask = SetThreadAffinityMask(thread_handle, 0x1);
-	if (prev_affinity_mask == 0) {
-		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
-		goto close_handle;
-	}
-
-	/* set it back! */
-	ret = SetThreadAffinityMask(thread_handle, prev_affinity_mask);
-	if (ret == 0) {
-		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
-		goto close_handle;
-	}
-
-	memset(cpuset, 0, cpuset_size);
-	*cpuset->_bits = prev_affinity_mask;
-
-close_handle:
-	if (CloseHandle(thread_handle) == 0) {
-		RTE_LOG_WIN32_ERR("SetThreadAffinityMask()");
-		return -1;
-	}
-	return (ret == 0) ? -1 : 0;
-}
-
-static inline int
-pthread_create(void *threadid, const void *threadattr, void *threadfunc,
-		void *args)
-{
-	RTE_SET_USED(threadattr);
-	HANDLE hThread;
-	hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc,
-		args, 0, (LPDWORD)threadid);
-	if (hThread) {
-		SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
-		SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL);
-	}
-	return ((hThread != NULL) ? 0 : E_FAIL);
-}
-
-static inline int
-pthread_detach(__rte_unused pthread_t thread)
-{
-	return 0;
-}
-
-static inline int
-pthread_join(__rte_unused pthread_t thread,
-	__rte_unused void **value_ptr)
-{
-	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
-
-#endif /* _PTHREAD_H_ */
diff --git a/lib/eal/windows/meson.build b/lib/eal/windows/meson.build
index ff9cbec417..4b7db4754b 100644
--- a/lib/eal/windows/meson.build
+++ b/lib/eal/windows/meson.build
@@ -19,7 +19,12 @@ sources += files(
         'eal_timer.c',
         'fnmatch.c',
         'getopt.c',
-        'rte_thread.c',
 )
 
+if get_option('use_external_thread_lib')
+	sources += 'eal/common/rte_thread.c'
+else
+	sources += 'eal/windows/rte_thread.c'
+endif
+
 dpdk_conf.set10('RTE_EAL_NUMA_AWARE_HUGEPAGES', true)
diff --git a/meson_options.txt b/meson_options.txt
index 56bdfd0f0a..2606c8b3a4 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -44,3 +44,5 @@ option('tests', type: 'boolean', value: true, description:
        'build unit tests')
 option('use_hpet', type: 'boolean', value: false, description:
        'use HPET timer in EAL')
+option('use_external_thread_lib', type: 'boolean', value: false,
+	description: 'use an external thread library')
-- 
2.31.0.vfs.0.1


  parent reply	other threads:[~2021-06-19  1:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 21:54 [dpdk-dev] [PATCH 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile
2021-06-19  1:57 ` [dpdk-dev] [PATCH v2 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-06-19  1:57   ` [dpdk-dev] [PATCH v2 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-06-20 23:53     ` Dmitry Kozlyuk
2021-06-19  1:57   ` [dpdk-dev] [PATCH v2 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-06-19  1:57   ` [dpdk-dev] [PATCH v2 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-06-19  1:57   ` [dpdk-dev] [PATCH v2 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-06-19  1:57   ` [dpdk-dev] [PATCH v2 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-06-19  1:57   ` Narcisa Ana Maria Vasile [this message]
2021-08-18 13:44   ` [dpdk-dev] [PATCH v3 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-08-18 13:44     ` [dpdk-dev] [PATCH v3 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-08-18 19:42       ` Tal Shnaiderman
2021-08-18 13:44     ` [dpdk-dev] [PATCH v3 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-08-18 13:44     ` [dpdk-dev] [PATCH v3 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-08-18 13:44     ` [dpdk-dev] [PATCH v3 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-08-18 13:44     ` [dpdk-dev] [PATCH v3 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-08-18 13:44     ` [dpdk-dev] [PATCH v3 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile
2021-08-18 21:19       ` [dpdk-dev] [PATCH v4 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-08-18 21:19         ` [dpdk-dev] [PATCH v4 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-08-18 21:19         ` [dpdk-dev] [PATCH v4 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-08-18 21:19         ` [dpdk-dev] [PATCH v4 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-08-18 21:19         ` [dpdk-dev] [PATCH v4 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-08-18 21:19         ` [dpdk-dev] [PATCH v4 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-08-18 21:19         ` [dpdk-dev] [PATCH v4 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1624067878-2130-7-git-send-email-navasile@linux.microsoft.com \
    --to=navasile@linux.microsoft.com \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=khot@microsoft.com \
    --cc=navasile@microsoft.com \
    --cc=ocardona@microsoft.com \
    --cc=pallavi.kadam@intel.com \
    --cc=roretzla@microsoft.com \
    --cc=talshn@nvidia.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.