[v4,4/6] lib: enable the new EAL thread API

Message ID 1629321579-10788-5-git-send-email-navasile@linux.microsoft.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series Enable the internal EAL thread API |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Narcisa Ana Maria Vasile Aug. 18, 2021, 9:19 p.m. UTC
From: Narcisa Vasile <navasile@microsoft.com>

Rename pthread* with the new rte_thread* API.

Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
---
 lib/eal/common/eal_common_options.c     |  6 ++---
 lib/eal/common/eal_common_thread.c      | 13 +++++----
 lib/eal/common/eal_common_trace.c       |  1 +
 lib/eal/common/eal_private.h            |  2 +-
 lib/eal/common/malloc_mp.c              |  2 ++
 lib/eal/freebsd/eal.c                   | 18 ++++++-------
 lib/eal/freebsd/eal_alarm.c             | 12 ++++-----
 lib/eal/freebsd/eal_interrupts.c        |  6 ++---
 lib/eal/freebsd/eal_thread.c            | 10 ++++---
 lib/eal/include/rte_lcore.h             |  6 +++++
 lib/eal/include/rte_per_lcore.h         |  2 +-
 lib/eal/linux/eal.c                     | 22 ++++++++--------
 lib/eal/linux/eal_alarm.c               | 10 ++++---
 lib/eal/linux/eal_interrupts.c          |  8 +++---
 lib/eal/linux/eal_thread.c              | 11 +++++---
 lib/eal/linux/eal_timer.c               |  6 ++---
 lib/eal/version.map                     |  4 +--
 lib/eal/windows/eal.c                   |  4 ++-
 lib/eal/windows/eal_interrupts.c        |  8 +++---
 lib/eal/windows/eal_thread.c            | 35 ++++---------------------
 lib/eal/windows/eal_windows.h           | 10 -------
 lib/eal/windows/include/rte_windows.h   |  1 +
 lib/ethdev/rte_ethdev.c                 |  4 +--
 lib/ethdev/rte_ethdev_core.h            |  4 +--
 lib/ethdev/rte_flow.c                   |  4 +--
 lib/eventdev/rte_event_eth_rx_adapter.c |  1 +
 lib/vhost/vhost.c                       |  1 +
 27 files changed, 99 insertions(+), 112 deletions(-)
  

Patch

diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index 9d29696b84..1f6aba498c 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -1872,8 +1872,7 @@  eal_auto_detect_cores(struct rte_config *cfg)
 	unsigned int removed = 0;
 	rte_cpuset_t affinity_set;
 
-	if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
-				&affinity_set))
+	if (rte_thread_get_affinity_by_id(rte_thread_self(), &affinity_set))
 		CPU_ZERO(&affinity_set);
 
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
@@ -1901,8 +1900,7 @@  compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 	}
 	RTE_CPU_NOT(cpuset, cpuset);
 
-	if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
-				&default_set))
+	if (rte_thread_get_affinity_by_id(rte_thread_self(), &default_set))
 		CPU_ZERO(&default_set);
 
 	RTE_CPU_AND(cpuset, cpuset, &default_set);
diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 79545c67d9..62d28e7b28 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -6,7 +6,10 @@ 
 #include <stdlib.h>
 #include <stdint.h>
 #include <unistd.h>
+#ifndef RTE_EXEC_ENV_WINDOWS
 #include <pthread.h>
+#endif /* RTE_EXEC_ENV_WINDOWS */
+#include <rte_thread.h>
 #include <signal.h>
 #include <sched.h>
 #include <assert.h>
