]> git.droids-corp.org - dpdk.git/commitdiff
eal/windows: do not expose private facilities
authorDmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Tue, 14 Apr 2020 19:44:17 +0000 (22:44 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 21 Apr 2020 22:49:50 +0000 (00:49 +0200)
The goal of rte_os.h is to mitigate OS differences for EAL users.
In Windows EAL, rte_os.h did excessive things:

1. It included platform SDK headers (windows.h, etc). Those files are
   huge, require specific inclusion order, and are generally unused by
   the code including rte_os.h. Declarations from platform SDK may
   break otherwise platform-independent code, e.g. min, max, ERROR.

2. It included pthread.h, which is clearly not always required.

3. It defined functions private to Windows EAL.

Reorganize Windows EAL includes in the following way:

1. Create rte_windows.h to properly import Windows-specific facilities.
   Primary users are bus drivers, tests, and external applications.

2. Remove platform SDK includes from rte_os.h to prevent breaking
   otherwise portable code by including rte_os.h on Windows.
   Copy necessary definitions to avoid including those headers.

3. Remove pthread.h include from rte_os.h.

4. Move declarations private to Windows EAL into eal_windows.h.

Fixes: 428eb983f5f7 ("eal: add OS specific header file")
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
lib/librte_eal/windows/eal.c
lib/librte_eal/windows/eal_lcore.c
lib/librte_eal/windows/eal_thread.c
lib/librte_eal/windows/eal_windows.h [new file with mode: 0644]
lib/librte_eal/windows/include/meson.build
lib/librte_eal/windows/include/pthread.h
lib/librte_eal/windows/include/rte_os.h
lib/librte_eal/windows/include/rte_windows.h [new file with mode: 0644]

index e4b50df3b7ded1d52d4889fa214b6fcd59330074..2cf7a04eff2ea8427f3e37f03f69aaaccdc54a0a 100644 (file)
@@ -18,6 +18,8 @@
 #include <eal_options.h>
 #include <eal_private.h>
 
+#include "eal_windows.h"
+
  /* Allow the application to print its usage message too if set */
 static rte_usage_hook_t        rte_application_usage_hook;
 
index b3a6c63afad8995129eccbfe5c8db048ec70d360..82ee4541348430f9665662f57d879462e1fb75f8 100644 (file)
@@ -2,12 +2,14 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <pthread.h>
 #include <stdint.h>
 
 #include <rte_common.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
+#include "eal_windows.h"
 
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
index 9e4bbaa08283d2c7c401accf432a63397dbb06b1..e149199a6fa1f7ed2f657f267778a49c0e59efce 100644 (file)
@@ -14,6 +14,7 @@
 #include <eal_thread.h>
 
 #include "eal_private.h"
+#include "eal_windows.h"
 
 RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY;
 RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY;
diff --git a/lib/librte_eal/windows/eal_windows.h b/lib/librte_eal/windows/eal_windows.h
new file mode 100644 (file)
index 0000000..fadd676
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Dmitry Kozlyuk
+ */
+
+#ifndef _EAL_WINDOWS_H_
+#define _EAL_WINDOWS_H_
+
+/**
+ * @file Facilities private to Windows EAL
+ */
+
+#include <rte_windows.h>
+
+/**
+ * Create a map of processors and cores on the system.
+ */
+void 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);
+
+#endif /* _EAL_WINDOWS_H_ */
index 7d18dd52f1c59fc434568c50309d5ab2ff0a763b..5fb1962ac788f82f93281c6b43f98d50e793c344 100644 (file)
@@ -5,4 +5,5 @@ includes += include_directories('.')
 
 headers += files(
         'rte_os.h',
+        'rte_windows.h',
 )
index 7be4411239c872517217512d473447f473a6c75d..7c0caaf07eca635b521aff04b680bdda6ea2031b 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef _PTHREAD_H_
 #define _PTHREAD_H_
 
+#include <stdint.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
index e1e0378e6f11930281878b3d5da741485294eff0..510e39e03ba65fc2a6e018dfb692489fbaf7041d 100644 (file)
@@ -8,20 +8,18 @@
 /**
  * This is header should contain any function/macro definition
  * which are not supported natively or named differently in the
- * Windows OS. Functions will be added in future releases.
+ * Windows OS. It must not include Windows-specific headers.
  */
 
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <windows.h>
-#include <basetsd.h>
-#include <pthread.h>
-#include <stdio.h>
-
-/* limits.h replacement */
-#include <stdlib.h>
+/* limits.h replacement, value as in <windows.h> */
 #ifndef PATH_MAX
 #define PATH_MAX _MAX_PATH
 #endif
@@ -31,8 +29,6 @@ extern "C" {
 /* strdup is deprecated in Microsoft libc and _strdup is preferred */
 #define strdup(str) _strdup(str)
 
-typedef SSIZE_T ssize_t;
-
 #define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
 
 #define index(a, b)     strchr(a, b)
@@ -40,22 +36,14 @@ typedef SSIZE_T ssize_t;
 
 #define strncasecmp(s1, s2, count)        _strnicmp(s1, s2, count)
 
-/**
- * Create a thread.
- * This function is private to EAL.
- *
- * @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);
+/* 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)
 
-/**
- * Create a map of processors and cores on the system.
- * This function is private to EAL.
- */
-void eal_create_cpu_map(void);
+/* as in <windows.h> */
+typedef long long ssize_t;
 
 #ifndef RTE_TOOLCHAIN_GCC
 static inline int
@@ -86,12 +74,6 @@ asprintf(char **buffer, const char *format, ...)
 }
 #endif /* RTE_TOOLCHAIN_GCC */
 
-/* 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/include/rte_windows.h b/lib/librte_eal/windows/include/rte_windows.h
new file mode 100644 (file)
index 0000000..ed6e4c1
--- /dev/null
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2020 Dmitry Kozlyuk
+ */
+
+#ifndef _RTE_WINDOWS_H_
+#define _RTE_WINDOWS_H_
+
+/**
+ * @file Windows-specific facilities
+ *
+ * This file should be included by DPDK libraries and applications
+ * that need access to Windows API. It includes platform SDK headers
+ * in compatible order with proper options and defines error-handling macros.
+ */
+
+/* Disable excessive libraries. */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+/* Must come first. */
+#include <windows.h>
+
+#include <basetsd.h>
+#include <psapi.h>
+
+/* Have GUIDs defined. */
+#ifndef INITGUID
+#define INITGUID
+#endif
+#include <initguid.h>
+
+/**
+ * Log GetLastError() with context, usually a Win32 API function and arguments.
+ */
+#define RTE_LOG_WIN32_ERR(...) \
+       RTE_LOG(DEBUG, EAL, RTE_FMT("GetLastError()=%lu: " \
+               RTE_FMT_HEAD(__VA_ARGS__,) "\n", GetLastError(), \
+               RTE_FMT_TAIL(__VA_ARGS__,)))
+
+#endif /* _RTE_WINDOWS_H_ */