[5/9] eal: add additional function overrides in windows header files

Message ID 20190909195404.4760-6-pallavi.kadam@intel.com
State New
Delegated to: Thomas Monjalon
Headers show
Series
  • [1/9] eal: eal stub to support parsing feature on windows
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Pallavi Kadam Sept. 9, 2019, 7:54 p.m.
Adding additional function definitions for pthread, cpuset
implementation, asprintf implementation, in order to support
common code.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/common/include/rte_lcore.h     |  5 ++
 lib/librte_eal/windows/eal/include/pthread.h  | 66 +++++++++++++++++++
 lib/librte_eal/windows/eal/include/rte_os.h   | 28 ++++++++
 lib/librte_eal/windows/eal/include/sched.h    | 58 ++++++++++++++--
 .../windows/eal/include/sys/queue.h           |  8 +++
 5 files changed, 159 insertions(+), 6 deletions(-)

Patch

diff --git a/lib/librte_eal/common/include/rte_lcore.h b/lib/librte_eal/common/include/rte_lcore.h
index c86f72eb1..d5e7e3e33 100644
--- a/lib/librte_eal/common/include/rte_lcore.h
+++ b/lib/librte_eal/common/include/rte_lcore.h
@@ -64,6 +64,11 @@  typedef cpuset_t rte_cpuset_t;
 	CPU_NAND(&tmp, src); \
 	CPU_COPY(&tmp, dst); \
 } while (0)