@@ -86,9 +89,8 @@  thread_update_affinity(rte_cpuset_t *cpusetp)
 int
 rte_thread_set_affinity(rte_cpuset_t *cpusetp)
 {
-	if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
-			cpusetp) != 0) {
-		RTE_LOG(ERR, EAL, "pthread_setaffinity_np failed\n");
+	if (rte_thread_set_affinity_by_id(rte_thread_self(), cpusetp) != 0) {
+		RTE_LOG(ERR, EAL, "rte_thread_set_affinity_by_id failed\n");
 		return -1;
 	}
 
@@ -166,6 +168,7 @@  __rte_thread_uninit(void)
 	RTE_PER_LCORE(_lcore_id) = LCORE_ID_ANY;
 }
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 struct rte_thread_ctrl_params {
 	void *(*start_routine)(void *);
 	void *arg;
@@ -258,6 +261,7 @@  rte_ctrl_thread_create(pthread_t *thread, const char *name,
 
 	return -ret;
 }
+#endif
 
 struct rte_thread_ctrl_ctx {
 	rte_thread_func start_routine;
@@ -357,8 +361,7 @@  rte_thread_register(void)
 		rte_errno = EINVAL;
 		return -1;
 	}
-	if (pthread_getaffinity_np(pthread_self(), sizeof(cpuset),
-			&cpuset) != 0)
+	if (rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset) != 0)
 		CPU_ZERO(&cpuset);
 	lcore_id = eal_lcore_non_eal_allocate();
 	if (lcore_id >= RTE_MAX_LCORE)
diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 7bff1cd2ce..94323e2c28 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -7,6 +7,7 @@ 
 #include <sys/queue.h>
 #include <regex.h>
 
