From patchwork Thu Jan 9 03:13:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kadam, Pallavi" X-Patchwork-Id: 64307 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 53390A04F3; Thu, 9 Jan 2020 04:14:28 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8A4C71DAFD; Thu, 9 Jan 2020 04:13:39 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id E3F8A1C2AD for ; Thu, 9 Jan 2020 04:13:29 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2020 19:13:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,412,1571727600"; d="scan'208";a="216163133" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.58]) by orsmga008.jf.intel.com with ESMTP; 08 Jan 2020 19:13:26 -0800 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, keith.wiles@intel.com, bruce.richardson@intel.com, david.marchand@redhat.com, jerinjacobk@gmail.com, ranjit.menon@intel.com, antara.ganesh.kolar@intel.com, stephen@networkplumber.org, pallavi.kadam@intel.com Date: Wed, 8 Jan 2020 19:13:07 -0800 Message-Id: <20200109031312.6344-5-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20200109031312.6344-1-pallavi.kadam@intel.com> References: <20191022200227.1920-1-pallavi.kadam@intel.com> <20200109031312.6344-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH v4 4/9] eal: add additional function overrides in windows header files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Adding additional function definitions for pthread, cpuset implementation, asprintf implementation, in order to support common code. Signed-off-by: Bruce Richardson Signed-off-by: Pallavi Kadam Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- lib/librte_eal/windows/eal/include/pthread.h | 66 +++++++++++++++++++ lib/librte_eal/windows/eal/include/rte_os.h | 40 +++++++++++ lib/librte_eal/windows/eal/include/sched.h | 58 ++++++++++++++-- .../windows/eal/include/sys/queue.h | 8 +++ 4 files changed, 166 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/windows/eal/include/pthread.h b/lib/librte_eal/windows/eal/include/pthread.h index 503329266..91046db74 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 + +#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) \ + eal_set_thread_affinity_mask(thread, (unsigned long *) cpuset) +#define pthread_getaffinity_np(thread, size, cpuset) \ + eal_get_thread_affinity_mask(thread, (unsigned long *) cpuset) +#define pthread_create(threadID, threadattr, threadfunc, args) \ + eal_create_thread(threadID, threadfunc, args) + +static inline int +eal_set_thread_affinity_mask(pthread_t threadID, unsigned long *cpuset) +{ + SetThreadAffinityMask((HANDLE) threadID, *cpuset); + return 0; +} + +static inline int +eal_get_thread_affinity_mask(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 +eal_create_thread(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..93f25a3c1 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 #include #include +#include + +/* limits.h replacement */ +#include +#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,34 @@ int eal_thread_create(pthread_t *thread); */ void eal_create_cpu_map(void); +static inline int +asprintf(char **buffer, const char *format, ...) +{ + int size, ret; + va_list arg; + + va_start(arg, format); + size = vsnprintf(NULL, 0, format, arg) + 1; + va_end(arg); + + *buffer = malloc(size); + + va_start(arg, format); + ret = vsnprintf(*buffer, size, format, arg); + va_end(arg); + if (ret != size - 1) { + free(*buffer); + return -1; + } + return ret; +} + +/* cpu_set macros implementation */ +#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) + #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 6b9446a17..a65949a78 100644 --- a/lib/librte_eal/windows/eal/include/sys/queue.h +++ b/lib/librte_eal/windows/eal/include/sys/queue.h @@ -59,6 +59,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