+#elif defined(_WIN64)
+#define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2)
+#define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
+#define RTE_CPU_FILL(set) CPU_FILL(set)
+#define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
 #endif
 
 /**
diff --git a/lib/librte_eal/windows/eal/include/pthread.h b/lib/librte_eal/windows/eal/include/pthread.h
index 503329266..4a3533b96 100644
--- a/lib/librte_eal/windows/eal/include/pthread.h
+++ b/lib/librte_eal/windows/eal/include/pthread.h
@@ -14,12 +14,78 @@ 
 extern "C" {
 #endif
 
+#include <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 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())
+#define pthread_setaffinity_np(thread, size, cpuset) \
+	WinSetThreadAffinityMask(thread, (unsigned long *) cpuset)
+#define pthread_getaffinity_np(thread, size, cpuset) \
+	WinGetThreadAffinityMask(thread, (unsigned long *) cpuset)
+#define pthread_create(threadID, threadattr, threadfunc, args) \
+	WinCreateThreadOverride(threadID, threadfunc, args)
+
+static inline int
+WinSetThreadAffinityMask(pthread_t threadID, unsigned long *cpuset)
+{
+	SetThreadAffinityMask((HANDLE) threadID, *cpuset);
+	return 0;
+}
+
+static inline int
+WinGetThreadAffinityMask(pthread_t threadID, unsigned long *cpuset)
+{
+	/* Workaround for the lack of a GetThreadAffinityMask()
+	 *API in Windows
+	 */
+		/* obtain previous mask by setting dummy mask */
+	DWORD dwPrevAffinityMask =
+		SetThreadAffinityMask((HANDLE) threadID, 0x1);
+	/* set it back! */
+	SetThreadAffinityMask((HANDLE) threadID, dwPrevAffinityMask);
+	*cpuset = dwPrevAffinityMask;
+	return 0;
+}
+
+static inline int
+WinCreateThreadOverride(void *threadID, void *threadfunc, void *args)
+{
+	HANDLE hThread;
+	hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)threadfunc,
+		args, 0, (LPDWORD)threadID);
+	if (hThread) {
+		SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
+		SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL);
+	}
+	return ((hThread != NULL) ? 0 : E_FAIL);
+}
+
+static inline int
+pthread_join(pthread_t thread __attribute__((__unused__)),
+	void **value_ptr __attribute__((__unused__)))
+{
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/windows/eal/include/rte_os.h b/lib/librte_eal/windows/eal/include/rte_os.h
index fdeae0c8f..32c5efd2d 100644
--- a/lib/librte_eal/windows/eal/include/rte_os.h
+++ b/lib/librte_eal/windows/eal/include/rte_os.h
@@ -18,6 +18,13 @@  extern "C" {
 #include <Windows.h>
 #include <BaseTsd.h>
 #include <pthread.h>
+#include <stdio.h>
+
+/* limits.h replacement */
+#include <stdlib.h>
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
 
 #define strerror_r(a, b, c) strerror_s(b, c, a)
 
@@ -28,6 +35,11 @@  typedef SSIZE_T ssize_t;
 
 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
 
+#define index(a, b)     strchr(a, b)
+#define rindex(a, b)    strrchr(a, b)
+
+#define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
+
 /**
  * Create a thread.
  * This function is private to EAL.
@@ -45,6 +57,22 @@  int eal_thread_create(pthread_t *thread);
  */
 void eal_create_cpu_map(void);
 
+static inline int
+asprintf(char **buffer, const char *format, ...)
+{
+	va_list arg;
+
+	va_start(arg, format);
+
+	*buffer = (char *)malloc(255);
+	if (!*buffer)
+		return -ENOMEM;
+	sprintf(*buffer, format, arg);
+
+	va_end(arg);
+	return 0;
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/windows/eal/include/sched.h b/lib/librte_eal/windows/eal/include/sched.h
index 257060594..cab166111 100644
--- a/lib/librte_eal/windows/eal/include/sched.h
+++ b/lib/librte_eal/windows/eal/include/sched.h
@@ -31,14 +31,60 @@  typedef struct _rte_cpuset_s {
 
 #define CPU_SET(b, s) ((s)->_bits[_WHICH_SET(b)] |= (1LL << _WHICH_BIT(b)))
 
-#define CPU_ZERO(s)							\
-	do {								\
-		unsigned int _i;					\
-									\
-		for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++)	\
-			(s)->_bits[_i] = 0LL;				\
+#define CPU_ZERO(s) \
+	do { \
+		unsigned int _i; \
+	\
+		for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++) \
+			(s)->_bits[_i] = 0LL; \
 	} while (0)
 
+#define CPU_ISSET(b, s) (((s)->_bits[_WHICH_SET(b)] & \
+	(1LL << _WHICH_BIT(b))) != 0LL)
+
+static inline int
+count_cpu(rte_cpuset_t *s)
+{
+	unsigned int _i;
+	int count = 0;
+
+	for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++)
+		if (CPU_ISSET(_i, s) != 0LL)
+			count++;
+	return count;
+}
+#define CPU_COUNT(s) count_cpu(s)
+
+#define CPU_AND(dst, src1, src2) \
+do { \
+	unsigned int _i; \
+	\
+	for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++) \
+		(dst)->_bits[_i] = (src1)->_bits[_i] & (src2)->_bits[_i]; \
+} while (0)
+
+#define CPU_OR(dst, src1, src2) \
+do { \
+	unsigned int _i; \
+	\
+	for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++) \
+		(dst)->_bits[_i] = (src1)->_bits[_i] | (src2)->_bits[_i]; \
+} while (0)
+
+#define CPU_FILL(s) \
+do { \
+	unsigned int _i; \
+	for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++) \
+		(s)->_bits[_i] = -1LL; \
+} while (0)
+
+#define CPU_NOT(dst, src) \
+do { \
+	unsigned int _i; \
+	for (_i = 0; _i < _NUM_SETS(CPU_SET_SIZE); _i++) \
+		(dst)->_bits[_i] = (src)->_bits[_i] ^ -1LL; \
+} while (0)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/windows/eal/include/sys/queue.h b/lib/librte_eal/windows/eal/include/sys/queue.h
index 5ee4916ad..af30c8a62 100644
--- a/lib/librte_eal/windows/eal/include/sys/queue.h
+++ b/lib/librte_eal/windows/eal/include/sys/queue.h
@@ -85,6 +85,14 @@ 
 extern "C" {
 #endif
 
+/*
+ * List definitions.
+ */
+#define	LIST_HEAD(name, type)						\
+struct name {								\
+	struct type *lh_first;	/* first element */			\
+}
+
 #define	QMD_TRACE_ELEM(elem)
 #define	QMD_TRACE_HEAD(head)
 #define	TRACEBUF