+#include <pthread.h>
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
index 64cf4e81c8..4b95001d7d 100644
--- a/lib/eal/common/eal_private.h
+++ b/lib/eal/common/eal_private.h
@@ -19,7 +19,7 @@ 
  * Structure storing internal configuration (per-lcore)
  */
 struct lcore_config {
-	pthread_t thread_id;       /**< pthread identifier */
+	rte_thread_t thread_id;       /**< pthread identifier */
 	int pipe_main2worker[2];   /**< communication pipe with main */
 	int pipe_worker2main[2];   /**< communication pipe with main */
 
diff --git a/lib/eal/common/malloc_mp.c b/lib/eal/common/malloc_mp.c
index 2e597a17a2..7f7109d954 100644
--- a/lib/eal/common/malloc_mp.c
+++ b/lib/eal/common/malloc_mp.c
@@ -5,6 +5,8 @@ 
 #include <string.h>
 #include <sys/time.h>
 
+#include <pthread.h>
+
 #include <rte_alarm.h>
 #include <rte_errno.h>
 #include <rte_string_fns.h>
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 6cee5ae369..c92fdaa598 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -9,7 +9,7 @@ 
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
-#include <pthread.h>
+#include <rte_thread.h>
 #include <syslog.h>
 #include <getopt.h>
 #include <sys/file.h>
@@ -669,7 +669,7 @@  int
 rte_eal_init(int argc, char **argv)
 {
 	int i, fctret, ret;
-	pthread_t thread_id;
+	rte_thread_t thread_id;
 	static uint32_t run_once;
 	uint32_t has_run = 0;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
@@ -692,7 +692,7 @@  rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	thread_id = pthread_self();
+	thread_id = rte_thread_self();
 
 	eal_reset_internal_config(internal_conf);
 
@@ -856,7 +856,7 @@  rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
+	if (rte_thread_set_affinity_by_id(rte_thread_self(),
 			&lcore_config[config->main_lcore].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
@@ -868,7 +868,7 @@  rte_eal_init(int argc, char **argv)
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 
 	RTE_LOG(DEBUG, EAL, "Main lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
-		config->main_lcore, thread_id, cpuset,
+		config->main_lcore, (void *)thread_id.opaque_id, cpuset,
 		ret == 0 ? "" : "...");
 
 	RTE_LCORE_FOREACH_WORKER(i) {
@@ -885,7 +885,7 @@  rte_eal_init(int argc, char **argv)
 		lcore_config[i].state = WAIT;
 
 		/* create a thread for each lcore */
-		ret = pthread_create(&lcore_config[i].thread_id, NULL,
+		ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
 				     eal_thread_loop, NULL);
 		if (ret != 0)
 			rte_panic("Cannot create thread\n");
@@ -893,10 +893,10 @@  rte_eal_init(int argc, char **argv)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 				"lcore-worker-%d", i);
-		rte_thread_setname(lcore_config[i].thread_id, thread_name);
+		rte_thread_name_set(lcore_config[i].thread_id, thread_name);
 
-		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
-			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
+		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
+				&lcore_config[i].cpuset);
 		if (ret != 0)
 			rte_panic("Cannot set affinity\n");
 	}
diff --git a/lib/eal/freebsd/eal_alarm.c b/lib/eal/freebsd/eal_alarm.c
index c38b2e04f8..e5d7b130b1 100644
--- a/lib/eal/freebsd/eal_alarm.c
+++ b/lib/eal/freebsd/eal_alarm.c
@@ -37,7 +37,7 @@  struct alarm_entry {
 	rte_eal_alarm_callback cb_fn;
 	void *cb_arg;
 	volatile uint8_t executing;
-	volatile pthread_t executing_id;
+	volatile rte_thread_t executing_id;
 };
 
 static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER();
@@ -156,7 +156,7 @@  eal_alarm_callback(void *arg __rte_unused)
 
 	while (ap != NULL && timespec_cmp(&now, &ap->time) >= 0) {
 		ap->executing = 1;
-		ap->executing_id = pthread_self();
+		ap->executing_id = rte_thread_self();
 		rte_spinlock_unlock(&alarm_list_lk);
 
 		ap->cb_fn(ap->cb_arg);
@@ -263,8 +263,8 @@  rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
 				 * finish. Otherwise we are trying to cancel
 				 * ourselves - mark it by EINPROGRESS.
 				 */
-				if (pthread_equal(ap->executing_id,
-						pthread_self()) == 0)
+				if (rte_thread_equal(ap->executing_id,
+						rte_thread_self()) == 0)
 					executing++;
 				else
 					err = EINPROGRESS;
@@ -285,8 +285,8 @@  rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
 					free(ap);
 					count++;
 					ap = ap_prev;
-				} else if (pthread_equal(ap->executing_id,
-							 pthread_self()) == 0) {
+				} else if (rte_thread_equal(ap->executing_id,
+						rte_thread_self()) == 0) {
 					executing++;
 				} else {
 					err = EINPROGRESS;
diff --git a/lib/eal/freebsd/eal_interrupts.c b/lib/eal/freebsd/eal_interrupts.c
index 86810845fe..61b6ef1f48 100644
--- a/lib/eal/freebsd/eal_interrupts.c
+++ b/lib/eal/freebsd/eal_interrupts.c
@@ -52,7 +52,7 @@  static rte_spinlock_t intr_lock = RTE_SPINLOCK_INITIALIZER;
 static struct rte_intr_source_list intr_sources;
 
 /* interrupt handling thread */
-static pthread_t intr_thread;
+static rte_thread_t intr_thread;
 
 static volatile int kq = -1;
 
@@ -628,7 +628,7 @@  rte_eal_intr_init(void)
 	}
 
 	/* create the host thread to wait/handle the interrupt */
-	ret = rte_ctrl_thread_create(&intr_thread, "eal-intr-thread", NULL,
+	ret = rte_thread_ctrl_thread_create(&intr_thread, "eal-intr-thread",
 			eal_intr_thread_main, NULL);
 	if (ret != 0) {
 		rte_errno = -ret;
@@ -737,5 +737,5 @@  rte_intr_free_epoll_fd(struct rte_intr_handle *intr_handle)
 
 int rte_thread_is_intr(void)
 {
-	return pthread_equal(intr_thread, pthread_self());
+	return rte_thread_equal(intr_thread, rte_thread_self());
 }
diff --git a/lib/eal/freebsd/eal_thread.c b/lib/eal/freebsd/eal_thread.c
index 1dce9b04f2..8c572c7930 100644
--- a/lib/eal/freebsd/eal_thread.c
+++ b/lib/eal/freebsd/eal_thread.c
@@ -9,6 +9,7 @@ 
 #include <unistd.h>
 #include <sched.h>
 #include <pthread_np.h>
+#include <rte_thread.h>
 #include <sys/queue.h>
 #include <sys/thr.h>
 
@@ -73,15 +74,16 @@  eal_thread_loop(__rte_unused void *arg)
 	char c;
 	int n, ret;
 	unsigned lcore_id;
-	pthread_t thread_id;
+	rte_thread_t thread_id;
 	int m2w, w2m;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 
-	thread_id = pthread_self();
+	thread_id = rte_thread_self();
 
 	/* retrieve our lcore_id from the configuration structure */
 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
-		if (thread_id == lcore_config[lcore_id].thread_id)
+		if (rte_thread_equal(thread_id,
+				lcore_config[lcore_id].thread_id))
 			break;
 	}
 	if (lcore_id == RTE_MAX_LCORE)
@@ -94,7 +96,7 @@  eal_thread_loop(__rte_unused void *arg)
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
-		lcore_id, thread_id, cpuset, ret == 0 ? "" : "...");
+		lcore_id, (void *)thread_id.opaque_id, cpuset, ret == 0 ? "" : "...");
 
 	rte_eal_trace_thread_lcore_ready(lcore_id, cpuset);
 
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 1550b75da0..8fab21299a 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -362,6 +362,7 @@  __rte_experimental
 void
 rte_lcore_dump(FILE *f);
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 /**
  * Set thread names.
  *
@@ -393,6 +394,8 @@  int rte_thread_setname(pthread_t id, const char *name);
 __rte_experimental
 int rte_thread_getname(pthread_t id, char *name, size_t len);
 
+#endif /* !RTE_EXEC_ENV_WINDOWS */
+
 /**
  * Register current non-EAL thread as a lcore.
  *
@@ -417,6 +420,7 @@  __rte_experimental
 void
 rte_thread_unregister(void);
 
+#ifndef RTE_EXEC_ENV_WINDOWS
 /**
  * Create a control thread.
  *
@@ -444,6 +448,8 @@  rte_ctrl_thread_create(pthread_t *thread, const char *name,
 		const pthread_attr_t *attr,
 		void *(*start_routine)(void *), void *arg);
 
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/eal/include/rte_per_lcore.h b/lib/eal/include/rte_per_lcore.h
index eaedf0cb37..df1e51dcb8 100644
--- a/lib/eal/include/rte_per_lcore.h
+++ b/lib/eal/include/rte_per_lcore.h
@@ -22,7 +22,7 @@ 
 extern "C" {
 #endif
 
-#include <pthread.h>
+#include <rte_thread.h>
 
 /**
  * Macro to define a per lcore variable "var" of type "type", don't
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 3577eaeaa4..cd5e9953d0 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -9,7 +9,7 @@ 
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
-#include <pthread.h>
+#include <rte_thread.h>
 #include <syslog.h>
 #include <getopt.h>
 #include <sys/file.h>
@@ -965,7 +965,7 @@  int
 rte_eal_init(int argc, char **argv)
 {
 	int i, fctret, ret;
-	pthread_t thread_id;
+	rte_thread_t thread_id;
 	static uint32_t run_once;
 	uint32_t has_run = 0;
 	const char *p;
@@ -993,7 +993,7 @@  rte_eal_init(int argc, char **argv)
 
 	p = strrchr(argv[0], '/');
 	strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
-	thread_id = pthread_self();
+	thread_id = rte_thread_self();
 
 	eal_reset_internal_config(internal_conf);
 
@@ -1221,7 +1221,7 @@  rte_eal_init(int argc, char **argv)
 
 	eal_check_mem_on_local_socket();
 
-	if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
+	if (rte_thread_set_affinity_by_id(rte_thread_self(),
 			&lcore_config[config->main_lcore].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
@@ -1231,8 +1231,8 @@  rte_eal_init(int argc, char **argv)
 		&lcore_config[config->main_lcore].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
-	RTE_LOG(DEBUG, EAL, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
-		config->main_lcore, (uintptr_t)thread_id, cpuset,
+	RTE_LOG(DEBUG, EAL, "Main lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
+		config->main_lcore, (void *)thread_id.opaque_id, cpuset,
 		ret == 0 ? "" : "...");
 
 	RTE_LCORE_FOREACH_WORKER(i) {
@@ -1249,7 +1249,7 @@  rte_eal_init(int argc, char **argv)
 		lcore_config[i].state = WAIT;
 
 		/* create a thread for each lcore */
-		ret = pthread_create(&lcore_config[i].thread_id, NULL,
+		ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
 				     eal_thread_loop, NULL);
 		if (ret != 0)
 			rte_panic("Cannot create thread\n");
@@ -1257,14 +1257,14 @@  rte_eal_init(int argc, char **argv)
 		/* Set thread_name for aid in debugging. */
 		snprintf(thread_name, sizeof(thread_name),
 			"lcore-worker-%d", i);
-		ret = rte_thread_setname(lcore_config[i].thread_id,
-						thread_name);
+		ret = rte_thread_name_set(lcore_config[i].thread_id,
+				thread_name);
 		if (ret != 0)
 			RTE_LOG(DEBUG, EAL,
 				"Cannot set name for lcore thread\n");
 
-		ret = pthread_setaffinity_np(lcore_config[i].thread_id,
-			sizeof(rte_cpuset_t), &lcore_config[i].cpuset);
+		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
+				&lcore_config[i].cpuset);
 		if (ret != 0)
 			rte_panic("Cannot set affinity\n");
 	}
diff --git a/lib/eal/linux/eal_alarm.c b/lib/eal/linux/eal_alarm.c
index 3252c6fa59..fef22a347c 100644
--- a/lib/eal/linux/eal_alarm.c
+++ b/lib/eal/linux/eal_alarm.c
@@ -48,7 +48,7 @@  struct alarm_entry {
 	rte_eal_alarm_callback cb_fn;
 	void *cb_arg;
 	volatile uint8_t executing;
-	volatile pthread_t executing_id;
+	volatile rte_thread_t executing_id;
 };
 
 static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER();
@@ -86,7 +86,7 @@  eal_alarm_callback(void *arg __rte_unused)
 			(ap->time.tv_sec < now.tv_sec || (ap->time.tv_sec == now.tv_sec &&
 						(ap->time.tv_usec * NS_PER_US) <= now.tv_nsec))) {
 		ap->executing = 1;
-		ap->executing_id = pthread_self();
+		ap->executing_id = rte_thread_self();
 		rte_spinlock_unlock(&alarm_list_lk);
 
 		ap->cb_fn(ap->cb_arg);
@@ -207,7 +207,8 @@  rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
 				/* If calling from other context, mark that alarm is executing
 				 * so loop can spin till it finish. Otherwise we are trying to
 				 * cancel our self - mark it by EINPROGRESS */
-				if (pthread_equal(ap->executing_id, pthread_self()) == 0)
+				if (rte_thread_equal(ap->executing_id,
+						rte_thread_self()) == 0)
 					executing++;
 				else
 					err = EINPROGRESS;
@@ -228,7 +229,8 @@  rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
 					free(ap);
 					count++;
 					ap = ap_prev;
-				} else if (pthread_equal(ap->executing_id, pthread_self()) == 0)
+				} else if (rte_thread_equal(ap->executing_id,
+						rte_thread_self()) == 0)
 					executing++;
 				else
 					err = EINPROGRESS;
diff --git a/lib/eal/linux/eal_interrupts.c b/lib/eal/linux/eal_interrupts.c
index 22b3b7bcd9..d8ce854d90 100644
--- a/lib/eal/linux/eal_interrupts.c
+++ b/lib/eal/linux/eal_interrupts.c
@@ -5,7 +5,7 @@ 
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <pthread.h>
+#include <rte_thread.h>
 #include <sys/queue.h>
 #include <stdarg.h>
 #include <unistd.h>
@@ -97,7 +97,7 @@  static union intr_pipefds intr_pipe;
 static struct rte_intr_source_list intr_sources;
 
 /* interrupt handling thread */
-static pthread_t intr_thread;
+static rte_thread_t intr_thread;
 
 /* VFIO interrupts */
 #ifdef VFIO_PRESENT
@@ -1167,7 +1167,7 @@  rte_eal_intr_init(void)
 	}
 
 	/* create the host thread to wait/handle the interrupt */
-	ret = rte_ctrl_thread_create(&intr_thread, "eal-intr-thread", NULL,
+	ret = rte_thread_ctrl_thread_create(&intr_thread, "eal-intr-thread",
 			eal_intr_thread_main, NULL);
 	if (ret != 0) {
 		rte_errno = -ret;
@@ -1570,5 +1570,5 @@  rte_intr_cap_multiple(struct rte_intr_handle *intr_handle)
 
 int rte_thread_is_intr(void)
 {
-	return pthread_equal(intr_thread, pthread_self());
+	return rte_thread_equal(intr_thread, rte_thread_self());
 }
diff --git a/lib/eal/linux/eal_thread.c b/lib/eal/linux/eal_thread.c
index 83c2034b93..91c239a217 100644
--- a/lib/eal/linux/eal_thread.c
+++ b/lib/eal/linux/eal_thread.c
@@ -8,6 +8,7 @@ 
 #include <stdint.h>
 #include <unistd.h>
 #include <pthread.h>
+#include <rte_thread.h>
 #include <sched.h>
 #include <sys/queue.h>
 #include <sys/syscall.h>
@@ -73,15 +74,16 @@  eal_thread_loop(__rte_unused void *arg)
 	char c;
 	int n, ret;
 	unsigned lcore_id;
-	pthread_t thread_id;
+	rte_thread_t thread_id;
 	int m2w, w2m;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 
-	thread_id = pthread_self();
+	thread_id = rte_thread_self();
 
 	/* retrieve our lcore_id from the configuration structure */
 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
-		if (thread_id == lcore_config[lcore_id].thread_id)
+		if (rte_thread_equal(thread_id,
+				lcore_config[lcore_id].thread_id))
 			break;
 	}
 	if (lcore_id == RTE_MAX_LCORE)
@@ -94,7 +96,8 @@  eal_thread_loop(__rte_unused void *arg)
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
-		lcore_id, (uintptr_t)thread_id, cpuset, ret == 0 ? "" : "...");
+		lcore_id, (uintptr_t)thread_id.opaque_id, cpuset,
+		ret == 0 ? "" : "...");
 
 	rte_eal_trace_thread_lcore_ready(lcore_id, cpuset);
 
diff --git a/lib/eal/linux/eal_timer.c b/lib/eal/linux/eal_timer.c
index 7cf15cabac..dc0308c761 100644
--- a/lib/eal/linux/eal_timer.c
+++ b/lib/eal/linux/eal_timer.c
@@ -12,7 +12,7 @@ 
 #include <inttypes.h>
 #include <sys/mman.h>
 #include <sys/queue.h>
-#include <pthread.h>
+#include <rte_thread.h>
 #include <errno.h>
 
 #include <rte_common.h>
@@ -80,7 +80,7 @@  static uint64_t eal_hpet_resolution_hz = 0;
 /* Incremented 4 times during one 32bits hpet full count */
 static uint32_t eal_hpet_msb;
 
-static pthread_t msb_inc_thread_id;
+static rte_thread_t msb_inc_thread_id;
 
 /*
  * This function runs on a specific thread to update a global variable
@@ -185,7 +185,7 @@  rte_eal_hpet_init(int make_default)
 
 	/* create a thread that will increment a global variable for
 	 * msb (hpet is 32 bits by default under linux) */
-	ret = rte_ctrl_thread_create(&msb_inc_thread_id, "hpet-msb-inc", NULL,
+	ret = rte_thread_ctrl_thread_create(&msb_inc_thread_id, "hpet-msb-inc",
 				     hpet_msb_inc, NULL);
 	if (ret != 0) {
 		RTE_LOG(ERR, EAL, "ERROR: Cannot create HPET timer thread!\n");
diff --git a/lib/eal/version.map b/lib/eal/version.map
index 67569b1bf9..9a130120e7 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -21,7 +21,7 @@  DPDK_22 {
 	rte_cpu_get_flag_enabled;
 	rte_cpu_get_flag_name;
 	rte_cpu_is_supported; # WINDOWS_NO_EXPORT
-	rte_ctrl_thread_create;
+	rte_ctrl_thread_create; # WINDOWS_NO_EXPORT
 	rte_cycles_vmware_tsc_map; # WINDOWS_NO_EXPORT
 	rte_delay_us;
 	rte_delay_us_block;
@@ -193,7 +193,7 @@  DPDK_22 {
 	rte_sys_gettid;
 	rte_thread_get_affinity;
 	rte_thread_set_affinity;
-	rte_thread_setname;
+	rte_thread_setname; # WINDOWS_NO_EXPORT
 	rte_uuid_compare; # WINDOWS_NO_EXPORT
 	rte_uuid_is_null; # WINDOWS_NO_EXPORT
 	rte_uuid_parse; # WINDOWS_NO_EXPORT
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index 3d8c520412..d90c635ddc 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -395,7 +395,9 @@  rte_eal_init(int argc, char **argv)
 		lcore_config[i].state = WAIT;
 
 		/* create a thread for each lcore */
-		if (eal_thread_create(&lcore_config[i].thread_id) != 0)
+		ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
+				eal_thread_loop, NULL);
+		if (ret != 0)
 			rte_panic("Cannot create thread\n");
 	}
 
diff --git a/lib/eal/windows/eal_interrupts.c b/lib/eal/windows/eal_interrupts.c
index bb0585cb34..43b0071da0 100644
--- a/lib/eal/windows/eal_interrupts.c
+++ b/lib/eal/windows/eal_interrupts.c
@@ -9,7 +9,7 @@ 
 
 #define IOCP_KEY_SHUTDOWN UINT32_MAX
 
-static pthread_t intr_thread;
+static rte_thread_t intr_thread;
 
 static HANDLE intr_iocp;
 static HANDLE intr_thread_handle;
@@ -78,7 +78,7 @@  eal_intr_thread_main(LPVOID arg __rte_unused)
 	intr_thread_handle = NULL;
 
 cleanup:
-	intr_thread = 0;
+	intr_thread.opaque_id = 0;
 
 	CloseHandle(intr_iocp);
 	intr_iocp = NULL;
@@ -98,7 +98,7 @@  rte_eal_intr_init(void)
 		return -1;
 	}
 
-	ret = rte_ctrl_thread_create(&intr_thread, "eal-intr-thread", NULL,
+	ret = rte_thread_ctrl_thread_create(&intr_thread, "eal-intr-thread",
 			eal_intr_thread_main, NULL);
 	if (ret != 0) {
 		rte_errno = -ret;
@@ -111,7 +111,7 @@  rte_eal_intr_init(void)
 int
 rte_thread_is_intr(void)
 {
-	return pthread_equal(intr_thread, pthread_self());
+	return rte_thread_equal(intr_thread, rte_thread_self());
 }
 
 int
diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c
index 9c3f6d69fd..fbdb7dbc76 100644
--- a/lib/eal/windows/eal_thread.c
+++ b/lib/eal/windows/eal_thread.c
@@ -60,15 +60,16 @@  eal_thread_loop(void *arg __rte_unused)
 	char c;
 	int n, ret;
 	unsigned int lcore_id;
-	pthread_t thread_id;
+	rte_thread_t thread_id;
 	int m2w, w2m;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 
-	thread_id = pthread_self();
+	thread_id = rte_thread_self();
 
 	/* retrieve our lcore_id from the configuration structure */
 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
-		if (thread_id == lcore_config[lcore_id].thread_id)
+		if (rte_thread_equal(thread_id,
+				lcore_config[lcore_id].thread_id))
 			break;
 	}
 	if (lcore_id == RTE_MAX_LCORE)
@@ -80,7 +81,7 @@  eal_thread_loop(void *arg __rte_unused)
 	__rte_thread_init(lcore_id, &lcore_config[lcore_id].cpuset);
 
 	RTE_LOG(DEBUG, EAL, "lcore %u is ready (tid=%zx;cpuset=[%s])\n",
-		lcore_id, (uintptr_t)thread_id, cpuset);
+		lcore_id, (uintptr_t)thread_id.opaque_id, cpuset);
 
 	/* read on our pipe to get commands */
 	while (1) {
@@ -122,35 +123,9 @@  eal_thread_loop(void *arg __rte_unused)
 	}
 }
 
-/* function to create threads */
-int
-eal_thread_create(pthread_t *thread)
-{
-	HANDLE th;
-
-	th = CreateThread(NULL, 0,
-		(LPTHREAD_START_ROUTINE)(ULONG_PTR)eal_thread_loop,
-						NULL, 0, (LPDWORD)thread);
-	if (!th)
-		return -1;
-
-	SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
-	SetThreadPriority(th, THREAD_PRIORITY_NORMAL);
-
-	return 0;
-}
-
 /* get current thread ID */
 int
 rte_sys_gettid(void)
 {
 	return GetCurrentThreadId();
 }
-
-int
-rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name)
-{
-	/* TODO */
-	/* This is a stub, not the expected result */
-	return 0;
-}
diff --git a/lib/eal/windows/eal_windows.h b/lib/eal/windows/eal_windows.h
index 355ef181a5..4ace532aac 100644
--- a/lib/eal/windows/eal_windows.h
+++ b/lib/eal/windows/eal_windows.h
@@ -35,16 +35,6 @@ 
  */
 int eal_create_cpu_map(void);
 
-/**
- * Create a thread.
- *
- * @param thread
- *   The location to store the thread id if successful.
- * @return
- *   0 for success, -1 if the thread is not created.
- */
-int eal_thread_create(pthread_t *thread);
-
 /**
  * Get system NUMA node number for a socket ID.
  *
diff --git a/lib/eal/windows/include/rte_windows.h b/lib/eal/windows/include/rte_windows.h
index 0063b5d78c..d8c4ed10d7 100644
--- a/lib/eal/windows/include/rte_windows.h
+++ b/lib/eal/windows/include/rte_windows.h
@@ -28,6 +28,7 @@ 
 #include <windows.h>
 
 #include <basetsd.h>
+#include <processthreadsapi.h>
 #include <psapi.h>
 #include <setupapi.h>
 #include <winioctl.h>
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 9d95cd11e1..e44e5bb6af 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -526,7 +526,7 @@  rte_eth_dev_allocate(const char *name)
 	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);
+	rte_thread_mutex_init(&eth_dev->data->flow_ops_mutex);
 
 unlock:
 	rte_spinlock_unlock(&eth_dev_shared_data->ownership_lock);
@@ -600,7 +600,7 @@  rte_eth_dev_release_port(struct rte_eth_dev *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);
+		rte_thread_mutex_destroy(&eth_dev->data->flow_ops_mutex);
 		memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data));
 	}
 
diff --git a/lib/ethdev/rte_ethdev_core.h b/lib/ethdev/rte_ethdev_core.h
index edf96de2dc..8c8f83f9e3 100644
--- a/lib/ethdev/rte_ethdev_core.h
+++ b/lib/ethdev/rte_ethdev_core.h
@@ -5,7 +5,7 @@ 
 #ifndef _RTE_ETHDEV_CORE_H_
 #define _RTE_ETHDEV_CORE_H_
 
-#include <pthread.h>
+#include <rte_thread.h>
 
 /**
  * @file
@@ -186,7 +186,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. */
+	rte_thread_mutex 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;
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 8cb7a069c8..4f112d1af7 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -226,14 +226,14 @@  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->flow_ops_mutex);
+		rte_thread_mutex_lock(&dev->data->flow_ops_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->flow_ops_mutex);
+		rte_thread_mutex_unlock(&dev->data->flow_ops_mutex);
 }
 
 static int
diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c
index 13dfb28401..47f10cf5a9 100644
--- a/lib/eventdev/rte_event_eth_rx_adapter.c
+++ b/lib/eventdev/rte_event_eth_rx_adapter.c
@@ -7,6 +7,7 @@ 
 #endif
 #include <unistd.h>
 
+#include <pthread.h>
 #include <rte_cycles.h>
 #include <rte_common.h>
 #include <rte_dev.h>
diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index 355ff37651..a788fb0ed8 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -12,6 +12,7 @@ 
 #include <numaif.h>
 #endif
 
+#include <pthread.h>
 #include <rte_errno.h>
 #include <rte_ethdev.h>
 #include <rte_log.h>